From b37ef48e99a5729a21356e30ab36f1f671eebd5a Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Tue, 29 Mar 2016 22:36:26 -0500 Subject: [PATCH] Allow ACS's GetUserVariable to access non-user variables - Since DECORATE already allows reading all declared variables in a class, where's the utility in keeping this restriction in ACS? - Variables must still be numeric types. - SetUserVariable is still restricted to user variables only. --- src/p_acs.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/p_acs.cpp b/src/p_acs.cpp index 42048c159e..9dbbd5eea4 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -4529,12 +4529,12 @@ int DLevelScript::LineFromID(int id) } } -bool GetVarAddrType(AActor *self, FName varname, int index, void *&addr, PType *&type) +bool GetVarAddrType(AActor *self, FName varname, int index, void *&addr, PType *&type, bool allownative) { PField *var = dyn_cast(self->GetClass()->Symbols.FindSymbol(varname, true)); PArray *arraytype; - if (var == NULL || (var->Flags & VARF_Native)) + if (var == NULL || (!allownative && (var->Flags & VARF_Native))) { return false; } @@ -4557,6 +4557,12 @@ bool GetVarAddrType(AActor *self, FName varname, int index, void *&addr, PType * return false; } addr = baddr; + // We don't want Int subclasses like Name or Color to be accessible, + // but we do want to support Float subclasses like Fixed. + if (!type->IsA(RUNTIME_CLASS(PInt)) || !type->IsKindOf(RUNTIME_CLASS(PFloat))) + { + return false; + } return true; } @@ -4565,7 +4571,7 @@ static void SetUserVariable(AActor *self, FName varname, int index, int value) void *addr; PType *type; - if (GetVarAddrType(self, varname, index, addr, type)) + if (GetVarAddrType(self, varname, index, addr, type, false)) { if (!type->IsKindOf(RUNTIME_CLASS(PFloat))) { @@ -4583,7 +4589,7 @@ static int GetUserVariable(AActor *self, FName varname, int index) void *addr; PType *type; - if (GetVarAddrType(self, varname, index, addr, type)) + if (GetVarAddrType(self, varname, index, addr, type, true)) { if (!type->IsKindOf(RUNTIME_CLASS(PFloat))) {