CBaddy::CleanUpAIProcList

This commit is contained in:
krystalgamer 2024-07-01 18:17:13 +01:00
parent 43dd67c57c
commit ab8e9acfa1
4 changed files with 34 additions and 42 deletions

34
ai.cpp
View File

@ -35,11 +35,11 @@ void __inline CAIProc::AttachProc(AIProcType a2, CBaddy* a3, int a4)
{ {
this->pBaddy = a3; this->pBaddy = a3;
this->field_1C = reinterpret_cast<CAIProc*>(a3->field_28C); this->mNext = a3->mAIProcList;
if (this->field_1C) if (this->mNext)
this->field_1C->field_18 = this; this->mNext->field_18 = this;
a3->field_28C = reinterpret_cast<unsigned int*>(this); a3->mAIProcList = this;
if (!(a2 & 0x40000)) if (!(a2 & 0x40000))
a3->MarkAIProcList(0, a2 & 0xFF00, 0); a3->MarkAIProcList(0, a2 & 0xFF00, 0);
@ -104,8 +104,8 @@ void CAIProc_LookAt::Execute(void)
{ {
if (this->Wait()) if (this->Wait())
{ {
if (this->field_1C) if (this->mNext)
this->field_1C->Execute(); this->mNext->Execute();
} }
else else
{ {
@ -152,8 +152,8 @@ void CAIProc_Fall::Execute(void)
this->field_10 |= 1; this->field_10 |= 1;
} }
if (this->field_1C) if (this->mNext)
this->field_1C->Execute(); this->mNext->Execute();
} }
// @Ok // @Ok
@ -174,8 +174,8 @@ void CAIProc_StateSwitchSendMessage::Execute(void)
this->field_10 |= 1; this->field_10 |= 1;
} }
if (this->field_1C) if (this->mNext)
this->field_1C->Execute(); this->mNext->Execute();
} }
// @Ok // @Ok
@ -225,8 +225,8 @@ void CAIProc_MonitorAttack::Execute(void)
} }
if (this->field_1C) if (this->mNext)
this->field_1C->Execute(); this->mNext->Execute();
} }
// @Ok // @Ok
@ -308,8 +308,8 @@ void CAIProc_AccZ::Execute(void)
} }
} }
if (this->field_1C) if (this->mNext)
this->field_1C->Execute(); this->mNext->Execute();
} }
// @Ok // @Ok
@ -432,8 +432,8 @@ void CAIProc_MoveTo::Execute(void)
} }
} }
if (this->field_1C) if (this->mNext)
this->field_1C->Execute(); this->mNext->Execute();
} }
void validate_CAIProc(void) void validate_CAIProc(void)
@ -447,7 +447,7 @@ void validate_CAIProc(void)
VALIDATE(CAIProc, field_14, 0x14); VALIDATE(CAIProc, field_14, 0x14);
VALIDATE(CAIProc, field_18, 0x18); VALIDATE(CAIProc, field_18, 0x18);
VALIDATE(CAIProc, field_1C, 0x1C); VALIDATE(CAIProc, mNext, 0x1C);
} }
void validate_CAIProc_LookAt(void) void validate_CAIProc_LookAt(void)

2
ai.h
View File

@ -50,7 +50,7 @@ class CAIProc : public CClass
int field_14; int field_14;
CAIProc* field_18; CAIProc* field_18;
CAIProc* field_1C; CAIProc* mNext;
}; };
class CAIProc_LookAt : public CAIProc class CAIProc_LookAt : public CAIProc

View File

@ -6,6 +6,7 @@
#include "web.h" #include "web.h"
#include <cmath> #include <cmath>
#include "trig.h" #include "trig.h"
#include "ai.h"
// @TODO // @TODO
i32 CBaddy::GetNextWaypoint(void) i32 CBaddy::GetNextWaypoint(void)
@ -442,29 +443,19 @@ int CBaddy::Die(int a2)
return 0; return 0;
} }
// @Ok
INLINE void CBaddy::CleanUpAIProcList(i32 a2)
// @NotOk
// Calling a vfunc with fastcall, basically matching but polluting edx
void CBaddy::CleanUpAIPRocList(int a2)
{ {
int v2 = reinterpret_cast<int>(this->field_28C); CAIProc *pProc = this->mAIProcList;
int v3; while (pProc)
while (v2)
{ {
v3 = v2; CAIProc *curProc = pProc;
v2 = *reinterpret_cast<int*>(v2 + 28); pProc = pProc->mNext;
if (
if (a2 || (*reinterpret_cast<unsigned char*>(v3 + 16) & 1)) a2
|| curProc->field_10 & 1)
{ {
if (v3) delete curProc;
{
typedef void (FASTCALL *wtvHappeningPtr)(void*, void*, int);
wtvHappeningPtr wtvHappening = reinterpret_cast<wtvHappeningPtr>(**reinterpret_cast<int**>(v3));
wtvHappening(reinterpret_cast<void*>(v3), NULL, 1);
}
} }
} }
} }
@ -764,7 +755,7 @@ CBaddy* FindBaddyOfType(int type)
// @Ok // @Ok
void CBaddy::MarkAIProcList(int a2, int a3, int a4) void CBaddy::MarkAIProcList(int a2, int a3, int a4)
{ {
unsigned int *head = this->field_28C; unsigned int *head = reinterpret_cast<u32*>(this->mAIProcList);
while (head) while (head)
{ {
unsigned int *v5 = head; unsigned int *v5 = head;
@ -833,7 +824,7 @@ void validate_CBaddy(void){
VALIDATE(CBaddy, field_288, 0x288); VALIDATE(CBaddy, field_288, 0x288);
VALIDATE(CBaddy, field_28C, 0x28C); VALIDATE(CBaddy, mAIProcList, 0x28C);
VALIDATE(CBaddy, pMessage, 0x290); VALIDATE(CBaddy, pMessage, 0x290);
VALIDATE(CBaddy, field_294, 0x294); VALIDATE(CBaddy, field_294, 0x294);

View File

@ -14,6 +14,7 @@ union IntToBytes
}; };
class CMessage; class CMessage;
class CAIProc;
class CBaddy : public CSuper { class CBaddy : public CSuper {
public: public:
@ -35,7 +36,7 @@ public:
EXPORT int SetHeight(int, int, int); EXPORT int SetHeight(int, int, int);
EXPORT void SendDeathPulse(void); EXPORT void SendDeathPulse(void);
EXPORT int Die(int); EXPORT int Die(int);
EXPORT void CleanUpAIPRocList(int); EXPORT void CleanUpAIProcList(i32);
EXPORT int BumpedIntoSpidey(int); EXPORT int BumpedIntoSpidey(int);
EXPORT int ShouldFall(int, int); EXPORT int ShouldFall(int, int);
EXPORT int CheckSightCone(int, int, int, int, CBody*); EXPORT int CheckSightCone(int, int, int, int, CBody*);
@ -115,7 +116,7 @@ public:
int field_288; int field_288;
unsigned int *field_28C; CAIProc *mAIProcList;
CMessage* pMessage; CMessage* pMessage;
IntToBytes field_294; IntToBytes field_294;