Skip to content

Commit

Permalink
Add RaceManager, split KartState
Browse files Browse the repository at this point in the history
  • Loading branch information
em-eight committed Jul 15, 2024
1 parent ab7ef87 commit a84e5aa
Show file tree
Hide file tree
Showing 16 changed files with 187 additions and 116 deletions.
10 changes: 5 additions & 5 deletions pack/symbols.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18083,7 +18083,7 @@ global:
0x805940d4: 'unk_805940d4'
0x80594134: 'unk_80594134'
0x805941bc: 'unk_805941bc'
0x805943b4: 'PlayerSub1c_construct'
0x805943b4: '__ct__Q24Kart9KartStateFPQ24Kart12KartSettings'
0x8059455c: 'init__Q24Kart9KartStateFv'
0x80594594: 'reset__Q24Kart9KartStateFv'
0x80594634: 'resetOob__Q24Kart9KartStateFv'
Expand Down Expand Up @@ -36585,7 +36585,7 @@ global:
0x808b64e8: 'lbl_808b64e8'
0x808b64f8: 'lbl_808b64f8'
0x808b6528: 'lbl_808b6528'
0x808b6534: 'lbl_808b6534'
0x808b6534: '__vt__Q24Kart9KartState'
0x808b6540: 'lbl_808b6540'
0x808b6558: 'lbl_808b6558'
0x808b656c: 'lbl_808b656c'
Expand Down Expand Up @@ -38849,7 +38849,7 @@ global:
0x809bd718: 'lbl_809bd718'
0x809bd720: 'lbl_809bd720'
0x809bd728: 'spInstance__Q26System10RaceConfig'
0x809bd730: 'lbl_809bd730'
0x809bd730: 'spInstance__Q26System11RaceManager'
0x809bd738: 'spInstance__Q26System15ResourceManager'
0x809bd740: 'spInstance__Q26System9InitScene'
0x809bd748: 'lbl_809bd748'
Expand Down Expand Up @@ -38908,8 +38908,8 @@ global:
0x809c1940: 'lbl_809c1940'
0x809c1944: 'lbl_809c1944'
0x809c1948: 'lbl_809c1948'
0x809c1950: 'lbl_809c1950'
0x809c1951: 'lbl_809c1951'
0x809c1950: 'isPlayerOnlineLocal__4Kart'
0x809c1951: 'isPlayerOnlineRemote__4Kart'
0x809c1954: 'lbl_809c1954'
0x809c1958: 'lbl_809c1958'
0x809c1960: 'lbl_809c1960'
Expand Down
9 changes: 9 additions & 0 deletions source/decomp.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ typedef struct {
__RelSymbolDef rel_sym_##name = {addr, (const void*)&name}; \
FORCEACTIVE_DATA(rel_sym_##name)

#ifndef SHIFTABLE
#define DEFINE_REL_DATA(name, addr, type, val) \
extern "C" UNKNOWN_DATA(name); \
REL_SYMBOL_AT(name, addr);
#else
#define DEFINE_REL_DATA(name, addr, type, val) \
static type name = val;
#endif

#define cr0lt 0
#define cr0gt 1
#define cr0eq 2
Expand Down
2 changes: 1 addition & 1 deletion source/game/geo/ObjKoopaFigure64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ extern UNKNOWN_DATA(lbl_808c5c84);
// PAL: 0x809bd728
extern UNKNOWN_DATA(spInstance__Q26System10RaceConfig);
// PAL: 0x809bd730
extern UNKNOWN_DATA(lbl_809bd730);
extern UNKNOWN_DATA(spInstance__Q26System11RaceManager);
// PAL: 0x809c18f8
extern UNKNOWN_DATA(lbl_809c18f8);
// PAL: 0x809c21d0
Expand Down
2 changes: 1 addition & 1 deletion source/game/geo/ObjKuribo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ extern UNKNOWN_DATA(lbl_808c5f0c);
// PAL: 0x809bd728
extern UNKNOWN_DATA(spInstance__Q26System10RaceConfig);
// PAL: 0x809bd730
extern UNKNOWN_DATA(lbl_809bd730);
extern UNKNOWN_DATA(spInstance__Q26System11RaceManager);
// PAL: 0x809c2f44
extern UNKNOWN_DATA(spInstance__Q25Field11CourseModel);
// PAL: 0x809c3618
Expand Down
2 changes: 1 addition & 1 deletion source/game/geo/ObjSunDS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extern UNKNOWN_DATA(lbl_808c6310);
// PAL: 0x808c6410
extern UNKNOWN_DATA(lbl_808c6410);
// PAL: 0x809bd730
extern UNKNOWN_DATA(lbl_809bd730);
extern UNKNOWN_DATA(spInstance__Q26System11RaceManager);
// PAL: 0x809c19b8
extern UNKNOWN_DATA(lbl_809c19b8);
}
Expand Down
2 changes: 1 addition & 1 deletion source/game/kart/KartCollide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ extern UNKNOWN_DATA(spInstance__Q26System9CourseMap);
// PAL: 0x809bd728
extern UNKNOWN_DATA(spInstance__Q26System10RaceConfig);
// PAL: 0x809bd730
extern UNKNOWN_DATA(lbl_809bd730);
extern UNKNOWN_DATA(spInstance__Q26System11RaceManager);
// PAL: 0x809c18d8
extern UNKNOWN_DATA(lbl_809c18d8);
// PAL: 0x809c18f8
Expand Down
2 changes: 1 addition & 1 deletion source/game/kart/KartMove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ extern UNKNOWN_DATA(spInstance__Q26System9CourseMap);
// PAL: 0x809bd728
extern UNKNOWN_DATA(spInstance__Q26System10RaceConfig);
// PAL: 0x809bd730
extern UNKNOWN_DATA(lbl_809bd730);
extern UNKNOWN_DATA(spInstance__Q26System11RaceManager);
// PAL: 0x809c18e0
extern UNKNOWN_DATA(lbl_809c18e0);
// PAL: 0x809c18f8
Expand Down
4 changes: 2 additions & 2 deletions source/game/kart/KartObjectProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ extern UNKNOWN_FUNCTION(unk_808646f0); // Extern data references.
// PAL: 0x809bd728
extern UNKNOWN_DATA(spInstance__Q26System10RaceConfig);
// PAL: 0x809bd730
extern UNKNOWN_DATA(lbl_809bd730);
extern UNKNOWN_DATA(spInstance__Q26System11RaceManager);
// PAL: 0x809c18f8
extern UNKNOWN_DATA(lbl_809c18f8);
}
Expand Down Expand Up @@ -530,7 +530,7 @@ asm UNKNOWN_FUNCTION(unk_80590a4c){
}

namespace Kart {
s8 KartObjectProxy::getPlayerIdx() const { return mAccessor->kartSettings->playerIdx; }
u8 KartObjectProxy::getPlayerIdx() const { return mAccessor->kartSettings->playerIdx; }
}

// Symbol: PlayerPointers_isBike
Expand Down
2 changes: 1 addition & 1 deletion source/game/kart/KartObjectProxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ class KartObjectProxy {
BspWheel* bspWheel(s32 idx) const;

KartModel* kartModel();
s8 getPlayerIdx() const;
u8 getPlayerIdx() const;
KartAction* kartAction();
const KartAction* kartAction() const;
bool hasCamera();
Expand Down
2 changes: 1 addition & 1 deletion source/game/kart/KartSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class KartSettings {
System::CharacterId character;
u16 susCount;
u16 wheelCount;
s8 playerIdx;
u8 playerIdx;
KartParam* kartParam;
void* _18;
KartDriverDispParams* kartDriverDispParams;
Expand Down
92 changes: 75 additions & 17 deletions source/game/kart/KartState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

extern "C" {


// PAL: 0x805943b4..0x8059455c
UNKNOWN_FUNCTION(PlayerSub1c_construct);
UNKNOWN_FUNCTION(__ct__Q24Kart9KartStateFPQ24Kart12KartSettings);
// PAL: 0x8059455c..0x80594594
UNKNOWN_FUNCTION(init__Q24Kart9KartStateFv);
// PAL: 0x80594594..0x80594634
Expand Down Expand Up @@ -145,13 +144,13 @@ extern UNKNOWN_DATA(RKSystem_ey);
// PAL: 0x809bd728
extern UNKNOWN_DATA(spInstance__Q26System10RaceConfig);
// PAL: 0x809bd730
extern UNKNOWN_DATA(lbl_809bd730);
extern UNKNOWN_DATA(spInstance__Q26System11RaceManager);
// PAL: 0x809c18f8
extern UNKNOWN_DATA(lbl_809c18f8);
// PAL: 0x809c1950
extern UNKNOWN_DATA(lbl_809c1950);
extern UNKNOWN_DATA(isPlayerOnlineLocal__4Kart);
// PAL: 0x809c1951
extern UNKNOWN_DATA(lbl_809c1951);
extern UNKNOWN_DATA(isPlayerOnlineRemote__4Kart);
}

// --- EXTERN DECLARATIONS END ---
Expand All @@ -160,13 +159,7 @@ extern UNKNOWN_DATA(lbl_809c1951);
const u32 lbl_80891ef0[] = {
0x00000000
};
const u32 lbl_80891ef4[] = {
0x3f800000
};
const u32 lbl_80891ef8[] = {
0x43300000, 0x80000000, 0x41200000, 0x3f4ccccd,
0x3f59999a, 0x3d4ccccd, 0xc1b00000, 0xc0e00000
};
//DEFINE_REL_DATA(lbl_80891ef0, 0x80891ef0, const f32, 0.0f);

// .data
#pragma explicit_zero_data on
Expand All @@ -181,18 +174,83 @@ u32 lbl_808b64f8[] = {
u32 lbl_808b6528[] = {
0x00b40000, 0x0000000a, 0x42200000
};
u32 lbl_808b6534[] = {
u32 __vt__Q24Kart9KartState[] = {
0x00000000, 0x00000000, (u32)&PlayerSub1c_destroy
};
#pragma explicit_zero_data off

// .bss

#include "KartState.hpp"

/*
* https://decomp.me/scratch/7prZZ
namespace Kart {
extern bool isPlayerOnlineLocal;
extern bool isPlayerOnlineRemote;
MARK_FLOW_CHECK(0x805943b4);
KartState::KartState(KartSettings* settings) {
using namespace System;
mAirtime = 0;
_24 = 0.0f;
mCannonPointId = 0;
mStartBoostIdx = 0;
mUp.setZero();
mProxy = new KartObjectProxy;
RaceConfig::Player::Type playerType = RaceConfig::spInstance->mRaceScenario.mPlayers[settings->playerIdx].mPlayerType;
switch (playerType) {
case RaceConfig::Player::TYPE_REAL_LOCAL:
set(KART_FLAG_LOCAL);
break;
case RaceConfig::Player::TYPE_CPU:
set(KART_FLAG_CPU);
break;
case RaceConfig::Player::TYPE_GHOST:
set(KART_FLAG_GHOST);
break;
}
if (isPlayerOnlineLocal) {
set(KART_FLAG_ONLINE_LOCAL);
} else if (isPlayerOnlineRemote) {
set(KART_FLAG_ONLINE_REMOTE);
}
KPadController* controller = RaceManager::spInstance->players[settings->playerIdx]->kpadPlayer->mController;
bool isAuto;
if (!controller) {
isAuto = false;
} else {
isAuto = controller->mDriftIsAuto;
}
if (isAuto) {
set(KART_FLAG_AUTOMATIC_DRIFT);
}
if (RaceConfig::spInstance->mRaceScenario.mSettings.mGameMode == RaceConfig::Settings::GAMEMODE_AWARDS &&
RaceConfig::spInstance->mRaceScenario.mSettings.mCameraMode == RaceConfig::Settings::CAMERA_MODE_LOSS) {
set(KART_FLAG_SET_SPEED_ZERO);
set(KART_FLAG_DEMO_LOSS);
}
}
}
*/

const u32 lbl_80891ef4[] = {
0x3f800000
};
const u32 lbl_80891ef8[] = {
0x43300000, 0x80000000, 0x41200000, 0x3f4ccccd,
0x3f59999a, 0x3d4ccccd, 0xc1b00000, 0xc0e00000
};

// Symbol: PlayerSub1c_construct
// Symbol: __ct__Q24Kart9KartStateFPQ24Kart12KartSettings
// PAL: 0x805943b4..0x8059455c
MARK_BINARY_BLOB(PlayerSub1c_construct, 0x805943b4, 0x8059455c);
asm UNKNOWN_FUNCTION(PlayerSub1c_construct) {
MARK_BINARY_BLOB(__ct__Q24Kart9KartStateFPQ24Kart12KartSettings, 0x805943b4, 0x8059455c);
asm UNKNOWN_FUNCTION(__ct__Q24Kart9KartStateFPQ24Kart12KartSettings) {
#include "asm/805943b4.s"
}

Expand Down
26 changes: 18 additions & 8 deletions source/game/kart/KartState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extern "C" {
#endif

// PAL: 0x805943b4..0x8059455c
UNKNOWN_FUNCTION(PlayerSub1c_construct);
UNKNOWN_FUNCTION(__ct__Q24Kart9KartStateFPQ24Kart12KartSettings);
// PAL: 0x8059455c..0x80594594
UNKNOWN_FUNCTION(init__Q24Kart9KartStateFv);
// PAL: 0x80594594..0x80594634
Expand Down Expand Up @@ -53,6 +53,8 @@ UNKNOWN_FUNCTION(PlayerSub1c_destroy);

#include <game/kart/KartObjectProxy.hpp>
#include <game/system/RKBitField.hpp>
#include <game/system/RaceConfig.hpp>
#include <game/system/RaceManager.hpp>

namespace Kart {

Expand All @@ -78,11 +80,20 @@ enum KartFlags {
KART_FLAG_STH_61 = 0x61,
KART_FLAG_STH_WALL_COL = 0x63,
KART_FLAG_STH_KILLER = 0x6a,
KART_FLAG_CPU = 0x80,
KART_FLAG_LOCAL = 0x81,
KART_FLAG_ONLINE_LOCAL = 0x82,
KART_FLAG_ONLINE_REMOTE = 0x83,
KART_FLAG_AUTOMATIC_DRIFT = 0x84,
KART_FLAG_GHOST = 0x86,
KART_FLAG_SET_SPEED_ZERO = 0x89,
KART_FLAG_DEMO_LOSS = 0x8b,
};

class KartState {
public:
KartState(KartSettings* settings);
virtual ~KartState();
void init();
void reset();
void resetOob();
Expand All @@ -102,16 +113,15 @@ class KartState {
void setHalfpipeInvisibilityTimer(s32 timer) { mHalfpipeInvisibilityTimer = timer; }

private:
u8 _00[0x04 - 0x00];
RKBitField<160> mFlags;
KartObjectProxy* mProxy;
u32 mAirtime;
u8 _20[0x24 - 0x20];
f32 m_24;
EGG::Vector3f mTop;
f32 _24;
EGG::Vector3f mUp;
u8 _34[0x40 - 0x34];
EGG::Vector3f _40;
EGG::Vector3f m_4c;
EGG::Vector3f _4c;
u32 _58;
u32 _5c;
u8 _60[0x6c - 0x60];
Expand All @@ -128,9 +138,9 @@ class KartState {
s16 mWipeFrame;
u8 _96[0x9c - 0x96];
f32 mStartBoostCharge;
u8 _a0[0xa4 - 0xa0];
u16 m_a4;
u16 m_a6;
s32 mStartBoostIdx;
u16 _a4;
u16 _a6;
EGG::Vector3f m_a8;
u8 _b4[0xc0 - 0xb4];
};
Expand Down
Loading

0 comments on commit a84e5aa

Please sign in to comment.