Skip to content
Open
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
6 changes: 6 additions & 0 deletions mc2hook/mc2hook/age/gfx/font.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "font.h"

void gfxFont::DrawFont(int x, int y, const char* string, void* a4)
{
hook::StaticThunk<0x5F9E40>::Call<void>(x, y, string, a4);
}
8 changes: 8 additions & 0 deletions mc2hook/mc2hook/age/gfx/font.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once
#include <mc2hook\mc2hook.h>

class gfxFont
{
public:
static void DrawFont(int x, int y, const char* string, void* a4);
};
4 changes: 4 additions & 0 deletions mc2hook/mc2hook/age/gfx/pipeline.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "pipeline.h"

declfield(gfxPipeline::m_iWidth) = 0x674FAC;
declfield(gfxPipeline::m_iHeight) = 0x674FB0;
9 changes: 9 additions & 0 deletions mc2hook/mc2hook/age/gfx/pipeline.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once
#include <mc2hook\mc2hook.h>

class gfxPipeline
{
public:
static hook::TypeProxy<int> m_iWidth;
static hook::TypeProxy<int> m_iHeight;
};
29 changes: 29 additions & 0 deletions mc2hook/mc2hook/handlers/FPSCounterHandler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "FPSCounterHandler.h"
#include <age/gfx/font.h>
#include <age/gfx/pipeline.h>

declfield(FPSCounterHandler::s_FrameTime) = 0x858348;

char fpsString[64];
float fps;

void FPSCounterHandler::DrawFontHook(int x, int y, void* a3, void* a4)
{
fps = 1000.0f / s_FrameTime; // Originally in the code it divides 1010.0f?
sprintf(fpsString, "%.0f", fps);
gfxFont::DrawFont(gfxPipeline::m_iWidth - (8 * strlen(fpsString) + 40), y, fpsString, a4);
}

void FPSCounterHandler::Install()
{
bool enableFPSCounter = HookConfig::GetBool("Graphics", "EnableFPSCounter", false);

if (enableFPSCounter)
{
mem::write(0x858330, static_cast<int>(1)); // Forces -frametime on
InstallCallback("FPS Counter", "FPS Counter",
&DrawFontHook, {
cb::call(0x5ED1A1)
});
}
}
11 changes: 11 additions & 0 deletions mc2hook/mc2hook/handlers/FPSCounterHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once
#include <mc2hook\mc2hook.h>

class FPSCounterHandler
{
private:
static hook::TypeProxy<float> s_FrameTime;
public:
void DrawFontHook(int x, int y, void* a3, void* a4);
static void Install();
};
2 changes: 2 additions & 0 deletions mc2hook/mc2hook/handlers/handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <handlers\InputHandler.h>
#include <handlers\BorderlessHandler.h>
#include <handlers\ReflectionFidelityHandler.h>
#include <handlers\FPSCounterHandler.h>

#include <handlers\StateResearchHook.h>

Expand Down Expand Up @@ -50,6 +51,7 @@ static void InstallMainHandlers()
InstallHandler<ChatHandler>("Chat Handler");
InstallHandler<InitHandler>("Game Init Handler");
InstallHandler<ReflectionFidelityHandler>("Reflection Fidelity Handller");
InstallHandler<FPSCounterHandler>("FPS Counter Handler");

InstallHandler<StateResearchHook>("SRH");
}
6 changes: 6 additions & 0 deletions mc2hook/mc2hook/mc2hook.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@
<ClInclude Include="age\data\refcount.h" />
<ClInclude Include="age\data\stack.h" />
<ClInclude Include="age\data\timemgr.h" />
<ClInclude Include="age\gfx\font.h" />
<ClInclude Include="age\gfx\pipeline.h" />
<ClInclude Include="age\gfx\rstate.h" />
<ClInclude Include="age\input\input.h" />
<ClInclude Include="age\input\keyboard.h" />
Expand Down Expand Up @@ -192,6 +194,7 @@
<ClInclude Include="handlers\CustomExceptionHandler.h" />
<ClInclude Include="handlers\CustomVehicleHandler.h" />
<ClInclude Include="handlers\FontCrashFixHandler.h" />
<ClInclude Include="handlers\FPSCounterHandler.h" />
<ClInclude Include="handlers\handlers.h" />
<ClInclude Include="handlers\HybridFileMethodsHandler.h" />
<ClInclude Include="handlers\InputHandler.h" />
Expand Down Expand Up @@ -224,6 +227,8 @@
<ClCompile Include="age\data\asset.cpp" />
<ClCompile Include="age\data\stack.cpp" />
<ClCompile Include="age\data\timemgr.cpp" />
<ClCompile Include="age\gfx\font.cpp" />
<ClCompile Include="age\gfx\pipeline.cpp" />
<ClCompile Include="age\gfx\rstate.cpp" />
<ClCompile Include="age\input\input.cpp" />
<ClCompile Include="age\input\keyboard.cpp" />
Expand All @@ -245,6 +250,7 @@
<ClCompile Include="handlers\CustomExceptionHandler.cpp" />
<ClCompile Include="handlers\CustomVehicleHandler.cpp" />
<ClCompile Include="handlers\FontCrashFixHandler.cpp" />
<ClCompile Include="handlers\FPSCounterHandler.cpp" />
<ClCompile Include="handlers\HybridFileMethodsHandler.cpp" />
<ClCompile Include="handlers\InputHandler.cpp" />
<ClCompile Include="handlers\PathHandler.cpp" />
Expand Down
18 changes: 18 additions & 0 deletions mc2hook/mc2hook/mc2hook.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,15 @@
<ClInclude Include="handlers\ReflectionFidelityHandler.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="age\gfx\font.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="age\gfx\pipeline.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="handlers\FPSCounterHandler.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
Expand Down Expand Up @@ -341,5 +350,14 @@
<ClCompile Include="handlers\ReflectionFidelityHandler.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="age\gfx\font.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="age\gfx\pipeline.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="handlers\FPSCounterHandler.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>