diff --git a/src/d_dehacked.cpp b/src/d_dehacked.cpp index 71deb01691..97d15e4d0d 100644 --- a/src/d_dehacked.cpp +++ b/src/d_dehacked.cpp @@ -808,22 +808,23 @@ void SetDehParams(FState *state, int codepointer) else { VMFunctionBuilder buildit(true); + int numargs = sym->GetImplicitArgs(); // Allocate registers used to pass parameters in. // self, stateowner, state (all are pointers) - buildit.Registers[REGT_POINTER].Get(NAP); + buildit.Registers[REGT_POINTER].Get(numargs); // Emit code to pass the standard action function parameters. - for (int i = 0; i < NAP; i++) + for (int i = 0; i < numargs; i++) { buildit.Emit(OP_PARAM, 0, REGT_POINTER, i); } // Emit code for action parameters. int argcount = MBFCodePointerFactories[codepointer](buildit, value1, value2); - buildit.Emit(OP_TAIL_K, buildit.GetConstantAddress(sym->Variants[0].Implementation, ATAG_OBJECT), NAP + argcount, 0); + buildit.Emit(OP_TAIL_K, buildit.GetConstantAddress(sym->Variants[0].Implementation, ATAG_OBJECT), numargs + argcount, 0); // Attach it to the state. VMScriptFunction *sfunc = new VMScriptFunction; buildit.MakeFunction(sfunc); - sfunc->NumArgs = NAP; - sfunc->ImplicitArgs = NAP; + sfunc->NumArgs = numargs; + sfunc->ImplicitArgs = numargs; state->SetAction(sfunc); sfunc->PrintableName.Format("Dehacked.%s.%d.%d", MBFCodePointers[codepointer].name.GetChars(), value1, value2); } @@ -2121,7 +2122,8 @@ static int PatchCodePtrs (int dummy) else { TArray &args = sym->Variants[0].ArgFlags; - if ((sym->Variants[0].Flags & (VARF_Method | VARF_Action)) != (VARF_Method | VARF_Action) || (args.Size() > NAP && !(args[NAP] & VARF_Optional))) + unsigned numargs = sym->GetImplicitArgs(); + if ((sym->Variants[0].Flags & VARF_Virtual || (args.Size() > numargs && !(args[numargs] & VARF_Optional)))) { Printf("Frame %d: Incompatible code pointer '%s'\n", frame, Line2); sym = NULL; @@ -2733,7 +2735,8 @@ static bool LoadDehSupp () else { TArray &args = sym->Variants[0].ArgFlags; - if ((sym->Variants[0].Flags & (VARF_Method|VARF_Action)) != (VARF_Method | VARF_Action) || (args.Size() > NAP && !(args[NAP] & VARF_Optional))) + unsigned numargs = sym->GetImplicitArgs(); + if ((sym->Variants[0].Flags & VARF_Virtual || (args.Size() > numargs && !(args[numargs] & VARF_Optional)))) { sc.ScriptMessage("Incompatible code pointer '%s'", sc.String); } diff --git a/src/p_enemy.cpp b/src/p_enemy.cpp index 1a2bddda49..14ea2b7c1e 100644 --- a/src/p_enemy.cpp +++ b/src/p_enemy.cpp @@ -2773,7 +2773,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_Chase) PARAM_STATE_OPT (missile) { missile = NULL; } PARAM_INT_OPT (flags) { flags = 0; } - if (numparam >= NAP + 1) + if (numparam > 1) { if ((flags & CHF_RESURRECT) && P_CheckForResurrection(self, false)) return 0; diff --git a/src/scripting/decorate/thingdef_states.cpp b/src/scripting/decorate/thingdef_states.cpp index 8b75b935f4..dda25f9265 100644 --- a/src/scripting/decorate/thingdef_states.cpp +++ b/src/scripting/decorate/thingdef_states.cpp @@ -38,7 +38,7 @@ ** */ -#include "actor.h" +#include "a_pickups.h" #include "info.h" #include "sc_man.h" #include "tarray.h" @@ -602,16 +602,16 @@ void ParseFunctionParameters(FScanner &sc, PClassActor *cls, TArrayVariants[0].Flags & VARF_Method) + if (afd->Variants[0].Flags & VARF_Action) + { + numparams -= NAP; + pnum += NAP; + } + else if (afd->Variants[0].Flags & VARF_Method) { numparams--; pnum++; } - if (afd->Variants[0].Flags & VARF_Action) - { - numparams -= 2; - pnum += 2; - } assert(numparams >= 0); zeroparm = numparams == 0; if (numparams > 0 && !(paramflags[pnum] & VARF_Optional)) diff --git a/src/scripting/thingdef.cpp b/src/scripting/thingdef.cpp index 45e77b3ad9..2798ab633a 100644 --- a/src/scripting/thingdef.cpp +++ b/src/scripting/thingdef.cpp @@ -143,7 +143,7 @@ PFunction *CreateAnonymousFunction(PClass *containingclass, PType *returntype, i SetImplicitArgs(&args, &argflags, &argnames, containingclass, flags); PFunction *sym = new PFunction(containingclass, NAME_None); // anonymous functions do not have names. - sym->AddVariant(NewPrototype(rets, args), argflags, argnames, nullptr, VARF_Action|VARF_Method); + sym->AddVariant(NewPrototype(rets, args), argflags, argnames, nullptr, flags); return sym; } diff --git a/src/scripting/zscript/zcc_compile.cpp b/src/scripting/zscript/zcc_compile.cpp index 9b4212820e..e702f7d2a4 100644 --- a/src/scripting/zscript/zcc_compile.cpp +++ b/src/scripting/zscript/zcc_compile.cpp @@ -32,7 +32,7 @@ ** */ -#include "actor.h" +#include "a_pickups.h" #include "thingdef.h" #include "sc_man.h" #include "c_console.h"