Skip to content

Commit

Permalink
Merge pull request #143 from bloppers/match-basic
Browse files Browse the repository at this point in the history
Match basic.c
  • Loading branch information
TheOnlyZac authored Feb 7, 2025
2 parents dc2f4b5 + 2fa62e5 commit a2cc2dc
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
1 change: 1 addition & 0 deletions config/symbol_addrs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ GGetActsegPoseGoal__FP6ACTSEGi = 0x123358; // type:func
////////////////////////////////////////////////////////////////
FIsBasicDerivedFrom__FP5BASIC3CID = 0x1300e8; // type:func
EnsureBasicSidebag__FP5BASIC = 0x130110; // type:func
GetBasicCid__FP5BASICP3CID = 0x130158; // type:func


////////////////////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions include/basic.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "common.h"
#include <splice/sidebag.h>
#include <cid.h>
#include <vtables.h>

/**
* @brief Basic object.
Expand All @@ -19,7 +19,7 @@
*/
struct BASIC
{
int field_0x0; // placeholder for vtable
VTBASIC *pvtbasic;
CSidebag *psidebag;
};

Expand Down
2 changes: 2 additions & 0 deletions include/splice/sidebag.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ class CSidebag
SBB m_asbb[16];
};

CSidebag* PsidebagNew();

#endif // SPLICE_SIDEBAG_H
13 changes: 13 additions & 0 deletions include/vtables.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,21 @@
#ifndef VTABLES_H
#define VTABLES_H

#include <cid.h>

struct BLOT;

/**
* @brief VT for basic objects.
*
* @todo pvtSuper should be VT* according to prototype.
*/
struct VTBASIC
{
VTBASIC *pvtSuper;
CID cid;
};

/**
* @brief VT for generic blots.
*/
Expand Down
27 changes: 24 additions & 3 deletions src/P2/basic.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
#include <basic.h>
#include <splice/gc.h>
#include <splice/sidebag.h>

INCLUDE_ASM(const s32, "P2/basic", FIsBasicDerivedFrom__FP5BASIC3CID);
extern CGc g_gc;

INCLUDE_ASM(const s32, "P2/basic", EnsureBasicSidebag__FP5BASIC);
int FIsBasicDerivedFrom(BASIC *pbasic, CID cid) {
VTBASIC *vt = pbasic->pvtbasic;
while (vt != nullptr) {
if (vt->cid == cid) return 1;
vt = vt->pvtSuper;
}

INCLUDE_ASM(const s32, "P2/basic", func_00130158);
return 0;
}

void EnsureBasicSidebag(BASIC *pbasic) {
if (pbasic->psidebag == nullptr) {
CSidebag *psidebag = PsidebagNew();
pbasic->psidebag = psidebag;
g_gc.AddRootSidebag(psidebag);
}
return;
}

void GetBasicCid(BASIC *pbasic, CID* pcid) {
*pcid = pbasic->pvtbasic->cid;
}

0 comments on commit a2cc2dc

Please sign in to comment.