Skip to content

Commit

Permalink
Support for in-game framerate limiter changes and audio config
Browse files Browse the repository at this point in the history
  • Loading branch information
andon authored and andon committed Jan 21, 2017
1 parent 9d50870 commit 71a9fa7
Show file tree
Hide file tree
Showing 12 changed files with 213 additions and 64 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 3
#define TBF_BUILD 0
#define TBF_BUILD 1
#define TBF_REV 0


Expand Down
11 changes: 11 additions & 0 deletions include/framerate.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ namespace tbf
void RenderTick (void);


// Call when re-engaging the framerate limiter to make it match
// user prefrences.
void BlipFramerate (void);

// Disable Special K's framerate limit, generally only useful
// when demonstrating what is wrong with Namco's.
void DisengageLimiter (void);

float GetTargetFrametime (void);


#if 0
//
// At key points during the game, we need to disable the code that
Expand Down
6 changes: 6 additions & 0 deletions include/render.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ namespace tbf
void Reset ( IDirect3DDevice9 *This,
D3DPRESENT_PARAMETERS *pPresentationParameters );

// Indicates whether setting changes need a device reset
struct reset_state_s {
bool textures = false;
bool graphics = false;
} extern need_reset;

class CommandProcessor : public SK_IVariableListener {
public:
CommandProcessor (void);
Expand Down
50 changes: 44 additions & 6 deletions src/framerate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ uint32_t tbf::FrameRateFix::target_fps = 0;
HMODULE tbf::FrameRateFix::bink_dll = 0;
HMODULE tbf::FrameRateFix::kernel32_dll = 0;

typedef void (*NamcoLimiter_pfn)(void);
NamcoLimiter_pfn NamcoLimiter_Original = nullptr;

typedef void* (__stdcall *BinkOpen_pfn)(const char* filename, DWORD unknown0);
BinkOpen_pfn BinkOpen_Original = nullptr;

Expand Down Expand Up @@ -172,6 +175,13 @@ CreateTimerQueueTimer_Override (
return CreateTimerQueueTimer_Original (phNewTimer, TimerQueue, Callback, Parameter, DueTime, Period, Flags);
}

void
NamcoLimiter_Detour(void)
{
if (! config.framerate.replace_limiter)
NamcoLimiter_Original ();
}

void
tbf::FrameRateFix::Init (void)
{
Expand Down Expand Up @@ -200,7 +210,7 @@ tbf::FrameRateFix::Init (void)

TBF_ApplyQueuedHooks ();

if (config.framerate.replace_limiter) {
//if (config.framerate.replace_limiter) {
/*
6D3610 0x48 0x83 0xec 0x38 ; Namco Limiter
6D3610 0xc3 0x90 0x90 0x90 ; No Limiter
Expand Down Expand Up @@ -230,16 +240,26 @@ tbf::FrameRateFix::Init (void)
if (limiter_addr != nullptr) {
//dll_log->LogEx (true, L"[FrameLimit] * Installing variable rate simulation... ");

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

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);


variable_speed_installed = true;
}
}
//}
}

void
Expand All @@ -249,13 +269,31 @@ tbf::FrameRateFix::Shutdown (void)

FreeLibrary (kernel32_dll);
FreeLibrary (bink_dll);
}

////TBF_DisableHook (pfnSK_SetPresentParamsD3D9);
// Force RevMatching when re-engaging the limiter
void
tbf::FrameRateFix::BlipFramerate (void)
{
tick_scale = 0;

if (variable_speed_installed) {
}
// A value of 0 will cause the game's preference be re-engaged.
}

void
tbf::FrameRateFix::DisengageLimiter (void)
{
SK_GetCommandProcessor ()->ProcessCommandLine ("TargetFPS 0.0");
}


float
tbf::FrameRateFix::GetTargetFrametime (void)
{
uint32_t* pTickScale =
(uint32_t *)(TBF_GetBaseAddr () + TICK_ADDR_BASE);

////TBF_DisableHook (pfnSleep);
return ( (float)(*pTickScale) * 16.6666666f );
}

//
Expand Down
10 changes: 5 additions & 5 deletions src/imgui/imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ ImGuiIO::ImGuiIO()
DisplaySize = ImVec2(-1.0f, -1.0f);
DeltaTime = 1.0f/60.0f;
IniSavingRate = 5.0f;
IniFilename = "TBFix_UI.ini";
//IniFilename = "TBFix_UI.ini";
LogFilename = "logs/ui.log";

Fonts = &GImDefaultFontAtlas;
Expand Down Expand Up @@ -2143,7 +2143,7 @@ void ImGui::NewFrame()
IM_PLACEMENT_NEW(g.LogClipboard) ImGuiTextBuffer();

IM_ASSERT(g.Settings.empty());
LoadIniSettingsFromDisk(g.IO.IniFilename);
//LoadIniSettingsFromDisk(g.IO.IniFilename);
g.Initialized = true;
}

Expand Down Expand Up @@ -2250,8 +2250,8 @@ void ImGui::NewFrame()
if (g.SettingsDirtyTimer > 0.0f)
{
g.SettingsDirtyTimer -= g.IO.DeltaTime;
if (g.SettingsDirtyTimer <= 0.0f)
SaveIniSettingsToDisk(g.IO.IniFilename);
//if (g.SettingsDirtyTimer <= 0.0f)
//SaveIniSettingsToDisk(g.IO.IniFilename);
}

// Find the window we are hovering. Child windows can extend beyond the limit of their parent so we need to derive HoveredRootWindow from HoveredWindow
Expand Down Expand Up @@ -2378,7 +2378,7 @@ void ImGui::Shutdown()
if (!g.Initialized)
return;

SaveIniSettingsToDisk(g.IO.IniFilename);
//SaveIniSettingsToDisk(g.IO.IniFilename);

for (int i = 0; i < g.Windows.Size; i++)
{
Expand Down
3 changes: 0 additions & 3 deletions src/imgui/imgui_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// You can call ImGui::ShowTestWindow() in your code to learn about various features of ImGui.
// Everything in this file will be stripped out by the linker if you don't call ImGui::ShowTestWindow().

#if 0
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
#define _CRT_SECURE_NO_WARNINGS
#endif
Expand Down Expand Up @@ -2636,6 +2635,4 @@ void ImGui::ShowTestWindow(bool*) {}
void ImGui::ShowUserGuide() {}
void ImGui::ShowStyleEditor(ImGuiStyle*) {}

#endif

#endif
11 changes: 9 additions & 2 deletions src/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1464,9 +1464,13 @@ tbf::RenderFix::Reset ( IDirect3DDevice9 *This,
if (pending_loads ())
TBFix_LoadQueuedTextures ();

tex_mgr.reset ();
tex_mgr.reset ();

need_reset.textures = false;
}

need_reset.graphics = false;

vs_checksums.clear ();
ps_checksums.clear ();

Expand Down Expand Up @@ -1934,4 +1938,7 @@ volatile ULONG tbf::RenderFix::dwRenderThreadID = 0UL;
IDirect3DSurface9* tbf::RenderFix::pPostProcessSurface = nullptr;
bool tbf::RenderFix::bink = false;

HMODULE tbf::RenderFix::user32_dll = 0;
HMODULE tbf::RenderFix::user32_dll = 0;

tbf::RenderFix::reset_state_s
tbf::RenderFix::need_reset;
Loading

0 comments on commit 71a9fa7

Please sign in to comment.