Browse Source

fix monsters sometimes having their data replaced by new monsters

master
Alison Watson 11 months ago
parent
commit
653aa19285
7 changed files with 51 additions and 18 deletions
  1. BIN
      pk7/acs/lithmain.bin
  2. +2
    -1
      source/debug.c
  3. +4
    -1
      source/include/w_data.h
  4. +2
    -4
      source/include/w_monster.h
  5. +3
    -6
      source/w_dmon.c
  6. +40
    -5
      source/w_monster.c
  7. +0
    -1
      source/w_world.c

BIN
pk7/acs/lithmain.bin View File


+ 2
- 1
source/debug.c View File

@@ -191,7 +191,8 @@ void Sc_DbgDumpAlloc(void) {

script_str ext("ACS") addr(OBJ "PrintMonsterInfo")
void Sc_PrintMonsterInfo(void) {
PrintMonsterInfo();
ifauto(dmon_t *, m, DmonPtr(0, AAPTR_PLAYER_GETTARGET))
PrintMonsterInfo(m);
}

script_str ext("ACS") addr(OBJ "TriggerEnding")


+ 4
- 1
source/include/w_data.h View File

@@ -84,7 +84,8 @@ enum /* DamageType */

enum /* ScriptNum */
{
lsc_getfontmetric = 17100,
lsc_gsinit = 17000,
lsc_getfontmetric,
lsc_metr_xadv,
lsc_metr_yofs,
lsc_metr_tex,
@@ -98,6 +99,8 @@ enum /* ScriptNum */
lsc_raindropspawn,
lsc_monstertype,
lsc_drawdmgnum,
lsc_preinit,
lsc_worldreopen,
};

enum /* BossType */


+ 2
- 4
source/include/w_monster.h View File

@@ -92,14 +92,12 @@ struct dmon {
/* address space, and then I'd have to do a bunch of rewriting again */
typedef struct dmon dmon_t;

void DmonInit();

script dmon_t *DmonPtr(i32 tid, i32 ptr);
dmon_t *DmonSelf(void);
dmon_t *Dmon(i32 id);
dmon_t *AllocDmon(void);
stkcall dmon_t *AllocDmon(void);

void PrintMonsterInfo(void);
void PrintMonsterInfo(dmon_t *m);
void PrintDmonAllocSize(struct player *p);

#endif


+ 3
- 6
source/w_dmon.c View File

@@ -24,7 +24,8 @@
*/
noinit
static dmon_t dmonalloc[DMON_MAX];
static i32 dmonid;

static i32 lmvar dmonid;

/* Extern Functions -------------------------------------------------------- */

@@ -33,11 +34,6 @@ void PrintDmonAllocSize(struct player *p)
p->logH(1, "dmonalloc is %.2k megabytes!", sizeof dmonalloc * 4 / 1024 / 1024.0);
}

void DmonInit(void)
{
dmonid = 0;
}

script
dmon_t *DmonPtr(i32 tid, i32 ptr)
{
@@ -57,6 +53,7 @@ dmon_t *Dmon(i32 id)
else return nil;
}

alloc_aut(0) stkcall
dmon_t *AllocDmon(void)
{
dmon_t *m = &dmonalloc[dmonid];


+ 40
- 5
source/w_monster.c View File

@@ -309,6 +309,28 @@ void MonsterMain(dmon_t *m) {
}
}

alloc_aut(0) stkcall static
bool faststrstr_str(str lhs, str rhs) {
i32 llen = ACS_StrLen(lhs);
i32 rlen = ACS_StrLen(rhs);
i32 i, j, k;

for(i = 0; i < llen; i++) {
for(j = 0, k = i; j < rlen; j++) {
if(lhs[i++] != rhs[j]) {
i = k;
break;
}
}

if(j == rlen) {
return true;
}
}

return false;
}

/* Extern Functions -------------------------------------------------------- */

#ifndef NDEBUG
@@ -357,7 +379,14 @@ void Sc_ResurrectMonster(i32 amt)
ifauto(dmon_t *, m, DmonSelf()) m->resurrect = true;
}

dynam_aut script ext("ACS") addr(lsc_monsterinfo)
#ifndef NDEBUG
script static
void LogError(str cname) {
Dbg_Log(log_dmon, "ERROR no monster %S", cname);
}
#endif

alloc_aut(0) script ext("ACS") addr(lsc_monsterinfo)
void Sc_MonsterInfo(void)
{
Str(rladaptive, s"RLAdaptive");
@@ -365,7 +394,7 @@ void Sc_MonsterInfo(void)

str cname = ACS_GetActorClass(0);

if(strstr_str(cname, rladaptive) || strstr_str(cname, rlhax))
if(faststrstr_str(cname, rladaptive) || faststrstr_str(cname, rlhax))
return;

for(i32 i = 0; i < countof(monsterinfo); i++) {
@@ -373,19 +402,25 @@ void Sc_MonsterInfo(void)
bool init;

if(get_bit(mi->flags, mif_full)) init = cname == mi->name;
else init = strstr_str(cname, mi->name);
else init = faststrstr_str(cname, mi->name);

if(init) {
ACS_Delay(1);
ifauto(dmon_t *, m, AllocDmon()) {

/* make sure it isn't already dead first */
if(GetMembI(0, sm_Health) > 0) {
dmon_t *m = AllocDmon();
m->mi = mi;
MonsterMain(m);
}

return;
}
}

Dbg_Log(log_dmon, "ERROR no monster %S", cname);
#ifndef NDEBUG
LogError(cname);
#endif

/* If the monster failed all checks, give them this so we don't
need to recheck every tick.


+ 0
- 1
source/w_world.c View File

@@ -220,7 +220,6 @@ static void HInitPre(void)
if(unloaded)
mapscleared++;

DmonInit();
bossspawned = false;

if(ACS_GetCVar(sc_sv_sky) && !islithmap) {


Loading…
Cancel
Save