Skip to content

Commit

Permalink
Merge branch 'main' into autohook/audio.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
GeckoEidechse authored Aug 27, 2024
2 parents 4fe4cdc + dafd7ab commit d388739
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 32 deletions.
26 changes: 12 additions & 14 deletions primedev/client/clientauthhooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,21 @@
#include "client/r2client.h"
#include "core/vanilla.h"

AUTOHOOK_INIT()

ConVar* Cvar_ns_has_agreed_to_send_token;

// mirrored in script
const int NOT_DECIDED_TO_SEND_TOKEN = 0;
const int AGREED_TO_SEND_TOKEN = 1;
const int DISAGREED_TO_SEND_TOKEN = 2;

// clang-format off
AUTOHOOK(AuthWithStryder, engine.dll + 0x1843A0,
void, __fastcall, (void* a1))
// clang-format on
static void (*__fastcall o_pAuthWithStryder)(void* a1) = nullptr;
static void __fastcall h_AuthWithStryder(void* a1)
{
// don't attempt to do Atlas auth if we are in vanilla compatibility mode
// this prevents users from joining untrustworthy servers (unless they use a concommand or something)
if (g_pVanillaCompatibility->GetVanillaCompatibility())
{
AuthWithStryder(a1);
o_pAuthWithStryder(a1);
return;
}

Expand All @@ -38,28 +34,30 @@ void, __fastcall, (void* a1))
*g_pLocalPlayerOriginToken = 0;
}

AuthWithStryder(a1);
o_pAuthWithStryder(a1);
}

char* p3PToken;

// clang-format off
AUTOHOOK(Auth3PToken, engine.dll + 0x183760,
char*, __fastcall, ())
// clang-format on
static char* (*__fastcall o_pAuth3PToken)() = nullptr;
static char* __fastcall h_Auth3PToken()
{
if (!g_pVanillaCompatibility->GetVanillaCompatibility() && g_pMasterServerManager->m_sOwnClientAuthToken[0])
{
memset(p3PToken, 0x0, 1024);
strcpy(p3PToken, "Protocol 3: Protect the Pilot");
}

return Auth3PToken();
return o_pAuth3PToken();
}

ON_DLL_LOAD_CLIENT_RELIESON("engine.dll", ClientAuthHooks, ConVar, (CModule module))
{
AUTOHOOK_DISPATCH()
o_pAuthWithStryder = module.Offset(0x1843A0).RCast<decltype(o_pAuthWithStryder)>();
HookAttach(&(PVOID&)o_pAuthWithStryder, (PVOID)h_AuthWithStryder);

o_pAuth3PToken = module.Offset(0x183760).RCast<decltype(o_pAuth3PToken)>();
HookAttach(&(PVOID&)o_pAuth3PToken, (PVOID)h_Auth3PToken);

p3PToken = module.Offset(0x13979D80).RCast<char*>();

Expand Down
13 changes: 5 additions & 8 deletions primedev/client/clientruihooks.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
#include "core/convar/convar.h"

AUTOHOOK_INIT()

ConVar* Cvar_rui_drawEnable;

// clang-format off
AUTOHOOK(DrawRUIFunc, engine.dll + 0xFC500,
bool, __fastcall, (void* a1, float* a2))
// clang-format on
static bool (*__fastcall o_pDrawRUIFunc)(void* a1, float* a2) = nullptr;
static bool __fastcall h_DrawRUIFunc(void* a1, float* a2)
{
if (!Cvar_rui_drawEnable->GetBool())
return 0;

return DrawRUIFunc(a1, a2);
return o_pDrawRUIFunc(a1, a2);
}

ON_DLL_LOAD_CLIENT_RELIESON("engine.dll", RUI, ConVar, (CModule module))
{
AUTOHOOK_DISPATCH()
o_pDrawRUIFunc = module.Offset(0xFC500).RCast<decltype(o_pDrawRUIFunc)>();
HookAttach(&(PVOID&)o_pDrawRUIFunc, (PVOID)h_DrawRUIFunc);

Cvar_rui_drawEnable = new ConVar("rui_drawEnable", "1", FCVAR_CLIENTDLL, "Controls whether RUI should be drawn");
}
20 changes: 10 additions & 10 deletions primedev/client/clientvideooverrides.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#include "mods/modmanager.h"

AUTOHOOK_INIT()

// clang-format off
AUTOHOOK_PROCADDRESS(BinkOpen, bink2w64.dll, BinkOpen,
void*, __fastcall, (const char* path, uint32_t flags))
// clang-format on
static void* (*__fastcall o_pBinkOpen)(const char* path, uint32_t flags) = nullptr;
static void* __fastcall h_BinkOpen(const char* path, uint32_t flags)
{
std::string filename(fs::path(path).filename().string());
spdlog::info("BinkOpen {}", filename);
Expand All @@ -25,16 +21,20 @@ void*, __fastcall, (const char* path, uint32_t flags))
{
// create new path
fs::path binkPath(fileOwner->m_ModDirectory / "media" / filename);
return BinkOpen(binkPath.string().c_str(), flags);
return o_pBinkOpen(binkPath.string().c_str(), flags);
}
else
return BinkOpen(path, flags);
return o_pBinkOpen(path, flags);
}

ON_DLL_LOAD_CLIENT("engine.dll", BinkVideo, (CModule module))
ON_DLL_LOAD_CLIENT("bink2w64.dll", BinkRead, (CModule module))
{
AUTOHOOK_DISPATCH()
o_pBinkOpen = module.GetExportedFunction("BinkOpen").RCast<decltype(o_pBinkOpen)>();
HookAttach(&(PVOID&)o_pBinkOpen, (PVOID)h_BinkOpen);
}

ON_DLL_LOAD_CLIENT("engine.dll", BinkVideo, (CModule module))
{
// remove engine check for whether the bik we're trying to load exists in r2/media, as this will fail for biks in mods
// note: the check in engine is actually unnecessary, so it's just useless in practice and we lose nothing by removing it
module.Offset(0x459AD).NOP(6);
Expand Down

0 comments on commit d388739

Please sign in to comment.