From c18b293ba739424bee6db39e2e5a3081b0010a13 Mon Sep 17 00:00:00 2001 From: p0358 Date: Wed, 29 Dec 2021 06:47:00 +0100 Subject: remove x86 configurations --- .../NorthstarDedicatedTest.vcxproj | 73 ---------------------- 1 file changed, 73 deletions(-) (limited to 'NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj') diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj index 29dea6dc..479585b0 100644 --- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj +++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj @@ -1,14 +1,6 @@  - - Debug - Win32 - - - Release - Win32 - Debug x64 @@ -27,19 +19,6 @@ Northstar - - DynamicLibrary - true - v143 - Unicode - - - DynamicLibrary - false - v143 - true - Unicode - DynamicLibrary true @@ -58,12 +37,6 @@ - - - - - - @@ -71,56 +44,12 @@ - - true - - - false - true false - - - Level3 - true - WIN32;_DEBUG;NORTHSTARDEDICATEDTEST_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - true - Use - pch.h - stdcpp17 - - - Windows - true - false - %(AdditionalDependencies) - - - - - Level3 - true - true - true - WIN32;NDEBUG;NORTHSTARDEDICATEDTEST_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - true - Use - pch.h - stdcpp17 - - - Windows - true - true - true - false - %(AdditionalDependencies) - - Level3 @@ -621,9 +550,7 @@ - Create Create - Create Create -- cgit v1.2.3 From b302ffcad2f433ccbe02674e381d4d27252bb122 Mon Sep 17 00:00:00 2001 From: p0358 Date: Thu, 30 Dec 2021 04:41:56 +0100 Subject: yeet unneeded two libs --- NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj') diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj index 137a5639..1a79bee8 100644 --- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj +++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj @@ -65,7 +65,7 @@ Windows true false - $(ProjectDir)include\MinHook.x64.lib;$(ProjectDir)include\libcrypto_static.lib;$(ProjectDir)include\libssl_static.lib;$(ProjectDir)include\libcurl\lib\libcurl_a.lib;dbghelp.lib;Wldap32.lib;Normaliz.lib;%(AdditionalDependencies) + $(ProjectDir)include\MinHook.x64.lib;$(ProjectDir)include\libcurl\lib\libcurl_a.lib;dbghelp.lib;Wldap32.lib;Normaliz.lib;%(AdditionalDependencies) %(AdditionalLibraryDirectories) @@ -87,6 +87,7 @@ pch.h stdcpp17 $(ProjectDir)include;%(AdditionalIncludeDirectories) + MultiThreadedDLL Windows @@ -94,7 +95,7 @@ true true false - $(ProjectDir)include\MinHook.x64.lib;$(ProjectDir)include\libcrypto_static.lib;$(ProjectDir)include\libssl_static.lib;$(ProjectDir)include\libcurl\lib\libcurl_a.lib;dbghelp.lib;Wldap32.lib;Normaliz.lib;%(AdditionalDependencies) + $(ProjectDir)include\MinHook.x64.lib;$(ProjectDir)include\libcurl\lib\libcurl_a.lib;dbghelp.lib;Wldap32.lib;Normaliz.lib;%(AdditionalDependencies) %(AdditionalLibraryDirectories) -- cgit v1.2.3 From 65c2e58a6a788a504c352d4ed34d43be17d0abdd Mon Sep 17 00:00:00 2001 From: p0358 Date: Sat, 1 Jan 2022 22:41:45 +0100 Subject: Language selection/detection fixes, no more "files corrupted" error, will throw the proper Origin error now :D --- .../NorthstarDedicatedTest.vcxproj | 2 + .../NorthstarDedicatedTest.vcxproj.filters | 6 ++ NorthstarDedicatedTest/dllmain.cpp | 4 +- NorthstarDedicatedTest/languagehooks.cpp | 109 +++++++++++++++++++++ NorthstarDedicatedTest/languagehooks.h | 3 + 5 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 NorthstarDedicatedTest/languagehooks.cpp create mode 100644 NorthstarDedicatedTest/languagehooks.h (limited to 'NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj') diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj index 1a79bee8..cabaf573 100644 --- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj +++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj @@ -515,6 +515,7 @@ + @@ -554,6 +555,7 @@ + diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters index e4ddd92c..ac2684a3 100644 --- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters +++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters @@ -1422,6 +1422,9 @@ Header Files\include\libcurl + + Header Files\Client + @@ -1532,6 +1535,9 @@ Source Files\Server + + Source Files\Client + diff --git a/NorthstarDedicatedTest/dllmain.cpp b/NorthstarDedicatedTest/dllmain.cpp index 87fb4d5f..79f54374 100644 --- a/NorthstarDedicatedTest/dllmain.cpp +++ b/NorthstarDedicatedTest/dllmain.cpp @@ -26,6 +26,7 @@ #include "miscclientfixes.h" #include "miscserverfixes.h" #include "memalloc.h" +#include "languagehooks.h" bool initialised = false; @@ -63,7 +64,7 @@ bool InitialiseNorthstar() { if (initialised) { - spdlog::warn("Called InitialiseNorthstar more than once!"); + //spdlog::warn("Called InitialiseNorthstar more than once!"); return false; } @@ -78,6 +79,7 @@ bool InitialiseNorthstar() InitialiseInterfaceCreationHooks(); AddDllLoadCallback("tier0.dll", InitialiseTier0GameUtilFunctions); + AddDllLoadCallback("tier0.dll", InitialiseTier0LanguageHooks); AddDllLoadCallback("engine.dll", WaitForDebugger); AddDllLoadCallback("engine.dll", InitialiseEngineGameUtilFunctions); AddDllLoadCallback("server.dll", InitialiseServerGameUtilFunctions); diff --git a/NorthstarDedicatedTest/languagehooks.cpp b/NorthstarDedicatedTest/languagehooks.cpp new file mode 100644 index 00000000..08bacaf9 --- /dev/null +++ b/NorthstarDedicatedTest/languagehooks.cpp @@ -0,0 +1,109 @@ +#include "pch.h" +#include "languagehooks.h" +#include "gameutils.h" +#include +#include + +namespace fs = std::filesystem; + +typedef char* (*GetGameLanguageType)(); +char* GetGameLanguage(); + +typedef LANGID(*Tier0_DetectDefaultLanguageType)(); + +GetGameLanguageType GetGameLanguageOriginal; + +bool CheckLangAudioExists(char* lang) +{ + std::string path{ "r2\\sound\\general_" }; + path += lang; + path += ".mstr"; + return fs::exists(path); +} + +std::vector file_list(fs::path dir, std::regex ext_pattern) +{ + std::vector result; + + using iterator = fs::directory_iterator; + + const iterator end; + for (iterator iter{ dir }; iter != end; ++iter) + { + const std::string filename = iter->path().filename().string(); + std::smatch matches; + if (fs::is_regular_file(*iter) && std::regex_match(filename, matches, ext_pattern)) + { + result.push_back(std::move(matches.str(1))); + } + } + + return result; +} + +std::string GetAnyInstalledAudioLanguage() +{ + for (const auto& lang : file_list("r2\\sound\\", std::regex(".*?general_([a-z]+)_patch_1\\.mstr"))) + if (lang != "general" || lang != "") + return lang; + return "NO LANGUAGE DETECTED"; +} + +char* GetGameLanguageHook() +{ + auto tier0Handle = GetModuleHandleA("tier0.dll"); + auto Tier0_DetectDefaultLanguageType = GetProcAddress(tier0Handle, "Tier0_DetectDefaultLanguage"); + char* ingameLang1 = (char*)tier0Handle + 0xA9B60; // one of the globals we need to override if overriding lang (size: 256) + bool& canOriginDictateLang = *(bool*)((char*)tier0Handle + 0xA9A90); + + const char* forcedLanguage; + if (CommandLine()->CheckParm("-language", &forcedLanguage)) + { + if (!CheckLangAudioExists((char*)forcedLanguage)) + { + spdlog::info("User tried to force the language (-language) to \"{}\", but audio for this language doesn't exist and the game is bound to error, falling back to next option...", forcedLanguage); + } + else + { + spdlog::info("User forcing the language (-language) to: {}", forcedLanguage); + strncpy(ingameLang1, forcedLanguage, 256); + return ingameLang1; + } + } + + canOriginDictateLang = true; // let it try + { + auto lang = GetGameLanguageOriginal(); + if (!CheckLangAudioExists(lang)) + { + spdlog::info("Origin detected language \"{}\", but we do not have audio for it installed, falling back to the next option", lang); + + } + else + { + spdlog::info("Origin detected language: {}", lang); + return lang; + } + } + + 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 = GetGameLanguageOriginal(); + spdlog::info("Detected system language: {}", lang); + if (!CheckLangAudioExists(lang)) + { + spdlog::warn("Caution, audio for this language does NOT exist. You might want to override your game language with -language command line option."); + auto lang = GetAnyInstalledAudioLanguage(); + spdlog::warn("Falling back to first installed audio language: {}", lang.c_str()); + strncpy(ingameLang1, lang.c_str(), 256); + return ingameLang1; + } + + return lang; +} + +void InitialiseTier0LanguageHooks(HMODULE baseAddress) +{ + HookEnabler hook; + ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0xF560, &GetGameLanguageHook, reinterpret_cast(&GetGameLanguageOriginal)); +} \ No newline at end of file diff --git a/NorthstarDedicatedTest/languagehooks.h b/NorthstarDedicatedTest/languagehooks.h new file mode 100644 index 00000000..55b591e0 --- /dev/null +++ b/NorthstarDedicatedTest/languagehooks.h @@ -0,0 +1,3 @@ +#pragma once + +void InitialiseTier0LanguageHooks(HMODULE baseAddress); -- cgit v1.2.3