From 185d1a4b281ef2b60d9c1c95b58238fb1e5bd63a Mon Sep 17 00:00:00 2001 From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com> Date: Wed, 29 Dec 2021 00:42:46 +0000 Subject: move to libcurl for masterserver as libhttp seems to be buggy and have bad error reporting for client --- .../NorthstarDedicatedTest.vcxproj.filters | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters') diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters index 306ac763..e4ddd92c 100644 --- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters +++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters @@ -118,6 +118,9 @@ {8cc1ae44-9dbf-4719-91a2-82e00b8d78e2} + + {ea1e17a6-40b7-4e1b-8edb-e9ae704ce604} + @@ -1389,6 +1392,36 @@ Header Files\Server + + Header Files\include\libcurl + + + Header Files\include\libcurl + + + Header Files\include\libcurl + + + Header Files\include\libcurl + + + Header Files\include\libcurl + + + Header Files\include\libcurl + + + Header Files\include\libcurl + + + Header Files\include\libcurl + + + Header Files\include\libcurl + + + Header Files\include\libcurl + -- 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.filters') 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 From f2e55278780b2c22067f69672ec5d9d23e40ca9d Mon Sep 17 00:00:00 2001 From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com> Date: Sun, 2 Jan 2022 01:20:02 +0000 Subject: setup for rpak filesystem hooks --- .../NorthstarDedicatedTest.vcxproj | 2 + .../NorthstarDedicatedTest.vcxproj.filters | 6 +++ NorthstarDedicatedTest/dllmain.cpp | 9 +++++ NorthstarDedicatedTest/masterserver.h | 2 - NorthstarDedicatedTest/rpakfilesystem.cpp | 44 ++++++++++++++++++++++ NorthstarDedicatedTest/rpakfilesystem.h | 4 ++ 6 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 NorthstarDedicatedTest/rpakfilesystem.cpp create mode 100644 NorthstarDedicatedTest/rpakfilesystem.h (limited to 'NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters') diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj index 03481a2c..67e9126f 100644 --- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj +++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj @@ -598,6 +598,7 @@ + @@ -640,6 +641,7 @@ + diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters index e4ddd92c..6e379a71 100644 --- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters +++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters @@ -1422,6 +1422,9 @@ Header Files\include\libcurl + + Header Files\Shared + @@ -1532,6 +1535,9 @@ Source Files\Server + + Source Files\Shared + diff --git a/NorthstarDedicatedTest/dllmain.cpp b/NorthstarDedicatedTest/dllmain.cpp index 78edb297..6acd4798 100644 --- a/NorthstarDedicatedTest/dllmain.cpp +++ b/NorthstarDedicatedTest/dllmain.cpp @@ -25,6 +25,7 @@ #include "scriptmainmenupromos.h" #include "miscclientfixes.h" #include "miscserverfixes.h" +#include "rpakfilesystem.h" #include "memalloc.h" bool initialised = false; @@ -66,6 +67,13 @@ void WaitForDebugger(HMODULE baseAddress) // in the future this will be called from launcher instead of dllmain void InitialiseNorthstar() { + if (initialised) + { + spdlog::error("Called InitialiseNorthstar more than once!"); + return; + } + initialised = true; + InitialiseLogging(); // apply initial hooks @@ -116,6 +124,7 @@ void InitialiseNorthstar() AddDllLoadCallback("engine.dll", InitialisePlaylistHooks); AddDllLoadCallback("filesystem_stdio.dll", InitialiseFilesystem); + AddDllLoadCallback("engine.dll", InitialiseEngineRpakFilesystem); AddDllLoadCallback("engine.dll", InitialiseKeyValues); // mod manager after everything else diff --git a/NorthstarDedicatedTest/masterserver.h b/NorthstarDedicatedTest/masterserver.h index 1c57904b..b4d0d476 100644 --- a/NorthstarDedicatedTest/masterserver.h +++ b/NorthstarDedicatedTest/masterserver.h @@ -1,6 +1,5 @@ #pragma once #include "convar.h" -#include "httplib.h" #include struct RemoteModInfo @@ -67,7 +66,6 @@ class MasterServerManager private: bool m_requestingServerList = false; bool m_authenticatingWithGameServer = false; - httplib::Client* m_httpClient = nullptr; public: char m_ownServerId[33]; diff --git a/NorthstarDedicatedTest/rpakfilesystem.cpp b/NorthstarDedicatedTest/rpakfilesystem.cpp new file mode 100644 index 00000000..006a57c5 --- /dev/null +++ b/NorthstarDedicatedTest/rpakfilesystem.cpp @@ -0,0 +1,44 @@ +#include "pch.h" +#include "rpakfilesystem.h" +#include "hookutils.h" +#include "modmanager.h" + +typedef void*(*LoadCommonPaksForMapType)(char* map); +LoadCommonPaksForMapType LoadCommonPaksForMap; + +typedef void*(*LoadPakSyncType)(char* path, void* unknownSingleton, int flags); +typedef void*(*LoadPakAsyncType)(char* path, void* unknownSingleton, int flags, void* callback0, void* callback1); + +// there are more i'm just too lazy to add +struct PakLoadFuncs +{ + void* unknown[2]; + LoadPakSyncType func2; + LoadPakAsyncType LoadPakAsync; +}; + +PakLoadFuncs* g_pakLoadApi; +void** pUnknownPakLoadSingleton; + +void LoadPakAsync(char* path) +{ + g_pakLoadApi->LoadPakAsync(path, *pUnknownPakLoadSingleton, 2, nullptr, nullptr); +} + +void LoadCommonPaksForMapHook(char* map) +{ + LoadCommonPaksForMap(map); + + // for sp => mp conversions, load the sp rpaks + if (!strcmp(map, "mp_skyway_v1") || !strcmp(map, "mp_crashsite") || !strcmp(map, "mp_hub_timeshift")) + map[0] = 's'; +} + +void InitialiseEngineRpakFilesystem(HMODULE baseAddress) +{ + g_pakLoadApi = (PakLoadFuncs*)((char*)baseAddress + 0x5BED78); + pUnknownPakLoadSingleton = (void**)((char*)baseAddress + 0x7C5E20); + + HookEnabler hook; + ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x15AD20, &LoadCommonPaksForMapHook, reinterpret_cast(&LoadCommonPaksForMap)); +} \ No newline at end of file diff --git a/NorthstarDedicatedTest/rpakfilesystem.h b/NorthstarDedicatedTest/rpakfilesystem.h new file mode 100644 index 00000000..a9cc9a93 --- /dev/null +++ b/NorthstarDedicatedTest/rpakfilesystem.h @@ -0,0 +1,4 @@ +#pragma once + +void InitialiseEngineRpakFilesystem(HMODULE baseAddress); +void LoadPakAsync(char* path); \ No newline at end of file -- cgit v1.2.3 From 5514ff036dbdbf7f4000934223a0d21bf0b9085d Mon Sep 17 00:00:00 2001 From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com> Date: Sun, 2 Jan 2022 03:06:04 +0000 Subject: initial work for ban system --- .../NorthstarDedicatedTest.vcxproj | 2 + .../NorthstarDedicatedTest.vcxproj.filters | 6 +++ NorthstarDedicatedTest/bansystem.cpp | 58 ++++++++++++++++++++++ NorthstarDedicatedTest/bansystem.h | 17 +++++++ NorthstarDedicatedTest/miscserverscript.h | 3 +- NorthstarDedicatedTest/serverauthentication.cpp | 7 ++- 6 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 NorthstarDedicatedTest/bansystem.cpp create mode 100644 NorthstarDedicatedTest/bansystem.h (limited to 'NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters') diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj index 67e9126f..bd0d9eb6 100644 --- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj +++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj @@ -176,6 +176,7 @@ + @@ -612,6 +613,7 @@ + diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters index 6e379a71..8d6bc246 100644 --- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters +++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters @@ -1425,6 +1425,9 @@ Header Files\Shared + + Header Files\Server\Authentication + @@ -1538,6 +1541,9 @@ Source Files\Shared + + Source Files\Server\Authentication + diff --git a/NorthstarDedicatedTest/bansystem.cpp b/NorthstarDedicatedTest/bansystem.cpp new file mode 100644 index 00000000..16c25b6b --- /dev/null +++ b/NorthstarDedicatedTest/bansystem.cpp @@ -0,0 +1,58 @@ +#pragma once +#include "pch.h" +#include "bansystem.h" +#include "serverauthentication.h" +#include "concommand.h" +#include + +const char* BANLIST_PATH = "R2Northstar/banlist.txt"; + +ServerBanSystem* g_ServerBanSystem; + +void ServerBanSystem::OpenBanlist() +{ + std::filesystem::create_directories(BANLIST_PATH); + + std::ifstream enabledModsStream(BANLIST_PATH); + std::stringstream enabledModsStringStream; + + if (!enabledModsStream.fail()) + { + std::string line; + while (std::getline(enabledModsStream, line)) + m_vBannedUids.push_back(strtoll(line.c_str(), nullptr, 10)); + + enabledModsStream.close(); + } + + // open write stream for banlist + m_sBanlistStream.open(BANLIST_PATH, std::ios::in | std::ios::binary); +} + +void ServerBanSystem::BanUID(uint64_t uid) +{ + m_vBannedUids.push_back(uid); + + m_sBanlistStream << std::to_string(uid) << std::endl; +} + +bool ServerBanSystem::IsUIDAllowed(uint64_t uid) +{ + return std::find(m_vBannedUids.begin(), m_vBannedUids.end(), uid) == m_vBannedUids.end(); +} + +void BanPlayerCommand(const CCommand& args) +{ + if (args.ArgC() < 2) + return; + + +} + +void InitialiseBanSystem(HMODULE baseAddress) +{ + g_ServerBanSystem = new ServerBanSystem; + g_ServerBanSystem->OpenBanlist(); + + RegisterConCommand("ban", BanPlayerCommand, "bans a given player by uid or name", FCVAR_GAMEDLL); +} \ No newline at end of file diff --git a/NorthstarDedicatedTest/bansystem.h b/NorthstarDedicatedTest/bansystem.h new file mode 100644 index 00000000..ea715ea2 --- /dev/null +++ b/NorthstarDedicatedTest/bansystem.h @@ -0,0 +1,17 @@ +#pragma once + +class ServerBanSystem +{ +private: + std::ofstream m_sBanlistStream; + std::vector m_vBannedUids; + +public: + void OpenBanlist(); + void BanUID(uint64_t uid); + bool IsUIDAllowed(uint64_t uid); +}; + +extern ServerBanSystem* g_ServerBanSystem; + +void InitialiseBanSystem(HMODULE baseAddress); \ No newline at end of file diff --git a/NorthstarDedicatedTest/miscserverscript.h b/NorthstarDedicatedTest/miscserverscript.h index b3e0580a..8197e502 100644 --- a/NorthstarDedicatedTest/miscserverscript.h +++ b/NorthstarDedicatedTest/miscserverscript.h @@ -1 +1,2 @@ -void InitialiseMiscServerScriptCommand(HMODULE baseAddress); \ No newline at end of file +void InitialiseMiscServerScriptCommand(HMODULE baseAddress); +void* GetPlayerByIndex(int playerIndex); \ No newline at end of file diff --git a/NorthstarDedicatedTest/serverauthentication.cpp b/NorthstarDedicatedTest/serverauthentication.cpp index c4208130..0fdb8664 100644 --- a/NorthstarDedicatedTest/serverauthentication.cpp +++ b/NorthstarDedicatedTest/serverauthentication.cpp @@ -5,6 +5,7 @@ #include "masterserver.h" #include "httplib.h" #include "gameutils.h" +#include "bansystem.h" #include #include #include @@ -116,8 +117,10 @@ void ServerAuthenticationManager::StopPlayerAuthServer() bool ServerAuthenticationManager::AuthenticatePlayer(void* player, int64_t uid, char* authToken) { - std::string strUid = std::to_string(uid); + if (!g_ServerBanSystem->IsUIDAllowed(uid)) + return false; + std::string strUid = std::to_string(uid); std::lock_guard guard(m_authDataMutex); bool authFail = true; @@ -221,7 +224,7 @@ void ServerAuthenticationManager::WritePersistentData(void* player) // store these in vars so we can use them in CBaseClient::Connect // this is fine because ptrs won't decay by the time we use this, just don't use it outside of cbaseclient::connect char* nextPlayerToken; -int64_t nextPlayerUid; +uint64_t nextPlayerUid; void* CBaseServer__ConnectClientHook(void* server, void* a2, void* a3, uint32_t a4, uint32_t a5, int32_t a6, void* a7, void* a8, char* serverFilter, void* a10, char a11, void* a12, char a13, char a14, int64_t uid, uint32_t a16, uint32_t a17) { -- cgit v1.2.3