Skip to content

Commit c8a2ae4

Browse files
committed
TH06NC: make a mockery of Steam
1 parent 57cd332 commit c8a2ae4

3 files changed

Lines changed: 68 additions & 5 deletions

File tree

‎thprac/src/thprac_hook.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,11 @@ struct PatchBufferImpl {
375375
: ptr(str.str)
376376
, size(str.size)
377377
{}
378+
379+
inline constexpr PatchBufferImpl(void* ptr_, size_t size_)
380+
: ptr(ptr_)
381+
, size(size_)
382+
{}
378383
};
379384

380385
struct PatchHookImpl {

‎thprac/src/thprac_th06nc.cpp‎

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <imgui_impl_dx11.h>
44
#include "wininternal.h"
55

6+
#include <inttypes.h>
7+
68
using namespace TH06;
79
using std::pair;
810

@@ -2367,10 +2369,6 @@ namespace TH06NC {
23672369
return 1.15f * GetWindowSize().x / 1280.f;
23682370
}
23692371

2370-
2371-
2372-
2373-
23742372
HOOKSET_DEFINE(THMainHooks)
23752373

23762374
// Prac Menu UX
@@ -2885,7 +2883,46 @@ namespace TH06NC {
28852883
thPracParam.Reset();
28862884
}
28872885

2886+
auto Fake_SteamInternal_InitContext(uintptr_t o) {
2887+
static uintptr_t(*fake_funcs[])() = {
2888+
[]() -> uintptr_t { return 1; }, []() -> uintptr_t { return 1; },
2889+
[]() -> uintptr_t { return 1; }, []() -> uintptr_t { return 1; },
2890+
[]() -> uintptr_t { return 1; }, []() -> uintptr_t { return 1; },
2891+
[]() -> uintptr_t { return 1; }, []() -> uintptr_t { return 1; },
2892+
[]() -> uintptr_t { return 1; }, []() -> uintptr_t { return 1; },
2893+
};
2894+
2895+
log_printf("Fake_SteamIntenal_InitContext call: 0x%" PRIxPTR "\r\n", o);
2896+
2897+
static auto* fake_vtable = &fake_funcs;
2898+
static auto* fake_class = &fake_vtable;
2899+
return &fake_class;
2900+
}
2901+
2902+
static constinit auto th06nc_fake_steam_patchbuf = &Fake_SteamInternal_InitContext;
2903+
2904+
// Could be hooks, but they're good enough as patches, so patches it is
2905+
HOOKSET_DEFINE(THFakeSteamHook)
2906+
{
2907+
.addr = STEAM_CONTEXTINIT_IAT,
2908+
.data = PatchBufferImpl(&th06nc_fake_steam_patchbuf, sizeof(th06nc_fake_steam_patchbuf))
2909+
},
2910+
PATCH_DY(, GET_CONTROLLERTYPE_STEAM, "B801000000C3")
2911+
HOOKSET_ENDDEF()
2912+
28882913
HOOKSET_DEFINE(THInitHook)
2914+
EHOOK_DY(th06nc_steam_init_failed, STEAM_INIT_FAILED, 6, {
2915+
// TODO: find a good way to not have to hardcode this
2916+
memcpy(((std_string*)LANG_CODE_ADDR)->_Bx._Buf, SIZED("en"));
2917+
2918+
// Needs to be an allocation because the game will try to free it
2919+
*(uintptr_t*)STEAM_CALLBACK_ADDR = OPERATOR_NEW(0x28);
2920+
2921+
EnableAllHooksVersion(THFakeSteamHook);
2922+
2923+
pCtx->Rax = 0;
2924+
pCtx->Rip = STEAM_INIT_FAILED_RET;
2925+
})
28892926
EHOOK_DY(th06nc_gui_init_main, GUI_INIT_MAIN, 1, { // main menu ontick (TODO: TEST THIS)
28902927
THGuiCreate();
28912928
self->Disable();
@@ -2901,6 +2938,12 @@ namespace TH06NC {
29012938

29022939

29032940
void TH06NC_Init(TH06NC::VERSION ver) {
2941+
// TODO: the launcher already has to associate a Steam AppId with every game,
2942+
// and SteamAppId is only part of the LauncherGame struct. Should SteamAppId
2943+
// be moved into the GameVersion struct, or is doing this in every game init
2944+
// function fine?
2945+
SetEnvironmentVariableW(L"SteamAppId", L"4659620");
2946+
29042947
ingame_image_base = (uintptr_t)CurrentPeb()->ImageBaseAddress;
29052948
SetupGameVersion(ver);
29062949
TH06NC::EnableAllHooksVersion(THInitHook);

‎thprac/src/thprac_th06nc.h‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ namespace TH06NC {
8585
X(VSYNC_FLAG_SET, 0x982a7, 0x9a017) \
8686
X(POST_RENDER_FINISH, 0x259b9a, 0x25baaa) \
8787
X(GUI_INIT_LAUNCH, 0x270725, 0x2724d5) \
88+
X(STEAM_INIT_FAILED, 0x678CB, 0x68FDB) \
89+
X(STEAM_CONTEXTINIT_IAT, 0x2C0630, 0x2F5428) \
90+
X(GET_CONTROLLERTYPE_STEAM, 0x67BC0, 0x692D0) \
8891

8992
#define HK_ENUM(name, ...) name,
9093
enum HOOKS { HOOK_LIST(HK_ENUM) };
@@ -125,6 +128,7 @@ namespace TH06NC {
125128
X(MENU_SET_SUBSHOT_SEL_STATE, 0x4be03, 0x4d563) \
126129
X(BOMB_INPUT_CHECK_PASS, 0x68a11, 0x6a121) \
127130
X(BOMB_INPUT_CHECK_FAIL, 0x68ad2, 0x6a1e2) \
131+
X(STEAM_INIT_FAILED_RET, 0x678EC, 0x68FFB) \
128132

129133
#define IS_VAR(name, ...) uintptr_t name;
130134
INST_LIST(IS_VAR)
@@ -209,6 +213,8 @@ namespace TH06NC {
209213
X(IS_SHIFT_HELD, 0xc21f9a, 0xc6e1ba) \
210214
X(FPS_LIMITER_CONSTANT, 0xc22100, 0xc6e320) \
211215
X(SAVE_REPLAY_MENU_PTR_ADDR, 0xc22158, 0xc6e378) \
216+
X(STEAM_CALLBACK_ADDR, 0xC22140, 0xC6E360) \
217+
X(LANG_CODE_ADDR, 0x4FF380, 0x549FD0) \
212218

213219
#define AD_VAR(name, ...) uintptr_t name;
214220
ADDR_LIST(AD_VAR)
@@ -242,6 +248,7 @@ namespace TH06NC {
242248
X(void, BGM_RESUME, 0xc8110, 0xc9df0) \
243249
X(void, BGM_PAUSE, 0xcce50, 0xceb30) \
244250
X(bool, RUN_ALL_ON_TICK, 0x3be80, 0x3d700) \
251+
X(uintptr_t,OPERATOR_NEW, 0x2BCF40, 0x2C01C0) \
245252

246253
template <typename R = void>
247254
struct Function {
@@ -375,7 +382,15 @@ namespace TH06NC {
375382

376383

377384
//-------------------------------------------------------------------------
378-
// Structs ----------------------------------------------------------------
385+
// Structs ----------------------------------------------------------------
386+
struct std_string {
387+
union _String_val {
388+
char _Buf[0x10];
389+
char* _Ptr;
390+
} _Bx;
391+
size_t _Mylen;
392+
size_t _Myres;
393+
};
379394

380395
constexpr uint8_t DIFFS = 0x5;
381396
constexpr uint8_t SHOTS = 0x4;

0 commit comments

Comments
 (0)