Update submodules and include some unit testing code.
This commit is contained in:
parent
dcd46633ca
commit
ad1e25bd56
2
deps/json11
vendored
2
deps/json11
vendored
@ -1 +1 @@
|
|||||||
Subproject commit a6a661e9240e0018b6be0f67a9e9ca2a6be2626f
|
Subproject commit afcc8d0d82b1ce2df587a7a0637d05ba493bf5e6
|
2
deps/libtomcrypt
vendored
2
deps/libtomcrypt
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 912eff4949f46c0b426d2180429a6fa4c1144f1d
|
Subproject commit bd7933cc2b43ebe7c4349614c6cf1271251ebee4
|
2
deps/libtommath
vendored
2
deps/libtommath
vendored
@ -1 +1 @@
|
|||||||
Subproject commit afb4224186662b585ffa456aadb91c6a1a916733
|
Subproject commit 1bd1320b198655ad8edd3dd791805d6a4a89437d
|
17
premake5.lua
17
premake5.lua
@ -205,7 +205,7 @@ workspace "iw4x"
|
|||||||
-- libtomcrypt
|
-- libtomcrypt
|
||||||
project "libtomcrypt"
|
project "libtomcrypt"
|
||||||
language "C"
|
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" }
|
links { "libtommath" }
|
||||||
includedirs { "./deps/libtomcrypt/src/headers" }
|
includedirs { "./deps/libtomcrypt/src/headers" }
|
||||||
@ -213,8 +213,19 @@ workspace "iw4x"
|
|||||||
|
|
||||||
files { "./deps/libtomcrypt/src/**.c" }
|
files { "./deps/libtomcrypt/src/**.c" }
|
||||||
|
|
||||||
-- remove ocb3 code
|
-- remove incorrect files
|
||||||
removefiles { "./deps/libtomcrypt/src/encauth/ocb3/**.c" }
|
-- 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
|
-- not our code, ignore POSIX usage warnings for now
|
||||||
warnings "Off"
|
warnings "Off"
|
||||||
|
@ -61,6 +61,36 @@ namespace Components
|
|||||||
Loader::Components.clear();
|
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::milliseconds>(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)
|
void Loader::Register(Component* component)
|
||||||
{
|
{
|
||||||
if (component)
|
if (component)
|
||||||
|
@ -6,6 +6,7 @@ namespace Components
|
|||||||
Component() {};
|
Component() {};
|
||||||
virtual ~Component() {};
|
virtual ~Component() {};
|
||||||
virtual const char* GetName() { return "Unknown"; };
|
virtual const char* GetName() { return "Unknown"; };
|
||||||
|
virtual bool UnitTest() { return true; }; // Unit testing entry
|
||||||
};
|
};
|
||||||
|
|
||||||
class Loader
|
class Loader
|
||||||
@ -13,6 +14,8 @@ namespace Components
|
|||||||
public:
|
public:
|
||||||
static void Initialize();
|
static void Initialize();
|
||||||
static void Uninitialize();
|
static void Uninitialize();
|
||||||
|
static bool PerformUnitTests();
|
||||||
|
static bool PerformingUnitTests();
|
||||||
static void Register(Component* component);
|
static void Register(Component* component);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -368,13 +368,26 @@ namespace Components
|
|||||||
|
|
||||||
Console::Console()
|
Console::Console()
|
||||||
{
|
{
|
||||||
|
// Console '%s: %s> ' string
|
||||||
|
Utils::Hook::Set<char*>(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
|
// External console
|
||||||
if (Flags::HasFlag("console") || ZoneBuilder::IsEnabled()) // ZoneBuilder uses the game's console, until the native one is adapted.
|
if (Flags::HasFlag("console") || ZoneBuilder::IsEnabled()) // ZoneBuilder uses the game's console, until the native one is adapted.
|
||||||
{
|
{
|
||||||
FreeConsole();
|
FreeConsole();
|
||||||
Utils::Hook::Nop(0x60BB58, 11);
|
Utils::Hook::Nop(0x60BB58, 11);
|
||||||
}
|
}
|
||||||
else if(Dedicated::IsDedicated()/* || ZoneBuilder::IsEnabled()*/)
|
else if (Dedicated::IsDedicated()/* || ZoneBuilder::IsEnabled()*/)
|
||||||
{
|
{
|
||||||
Utils::Hook::Nop(0x60BB58, 11);
|
Utils::Hook::Nop(0x60BB58, 11);
|
||||||
|
|
||||||
@ -388,15 +401,5 @@ namespace Components
|
|||||||
{
|
{
|
||||||
FreeConsole();
|
FreeConsole();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Console '%s: %s> ' string
|
|
||||||
Utils::Hook::Set<char*>(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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include "STDInclude.hpp"
|
#include "STDInclude.hpp"
|
||||||
|
|
||||||
|
using namespace std::literals;
|
||||||
|
|
||||||
namespace Components
|
namespace Components
|
||||||
{
|
{
|
||||||
Pipe* IPCPipe::ServerPipe = 0;
|
Pipe* IPCPipe::ServerPipe = 0;
|
||||||
@ -61,9 +63,14 @@ namespace Components
|
|||||||
this->hPipe = CreateNamedPipe(this->PipeFile, PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, sizeof(this->mPacket), sizeof(this->mPacket), NMPWAIT_USE_DEFAULT_WAIT, NULL);
|
this->hPipe = CreateNamedPipe(this->PipeFile, PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, sizeof(this->mPacket), sizeof(this->mPacket), NMPWAIT_USE_DEFAULT_WAIT, NULL);
|
||||||
|
|
||||||
if (INVALID_HANDLE_VALUE != this->hPipe)
|
if (INVALID_HANDLE_VALUE != this->hPipe)
|
||||||
|
{
|
||||||
|
// Only create the thread, when not performing unit tests!
|
||||||
|
if (!Loader::PerformingUnitTests())
|
||||||
{
|
{
|
||||||
this->mThreadAttached = true;
|
this->mThreadAttached = true;
|
||||||
this->mThread = new std::thread(Pipe::ReceiveThread, this);
|
this->mThread = new std::thread(Pipe::ReceiveThread, this);
|
||||||
|
}
|
||||||
|
|
||||||
Logger::Print("Pipe successfully created\n");
|
Logger::Print("Pipe successfully created\n");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ namespace Components
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
printf("%s", buffer);
|
||||||
OutputDebugStringA(buffer);
|
OutputDebugStringA(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,52 @@
|
|||||||
#include "STDInclude.hpp"
|
#include "STDInclude.hpp"
|
||||||
|
|
||||||
|
#define NEWS_MOTD_DEFUALT "Welcome to ReactIW4x Multiplayer!"
|
||||||
|
|
||||||
namespace Components
|
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()
|
News::News()
|
||||||
{
|
{
|
||||||
Localization::Set("MPUI_CHANGELOG_TEXT", "");
|
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([] ()
|
News::Thread = new std::thread([] ()
|
||||||
{
|
{
|
||||||
@ -30,6 +69,8 @@ namespace Components
|
|||||||
{
|
{
|
||||||
News::Thread->join();
|
News::Thread->join();
|
||||||
delete News::Thread;
|
delete News::Thread;
|
||||||
|
|
||||||
|
News::Thread = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ namespace Components
|
|||||||
News();
|
News();
|
||||||
~News();
|
~News();
|
||||||
const char* GetName() { return "News"; };
|
const char* GetName() { return "News"; };
|
||||||
|
bool UnitTest();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static std::thread* Thread;
|
static std::thread* Thread;
|
||||||
|
11
src/Main.cpp
11
src/Main.cpp
@ -8,6 +8,17 @@ namespace Main
|
|||||||
{
|
{
|
||||||
Main::EntryPointHook.Uninstall();
|
Main::EntryPointHook.Uninstall();
|
||||||
Components::Loader::Initialize();
|
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()
|
void Uninitialize()
|
||||||
|
@ -46,6 +46,7 @@
|
|||||||
|
|
||||||
#define ZLIB_CONST
|
#define ZLIB_CONST
|
||||||
|
|
||||||
|
#define USE_LTM
|
||||||
#define LTM_DESC
|
#define LTM_DESC
|
||||||
#define LTC_NO_FAST
|
#define LTC_NO_FAST
|
||||||
#define LTC_NO_PROTOTYPES
|
#define LTC_NO_PROTOTYPES
|
||||||
|
Loading…
Reference in New Issue
Block a user