From 01822c002fd01dc77d9aca9f679e8a6e6b2ad71e Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Wed, 21 Aug 2013 22:58:12 -0500 Subject: [PATCH] Use PField instead of PSymbolVariable for A_SetUserVar/Array --- src/thingdef/thingdef_codeptr.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/thingdef/thingdef_codeptr.cpp b/src/thingdef/thingdef_codeptr.cpp index 4cd725805..0b1884405 100644 --- a/src/thingdef/thingdef_codeptr.cpp +++ b/src/thingdef/thingdef_codeptr.cpp @@ -4365,16 +4365,16 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_SetUserVar) PARAM_NAME (varname); PARAM_INT (value); - PSymbolVariable *var = dyn_cast(self->GetClass()->Symbols.FindSymbol(varname, true)); + PField *var = dyn_cast(self->GetClass()->Symbols.FindSymbol(varname, true)); - if (var == NULL || !var->bUserVar || var->ValueType.Type != VAL_Int) + if (var == NULL || (var->Flags & VARF_Native) || !var->Type->IsKindOf(RUNTIME_CLASS(PBasicType))) { Printf("%s is not a user variable in class %s\n", varname.GetChars(), self->GetClass()->TypeName.GetChars()); return 0; } // Set the value of the specified user variable. - *(int *)(reinterpret_cast(self) + var->offset) = value; + var->Type->SetValue(reinterpret_cast(self) + var->Offset, value); return 0; } @@ -4391,22 +4391,25 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_SetUserArray) PARAM_INT (pos); PARAM_INT (value); - PSymbolVariable *var = dyn_cast(self->GetClass()->Symbols.FindSymbol(varname, true)); + PField *var = dyn_cast(self->GetClass()->Symbols.FindSymbol(varname, true)); - if (var == NULL || !var->bUserVar || var->ValueType.Type != VAL_Array || var->ValueType.BaseType != VAL_Int) + if (var == NULL || (var->Flags & VARF_Native) || + !var->Type->IsKindOf(RUNTIME_CLASS(PArray)) || + !static_cast(var->Type)->ElementType->IsKindOf(RUNTIME_CLASS(PBasicType))) { Printf("%s is not a user array in class %s\n", varname.GetChars(), self->GetClass()->TypeName.GetChars()); return 0; } - if (pos < 0 || pos >= var->ValueType.size) + PArray *arraytype = static_cast(var->Type); + if ((unsigned)pos >= arraytype->ElementCount) { Printf("%d is out of bounds in array %s in class %s\n", pos, varname.GetChars(), self->GetClass()->TypeName.GetChars()); return 0; } // Set the value of the specified user array at index pos. - ((int *)(reinterpret_cast(self) + var->offset))[pos] = value; + arraytype->ElementType->SetValue(reinterpret_cast(self) + var->Offset + arraytype->ElementSize * pos, value); return 0; }