Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Replaymanager #294

Merged
merged 16 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/ghidra_ns_to_obj.csv
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ MidiOutput,th06::MidiDevice,th06::MidiTimer,th06::MidiOutput
Pbg3Archive,th06::Pbg3Archive
Pbg3Parser,th06::Pbg3Parser
Player,th06::Player
ReplayManager,th06::ReplayManager
ResultScreen,th06::ResultScreen
Rng,th06::Rng
ScreenEffect,th06::ScreenEffect
Expand Down
1 change: 1 addition & 0 deletions config/globals.csv
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ _g_LastFrameTime, 0x006c6bf8
_g_ExclusiveMutex, 0x006c6c00
_g_Supervisor, 0x006c6d18
_g_Player, 0x006ca628
_g_ReplayManager, 0x006d3f18
_g_SoundPlayer, 0x006d3f50
_g_AnmManager, 0x006d4588
_g_PrimitivesToDrawNoVertexBuf, 0x006d4590
Expand Down
11 changes: 11 additions & 0 deletions config/implemented.csv
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,17 @@ th06::SoundPlayer::PlaySounds
th06::SoundPlayer::PlaySoundByIdx
th06::SoundPlayer::BackgroundMusicPlayerThread
th06::SoundPlayer::InitSoundBuffers
th06::ReplayManager::ValidateReplayData
th06::ReplayManager::RegisterChain
th06::ReplayManager::OnUpdate
th06::ReplayManager::OnUpdateDemoLowPrio
th06::ReplayManager::OnUpdateDemoHighPrio
th06::ReplayManager::OnDraw
th06::ReplayManager::AddedCallback
th06::ReplayManager::AddedCallbackDemo
th06::ReplayManager::DeletedCallback
th06::ReplayManager::StopRecording
th06::ReplayManager::SaveReplay
th06::Player::AddedCallback
th06::Player::DeletedCallback
th06::Player::RegisterChain
Expand Down
4 changes: 0 additions & 4 deletions config/stubbed.csv
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ th06::MusicRoom::RegisterChain
th06::ResultScreen::ReleaseScoreDat
th06::ScreenEffect::RegisterChain
th06::MainMenu::SelectRelated
th06::ReplayManager::RegisterChain
th06::ReplayManager::StopRecording
th06::ReplayManager::SaveReplay
th06::ReplayManager::ValidateReplayData
th06::ScreenEffect::DrawSquare
th06::TextHelper::ReleaseTextBuffer
th06::Pbg3Archive::Pbg3Archive
8 changes: 8 additions & 0 deletions objdiff.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@

"reverse_fn_order": false
},
{
"name": "ReplayManager",

"target_path": "build/objdiff/orig/ReplayManager.obj",
"base_path": "build/objdiff/reimpl/ReplayManager.obj",

"reverse_fn_order": false
},
{
"name": "ResultScreen",

Expand Down
1 change: 1 addition & 0 deletions scripts/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def configure(build_type):
"FileSystem",
"GameErrorContext",
"Rng",
"ReplayManager",
"ResultScreen",
"utils",
"TextHelper",
Expand Down
4 changes: 4 additions & 0 deletions src/ChainPriorities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
#define TH_CHAIN_PRIO_CALC_MAINMENU 2
#define TH_CHAIN_PRIO_CALC_ENDING 3
#define TH_CHAIN_PRIO_CALC_GAMEMANAGER 4
#define TH_CHAIN_PRIO_CALC_LOW_PRIO_REPLAYMANAGER_DEMO 5
#define TH_CHAIN_PRIO_CALC_STAGE 6
#define TH_CHAIN_PRIO_CALC_PLAYER 7
#define TH_CHAIN_PRIO_CALC_ENEMYMANAGER 9
#define TH_CHAIN_PRIO_CALC_EFFECTMANAGER 10
#define TH_CHAIN_PRIO_CALC_BULLETMANAGER 11
#define TH_CHAIN_PRIO_CALC_GUI 12
#define TH_CHAIN_PRIO_CALC_RESULTSCREEN 13
#define TH_CHAIN_PRIO_CALC_REPLAYMANAGER 15
#define TH_CHAIN_PRIO_CALC_HIGH_PRIO_REPLAYMANAGER_DEMO 16

#define TH_CHAIN_PRIO_DRAW_MAINMENU 0
#define TH_CHAIN_PRIO_DRAW_ENDING 1
Expand All @@ -26,5 +29,6 @@
#define TH_CHAIN_PRIO_DRAW_ASCIIMANAGER_POPUPS 10
#define TH_CHAIN_PRIO_DRAW_GUI 11
#define TH_CHAIN_PRIO_DRAW_RESULTSCREEN 12
#define TH_CHAIN_PRIO_DRAW_REPLAYMANAGER 13
#define TH_CHAIN_PRIO_DRAW_SUPERVISOR 14
#define TH_CHAIN_PRIO_DRAW_ASCIIMANAGER_MENUS 15
2 changes: 1 addition & 1 deletion src/GameManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ ZunResult GameManager::AddedCallback(GameManager *mgr)
g_GameManager.powerItemCountForScore = 0;
mgr->rank = 8;
mgr->grazeInTotal = 0;
mgr->unk_1816 = 0;
mgr->pointItemsCollected = 0;
for (catk = mgr->catk, i = 0; i < ARRAY_SIZE_SIGNED(mgr->catk); i++, catk++)
{
// Randomize catk content.
Expand Down
2 changes: 1 addition & 1 deletion src/GameManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ struct GameManager
i8 unk_1812;
i8 unk_1813;
u16 pointItemsCollectedInStage;
i16 unk_1816;
i16 pointItemsCollected;
u8 numRetries;
i8 powerItemCountForScore;
i8 livesRemaining;
Expand Down
2 changes: 1 addition & 1 deletion src/ItemManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ void ItemManager::OnUpdate()
}
g_GameManager.score += itemScore;
g_GameManager.pointItemsCollectedInStage++;
g_GameManager.unk_1816++;
g_GameManager.pointItemsCollected++;
g_Gui.flags.flag4 = 2;
if (curItem->currentPosition.y < 128.0f)
{
Expand Down
29 changes: 15 additions & 14 deletions src/MainMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,22 +499,23 @@ i32 MainMenu::ReplayHandling()
g_SoundPlayer.PlaySoundByIdx(SOUND_SELECT, 0);
this->currentReplay = (ReplayData *)FileSystem::OpenPath(this->replayFilePaths[this->chosenReplay], 1);
ReplayManager::ValidateReplayData(this->currentReplay, g_LastFileSize);
for (cur = 0; cur < ARRAY_SIZE_SIGNED(this->currentReplay->stageScore); cur++)
for (cur = 0; cur < ARRAY_SIZE_SIGNED(this->currentReplay->stageReplayData); cur++)
{
if (this->currentReplay->stageScore[cur] != NULL)
if (this->currentReplay->stageReplayData[cur] != NULL)
{
this->currentReplay->stageScore[cur] =
(StageReplayData *)((u32)this->currentReplay + (u32)this->currentReplay->stageScore[cur]);
this->currentReplay->stageReplayData[cur] =
(StageReplayData *)((u32)this->currentReplay +
(u32)this->currentReplay->stageReplayData[cur]);
}
}

do
{
// FIXME: there's an additional jump
if (this->replayFileData[this->chosenReplay].stageScore[this->cursor])
if (this->replayFileData[this->chosenReplay].stageReplayData[this->cursor])
goto leaveDo;
this->cursor = this->cursor + 1;
} while ((int)this->cursor < ARRAY_SIZE_SIGNED(this->currentReplay->stageScore));
} while ((int)this->cursor < ARRAY_SIZE_SIGNED(this->currentReplay->stageReplayData));
return ZUN_SUCCESS;
}
}
Expand All @@ -540,7 +541,7 @@ i32 MainMenu::ReplayHandling()
cur = MoveCursor(this, 7);
if (cur < 0)
{
while (this->replayFileData[this->chosenReplay].stageScore[this->cursor] == NULL)
while (this->replayFileData[this->chosenReplay].stageReplayData[this->cursor] == NULL)
{
this->cursor--;
if (this->cursor < 0)
Expand All @@ -551,7 +552,7 @@ i32 MainMenu::ReplayHandling()
}
else if (cur > 0)
{
while (this->replayFileData[this->chosenReplay].stageScore[this->cursor] == NULL)
while (this->replayFileData[this->chosenReplay].stageReplayData[this->cursor] == NULL)
{
this->cursor++;
if (this->cursor >= 7)
Expand All @@ -560,7 +561,7 @@ i32 MainMenu::ReplayHandling()
}
}
}
if (WAS_PRESSED(TH_BUTTON_SELECTMENU) && this->currentReplay[this->cursor].stageScore)
if (WAS_PRESSED(TH_BUTTON_SELECTMENU) && this->currentReplay[this->cursor].stageReplayData)
{
g_GameManager.isInReplay = 1;
g_Supervisor.framerateMultiplier = 1.0;
Expand All @@ -569,12 +570,12 @@ i32 MainMenu::ReplayHandling()
g_GameManager.character = this->currentReplay->shottypeChara / 2;
g_GameManager.shotType = this->currentReplay->shottypeChara % 2;
cur = 0;
while (this->currentReplay->stageScore[cur] == NULL)
while (this->currentReplay->stageReplayData[cur] == NULL)
{
cur++;
}
g_GameManager.livesRemaining = this->currentReplay->stageScore[cur]->livesRemaining;
g_GameManager.bombsRemaining = this->currentReplay->stageScore[cur]->bombsRemaining;
g_GameManager.livesRemaining = this->currentReplay->stageReplayData[cur]->livesRemaining;
g_GameManager.bombsRemaining = this->currentReplay->stageReplayData[cur]->bombsRemaining;
ReplayData *uh = this->currentReplay;
free(uh);
this->currentReplay = NULL;
Expand Down Expand Up @@ -2268,10 +2269,10 @@ ZunResult MainMenu::DrawReplayMenu()
g_AsciiManager.color = COLOR_GREY;
}
}
if (this->currentReplay->stageScore[i])
if (this->currentReplay->stageReplayData[i])
{
g_AsciiManager.AddFormatText(&vmRef->pos, "%s %9d", g_StageList[i],
this->currentReplay->stageScore[i]->score);
this->currentReplay->stageReplayData[i]->score);
}
else
{
Expand Down
27 changes: 14 additions & 13 deletions src/ReplayData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace th06
{
struct ReplayDataInput
{
u32 frameNum;
i32 frameNum;
u16 inputKey;
u16 padding;
};
Expand All @@ -15,11 +15,11 @@ struct StageReplayData
{
i32 score;
i16 randomSeed;
i16 unk_6;
i8 power;
i16 pointItemsCollected;
u8 power;
i8 livesRemaining;
i8 bombsRemaining;
i8 rank;
u8 rank;
i8 powerItemCountForScore;
i8 padding[3];
ReplayDataInput replayInputs[53998];
Expand All @@ -28,21 +28,22 @@ C_ASSERT(sizeof(StageReplayData) == 0x69780);

struct ReplayData
{
char *magic;
i16 version;
char magic[4];
u16 version;
u8 shottypeChara;
u8 difficulty;
i32 checksum;
i16 paddingBytes;
u8 rngValue1;
u8 rngValue2;
i8 key;
i8 unk_f;
char date[8];
i8 unk_21;
i8 rngValue3;
char date[9];
char name[8];
i8 padding[11];
i32 score;
f32 slowdownRate2;
f32 slowdownRate;
i8 padding2[4];
StageReplayData *stageScore[7];
f32 slowdownRate3;
StageReplayData *stageReplayData[7];
};
C_ASSERT(sizeof(ReplayData) == 0x50);
}; // namespace th06
Loading
Loading