Skip to content

Commit

Permalink
Merge pull request #210 from wroyca/unit-test
Browse files Browse the repository at this point in the history
Remove legacy unit-test code
  • Loading branch information
Rackover authored Jan 24, 2025
2 parents a81e7b3 + 7e7571e commit 58a7851
Show file tree
Hide file tree
Showing 21 changed files with 121 additions and 599 deletions.
172 changes: 85 additions & 87 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,87 +1,85 @@
![license](https://img.shields.io/github/license/iw4x/iw4x-client.svg)
[![build](https://github.com/iw4x/iw4x-client/actions/workflows/build.yml/badge.svg?branch=develop)](https://github.com/iw4x/iw4x-client/actions)

# IW4x: Client

<img src=".github/assets/readme/icon.png" align="right" width="100" height="100">

IW4x is a community-driven project that aims to revitalize and enhance the [Call of Duty: Modern Warfare 2 (2009)](https://store.steampowered.com/app/10180/Call_of_Duty_Modern_Warfare_2_2009/) multiplayer experience by providing a stable platform with support for dedicated servers and modding.

A [__Steam__](https://store.steampowered.com/app/10180/Call_of_Duty_Modern_Warfare_2_2009/) installation of Modern Warfare 2 is required to run IW4x, copies from the Microsoft Store are **not compatible**.

IW4x is currently distributed through the [AlterWare Launcher](https://github.com/mxve/alterware-launcher).

## Compiling from Source

> [!IMPORTANT]
> **Clone** the git repository instead of downloading the ZIP, as the latter will not work.
1. Clone the repository - `git clone https://github.com/iw4x/iw4x-client.git`
2. Run `generate.bat` to initialize and update submodules and generate the Visual Studio solution
3. Open/build the generated solution file `build\iw4x.sln` with Visual Studio

To use the `iw4x.dll`, you must have a valid Modern Warfare 2 installation with the [IW4x Rawfiles](https://github.com/iw4x/iw4x-rawfiles) installed.

<details>
<summary>Development Setup</summary>

### Build to MW2 Directory

1. Right-click the IW4x solution in Visual Studio
2. Select Properties
3. Set the output directory to your MW2 install path

![](.github/assets/readme/output_directory.png)

### Setup Debugger

1. Right-click the IW4x solution in Visual Studio
2. Select Properties
3. Select Debugging
4. Set the Command value to the path of your `iw4x.exe` inside your MW2 game files

> Tip:
> - Switch to Windowed mode in-game, as breakpoints will lock the window.
> - Pressing `F5` will launch the game and attach the debugger.
> - The default hotkey for stopping the debugger is `Shift+F5`.
![](.github/assets/readme/debug_command.png)
</details>

## Premake arguments

| Argument | Description |
|:----------------------------|:-----------------------------------------------|
| `--copy-to=PATH` | Optional, copy the DLL to a custom folder after build, define the path here if wanted. |
| `--copy-pdb` | Copy debug information for binaries as well to the path given via --copy-to. |
| `--force-unit-tests` | Always compile unit tests. |
| `--disable-binary-check` | Do not perform integrity checks on the exe. |

## Command line arguments

| Argument | Description |
|:------------------------|:-----------------------------------------------|
| `-tests` | Perform unit tests. |
| `-entries` | Print to the console a list of every asset as they are loaded from zonefiles. |
| `-stdout` | Redirect all logging output to the terminal iw4x is started from, or if there is none, creates a new terminal window to write log information in. |
| `-console` | Allow the game to display its own separate interactive console window. |
| `-dedicated` | Starts the game as a headless dedicated server. |
| `-bigminidumps` | Include all code sections from loaded modules in the dump. |
| `-reallybigminidumps` | Include data sections from all loaded modules in the dump. |
| `-dump` | Write info of loaded assets to the raw folder as they are being loaded. |
| `-nointro` | Skip game's cinematic intro. |
| `-version` | Print IW4x build info on startup. |
| `-nosteam` | Disable friends feature and do not update Steam about the game's current status just like an invisible mode. |
| `-unprotect-dvars` | Allow the server to modify saved/archive dvars. |
| `-zonebuilder` | Start the interactive zonebuilder tool console instead of starting the game. |
| `-original-str-parsing` | (ZoneBuilder mode only) Parse .str files in the same manner as the CoD4 Mod Tools. |
| `-disable-notifies` | Disable "Anti-CFG" checks |
| `-disable-mongoose` | Disable Mongoose HTTP server |
| `-disable-rate-limit-check` | Disable RCon rate limit checks |

## Disclaimer

This software has been created purely for the purposes of
academic research. It is not intended to be used to attack
other systems. Project maintainers are not responsible or
liable for misuse of the software. Use responsibly.
![license](https://img.shields.io/github/license/iw4x/iw4x-client.svg)
[![build](https://github.com/iw4x/iw4x-client/actions/workflows/build.yml/badge.svg?branch=develop)](https://github.com/iw4x/iw4x-client/actions)

# IW4x: Client

<img src=".github/assets/readme/icon.png" align="right" width="100" height="100">

IW4x is a community-driven project that aims to revitalize and enhance the [Call of Duty: Modern Warfare 2 (2009)](https://store.steampowered.com/app/10180/Call_of_Duty_Modern_Warfare_2_2009/) multiplayer experience by providing a stable platform with support for dedicated servers and modding.

A [__Steam__](https://store.steampowered.com/app/10180/Call_of_Duty_Modern_Warfare_2_2009/) installation of Modern Warfare 2 is required to run IW4x, copies from the Microsoft Store are **not compatible**.

IW4x is currently distributed through the [AlterWare Launcher](https://github.com/mxve/alterware-launcher).

## Compiling from Source

> [!IMPORTANT]
> **Clone** the git repository instead of downloading the ZIP, as the latter will not work.
1. Clone the repository - `git clone https://github.com/iw4x/iw4x-client.git`
2. Run `generate.bat` to initialize and update submodules and generate the Visual Studio solution
3. Open/build the generated solution file `build\iw4x.sln` with Visual Studio

To use the `iw4x.dll`, you must have a valid Modern Warfare 2 installation with the [IW4x Rawfiles](https://github.com/iw4x/iw4x-rawfiles) installed.

<details>
<summary>Development Setup</summary>

### Build to MW2 Directory

1. Right-click the IW4x solution in Visual Studio
2. Select Properties
3. Set the output directory to your MW2 install path

![](.github/assets/readme/output_directory.png)

### Setup Debugger

1. Right-click the IW4x solution in Visual Studio
2. Select Properties
3. Select Debugging
4. Set the Command value to the path of your `iw4x.exe` inside your MW2 game files

> Tip:
> - Switch to Windowed mode in-game, as breakpoints will lock the window.
> - Pressing `F5` will launch the game and attach the debugger.
> - The default hotkey for stopping the debugger is `Shift+F5`.
![](.github/assets/readme/debug_command.png)
</details>

## Premake arguments

| Argument | Description |
|:----------------------------|:-----------------------------------------------|
| `--copy-to=PATH` | Optional, copy the DLL to a custom folder after build, define the path here if wanted. |
| `--copy-pdb` | Copy debug information for binaries as well to the path given via --copy-to. |
| `--disable-binary-check` | Do not perform integrity checks on the exe. |

## Command line arguments

| Argument | Description |
|:------------------------|:-----------------------------------------------|
| `-entries` | Print to the console a list of every asset as they are loaded from zonefiles. |
| `-stdout` | Redirect all logging output to the terminal iw4x is started from, or if there is none, creates a new terminal window to write log information in. |
| `-console` | Allow the game to display its own separate interactive console window. |
| `-dedicated` | Starts the game as a headless dedicated server. |
| `-bigminidumps` | Include all code sections from loaded modules in the dump. |
| `-reallybigminidumps` | Include data sections from all loaded modules in the dump. |
| `-dump` | Write info of loaded assets to the raw folder as they are being loaded. |
| `-nointro` | Skip game's cinematic intro. |
| `-version` | Print IW4x build info on startup. |
| `-nosteam` | Disable friends feature and do not update Steam about the game's current status just like an invisible mode. |
| `-unprotect-dvars` | Allow the server to modify saved/archive dvars. |
| `-zonebuilder` | Start the interactive zonebuilder tool console instead of starting the game. |
| `-original-str-parsing` | (ZoneBuilder mode only) Parse .str files in the same manner as the CoD4 Mod Tools. |
| `-disable-notifies` | Disable "Anti-CFG" checks |
| `-disable-mongoose` | Disable Mongoose HTTP server |
| `-disable-rate-limit-check` | Disable RCon rate limit checks |

## Disclaimer

This software has been created purely for the purposes of
academic research. It is not intended to be used to attack
other systems. Project maintainers are not responsible or
liable for misuse of the software. Use responsibly.
13 changes: 1 addition & 12 deletions premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ newoption {
description = "Copy debug information for binaries as well to the path given via --copy-to."
}

newoption {
trigger = "force-unit-tests",
description = "Always compile unit tests."
}

newoption {
trigger = "disable-binary-check",
description = "Do not perform integrity checks on the exe."
Expand Down Expand Up @@ -207,10 +202,7 @@ workspace "iw4x"
linkoptions {"/IGNORE:4702", "/LTCG"}
defines {"NDEBUG"}
flags {"FatalCompileWarnings", "FatalLinkWarnings"}

if not _OPTIONS["force-unit-tests"] then
rtti ("Off")
end
rtti ("Off")
filter {}

filter "configurations:Debug"
Expand All @@ -236,9 +228,6 @@ workspace "iw4x"
}

-- Debug flags
if _OPTIONS["force-unit-tests"] then
defines {"FORCE_UNIT_TESTS"}
end
if _OPTIONS["disable-binary-check"] then
defines {"DISABLE_BINARY_CHECK"}
end
Expand Down
42 changes: 3 additions & 39 deletions src/Components/Loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,7 @@ namespace Components
for (auto& component : Components)
{
#ifdef DEBUG
if (!IsPerformingUnitTests())
{
Logger::Print("Unregister component: {}\n", component->getName());
}
Logger::Print("Unregister component: {}\n", component->getName());
#endif
delete component;
}
Expand Down Expand Up @@ -253,45 +250,12 @@ namespace Components
}
}

bool Loader::PerformUnitTests()
{
bool result = true;

Logger::Print("Performing unit tests for components:\n");

for (const auto& component : Components)
{
#if defined(FORCE_UNIT_TESTS)
Logger::Debug("Testing '{}'...\n", component->getName());
#endif
auto startTime = std::chrono::high_resolution_clock::now();
auto testRes = component->unitTest();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - startTime).count();
Logger::Print("Test done ({}ms): {}\n\n", duration, (testRes ? "Success" : "Error"));
result &= testRes;
}

return result;
}

bool Loader::IsPerformingUnitTests()
{
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
return Flags::HasFlag("tests");
#else
return false;
#endif
}

void Loader::Register(Component* component)
{
if (component)
{
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
if (!IsPerformingUnitTests())
{
Logger::Print("Component registered: {}\n", component->getName());
}
#if defined(DEBUG)
Logger::Print("Component registered: {}\n", component->getName());
#endif
Components.push_back(component);
}
Expand Down
5 changes: 1 addition & 4 deletions src/Components/Loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Components
Component() = default;
virtual ~Component() = default;

#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
#if defined(DEBUG)
virtual std::string getName()
{
std::string name = typeid(*this).name();
Expand All @@ -21,7 +21,6 @@ namespace Components
// This method is called before DLLMain (if possible) and should to destroy threads.
// It's not 100% guaranteed that it's called outside DLLMain, as it depends on the game, but it's 100% guaranteed, that it is called at all.
virtual void preDestroy() {}
virtual bool unitTest() { return true; } // Unit testing entry
};

class Loader
Expand All @@ -31,8 +30,6 @@ namespace Components
static void Uninitialize();
static void PreDestroy();
static void PreDestroyNoPostGame();
static bool PerformUnitTests();
static bool IsPerformingUnitTests();
static void Register(Component* component);

static bool IsPregame();
Expand Down
61 changes: 0 additions & 61 deletions src/Components/Modules/Auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,65 +685,4 @@ namespace Components
TokenContainer.thread.join();
}
}

bool Auth::unitTest()
{
bool success = true;

printf("Testing logical token operators:\n");

Utils::Cryptography::Token token1;
Utils::Cryptography::Token token2;
++token1, token2++; // Test incrementation operator

printf("Operator == : ");
if (token1 == token2 && !(++token1 == token2)) printf("Success\n");
else
{
printf("Error\n");
success = false;
}

printf("Operator != : ");
if (token1 != token2 && !(++token2 != token1)) printf("Success\n");
else
{
printf("Error\n");
success = false;
}

printf("Operator >= : ");
if (token1 >= token2 && ++token1 >= token2) printf("Success\n");
else
{
printf("Error\n");
success = false;
}

printf("Operator > : ");
if (token1 > token2) printf("Success\n");
else
{
printf("Error\n");
success = false;
}

printf("Operator <= : ");
if (token1 <= ++token2 && token1 <= ++token2) printf("Success\n");
else
{
printf("Error\n");
success = false;
}

printf("Operator < : ");
if (token1 < token2) printf("Success\n");
else
{
printf("Error\n");
success = false;
}

return success;
}
}
1 change: 0 additions & 1 deletion src/Components/Modules/Auth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace Components
~Auth();

void preDestroy() override;
bool unitTest() override;

static void StoreKey();
static void LoadKey(bool force = false);
Expand Down
7 changes: 2 additions & 5 deletions src/Components/Modules/Console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ namespace Components

void Console::FreeNativeConsole()
{
if (!Flags::HasFlag("stdout") && (!Dedicated::IsEnabled() || Flags::HasFlag("console")) && !Loader::IsPerformingUnitTests())
if (!Flags::HasFlag("stdout") && (!Dedicated::IsEnabled() || Flags::HasFlag("console")))
{
FreeConsole();
}
Expand Down Expand Up @@ -913,9 +913,6 @@ namespace Components
Scheduler::Loop(RefreshStatus, Scheduler::Pipeline::MAIN);
}

// Code below is not necessary when performing unit tests!
if (Loader::IsPerformingUnitTests()) return;

// External console
if (Flags::HasFlag("stdout"))
{
Expand Down Expand Up @@ -969,7 +966,7 @@ namespace Components
Utils::Hook(0x43D570, Error, HOOK_JUMP).install()->quick();
Utils::Hook(0x4859A5, Input, HOOK_CALL).install()->quick();
}
else if(!Loader::IsPerformingUnitTests())
else
{
FreeConsole();
}
Expand Down
Loading

0 comments on commit 58a7851

Please sign in to comment.