Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove uses of Autohook from languagehooks.cpp #787

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions primedev/client/languagehooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

namespace fs = std::filesystem;

AUTOHOOK_INIT()

typedef LANGID (*Tier0_DetectDefaultLanguageType)();

bool CheckLangAudioExists(char* lang)
Expand Down Expand Up @@ -48,10 +46,8 @@ std::string GetAnyInstalledAudioLanguage()
return "NO LANGUAGE DETECTED";
}

// clang-format off
AUTOHOOK(GetGameLanguage, tier0.dll + 0xF560,
char*, __fastcall, ())
// clang-format on
static char*(__fastcall* o_pGetGameLanguage)() = nullptr;
static char* __fastcall h_GetGameLanguage()
{
auto tier0Handle = GetModuleHandleA("tier0.dll");
auto Tier0_DetectDefaultLanguageType = GetProcAddress(tier0Handle, "Tier0_DetectDefaultLanguage");
Expand All @@ -78,7 +74,7 @@ char*, __fastcall, ())

canOriginDictateLang = true; // let it try
{
auto lang = GetGameLanguage();
auto lang = o_pGetGameLanguage();
if (!CheckLangAudioExists(lang))
{
if (strcmp(lang, "russian") !=
Expand All @@ -96,7 +92,7 @@ char*, __fastcall, ())
Tier0_DetectDefaultLanguageType(); // force the global in tier0 to be populated with language inferred from user's system rather than
// defaulting to Russian
canOriginDictateLang = false; // Origin has no say anymore, we will fallback to user's system setup language
auto lang = GetGameLanguage();
auto lang = o_pGetGameLanguage();
spdlog::info("Detected system language: {}", lang);
if (!CheckLangAudioExists(lang))
{
Expand All @@ -113,5 +109,6 @@ char*, __fastcall, ())

ON_DLL_LOAD_CLIENT("tier0.dll", LanguageHooks, (CModule module))
{
AUTOHOOK_DISPATCH()
o_pGetGameLanguage = module.Offset(0xF560).RCast<decltype(o_pGetGameLanguage)>();
HookAttach(&(PVOID&)o_pGetGameLanguage, (PVOID)h_GetGameLanguage);
}