diff --git a/deps/json11 b/deps/json11 index a6a661e9..afcc8d0d 160000 --- a/deps/json11 +++ b/deps/json11 @@ -1 +1 @@ -Subproject commit a6a661e9240e0018b6be0f67a9e9ca2a6be2626f +Subproject commit afcc8d0d82b1ce2df587a7a0637d05ba493bf5e6 diff --git a/deps/libtomcrypt b/deps/libtomcrypt index 912eff49..bd7933cc 160000 --- a/deps/libtomcrypt +++ b/deps/libtomcrypt @@ -1 +1 @@ -Subproject commit 912eff4949f46c0b426d2180429a6fa4c1144f1d +Subproject commit bd7933cc2b43ebe7c4349614c6cf1271251ebee4 diff --git a/deps/libtommath b/deps/libtommath index afb42241..1bd1320b 160000 --- a/deps/libtommath +++ b/deps/libtommath @@ -1 +1 @@ -Subproject commit afb4224186662b585ffa456aadb91c6a1a916733 +Subproject commit 1bd1320b198655ad8edd3dd791805d6a4a89437d diff --git a/premake5.lua b/premake5.lua index f3cd0b2b..a162e042 100644 --- a/premake5.lua +++ b/premake5.lua @@ -205,7 +205,7 @@ workspace "iw4x" -- libtomcrypt project "libtomcrypt" language "C" - defines { "_LIB", "LTC_SOURCE", "LTC_NO_RSA_BLINDING", "LTM_DESC" } + defines { "_LIB", "LTC_SOURCE", "LTC_NO_RSA_BLINDING", "LTM_DESC", "USE_LTM" } links { "libtommath" } includedirs { "./deps/libtomcrypt/src/headers" } @@ -213,8 +213,19 @@ workspace "iw4x" files { "./deps/libtomcrypt/src/**.c" } - -- remove ocb3 code - removefiles { "./deps/libtomcrypt/src/encauth/ocb3/**.c" } + -- remove incorrect files + -- for some reason, they lack the necessary header files + -- i might have to open a pull request which includes them + removefiles + { + "./deps/libtomcrypt/src/prngs/sober128tab.c", + "./deps/libtomcrypt/src/pk/dh/dh_sys.c", + "./deps/libtomcrypt/src/ciphers/aes/aes_tab.c", + "./deps/libtomcrypt/src/hashes/sha2/sha224.c", + "./deps/libtomcrypt/src/hashes/sha2/sha384.c", + "./deps/libtomcrypt/src/hashes/whirl/whirltab.c", + "./deps/libtomcrypt/src/encauth/ocb3/**.c", + } -- not our code, ignore POSIX usage warnings for now warnings "Off" diff --git a/src/Components/Loader.cpp b/src/Components/Loader.cpp index 333a3ebe..372067d7 100644 --- a/src/Components/Loader.cpp +++ b/src/Components/Loader.cpp @@ -61,6 +61,36 @@ namespace Components Loader::Components.clear(); } + bool Loader::PerformUnitTests() + { + bool result = true; + + Logger::Print("Performing unit tests for components:\n"); + + for (auto component : Loader::Components) + { + Logger::Print("Testing '%s'...\n", component->GetName()); + auto startTime = std::chrono::high_resolution_clock::now(); + bool testRes = component->UnitTest(); + auto duration = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - startTime).count(); + + + Logger::Print("Test done (%llims): %s\n\n", duration, (testRes ? "Success" : "Error"));// + result &= testRes; + } + + return result; + } + + bool Loader::PerformingUnitTests() + { +#if DEBUG + return Flags::HasFlag("tests"); +#else + return false; +#endif + } + void Loader::Register(Component* component) { if (component) diff --git a/src/Components/Loader.hpp b/src/Components/Loader.hpp index 0d492892..5cb4b38f 100644 --- a/src/Components/Loader.hpp +++ b/src/Components/Loader.hpp @@ -6,6 +6,7 @@ namespace Components Component() {}; virtual ~Component() {}; virtual const char* GetName() { return "Unknown"; }; + virtual bool UnitTest() { return true; }; // Unit testing entry }; class Loader @@ -13,6 +14,8 @@ namespace Components public: static void Initialize(); static void Uninitialize(); + static bool PerformUnitTests(); + static bool PerformingUnitTests(); static void Register(Component* component); private: diff --git a/src/Components/Modules/Console.cpp b/src/Components/Modules/Console.cpp index 14f0367c..0e111acd 100644 --- a/src/Components/Modules/Console.cpp +++ b/src/Components/Modules/Console.cpp @@ -368,13 +368,26 @@ namespace Components Console::Console() { + // Console '%s: %s> ' string + Utils::Hook::Set(0x5A44B4, "IW4x: r" REVISION_STR "> "); + + // Internal console + Utils::Hook(0x4F690C, Console::ToggleConsole, HOOK_CALL).Install()->Quick(); + Utils::Hook(0x4F65A5, Console::ToggleConsole, HOOK_JUMP).Install()->Quick(); + + // Check for bad food ;) + Utils::Hook(0x4CB9F4, Console::GetAutoCompleteFileList, HOOK_CALL).Install()->Quick(); + + // Code below is not necessary, when performing unit tests! + if (Loader::PerformingUnitTests()) return; + // External console if (Flags::HasFlag("console") || ZoneBuilder::IsEnabled()) // ZoneBuilder uses the game's console, until the native one is adapted. { FreeConsole(); Utils::Hook::Nop(0x60BB58, 11); } - else if(Dedicated::IsDedicated()/* || ZoneBuilder::IsEnabled()*/) + else if (Dedicated::IsDedicated()/* || ZoneBuilder::IsEnabled()*/) { Utils::Hook::Nop(0x60BB58, 11); @@ -388,15 +401,5 @@ namespace Components { FreeConsole(); } - - // Console '%s: %s> ' string - Utils::Hook::Set(0x5A44B4, "IW4x: r" REVISION_STR "> "); - - // Internal console - Utils::Hook(0x4F690C, Console::ToggleConsole, HOOK_CALL).Install()->Quick(); - Utils::Hook(0x4F65A5, Console::ToggleConsole, HOOK_JUMP).Install()->Quick(); - - // Check for bad food ;) - Utils::Hook(0x4CB9F4, Console::GetAutoCompleteFileList, HOOK_CALL).Install()->Quick(); } } diff --git a/src/Components/Modules/IPCPipe.cpp b/src/Components/Modules/IPCPipe.cpp index 45c124ef..73ea342d 100644 --- a/src/Components/Modules/IPCPipe.cpp +++ b/src/Components/Modules/IPCPipe.cpp @@ -1,5 +1,7 @@ #include "STDInclude.hpp" +using namespace std::literals; + namespace Components { Pipe* IPCPipe::ServerPipe = 0; @@ -62,8 +64,13 @@ namespace Components if (INVALID_HANDLE_VALUE != this->hPipe) { - this->mThreadAttached = true; - this->mThread = new std::thread(Pipe::ReceiveThread, this); + // Only create the thread, when not performing unit tests! + if (!Loader::PerformingUnitTests()) + { + this->mThreadAttached = true; + this->mThread = new std::thread(Pipe::ReceiveThread, this); + } + Logger::Print("Pipe successfully created\n"); return true; } diff --git a/src/Components/Modules/Logger.cpp b/src/Components/Modules/Logger.cpp index fd32f3f8..608a27e1 100644 --- a/src/Components/Modules/Logger.cpp +++ b/src/Components/Modules/Logger.cpp @@ -32,6 +32,7 @@ namespace Components } else { + printf("%s", buffer); OutputDebugStringA(buffer); } } diff --git a/src/Components/Modules/News.cpp b/src/Components/Modules/News.cpp index 30cf5dac..c9aa6742 100644 --- a/src/Components/Modules/News.cpp +++ b/src/Components/Modules/News.cpp @@ -1,13 +1,52 @@ #include "STDInclude.hpp" +#define NEWS_MOTD_DEFUALT "Welcome to ReactIW4x Multiplayer!" + namespace Components { - std::thread* News::Thread = 0; + std::thread* News::Thread = nullptr; + + bool News::UnitTest() + { + bool result = true; + + if (News::Thread) + { + Logger::Print("Awaiting thread termination...\n"); + + News::Thread->join(); + delete News::Thread; + + News::Thread = nullptr; + + if (!strlen(Localization::Get("MPUI_CHANGELOG_TEXT"))) + { + Logger::Print("Failed to fetch changelog!\n"); + result = false; + } + else + { + Logger::Print("Successfully fetched changelog.\n"); + } + + if (!strcmp(Localization::Get("MPUI_MOTD_TEXT"), NEWS_MOTD_DEFUALT)) + { + Logger::Print("Failed to fetch motd!\n"); + result = false; + } + else + { + Logger::Print("Successfully fetched motd.\n"); + } + } + + return result; + } News::News() { Localization::Set("MPUI_CHANGELOG_TEXT", ""); - Localization::Set("MPUI_MOTD_TEXT", "Welcome to ReactIW4x Multiplayer!"); + Localization::Set("MPUI_MOTD_TEXT", NEWS_MOTD_DEFUALT); News::Thread = new std::thread([] () { @@ -30,6 +69,8 @@ namespace Components { News::Thread->join(); delete News::Thread; + + News::Thread = nullptr; } } } diff --git a/src/Components/Modules/News.hpp b/src/Components/Modules/News.hpp index 4dd994c2..54ed7151 100644 --- a/src/Components/Modules/News.hpp +++ b/src/Components/Modules/News.hpp @@ -6,6 +6,7 @@ namespace Components News(); ~News(); const char* GetName() { return "News"; }; + bool UnitTest(); private: static std::thread* Thread; diff --git a/src/Main.cpp b/src/Main.cpp index 145d9189..4d571832 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -8,6 +8,17 @@ namespace Main { Main::EntryPointHook.Uninstall(); Components::Loader::Initialize(); + +#ifdef DEBUG + if (Components::Loader::PerformingUnitTests()) + { + DWORD result = (Components::Loader::PerformUnitTests() ? 0 : -1); + Components::Loader::Uninitialize(); + ExitProcess(result); + } +#else + Logger::Print("Unit tests are disabled outside the debug environment!\n"); +#endif } void Uninitialize() diff --git a/src/STDInclude.hpp b/src/STDInclude.hpp index e7be1ea1..ffc3505d 100644 --- a/src/STDInclude.hpp +++ b/src/STDInclude.hpp @@ -46,6 +46,7 @@ #define ZLIB_CONST +#define USE_LTM #define LTM_DESC #define LTC_NO_FAST #define LTC_NO_PROTOTYPES