Skip to content

Instantly share code, notes, and snippets.

@camden-smallwood-zz
Created January 16, 2018 22:27
Show Gist options
  • Save camden-smallwood-zz/328d23133f650d0125ab77906eacbec7 to your computer and use it in GitHub Desktop.
Save camden-smallwood-zz/328d23133f650d0125ab77906eacbec7 to your computer and use it in GitHub Desktop.
#include "..\Blam\BlamTypes.hpp"
#include "..\Modules\ModuleTime.hpp"
#include "..\ElDorito.hpp"
#include "..\Patch.hpp"
#include "LoadingScreen.hpp"
using namespace Patches::LoadingScreen;
namespace
{
void ShowLoadingScreenHook(const char *mapPath, short unk);
void BeginLoadingHook(uint32_t totalBytes);
void UpdateLoadingProgressHook(uint32_t bytes);
void HideLoadingScreenHook();
std::shared_ptr<LoadingScreenUi> ActiveUi;
}
namespace Patches::LoadingScreen
{
void ApplyAll()
{
Hook(0x167935, ShowLoadingScreenHook, HookFlags::IsCall).Apply();
Hook(0x161E1E, BeginLoadingHook, HookFlags::IsCall).Apply();
Hook(0x2EBA07, UpdateLoadingProgressHook, HookFlags::IsCall).Apply();
Hook(0x167ABA, HideLoadingScreenHook, HookFlags::IsCall).Apply();
// Force a jump so that the loading screen never renders
Patch(0x1064E7, { 0xEB }).Apply();
// fixes a rare issue were the game wouldn't render anything before the mainmenu finished loading
// See issue #323
Patch(0x167899, { 0xEB }).Apply();
}
void SetUi(std::shared_ptr<LoadingScreenUi> ui)
{
ActiveUi = ui;
}
}
namespace
{
int prevTick1 = 60;
int prevTick2 = 60;
int prevFps = 60;
float prevDt = 1.0f / 60;
void ShowLoadingScreenHook(const char *mapPath, short unk)
{
typedef void(*ShowLoadingScreenPtr)(const char *mapPath, short unk);
auto ShowLoadingScreen = reinterpret_cast<ShowLoadingScreenPtr>(0x52EE40);
ShowLoadingScreen(mapPath, unk);
if (ActiveUi)
ActiveUi->Show(mapPath);
Pointer(0x507E2A).Write<unsigned long>(200);
Pointer(0x165C83C).Write<unsigned long>(200);
auto gameTimeGlobalsPtr = ElDorito::GetMainTls(GameGlobals::Time::TLSOffset)[0];
gameTimeGlobalsPtr(GameGlobals::Time::FpsIndex).Write<unsigned short>(200);
gameTimeGlobalsPtr(GameGlobals::Time::DTInverseIndex).Write<float>(1.0f / 200);
}
void BeginLoadingHook(uint32_t totalBytes)
{
typedef void(*BeginLoadingPtr)(uint32_t totalBytes);
auto BeginLoading = reinterpret_cast<BeginLoadingPtr>(0x711C00);
BeginLoading(totalBytes);
if (ActiveUi)
ActiveUi->Begin(totalBytes);
}
void UpdateLoadingProgressHook(uint32_t bytes)
{
typedef void(*UpdateLoadingProgressPtr)(uint32_t bytes);
auto UpdateLoadingProgress = reinterpret_cast<UpdateLoadingProgressPtr>(0x711C30);
UpdateLoadingProgress(bytes);
if (ActiveUi)
ActiveUi->UpdateProgress(bytes);
}
void HideLoadingScreenHook()
{
typedef void(*HideLoadingScreenPtr)();
auto HideLoadingScreen = reinterpret_cast<HideLoadingScreenPtr>(0x52EE20);
HideLoadingScreen();
if (ActiveUi)
ActiveUi->Hide();
Pointer(0x507E2A).Write<unsigned long>(60);
Pointer(0x165C83C).Write<unsigned long>(60);
auto gameTimeGlobalsPtr = ElDorito::GetMainTls(GameGlobals::Time::TLSOffset)[0];
gameTimeGlobalsPtr(GameGlobals::Time::FpsIndex).Write<unsigned short>(60);
gameTimeGlobalsPtr(GameGlobals::Time::DTInverseIndex).Write<float>(1.0f / 60);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment