Skip to content

Commit

Permalink
SumoUIFlashingTextFix: add workaround for flashing signed-in text
Browse files Browse the repository at this point in the history
  • Loading branch information
emoose committed Aug 20, 2024
1 parent 65cbb5e commit 50aa1f1
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
#define D3DX_DEFAULT ULONG_MAX

typedef void (*fn_0args)();
typedef void* (*fn_0args_void)();
typedef void (*fn_1arg)(int);
typedef void (*fn_2args)(int, int);
typedef void (*fn_3args)(int, int, int);
typedef int (*fn_1arg_int)(int);
typedef void (*fn_2floats)(float, float);
typedef void (*fn_printf)(const char*, ...);
typedef void (__fastcall *fn_0args_class)(void* thisptr, void* unused);

#define XINPUT_DIGITAL_LEFT_TRIGGER 0x10000
#define XINPUT_DIGITAL_RIGHT_TRIGGER 0x20000
Expand Down
55 changes: 55 additions & 0 deletions src/hooks_framerate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,59 @@

#include <d3d9.h>

class SumoUIFlashingTextFix : public Hook
{
inline static fn_0args_void SumoFrontEnd_GetSingleton = nullptr;
inline static fn_0args_class SumoFrontEnd_animate = nullptr;

// Hacky fix for the flashing "Not Signed In" / "Signed In As" text when playing above 60FPS
// Normally SumoFrontEndEvent_Ctrl calls into SumoFrontEnd_animate function, which then handles drawing the text
// SumoFrontEndEvent_Ctrl is only ran at 60FPS however, and will skip frames when running above that
// (If playing at 120FPS, 1/2 frames will skip calling EventControl, which will skip running SumoFrontEndEvent_Ctrl, and the text won't be drawn that frame)
//
// Unfortunately running SumoFrontEndEvent_Ctrl every frame makes the C2C UI speed up too
// Instead this just removes the original SumoFrontEnd_animate caller, and handles calling that function ourselves every frame instead
//
// TODO: this fixes the Not Signed In text, but there are still other flashing Sumo menus that need a fix too (eg. showroom menus), maybe there's others too?
public:
static void draw()
{
// Make sure sumo FE event is active...
uint8_t* status = Module::exe_ptr<uint8_t>(0x39FB48);
if ((status[0x195] & 0x18) == 0 && (status[0x195] & 2) != 0) // 0x195 = EVENT_SUMOFE
{
uint8_t* frontend = (uint8_t*)SumoFrontEnd_GetSingleton();
// Check we're in the right state #
if (*(int*)(frontend + 0x218) == 2)
{
SumoFrontEnd_animate(frontend, 0);
}
}
}
std::string_view description() override
{
return "SumoUIFlashingTextFix";
}

bool validate() override
{
return (Settings::FramerateLimit == 0 || Settings::FramerateLimit > 60) && Settings::FramerateUnlockExperimental;
}

bool apply() override
{
SumoFrontEnd_GetSingleton = Module::fn_ptr<fn_0args_void>(0x35F0);
SumoFrontEnd_animate = Module::fn_ptr<fn_0args_class>(0x43110);

constexpr int SumoFe_Animate_CallerAddr = 0x45C4E;
Memory::VP::Nop(Module::exe_ptr(SumoFe_Animate_CallerAddr), 5);
return true;
}

static SumoUIFlashingTextFix instance;
};
SumoUIFlashingTextFix SumoUIFlashingTextFix::instance;

class ReplaceGameUpdateLoop : public Hook
{
inline static double FramelimiterFrequency = 0;
Expand Down Expand Up @@ -150,6 +203,8 @@ class ReplaceGameUpdateLoop : public Hook
DInput_RegisterNewDevices();
}

SumoUIFlashingTextFix::draw();

for (int curUpdateIdx = 0; curUpdateIdx < numUpdates; curUpdateIdx++)
{
// Fetch latest input state
Expand Down

0 comments on commit 50aa1f1

Please sign in to comment.