Skip to content

Commit

Permalink
Framerate limiter works again
Browse files Browse the repository at this point in the history
  • Loading branch information
andon authored and andon committed Jan 27, 2017
1 parent 5528463 commit 370bdd0
Show file tree
Hide file tree
Showing 7 changed files with 321 additions and 75 deletions.
2 changes: 1 addition & 1 deletion include/DLL_VERSION.H
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#define TBF_MAJOR 0
#define TBF_MINOR 4
#define TBF_BUILD 1
#define TBF_BUILD 2
#define TBF_REV 0


Expand Down
1 change: 1 addition & 0 deletions include/scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <stdint.h>

void* TBF_Scan (uint8_t* pattern, size_t len, uint8_t* mask = nullptr);
void* TBF_ScanEx (uint8_t* pattern, size_t len, uint8_t* mask, void* after);
uintptr_t TBF_GetBaseAddr (void);

#endif /* __TBF__SCANNER_H__ */
16 changes: 15 additions & 1 deletion src/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,23 @@ SKPlugIn_Init (HMODULE hModSpecialK)
//tbf::FileIO::Init ();
//tbf::SteamFix::Init ();
tbf::RenderFix::Init ();
tbf::FrameRateFix::Init ();
//tbf::KeyboardFix::Init ();


CreateThread ( nullptr, 0,
[](LPVOID user) ->
DWORD {
// Wait for Denuvo to finish its thing...
Sleep (15000UL);
tbf::FrameRateFix::Init ();

CloseHandle (GetCurrentThread ());

return 0;
},
nullptr, 0x00, nullptr );


// Uncomment this when spawning a thread
//CoUninitialize ();
}
Expand Down
101 changes: 45 additions & 56 deletions src/framerate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
// @TODO: Develop a heuristic to scan for this memory address;
// hardcoding it is going to break stuff :)
//
uintptr_t TICK_ADDR_BASE = 0xB1B074;
uintptr_t TICK_ADDR_BASE = 0xB15074;//0xB1B074;

int32_t tbf::FrameRateFix::tick_scale = INT32_MAX; // 0 FPS

Expand Down Expand Up @@ -210,73 +210,62 @@ tbf::FrameRateFix::Init (void)

TBF_ApplyQueuedHooks ();

//if (config.framerate.replace_limiter) {
/*
6D3610 0x48 0x83 0xec 0x38 ; Namco Limiter
6D3610 0xc3 0x90 0x90 0x90 ; No Limiter
//Tales of Berseria.Kaim::Thread::`default constructor closure'+251F60 - 48 83 EC 38 - sub rsp,38 { 56 }
//Tales of Berseria.Kaim::Thread::`default constructor closure'+251F64 - 8B 0D 3A691FFF - mov ecx,["Tales of Berseria.exe"+B15074] { [1104.03] }

Tales of Berseria.exe+6D3610 - 48 83 EC 38 - sub rsp,38 { 56 }

0x48 0x83 0xec 0x38 0x8b 0x0d -------- 0x85 0xc9
*/
uint8_t sig [] = { 0x48, 0x83, 0xec, 0x38, 0X8B, 0x0d, 0x3A, 0x69, 0x1F, 0xFF, 0x85, 0xc9 };
uint8_t mask [] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff };

uint8_t sig [] = { 0x48, 0x83, 0xec, 0x38,
0x8b, 0x0d, 0xff, 0xff, 0xff, 0xff,
0x85, 0xc9 };
uint8_t mask [] = { 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0xff, 0xff };
void* limiter_addr =
TBF_Scan (sig, sizeof (sig), mask);

void* limiter_addr =
TBF_Scan (sig, sizeof (sig), mask);

if (limiter_addr != nullptr) {
dll_log->Log ( L"[FrameLimit] Scanned Namco's Framerate Limit Bug Address: %ph",
limiter_addr );
} else {
dll_log->Log (L"[FrameLimit] >> ERROR: Unable to find Framerate Limiter code!");
}
if (limiter_addr != nullptr) {
dll_log->Log ( L"[FrameLimit] Scanned Namco's Framerate Limit Bug Address: %ph",
limiter_addr );
} else {
dll_log->Log (L"[FrameLimit] >> ERROR: Unable to find Framerate Limiter code!");
}

if (limiter_addr != nullptr) {
//dll_log->LogEx (true, L"[FrameLimit] * Installing variable rate simulation... ");
if (limiter_addr != nullptr) {
//dll_log->LogEx (true, L"[FrameLimit] * Installing variable rate simulation... ");

#if 0
uint8_t disable_inst [] = { 0xc3, 0x90, 0x90, 0x90 };
uint8_t disable_inst [] = { 0xc3, 0x90, 0x90, 0x90 };

TBF_InjectMachineCode ( limiter_addr,
disable_inst,
sizeof (disable_inst),
PAGE_EXECUTE_READWRITE );
TBF_InjectMachineCode ( limiter_addr,
disable_inst,
sizeof (disable_inst),
PAGE_EXECUTE_READWRITE );

#endif

TBF_CreateFuncHook ( L"NamcoLimiter",
limiter_addr,
NamcoLimiter_Detour,
(LPVOID *)&NamcoLimiter_Original );
TBF_EnableHook (limiter_addr);


MEMORY_BASIC_INFORMATION minfo;
DWORD* pTickAddr =
(DWORD *)(TBF_GetBaseAddr () + TICK_ADDR_BASE);

VirtualQuery (pTickAddr, &minfo, sizeof (minfo));

if ( (minfo.Protect & PAGE_READWRITE) &&
*pTickAddr <= 2 )
{
variable_speed_installed = true;
}

else if (config.framerate.replace_limiter)
{
SK_GetCommandProcessor ()->ProcessCommandFormatted (
"TargetFPS %f",
60.0f );
}
}
//}
TBF_CreateFuncHook ( L"NamcoLimiter",
limiter_addr,
NamcoLimiter_Detour,
(LPVOID *)&NamcoLimiter_Original );
TBF_EnableHook (limiter_addr);


DWORD* pTickAddr =
(DWORD *)(TBF_GetBaseAddr () + TICK_ADDR_BASE);

__try
{
if ( *pTickAddr <= 2 )
{
variable_speed_installed = true;
}
}

__except ( ( GetExceptionCode () == EXCEPTION_ACCESS_VIOLATION ) ?
EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH )
{
dll_log->Log ( L"[Import Tbl] Access Violation While Attempting to "
L"Install Variable Rate Limiter." );
}
}
}

void
Expand Down
37 changes: 26 additions & 11 deletions src/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,22 +585,37 @@ D3D9EndScene_Detour (IDirect3DDevice9* This)
=
(SKX_DrawExternalOSD_pfn)GetProcAddress (hMod, "SKX_DrawExternalOSD");

extern bool __show_cache;
static DWORD dwFirstTime = timeGetTime ();
static bool show_disclaimer = true;

if (__show_cache) {
static std::string output;
if (show_disclaimer)
{
if (timeGetTime() > dwFirstTime + 10000UL)
show_disclaimer = false;

SKX_DrawExternalOSD ("ToBFix", "Press Ctrl + Shift + O to toggle In-Game OSD\n"
"Press Ctrl + Shift + Backspace to access In-Game Config Menu");
}

output = "Texture Cache\n";
output += "-------------\n";
output += tbf::RenderFix::tex_mgr.osdStats ();
else
{
extern bool __show_cache;

output += mod_text;
if (__show_cache) {
static std::string output;

SKX_DrawExternalOSD ("ToBFix", output.c_str ());
output = "Texture Cache\n";
output += "-------------\n";
output += tbf::RenderFix::tex_mgr.osdStats ();

output = "";
} else
SKX_DrawExternalOSD ("ToBFix", mod_text.c_str ());
output += mod_text;

SKX_DrawExternalOSD ("ToBFix", output.c_str ());

output = "";
} else
SKX_DrawExternalOSD ("ToBFix", mod_text.c_str ());
}

mod_text = "";

Expand Down
Loading

0 comments on commit 370bdd0

Please sign in to comment.