CAIProc_LookAt::CAIProc_LookAt, CAIProc_LookAt::SetUpVariables and CAIProc::AttachTo

This commit is contained in:
krystalgamer 2024-06-04 17:46:43 +02:00
parent 20eb27fa57
commit 8783cae8e8
10 changed files with 118 additions and 15 deletions

72
ai.cpp
View File

@ -1,5 +1,6 @@
#include "ai.h"
#include "validate.h"
#include <cmath>
// @NotOk
@ -24,13 +25,84 @@ int __inline CAIProc::Wait(void)
return v3;
}
// @NotOk
// Fix casts
void __inline CAIProc::AttachProc(AIProcType a2, CBaddy* a3, int a4)
{
this->pBaddy = a3;
this->field_1C = reinterpret_cast<CAIProc*>(a3->field_28C);
if (this->field_1C)
this->field_1C->field_18 = this;
a3->field_28C = reinterpret_cast<unsigned int*>(this);
if (!(a2 & 0x40000))
a3->MarkAIProcList(0, a2 & 0xFF00, 0);
this->mAIProcType = a2;
this->field_14 = a4;
a3->field_288 &= ~a4;
}
// @Ok
void __inline CAIProc_LookAt::SetUpVariables(int a2, int a3)
{
int v3 = abs(a2);
if (v3 <= 16)
v3 = 16;
this->field_38 = v3;
this->field_3C = abs(a3);
this->pBaddy->field_2A8 &= 0xBFFFFFFF;
}
// @Ok
CAIProc_LookAt::CAIProc_LookAt(CBaddy* a2, CBody* a3, CVector * pTargetPos, int a5, int a6, int a7)
{
this->field_2C.vx = 0;
this->field_2C.vy = 0;
this->field_2C.vz = 0;
if (a3)
{
this->AttachProc(UNK_257, a2, a5);
this->field_24 = Mem_MakeHandle(a3);
}
else
{
print_if_false(pTargetPos != 0, "NULL pointer to targetPos.");
this->AttachProc(UNK_258, a2, a5);
this->field_2C = *pTargetPos;
}
this->SetUpVariables(a7, a6);
}
void validate_CAIProc(void)
{
VALIDATE(CAIProc, pBaddy, 0x4);
VALIDATE(CAIProc, mAIProcType, 0x8);
VALIDATE(CAIProc, field_C, 0xC);
VALIDATE(CAIProc, field_10, 0x10);
VALIDATE(CAIProc, field_14, 0x14);
VALIDATE(CAIProc, field_18, 0x18);
VALIDATE(CAIProc, field_1C, 0x1C);
}
void validate_CAIProc_LookAt(void)
{
VALIDATE_SIZE(CAIProc_LookAt, 0x40);
VALIDATE(CAIProc_LookAt, field_24, 0x24);
VALIDATE(CAIProc_LookAt, field_2C, 0x2C);
VALIDATE(CAIProc_LookAt, field_38, 0x38);
VALIDATE(CAIProc_LookAt, field_3C, 0x3C);
}

26
ai.h
View File

@ -5,20 +5,44 @@
#include "export.h"
#include "main.h"
#include "vector.h"
#include "baddy.h"
#include "mem.h"
enum AIProcType
{
UNK_257 = 257,
UNK_258 = 258,
};
class CAIProc : public CClass
{
public:
EXPORT int Wait(void);
EXPORT void AttachProc(AIProcType, CBaddy*, int);
unsigned char topPad[0x8];
CBaddy* pBaddy;
AIProcType mAIProcType;
int field_C;
int field_10;
int field_14;
CAIProc* field_18;
CAIProc* field_1C;
};
class CAIProc_LookAt : public CAIProc
{
public:
EXPORT CAIProc_LookAt(CBaddy*, CBody*, CVector *, int, int, int);
EXPORT void SetUpVariables(int, int);
unsigned char topPad[4];
SHandle field_24;
CVector field_2C;
int field_38;
int field_3C;
};

View File

@ -825,6 +825,8 @@ void validate_CBaddy(void){
VALIDATE(CBaddy, attributeArr, 0x270);
VALIDATE(CBaddy, field_27C, 0x27C);
VALIDATE(CBaddy, field_288, 0x288);
VALIDATE(CBaddy, field_28C, 0x28C);
VALIDATE(CBaddy, field_290, 0x290);
VALIDATE(CBaddy, field_294, 0x294);

View File

@ -110,8 +110,9 @@ public:
unsigned char morerPad[0x84 - 0x14 - 4 - 0x10 - 0x30 - 0xC];
__int16 attributeArr[6];
CVector field_27C;
int field_288;
unsigned char weirdpad[0x02];
unsigned int *field_28C;
int field_290;
unsigned char field_294;

1
cop.h
View File

@ -44,7 +44,6 @@ class CCopPing : public CSimpleAnim
unsigned char padTop[8];
SHandle field_70;
unsigned char padAfter70[4];
SHook field_78;
};

13
mem.cpp
View File

@ -363,10 +363,12 @@ void *DCMem_New(unsigned int a1, int a2, int a3, void* a4, bool a5)
}
// @Ok
// @NotOk
// slightly different due to many jumps to same printf_if_false, no biggie
int Mem_MakeHandle(void* a1)
// completly wrong
SHandle Mem_MakeHandle(void* a1)
{
/*
char *v1; // esi
int v2; // eax
char *v3; // esi
@ -400,6 +402,10 @@ int Mem_MakeHandle(void* a1)
}
}
return 0;
*/
SHandle tmp;
return tmp;
}
@ -433,9 +439,10 @@ void *Mem_RecoverPointer(SHandle *a1)
}
void validate_SHandle(void){
VALIDATE_SIZE(SHandle, 4);
VALIDATE_SIZE(SHandle, 8);
VALIDATE(SHandle, field_0, 0x0);
VALIDATE(SHandle, field_4, 0x4);
}
void validate_SBlockHeader(void){

13
mem.h
View File

@ -3,6 +3,12 @@
#include "export.h"
struct SHandle
{
int field_0;
int field_4;
};
struct SBlockHeader {
unsigned int ParentHeap;
@ -20,12 +26,7 @@ EXPORT void Mem_Copy(void*, void*, int);
EXPORT void *Mem_NewTop(unsigned int);
EXPORT void *Mem_CoreNew(unsigned int);
EXPORT void *DCMem_New(unsigned int, int, int, void*, bool);
EXPORT int Mem_MakeHandle(void*);
struct SHandle
{
int field_0;
};
EXPORT SHandle Mem_MakeHandle(void*);
EXPORT void *Mem_RecoverPointer(SHandle*);

1
ob.h
View File

@ -181,7 +181,6 @@ public:
unsigned char padAfter10C[4];
SHandle field_114;
unsigned char padAfter114[0x11C-0x114-sizeof(SHandle)];
int SNbrFaces;
int alsoOutlineRelated;

View File

@ -19,7 +19,6 @@ class CScorpion : public CBaddy {
CSuper* field_BEC;
SHandle field_BF0;
unsigned char padAfterBF0[0xBF8-0xBF0 - sizeof(SHandle)];
int field_BF8;

1
thug.h
View File

@ -47,7 +47,6 @@ class CThugPing : public CSimpleAnim
unsigned char padTop[8];
SHandle field_70;
unsigned char padAfter70[4];
SHook field_78;
};