From cda4fece1b41b0675feed62cb270640aa3933873 Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Thu, 30 Apr 2015 12:35:29 +0200 Subject: [PATCH 1/6] - Fixed compiler errors and warnings from TFlags. --- src/d_dehacked.cpp | 4 ++-- src/p_interaction.cpp | 2 +- src/p_mobj.cpp | 18 +++++++++--------- src/tflags.h | 3 ++- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/d_dehacked.cpp b/src/d_dehacked.cpp index 7d3a5f0ee..a994f7603 100644 --- a/src/d_dehacked.cpp +++ b/src/d_dehacked.cpp @@ -1180,8 +1180,8 @@ static int PatchThing (int thingy) else info->renderflags &= ~RF_INVISIBLE; } - DPrintf ("Bits: %d,%d (0x%08x,0x%08x)\n", info->flags, info->flags2, - info->flags, info->flags2); + DPrintf ("Bits: %d,%d (0x%08x,0x%08x)\n", info->flags.GetValue(), info->flags2.GetValue(), + info->flags.GetValue(), info->flags2.GetValue()); } else if (stricmp (Line1, "ID #") == 0) { diff --git a/src/p_interaction.cpp b/src/p_interaction.cpp index 36f50a897..e25dcf7ac 100644 --- a/src/p_interaction.cpp +++ b/src/p_interaction.cpp @@ -660,7 +660,7 @@ void AActor::Die (AActor *source, AActor *inflictor, int dmgflags) FState *diestate = NULL; int gibhealth = GibHealth(); - int iflags4 = inflictor == NULL ? 0 : inflictor->flags4; + ActorFlags4 iflags4 = inflictor == NULL ? ActorFlags4::FromInt(0) : inflictor->flags4; bool extremelydead = ((health < gibhealth || iflags4 & MF4_EXTREMEDEATH) && !(iflags4 & MF4_NOEXTREMEDEATH)); // Special check for 'extreme' damage type to ensure that it gets recorded properly as an extreme death for subsequent checks. diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index abfe888ec..588bc2dcc 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -6465,35 +6465,35 @@ void PrintMiscActorInfo(AActor *query) "OptFuzzy", "Stencil", "Translucent", "Add", "Shaded", "TranslucentStencil", "Shadow", "Subtract", "AddStencil", "AddShaded"}; - Printf("%s @ %p has the following flags:\n flags: %x", query->GetTag(), query, query->flags); + Printf("%s @ %p has the following flags:\n flags: %x", query->GetTag(), query, query->flags.GetValue()); for (flagi = 0; flagi <= 31; flagi++) if (query->flags & 1<flags2); + Printf("\n flags2: %x", query->flags2.GetValue()); for (flagi = 0; flagi <= 31; flagi++) if (query->flags2 & 1<flags3); + Printf("\n flags3: %x", query->flags3.GetValue()); for (flagi = 0; flagi <= 31; flagi++) if (query->flags3 & 1<flags4); + Printf("\n flags4: %x", query->flags4.GetValue()); for (flagi = 0; flagi <= 31; flagi++) if (query->flags4 & 1<flags5); + Printf("\n flags5: %x", query->flags5.GetValue()); for (flagi = 0; flagi <= 31; flagi++) if (query->flags5 & 1<flags6); + Printf("\n flags6: %x", query->flags6.GetValue()); for (flagi = 0; flagi <= 31; flagi++) if (query->flags6 & 1<flags7); + Printf("\n flags7: %x", query->flags7.GetValue()); for (flagi = 0; flagi <= 31; flagi++) if (query->flags7 & 1<BounceFlags, FIXED2FLOAT(query->bouncefactor), + query->BounceFlags.GetValue(), FIXED2FLOAT(query->bouncefactor), FIXED2FLOAT(query->wallbouncefactor)); /*for (flagi = 0; flagi < 31; flagi++) if (query->BounceFlags & 1<alpha), query->renderflags); + FIXED2FLOAT(query->alpha), query->renderflags.GetValue()); /*for (flagi = 0; flagi < 31; flagi++) if (query->renderflags & 1< Date: Thu, 30 Apr 2015 12:44:19 +0200 Subject: [PATCH 2/6] - Plug some lemon leaks during xlat generation. Found with Address Sanitizer. --- tools/lemon/lemon.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/lemon/lemon.c b/tools/lemon/lemon.c index f4a08f789..5e8f03a8b 100644 --- a/tools/lemon/lemon.c +++ b/tools/lemon/lemon.c @@ -437,7 +437,8 @@ struct acttab { #define acttab_yylookahead(X,N) ((X)->aAction[N].lookahead) /* Free all memory associated with the given acttab */ -void acttab_free(acttab *p){ +void acttab_free(acttab **pp){ + acttab *p = *pp; free( p->aAction ); free( p->aLookahead ); free( p ); @@ -2506,12 +2507,14 @@ struct lemon *gp; ErrorMsg(ps.filename,0,"Can't allocate %d of memory to hold this file.", filesize+1); gp->errorcnt++; + fclose(fp); return; } if( fread(filebuf,1,filesize,fp)!=filesize ){ ErrorMsg(ps.filename,0,"Can't read in all %d bytes of this file.", filesize); free(filebuf); + fclose(fp); gp->errorcnt++; return; } @@ -3081,9 +3084,11 @@ struct lemon *lemp; in = fopen(tpltname,"rb"); if( in==0 ){ fprintf(stderr,"Can't open the template file \"%s\".\n",templatename); + free(tpltname); lemp->errorcnt++; return 0; } + free(tpltname); return in; } @@ -3942,6 +3947,7 @@ int mhflag; /* Output in makeheaders format if true */ /* Append any addition code the user desires */ tplt_print(out,lemp,lemp->extracode,lemp->extracodeln,&lineno); + acttab_free(&pActtab); fclose(in); fclose(out); return; From 97e63b13199cedd82ee8c1afb9755b744c5432b3 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 30 Apr 2015 12:53:44 +0200 Subject: [PATCH 3/6] - split up FBehavior constructor to better be able to weed out broken ACS modules. Please note that this WILL break old savegames from mods which put ACS sources or unrelated data in the ACS namespace! --- src/p_acs.cpp | 38 ++++++++++++++++++++++++++++---------- src/p_acs.h | 3 ++- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/p_acs.cpp b/src/p_acs.cpp index 86674c149..f53eddaf0 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -1409,7 +1409,17 @@ FBehavior *FBehavior::StaticLoadModule (int lumpnum, FileReader *fr, int len) } } - return new FBehavior (lumpnum, fr, len); + FBehavior * behavior = new FBehavior (); + if (behavior->Init(lumpnum, fr, len)) + { + return behavior; + } + else + { + delete behavior; + Printf("%s: invalid ACS module", Wads.GetLumpFullName(lumpnum)); + return NULL; + } } bool FBehavior::StaticCheckAllGood () @@ -1668,11 +1678,8 @@ static int ParseLocalArrayChunk(void *chunk, ACSLocalArrays *arrays, int offset) return offset; } -FBehavior::FBehavior (int lumpnum, FileReader * fr, int len) +FBehavior::FBehavior() { - BYTE *object; - int i; - NumScripts = 0; NumFunctions = 0; NumArrays = 0; @@ -1684,11 +1691,21 @@ FBehavior::FBehavior (int lumpnum, FileReader * fr, int len) Chunks = NULL; Data = NULL; Format = ACS_Unknown; - LumpNum = lumpnum; + LumpNum = -1; memset (MapVarStore, 0, sizeof(MapVarStore)); ModuleName[0] = 0; FunctionProfileData = NULL; +} + + +bool FBehavior::Init(int lumpnum, FileReader * fr, int len) +{ + BYTE *object; + int i; + + LumpNum = lumpnum; + // Now that everything is set up, record this module as being among the loaded modules. // We need to do this before resolving any imports, because an import might (indirectly) // need to resolve exports in this module. The only things that can be exported are @@ -1699,7 +1716,6 @@ FBehavior::FBehavior (int lumpnum, FileReader * fr, int len) // 1. If not, corrupt modules cause memory leaks // 2. Corrupt modules won't be reported when a level is being loaded if this function quits before // adding it to the list. - LibraryID = StaticModules.Push (this) << LIBRARYID_SHIFT; if (fr == NULL) len = Wads.LumpLength (lumpnum); @@ -1711,7 +1727,7 @@ FBehavior::FBehavior (int lumpnum, FileReader * fr, int len) // has 24 bytes if it is completely empty. An empty SPTR chunk adds 8 bytes.) if (len < 32) { - return; + return false; } object = new BYTE[len]; @@ -1727,7 +1743,7 @@ FBehavior::FBehavior (int lumpnum, FileReader * fr, int len) if (object[0] != 'A' || object[1] != 'C' || object[2] != 'S') { delete[] object; - return; + return false; } switch (object[3]) @@ -1743,8 +1759,9 @@ FBehavior::FBehavior (int lumpnum, FileReader * fr, int len) break; default: delete[] object; - return; + return false; } + LibraryID = StaticModules.Push (this) << LIBRARYID_SHIFT; if (fr == NULL) { @@ -2135,6 +2152,7 @@ FBehavior::FBehavior (int lumpnum, FileReader * fr, int len) } DPrintf ("Loaded %d scripts, %d functions\n", NumScripts, NumFunctions); + return true; } FBehavior::~FBehavior () diff --git a/src/p_acs.h b/src/p_acs.h index 88016f0db..d5971e349 100644 --- a/src/p_acs.h +++ b/src/p_acs.h @@ -283,8 +283,9 @@ enum ACSFormat { ACS_Old, ACS_Enhanced, ACS_LittleEnhanced, ACS_Unknown }; class FBehavior { public: - FBehavior (int lumpnum, FileReader * fr=NULL, int len=0); + FBehavior (); ~FBehavior (); + bool Init(int lumpnum, FileReader * fr = NULL, int len = 0); bool IsGood (); BYTE *FindChunk (DWORD id) const; From 4316740ee917c930bff6a2364936c7ed272259a2 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 30 Apr 2015 12:59:26 +0200 Subject: [PATCH 4/6] - some color coding of error messages during ACS loading. (not that I expect that the people these are meant for will read them anyway...) --- src/p_acs.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/p_acs.cpp b/src/p_acs.cpp index f53eddaf0..5cd5774f4 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -1391,7 +1391,7 @@ void FBehavior::StaticLoadDefaultModules () } else { - Printf ("Could not find autoloaded ACS library %s\n", sc.String); + Printf (TEXTCOLOR_RED "Could not find autoloaded ACS library %s\n", sc.String); } } } @@ -1417,7 +1417,7 @@ FBehavior *FBehavior::StaticLoadModule (int lumpnum, FileReader *fr, int len) else { delete behavior; - Printf("%s: invalid ACS module", Wads.GetLumpFullName(lumpnum)); + Printf(TEXTCOLOR_RED "%s: invalid ACS module", Wads.GetLumpFullName(lumpnum)); return NULL; } } @@ -2044,7 +2044,7 @@ bool FBehavior::Init(int lumpnum, FileReader * fr, int len) int lump = Wads.CheckNumForName (&parse[i], ns_acslibrary); if (lump < 0) { - Printf ("Could not find ACS library %s.\n", &parse[i]); + Printf (TEXTCOLOR_RED "Could not find ACS library %s.\n", &parse[i]); } else { @@ -2085,7 +2085,7 @@ bool FBehavior::Init(int lumpnum, FileReader * fr, int len) func->ImportNum = i+1; if (realfunc->ArgCount != func->ArgCount) { - Printf ("Function %s in %s has %d arguments. %s expects it to have %d.\n", + Printf (TEXTCOLOR_ORANGE "Function %s in %s has %d arguments. %s expects it to have %d.\n", (char *)(chunk + 2) + chunk[3+j], lib->ModuleName, realfunc->ArgCount, ModuleName, func->ArgCount); Format = ACS_Unknown; @@ -2138,7 +2138,7 @@ bool FBehavior::Init(int lumpnum, FileReader * fr, int len) if (lib->ArrayStore[impNum].ArraySize != expectedSize) { Format = ACS_Unknown; - Printf ("The array %s in %s has %u elements, but %s expects it to only have %u.\n", + Printf (TEXTCOLOR_ORANGE "The array %s in %s has %u elements, but %s expects it to only have %u.\n", parse, lib->ModuleName, lib->ArrayStore[impNum].ArraySize, ModuleName, expectedSize); } @@ -2311,7 +2311,7 @@ void FBehavior::LoadScriptsDirectory () { if (Scripts[i].Number == Scripts[i+1].Number) { - Printf("%s appears more than once.\n", + Printf(TEXTCOLOR_ORANGE "%s appears more than once.\n", ScriptPresentation(Scripts[i].Number).GetChars()); // Make the closed version the first one. if (Scripts[i+1].Type == SCRIPT_Closed) @@ -2508,7 +2508,7 @@ bool FBehavior::IsGood () if (funcdef->Address == 0 && funcdef->ImportNum == 0) { DWORD *chunk = (DWORD *)FindChunk (MAKE_ID('F','N','A','M')); - Printf ("Could not find ACS function %s for use in %s.\n", + Printf (TEXTCOLOR_RED "Could not find ACS function %s for use in %s.\n", (char *)(chunk + 2) + chunk[3+i], ModuleName); bad = true; } @@ -2519,7 +2519,7 @@ bool FBehavior::IsGood () { if (Imports[i] == NULL) { - Printf ("Not all the libraries used by %s could be found.\n", ModuleName); + Printf (TEXTCOLOR_RED "Not all the libraries used by %s could be found.\n", ModuleName); return false; } } From 492ef1b7168d2f6055dd29d7cf5f1f510ea44e1e Mon Sep 17 00:00:00 2001 From: MajorCooke Date: Thu, 30 Apr 2015 08:15:48 -0500 Subject: [PATCH 5/6] - Added A_JumpIfHigherOrLower. - (int ptr = AAPTR_TARGET, state high, state low, float offsethigh = 0, float offsetlow = 0, bool includeHeight = true) - Jumps if the pointer of the calling actor is higher or lower than itself, adding offsethigh or offsetlow depending on the circumstance. - includeHeight works twofold. - Includes the height of the calling actor if the pointer is higher to truly determine if they are completely above them or not. - Includes the height of the pointer if the pointer is lower. - Disable it to only check z differences without adding height. --- src/thingdef/thingdef_codeptr.cpp | 37 +++++++++++++++++++++++++++++++ wadsrc/static/actors/actor.txt | 1 + 2 files changed, 38 insertions(+) diff --git a/src/thingdef/thingdef_codeptr.cpp b/src/thingdef/thingdef_codeptr.cpp index b0147113e..722cae8ce 100644 --- a/src/thingdef/thingdef_codeptr.cpp +++ b/src/thingdef/thingdef_codeptr.cpp @@ -5844,6 +5844,43 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_ResetHealth) } } +//=========================================================================== +// A_JumpIfHigherOrLower +// +// Jumps if a target, master, or tracer is higher or lower than the calling +// actor. Can also specify how much higher/lower the actor needs to be than +// itself. Can also take into account the height of the actor in question, +// depending on which it's checking. This means adding height of the +// calling actor's self if the pointer is higher, or height of the pointer +// if its lower. +//=========================================================================== + +DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfHigherOrLower) +{ + ACTION_PARAM_START(6); + ACTION_PARAM_INT(ptr, 0); + ACTION_PARAM_STATE(high, 1); + ACTION_PARAM_STATE(low, 2); + ACTION_PARAM_FIXED(offsethigh, 3); + ACTION_PARAM_FIXED(offsetlow, 4); + ACTION_PARAM_BOOL(includeHeight, 5); + + AActor *mobj = COPY_AAPTR(self, ptr); + + + if (!mobj || (mobj == self)) //AAPTR_DEFAULT is completely useless in this regard. + { + return; + } + ACTION_SET_RESULT(false); //No inventory jump chains please. + + if ((high) && (mobj->z > ((includeHeight ? self->height : 0) + self->z + offsethigh))) + ACTION_JUMP(high); + else if ((low) && (mobj->z + (includeHeight ? mobj->height : 0)) < (self->z + offsetlow)) + ACTION_JUMP(low); +} + + //=========================================================================== // // A_SetRipperLevel(int level) diff --git a/wadsrc/static/actors/actor.txt b/wadsrc/static/actors/actor.txt index 5d3fcf2ec..25e5ab1b5 100644 --- a/wadsrc/static/actors/actor.txt +++ b/wadsrc/static/actors/actor.txt @@ -330,6 +330,7 @@ ACTOR Actor native //: Thinker action native A_SetFloatBobPhase(int bob); action native A_SetHealth(int health, int ptr = AAPTR_DEFAULT); action native A_ResetHealth(int ptr = AAPTR_DEFAULT); + action native A_JumpIfHigherOrLower(int ptr = AAPTR_TARGET, state high, state low, float offsethigh = 0, float offsetlow = 0, bool includeHeight = true); action native A_SetRipperLevel(int level); action native A_SetRipMin(int min); action native A_SetRipMax(int max); From 1ecc048441681c52cd63baabf4335b51f65b2768 Mon Sep 17 00:00:00 2001 From: MajorCooke Date: Thu, 30 Apr 2015 08:28:41 -0500 Subject: [PATCH 6/6] - Change the pointer to be at the end instead of the start. --- src/thingdef/thingdef_codeptr.cpp | 12 ++++++------ wadsrc/static/actors/actor.txt | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/thingdef/thingdef_codeptr.cpp b/src/thingdef/thingdef_codeptr.cpp index 722cae8ce..21dc93036 100644 --- a/src/thingdef/thingdef_codeptr.cpp +++ b/src/thingdef/thingdef_codeptr.cpp @@ -5858,12 +5858,12 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_ResetHealth) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfHigherOrLower) { ACTION_PARAM_START(6); - ACTION_PARAM_INT(ptr, 0); - ACTION_PARAM_STATE(high, 1); - ACTION_PARAM_STATE(low, 2); - ACTION_PARAM_FIXED(offsethigh, 3); - ACTION_PARAM_FIXED(offsetlow, 4); - ACTION_PARAM_BOOL(includeHeight, 5); + ACTION_PARAM_STATE(high, 0); + ACTION_PARAM_STATE(low, 1); + ACTION_PARAM_FIXED(offsethigh, 2); + ACTION_PARAM_FIXED(offsetlow, 3); + ACTION_PARAM_BOOL(includeHeight, 4); + ACTION_PARAM_INT(ptr, 5); AActor *mobj = COPY_AAPTR(self, ptr); diff --git a/wadsrc/static/actors/actor.txt b/wadsrc/static/actors/actor.txt index 25e5ab1b5..b7fea4189 100644 --- a/wadsrc/static/actors/actor.txt +++ b/wadsrc/static/actors/actor.txt @@ -330,7 +330,7 @@ ACTOR Actor native //: Thinker action native A_SetFloatBobPhase(int bob); action native A_SetHealth(int health, int ptr = AAPTR_DEFAULT); action native A_ResetHealth(int ptr = AAPTR_DEFAULT); - action native A_JumpIfHigherOrLower(int ptr = AAPTR_TARGET, state high, state low, float offsethigh = 0, float offsetlow = 0, bool includeHeight = true); + action native A_JumpIfHigherOrLower(state high, state low, float offsethigh = 0, float offsetlow = 0, bool includeHeight = true, int ptr = AAPTR_TARGET); action native A_SetRipperLevel(int level); action native A_SetRipMin(int min); action native A_SetRipMax(int max);