diff --git a/src/common/scripting/backend/codegen.cpp b/src/common/scripting/backend/codegen.cpp index bfcf83e53bb..ac49b3a1540 100644 --- a/src/common/scripting/backend/codegen.cpp +++ b/src/common/scripting/backend/codegen.cpp @@ -177,9 +177,9 @@ void FCompileContext::CheckReturn(PPrototype *proto, FScriptPosition &pos) } } -bool FCompileContext::IsWritable(int flags) +bool FCompileContext::IsWritable(int flags, int checkFileNo) { - return !(flags & VARF_ReadOnly) || ((flags & VARF_InternalAccess) && fileSystem.GetFileContainer(Lump) == 0); + return !(flags & VARF_ReadOnly) || ((flags & VARF_InternalAccess) && fileSystem.GetFileContainer(Lump) == checkFileNo); } FxLocalVariableDeclaration *FCompileContext::FindLocalVariable(FName name) @@ -6882,7 +6882,7 @@ FxGlobalVariable::FxGlobalVariable(PField* mem, const FScriptPosition &pos) bool FxGlobalVariable::RequestAddress(FCompileContext &ctx, bool *writable) { AddressRequested = true; - if (writable != nullptr) *writable = AddressWritable && ctx.IsWritable(membervar->Flags); + if (writable != nullptr) *writable = AddressWritable && ctx.IsWritable(membervar->Flags, membervar->mDefFileNo); return true; } @@ -7075,7 +7075,7 @@ FxStackVariable::~FxStackVariable() bool FxStackVariable::RequestAddress(FCompileContext &ctx, bool *writable) { AddressRequested = true; - if (writable != nullptr) *writable = AddressWritable && ctx.IsWritable(membervar->Flags); + if (writable != nullptr) *writable = AddressWritable && ctx.IsWritable(membervar->Flags, membervar->mDefFileNo); return true; } @@ -7177,7 +7177,7 @@ bool FxStructMember::RequestAddress(FCompileContext &ctx, bool *writable) else if (writable != nullptr) { // [ZZ] original check. - bool bWritable = (AddressWritable && ctx.IsWritable(membervar->Flags) && + bool bWritable = (AddressWritable && ctx.IsWritable(membervar->Flags, membervar->mDefFileNo) && (!classx->ValueType->isPointer() || !classx->ValueType->toPointer()->IsConst)); // [ZZ] implement write barrier between different scopes if (bWritable) diff --git a/src/common/scripting/backend/codegen.h b/src/common/scripting/backend/codegen.h index a52b546aebd..c12e33d3f3c 100644 --- a/src/common/scripting/backend/codegen.h +++ b/src/common/scripting/backend/codegen.h @@ -101,7 +101,7 @@ struct FCompileContext void HandleJumps(int token, FxExpression *handler); void CheckReturn(PPrototype *proto, FScriptPosition &pos); - bool IsWritable(int flags); + bool IsWritable(int flags, int checkFileNo = 0); FxLocalVariableDeclaration *FindLocalVariable(FName name); };