Skip to content

Commit

Permalink
Fix font functions and add watermark
Browse files Browse the repository at this point in the history
  • Loading branch information
TheIndra55 committed Jan 24, 2024
1 parent b5cd5bd commit 096e963
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 7 deletions.
15 changes: 15 additions & 0 deletions src/game/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ struct MemCardInfo;
struct Level;
struct VertexPool;

enum MainState
{
MS_NONE,
MS_PLAYGAME,
MS_LOADLEVEL,
MS_PLAY_CINEMATIC,
MS_SAMPLER_DEMO_DONE,
MS_ATTRACT_MODE,
MS_DISPLAY_MAIN_MENU,
MS_SHOW_STATIC_SCREEN,
MS_QUITGAME,
MS_PLAY_DARKCHRONICLE_CINEMATIC,
MS_PLAY_DARKCHRONICLE_CINEMATICMOVIE,
};

struct WipeInfo
{
float wipeCur;
Expand Down
15 changes: 15 additions & 0 deletions src/modules/MainMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "MainMenu.h"
#include "level/Stream.h"
#include "game/Game.h"
#include "util/Hooking.h"
#include "render/Font.h"

void MainMenu::OnDraw()
{
Expand Down Expand Up @@ -45,4 +47,17 @@ void MainMenu::BirthObject(char* name)

// Birth the instance at the player position
INSTANCE_BirthObjectNoParent(game->StreamUnitID, &player->position, &player->rotation, nullptr, tracker->object, 0, 1);
}

void MainMenu::OnFrame()
{
auto mainState = *(int*)GET_ADDRESS(0x10E5868, 0x838838, 0x000000);

if (mainState == MS_DISPLAY_MAIN_MENU)
{
auto font = Font::GetMainFont();

font->SetCursor(5.f, 430.f);
font->Print("TRLAU-Menu-Hook");
}
}
1 change: 1 addition & 0 deletions src/modules/MainMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ class MainMenu : public Module

public:
void OnDraw();
void OnFrame();
};
27 changes: 20 additions & 7 deletions src/render/Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,28 @@ char Font::s_formatted[1024];

Font* Font::GetMainFont()
{
return *(Font**)0x7D1800;
return *(Font**)GET_ADDRESS(0x107F680, 0x7D1800, 0x9DE6D4);
}

void Font::SetCursor(float x, float y)
{
Hooking::Call(0x433C70, x, y);
auto addr = GET_ADDRESS(0x431670, 0x433C70, 0x474C90);

Hooking::Call(addr, x, y);
}

void Font::GetCursor(float* x, float* y)
{
Hooking::Call(0x433C90, x, y);
auto addr = GET_ADDRESS(0x431690, 0x433C90, 0x474CB0);

Hooking::Call(addr, x, y);
}

void Font::SetScale(float scaleX, float scaleY)
{
Hooking::Call(0x433E60, scaleX, scaleY);
auto addr = GET_ADDRESS(0x431860, 0x433E60, 0x000000);

Hooking::Call(addr, scaleX, scaleY);
}

void Font::Print(const char* fmt, ...)
Expand Down Expand Up @@ -69,19 +75,26 @@ void Font::PrintCentered(const char* fmt, ...)

void Font::PrintFormatted(const char* formatted, int backdrop)
{
Hooking::ThisCall(0x434A70, this, formatted, backdrop);
auto addr = GET_ADDRESS(0x4323D0, 0x434A70, 0x476BC0);

Hooking::ThisCall(addr, this, formatted, backdrop);
}

float Font::GetTextWidth(const char* text)
{
return Hooking::ThisCallReturn<float>(0x434510, this, text);
auto addr = GET_ADDRESS(0x431EA0, 0x434510, 0x000000);

return Hooking::ThisCallReturn<float>(addr, this, text);
}

void Font::OnFlush(std::function<void()> callback)
{
if (!s_callback)
{
MH_CreateHook((void*)0x434C40, Flush, (void**)&s_Flush);
// TODO pattern
auto addr = GET_ADDRESS(0x432570, 0x434C40, 0x476D80);

MH_CreateHook((void*)addr, Flush, (void**)&s_Flush);
MH_EnableHook(MH_ALL_HOOKS);
}

Expand Down

0 comments on commit 096e963

Please sign in to comment.