Skip to content

Commit

Permalink
show version in options screen
Browse files Browse the repository at this point in the history
  • Loading branch information
ianpatt committed Sep 1, 2023
1 parent f5f748b commit 53950fd
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sfse/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ source_group(
source_group(
${PROJECT_NAME}/hooks
FILES
Hooks_Version.cpp
Hooks_Version.h
)

source_group(
Expand Down
44 changes: 44 additions & 0 deletions sfse/Hooks_Version.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "Hooks_Version.h"
#include "sfse_common/SafeWrite.h"
#include "sfse_common/sfse_version.h"
#include "sfse_common/Errors.h"
#include "sfse_common/BranchTrampoline.h"
#include "sfse_common/Relocation.h"
#include "xbyak/xbyak.h"
#include <cstring>

const char * kHook_ShowVersion_FormatString =
"%08x v%s [SFSE " __PREPRO_TOKEN_STR__(SFSE_VERSION_INTEGER) "."
__PREPRO_TOKEN_STR__(SFSE_VERSION_INTEGER_MINOR) "."
__PREPRO_TOKEN_STR__(SFSE_VERSION_INTEGER_BETA) "]";
RelocAddr <uintptr_t> kHook_ShowVersion_Offset(0x02079A7D);

void Hooks_Version_Apply()
{
// show SFSE version in menu
{
struct ShowVersion_Code: Xbyak::CodeGenerator {
ShowVersion_Code(void * buf) : Xbyak::CodeGenerator(4096, buf)
{
Xbyak::Label retnLabel;
Xbyak::Label dataLabel;

mov(rdx, ptr[rip + dataLabel]);
jmp(ptr[rip + retnLabel]);

L(retnLabel);
dq(kHook_ShowVersion_Offset.getUIntPtr() + 0x7);

L(dataLabel);
dq(uintptr_t(kHook_ShowVersion_FormatString));
}
};

void * codeBuf = g_localTrampoline.startAlloc();
ShowVersion_Code code(codeBuf);
g_localTrampoline.endAlloc(code.getCurr());

g_branchTrampoline.write6Branch(kHook_ShowVersion_Offset.getUIntPtr(), uintptr_t(code.getCode()));
safeWrite8(kHook_ShowVersion_Offset.getUIntPtr() + 6, 0x90);
}
}
3 changes: 3 additions & 0 deletions sfse/Hooks_Version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

void Hooks_Version_Apply();
4 changes: 4 additions & 0 deletions sfse/sfse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "sfse_common/BranchTrampoline.h"
#include "PluginManager.h"

#include "Hooks_Version.h"

HINSTANCE g_moduleHandle = nullptr;

void SFSE_Preinit();
Expand Down Expand Up @@ -136,6 +138,8 @@ void SFSE_Initialize()
g_pluginManager.installPlugins(PluginManager::kPhase_Preload);
g_pluginManager.loadComplete();

Hooks_Version_Apply();

FlushInstructionCache(GetCurrentProcess(), NULL, 0);

_MESSAGE("init complete");
Expand Down

0 comments on commit 53950fd

Please sign in to comment.