Skip to content

Commit

Permalink
Add no death fade
Browse files Browse the repository at this point in the history
  • Loading branch information
TheIndra55 committed Feb 17, 2024
1 parent e0c86f3 commit 9ae57ed
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/game/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ void GAMELOOP_RequestLevelChangeByName(char* name, GameTracker* gameTracker, int
Hooking::Call(addr, name, gameTracker, doneType);
}

bool GAMELOOP_IsWipeDone(int type)
{
auto addr = GET_ADDRESS(0x450310, 0x452970, 0x52E880);

return Hooking::CallReturn<bool>(addr, type);
}

void GAMELOOP_SetScreenWipe(int type, int target, int time)
{
auto addr = GET_ADDRESS(0x4503D0, 0x452A30, 0x52E8B0);

Hooking::Call(addr, type, target, time);
}

void PLAYER_DebugSwitchPlayerCharacter()
{
auto addr = GET_ADDRESS(0x5A40B0, 0x5A39A0, 0x79DB50);
Expand Down
2 changes: 2 additions & 0 deletions src/game/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ class Game
};

void GAMELOOP_RequestLevelChangeByName(char* name, GameTracker* gameTracker, int doneType);
bool GAMELOOP_IsWipeDone(int type);
void GAMELOOP_SetScreenWipe(int type, int target, int time);

void PLAYER_DebugSwitchPlayerCharacter();
int OBTABLE_GetObjectID(char* name);
Expand Down
6 changes: 4 additions & 2 deletions src/modules/MainMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ void MainMenu::OnDraw()
BirthObject(object);
}

#ifndef TR8
// Player
if (ImGui::CollapsingHeader("Player"))
{
#ifndef TR8
// Fill 'er up
if (ImGui::Button("Fill 'er up"))
{
Expand Down Expand Up @@ -76,9 +76,11 @@ void MainMenu::OnDraw()
*flags &= ~0x80;
}
}
}
#endif

ImGui::Checkbox("No death fade", &m_noDeathFade);
}

// Time
if (ImGui::CollapsingHeader("Time"))
{
Expand Down
3 changes: 3 additions & 0 deletions src/modules/MainMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ class MainMenu : public Module
{
private:
bool m_switchPlayerNextFrame = false;
bool m_noDeathFade = false;

Option<bool> m_noWatermark{ "NoWatermark", false };

void BirthObject(char* name);
void SwitchPlayerCharacter(char* name = nullptr);

public:
bool IsNoDeathFade() { return m_noDeathFade; }

void OnDraw();
void OnFrame();
void OnLoop();
Expand Down
43 changes: 42 additions & 1 deletion src/modules/Patches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
#include "Patches.h"
#include "util/Hooking.h"
#include "game/Game.h"
#include "MainMenu.h"

// Instance of patches so we can get it in our hooks without calling GetModule<T>
static Patches* s_patches;
static MainMenu* s_menu;

#ifndef TR8
// Original functions
Expand Down Expand Up @@ -40,9 +42,40 @@ static void GAMELOOP_HandleScreenWipes()
}
#endif

// No death fade code
int(__stdcall* s_DeathState_Entry)(int player, int data);
void(__stdcall* s_DeathState_Process)(int player, int data);

static int __stdcall DeathState_Entry(int player, int data)
{
auto ret = s_DeathState_Entry(player, data);

if (!s_menu->IsNoDeathFade())
{
// We NOPed the original code, so we call the wipe manually
// like the game code does
if (GAMELOOP_IsWipeDone(10))
{
// TODO refactor, 90 is not a constant value in the game code
GAMELOOP_SetScreenWipe(10, 100, 90);
}
}

return ret;
}

static void __stdcall DeathState_Process(int player, int data)
{
if (!s_menu->IsNoDeathFade())
{
s_DeathState_Process(player, data);
}
}

Patches::Patches()
{
s_patches = this;
s_menu = Hook::GetInstance().GetModule<MainMenu>().get();

#ifndef TR8
if (m_disableIntro.GetValue())
Expand All @@ -53,8 +86,16 @@ Patches::Patches()
// Insert hooks
MH_CreateHook((void*)GET_ADDRESS(0x40CA80, 0x43AB40, 0x000000), RenderG2_MotionBlur, (void**)&s_RenderG2_MotionBlur);
MH_CreateHook((void*)GET_ADDRESS(0x450430, 0x452A90, 0x000000), GAMELOOP_HandleScreenWipes, (void**)&s_GAMELOOP_HandleScreenWipes);
MH_EnableHook(MH_ALL_HOOKS);
#endif

// Insert DeathState hooks
MH_CreateHook((void*)GET_ADDRESS(0x55DEC0, 0x5581D0, 0x75AA50), DeathState_Entry, (void**)&s_DeathState_Entry);
MH_CreateHook((void*)GET_ADDRESS(0x56EC70, 0x5699C0, 0x75AF90), DeathState_Process, (void**)&s_DeathState_Process);

// NOP the original death wipe code in DeathState::Entry
Hooking::Nop((void*)GET_ADDRESS(0x55E188, 0x5584DC, 0x75AEDE), 5);

MH_EnableHook(MH_ALL_HOOKS);
}

void Patches::RemoveIntro()
Expand Down

0 comments on commit 9ae57ed

Please sign in to comment.