Move FrontendKitLib to WormKitTools to reuse it for other modules.

This commit is contained in:
Ray Koopa 2020-07-20 18:38:10 +02:00
parent a314377c13
commit 2b94e09e39
24 changed files with 493 additions and 151 deletions

View File

@ -53,7 +53,9 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fkNetcode", "tool\fkNetcode
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FrontendKitWS", "tool\FrontendKitWS\FrontendKitWS.vcxproj", "{E391EA12-B929-466C-932F-DEF72B8CEB5D}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FrontendKitLib", "tool\FrontendKitLib\FrontendKitLib.vcxproj", "{068A8647-0A66-4E39-983B-43ACEAC5C937}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wkUnlimiter", "tool\wkUnlimiter\wkUnlimiter.vcxproj", "{CDED4B7C-91DF-45D3-9704-DB8750BDAF5B}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WormKitTools", "tool\WormKitTools\FrontendKitLib.vcxproj", "{068A8647-0A66-4E39-983B-43ACEAC5C937}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -137,6 +139,10 @@ Global
{E391EA12-B929-466C-932F-DEF72B8CEB5D}.Debug|Any CPU.Build.0 = Debug|Win32
{E391EA12-B929-466C-932F-DEF72B8CEB5D}.Release|Any CPU.ActiveCfg = Release|Win32
{E391EA12-B929-466C-932F-DEF72B8CEB5D}.Release|Any CPU.Build.0 = Release|Win32
{CDED4B7C-91DF-45D3-9704-DB8750BDAF5B}.Debug|Any CPU.ActiveCfg = Debug|Win32
{CDED4B7C-91DF-45D3-9704-DB8750BDAF5B}.Debug|Any CPU.Build.0 = Debug|Win32
{CDED4B7C-91DF-45D3-9704-DB8750BDAF5B}.Release|Any CPU.ActiveCfg = Release|Win32
{CDED4B7C-91DF-45D3-9704-DB8750BDAF5B}.Release|Any CPU.Build.0 = Release|Win32
{068A8647-0A66-4E39-983B-43ACEAC5C937}.Debug|Any CPU.ActiveCfg = Debug|Win32
{068A8647-0A66-4E39-983B-43ACEAC5C937}.Debug|Any CPU.Build.0 = Debug|Win32
{068A8647-0A66-4E39-983B-43ACEAC5C937}.Release|Any CPU.ActiveCfg = Release|Win32
@ -165,6 +171,7 @@ Global
{13ABF717-5809-441D-A5D8-66E1EE75A390} = {0B9B0B74-3EB1-46A4-BCCC-F2D6AE59A9EE}
{C4138811-7CFA-4826-A3DD-AF2B618EAFC1} = {0B9B0B74-3EB1-46A4-BCCC-F2D6AE59A9EE}
{E391EA12-B929-466C-932F-DEF72B8CEB5D} = {0B9B0B74-3EB1-46A4-BCCC-F2D6AE59A9EE}
{CDED4B7C-91DF-45D3-9704-DB8750BDAF5B} = {0B9B0B74-3EB1-46A4-BCCC-F2D6AE59A9EE}
{068A8647-0A66-4E39-983B-43ACEAC5C937} = {0B9B0B74-3EB1-46A4-BCCC-F2D6AE59A9EE}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution

View File

@ -1,18 +0,0 @@
#pragma once
#include <Windows.h>
struct PEInfo
{
PEInfo(HMODULE hModule = 0);
void Reset(HMODULE hModule);
ULONG_PTR Offset(ULONG_PTR off);
BOOL IsCode(LPVOID ptr);
BOOL IsData(LPVOID ptr);
HANDLE Handle;
IMAGE_DOS_HEADER* DOS;
IMAGE_NT_HEADERS* NT;
IMAGE_FILE_HEADER* FH;
IMAGE_OPTIONAL_HEADER* OPT;
};

View File

@ -1,20 +0,0 @@
#pragma once
#include <stdexcept>
#include <Windows.h>
namespace fk
{
enum GameVersion
{
GAME_VERSION_NONE = -1,
GAME_VERSION_BR, // 1.05 Br
GAME_VERSION_EN, // 1.05 Du, En, Fr, It, Po, Sp, Sw
GAME_VERSION_GE, // 1.05
GAME_VERSION_NA, // 1.05
GAME_VERSION_SA, // 1.05
GAME_VERSION_TRY // 1.07 Trymedia
};
int getGameVersion(DWORD timeDateStamp);
std::string getErrorMessage(int error);
}

View File

@ -1,32 +0,0 @@
#include "PEInfo.h"
PEInfo::PEInfo(HMODULE hModule)
{
Reset(hModule);
}
void PEInfo::Reset(HMODULE hModule)
{
Handle = hModule == 0 ? GetModuleHandleA(NULL) : hModule;
DOS = (IMAGE_DOS_HEADER*)Handle;
NT = (IMAGE_NT_HEADERS*)((DWORD)DOS + DOS->e_lfanew);
FH = (IMAGE_FILE_HEADER*)&NT->FileHeader;
OPT = (IMAGE_OPTIONAL_HEADER*)&NT->OptionalHeader;
}
ULONG_PTR PEInfo::Offset(ULONG_PTR off)
{
return (DWORD)Handle + off;
}
BOOL PEInfo::IsCode(LPVOID ptr)
{
return DWORD(ptr) >= Offset(OPT->BaseOfCode)
&& DWORD(ptr) < Offset(OPT->BaseOfCode) + OPT->SizeOfCode;
}
BOOL PEInfo::IsData(LPVOID ptr)
{
return DWORD(ptr) >= Offset(OPT->BaseOfData)
&& DWORD(ptr) < Offset(OPT->BaseOfData) + OPT->SizeOfInitializedData + OPT->SizeOfUninitializedData;
}

View File

@ -14,8 +14,9 @@
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{068a8647-0a66-4e39-983b-43aceac5c937}</ProjectGuid>
<RootNamespace>FrontendKitLib</RootNamespace>
<RootNamespace>WormKitTools</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>WormKitTools</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
@ -92,24 +93,24 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="src\fkConfig.cpp" />
<ClCompile Include="src\fkPatch.cpp" />
<ClCompile Include="src\fkUtils.cpp" />
<ClCompile Include="src\wkConfig.cpp" />
<ClCompile Include="src\wkPatch.cpp" />
<ClCompile Include="src\wkUtils.cpp" />
<ClCompile Include="src\pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="src\PEInfo.cpp" />
<ClCompile Include="src\wkExe.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\fkConfig.h" />
<ClInclude Include="include\fkPatch.h" />
<ClInclude Include="include\fkUtils.h" />
<ClInclude Include="include\PEInfo.h" />
<ClInclude Include="include\wkConfig.h" />
<ClInclude Include="include\wkPatch.h" />
<ClInclude Include="include\wkUtils.h" />
<ClInclude Include="include\wkExe.h" />
<ClInclude Include="src\pch.h" />
</ItemGroup>
<ItemGroup>
<None Include="include\fkPatch.inl" />
<None Include="include\wkPatch.inl" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@ -15,41 +15,41 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\PEInfo.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\fkUtils.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\fkPatch.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\fkConfig.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\pch.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\wkConfig.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\wkUtils.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\wkPatch.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\wkExe.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\fkConfig.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\fkPatch.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\fkUtils.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\pch.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\PEInfo.h">
<ClInclude Include="include\wkConfig.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\wkUtils.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\wkPatch.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\wkExe.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="include\fkPatch.inl">
<None Include="include\wkPatch.inl">
<Filter>Header Files</Filter>
</None>
</ItemGroup>

View File

@ -1,7 +1,7 @@
#pragma once
#include <Windows.h>
namespace fk
namespace wk
{
class Config
{

View File

@ -0,0 +1,21 @@
#pragma once
#include <Windows.h>
namespace wk
{
struct Exe
{
public:
HANDLE Handle;
IMAGE_DOS_HEADER* DosHeader;
IMAGE_NT_HEADERS* NtHeader;
IMAGE_FILE_HEADER* FileHeader;
IMAGE_OPTIONAL_HEADER* OptionalHeader;
Exe(HMODULE hModule = NULL);
ULONG_PTR Offset(ULONG_PTR off);
BOOL IsCode(LPVOID ptr);
BOOL IsData(LPVOID ptr);
};
}

View File

@ -1,7 +1,7 @@
#pragma once
#include <Windows.h>
namespace fk
namespace wk
{
enum InsertJump
{
@ -23,6 +23,7 @@ namespace fk
void close() const;
template <class T> void write(const T& value);
static void byte(ULONG_PTR address, BYTE newValue);
static void nops(ULONG_PTR address, SIZE_T size);
static void jump(ULONG_PTR address, SIZE_T size, PVOID callee, DWORD jumpType);
@ -33,4 +34,4 @@ namespace fk
};
}
#include "fkPatch.inl"
#include "wkPatch.inl"

View File

@ -1,4 +1,4 @@
namespace fk
namespace wk
{
template <class T>
void Patch::write(const T& value)

View File

@ -0,0 +1,36 @@
#pragma once
#include <stdexcept>
#include <Windows.h>
namespace wk
{
// 0x 00 0000 00
// [Game][Version][Release]
enum GameID
{
GAMEID_NONE,
GAMEID_W2 = 0x20000000,
GAMEID_W2_1_05 = GAMEID_W2 | 0x010500,
GAMEID_W2_1_05_BR = GAMEID_W2_1_05 | 0x10, // Worms2 1.05 Br
GAMEID_W2_1_05_EN = GAMEID_W2_1_05 | 0x20, // Worms2 1.05 Du, En, Fr, It, Po, Sp, Sw
GAMEID_W2_1_05_GE = GAMEID_W2_1_05 | 0x30, // Worms2 1.05
GAMEID_W2_1_05_NA = GAMEID_W2_1_05 | 0x40, // Worms2 1.05
GAMEID_W2_1_05_SA = GAMEID_W2_1_05 | 0x50, // Worms2 1.05
GAMEID_W2_1_07 = GAMEID_W2 | 0x010700,
GAMEID_W2_1_07_TRY = GAMEID_W2_1_07 | 0x60, // Worms2 1.07 Trymedia
GAMEID_WA = 0x30000000,
GAMEID_WA_3_8 = GAMEID_WA | 0x030800,
GAMEID_WA_3_8_CD = GAMEID_WA_3_8 | 0x10, // Worms Armageddon 3.8 CD
GAMEID_WWP = 0x40000000,
GAMEID_OW = 0x50000000,
GAMEID_WWPA = 0x60000000,
};
int getGameID(DWORD timeDateStamp);
std::string getErrorMessage(int error);
}

View File

@ -1,7 +1,7 @@
#include "fkConfig.h"
#include "wkConfig.h"
#include <stdio.h>
namespace fk
namespace wk
{
Config::Config(LPCSTR fileName)
{

View File

@ -0,0 +1,30 @@
#include "wkExe.h"
namespace wk
{
Exe::Exe(HMODULE hModule)
{
Handle = hModule == 0 ? GetModuleHandleA(NULL) : hModule;
DosHeader = (IMAGE_DOS_HEADER*)Handle;
NtHeader = (IMAGE_NT_HEADERS*)((DWORD)DosHeader + DosHeader->e_lfanew);
FileHeader = (IMAGE_FILE_HEADER*)&NtHeader->FileHeader;
OptionalHeader = (IMAGE_OPTIONAL_HEADER*)&NtHeader->OptionalHeader;
}
ULONG_PTR Exe::Offset(ULONG_PTR off)
{
return (DWORD)Handle + off;
}
BOOL Exe::IsCode(LPVOID ptr)
{
return DWORD(ptr) >= Offset(OptionalHeader->BaseOfCode)
&& DWORD(ptr) < Offset(OptionalHeader->BaseOfCode) + OptionalHeader->SizeOfCode;
}
BOOL Exe::IsData(LPVOID ptr)
{
return DWORD(ptr) >= Offset(OptionalHeader->BaseOfData)
&& DWORD(ptr) < Offset(OptionalHeader->BaseOfData) + OptionalHeader->SizeOfInitializedData + OptionalHeader->SizeOfUninitializedData;
}
}

View File

@ -1,7 +1,7 @@
#include "fkPatch.h"
#include "wkPatch.h"
#include <stdexcept>
namespace fk
namespace wk
{
Patch::Patch(ULONG_PTR address, SIZE_T size)
: _address(reinterpret_cast<LPBYTE>(address))
@ -26,16 +26,22 @@ namespace fk
throw std::exception("VirtualProtect failed, call GetLastError for more info.");
}
void Patch::byte(ULONG_PTR address, BYTE newValue)
{
wk::Patch patch(address, 1);
patch.write(newValue);
}
void Patch::nops(ULONG_PTR address, SIZE_T size)
{
fk::Patch patch(address, size);
wk::Patch patch(address, size);
while (size--)
patch.write<BYTE>(0x90);
}
void Patch::jump(ULONG_PTR address, SIZE_T size, PVOID callee, DWORD jumpType)
{
fk::Patch patch(address, size);
wk::Patch patch(address, size);
if (size >= 5 && address)
{

View File

@ -1,21 +1,22 @@
#include "fkUtils.h"
#include "wkUtils.h"
#include <string>
#include "fkPatch.h"
#include "wkPatch.h"
namespace fk
namespace wk
{
int getGameVersion(DWORD timeDateStamp)
int getGameID(DWORD timeDateStamp)
{
switch (timeDateStamp)
{
case 0x3528DAFA: return GAME_VERSION_BR;
case 0x3528DCB1: return GAME_VERSION_EN;
case 0x3528DB52: return GAME_VERSION_GE;
case 0x3528DA98: return GAME_VERSION_NA;
case 0x3528DBDA: return GAME_VERSION_SA;
case 0x3587BE19: return GAME_VERSION_TRY;
case 0x3528DAFA: return GAMEID_W2_1_05_BR;
case 0x3528DCB1: return GAMEID_W2_1_05_EN;
case 0x3528DB52: return GAMEID_W2_1_05_GE;
case 0x3528DA98: return GAMEID_W2_1_05_NA;
case 0x3528DBDA: return GAMEID_W2_1_05_SA;
case 0x3587BE19: return GAMEID_W2_1_07_TRY;
case 0x5EF04515: return GAMEID_WA_3_8_CD;
default: return GAMEID_NONE;
}
return GAME_VERSION_NONE;
}
std::string getErrorMessage(int error)

View File

@ -60,7 +60,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;FKNETCODE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(ProjectDir)..\FrontendKitLib\include\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ProjectDir)..\WormKitTools\include\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@ -77,7 +77,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;FKNETCODE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(ProjectDir)..\FrontendKitLib\include\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ProjectDir)..\WormKitTools\include\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@ -98,7 +98,7 @@
<ResourceCompile Include="fkNetcode.rc" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FrontendKitLib\FrontendKitLib.vcxproj">
<ProjectReference Include="..\WormKitTools\FrontendKitLib.vcxproj">
<Project>{068a8647-0a66-4e39-983b-43aceac5c937}</Project>
</ProjectReference>
</ItemGroup>

View File

@ -2,10 +2,10 @@
#include <Windows.h>
#include <WinInet.h>
#include <winsock.h>
#include "fkConfig.h"
#include "fkPatch.h"
#include "fkUtils.h"
#include "PEInfo.h"
#include "wkConfig.h"
#include "wkExe.h"
#include "wkPatch.h"
#include "wkUtils.h"
// ---- Configuration ----
@ -15,7 +15,7 @@ BOOL cfgShowErrors;
void configure()
{
fk::Config config("fkNetcode.ini");
wk::Config config("fkNetcode.ini");
// Load INI settings.
config.get("AddressResolval", "FallbackIP", cfgFallbackIP, 16);
@ -87,7 +87,7 @@ bool resolveIPExternal(LPSTR buffer)
if (error && cfgShowErrors)
{
CHAR msg[512];
sprintf_s(msg, "Could not resolve your IP through the web service. %s", fk::getErrorMessage(error).c_str());
sprintf_s(msg, "Could not resolve your IP through the web service. %s", wk::getErrorMessage(error).c_str());
MessageBox(NULL, msg, "fkNetcode", MB_ICONWARNING);
}
return !error;
@ -134,45 +134,62 @@ bool __stdcall patchResolveIP(LPSTR buffer, int bufferLength)
// ---- Patch ----
void patch(PEInfo& pe, int gameVersion)
void patch(wk::Exe& exe, int gameVersion)
{
fk::Patch::jump(pe.Offset(0x00001799), 5, &patchResolveIP, fk::IJ_JUMP); // replace IP resolve with web service
wk::Patch::jump(exe.Offset(0x00001799), 5, &patchResolveIP, wk::IJ_JUMP); // replace IP resolve with web service
if (gameVersion == fk::GAME_VERSION_TRY)
if (gameVersion == wk::GAMEID_W2_1_07_TRY)
{
fk::Patch::nops(pe.Offset(0x00053B96), 5); // prevent overriding IP with user name
fk::Patch::nops(pe.Offset(0x00054693), 5); // prevent overriding IP with NAT IP
fk::Patch::nops(pe.Offset(0x00054635), 11); // useless sleep when connecting to server
wk::Patch::nops(exe.Offset(0x00053B96), 5); // prevent overriding IP with user name
wk::Patch::nops(exe.Offset(0x00054693), 5); // prevent overriding IP with NAT IP
wk::Patch::nops(exe.Offset(0x00054635), 11); // useless sleep when connecting to server
}
else
{
fk::Patch::nops(pe.Offset(0x00053E96), 5); // prevent overriding IP with user name
fk::Patch::nops(pe.Offset(0x00054935), 11); // useless sleep when connecting to server
fk::Patch::nops(pe.Offset(0x00054993), 5); // prevent overriding IP with NAT IP
wk::Patch::nops(exe.Offset(0x00053E96), 5); // prevent overriding IP with user name
wk::Patch::nops(exe.Offset(0x00054935), 11); // useless sleep when connecting to server
wk::Patch::nops(exe.Offset(0x00054993), 5); // prevent overriding IP with NAT IP
}
}
// ---- Main ----
int getVersion(DWORD timeDateStamp)
{
int id = wk::getGameID(timeDateStamp);
switch (id)
{
case wk::GAMEID_W2_1_05_BR:
case wk::GAMEID_W2_1_05_EN:
case wk::GAMEID_W2_1_05_GE:
case wk::GAMEID_W2_1_05_NA:
case wk::GAMEID_W2_1_05_SA:
case wk::GAMEID_W2_1_07_TRY:
return id;
default:
return 0;
}
}
BOOL WINAPI DllMain(HMODULE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
{
PEInfo pe;
int version = fk::getGameVersion(pe.FH->TimeDateStamp);
if (version == fk::GAME_VERSION_NONE)
wk::Exe exe;
int version = getVersion(exe.FileHeader->TimeDateStamp);
if (version)
{
configure();
patch(exe, version);
}
else
{
MessageBox(NULL, "fkNetcode is incompatible with your game version. Please run the 1.05 patch or 1.07 "
"release of Worms 2. Otherwise, you can delete the module to remove this warning.", "fkNetcode",
MB_ICONWARNING);
}
else
{
configure();
patch(pe, version);
}
}
break;

View File

@ -0,0 +1,100 @@
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include "wkConfig.h"
#include "wkExe.h"
#include "wkPatch.h"
#include "wkUtils.h"
// ---- Configuration ----
BOOL cfgEnableAllControls;
BOOL cfgUnlockCamera;
BOOL cfgUnlockCursor;
void configure()
{
wk::Config config("wkUnlimiter.ini");
// Load INI settings.
config.get("Frontend", "EnableAllControls", cfgEnableAllControls, TRUE);
config.get("Game", "UnlockCamera", cfgUnlockCamera, TRUE);
config.get("Game", "UnlockCursor", cfgUnlockCursor, TRUE);
// Ensure INI file has been created with default setting.
config.set("Frontend", "EnableAllControls", cfgEnableAllControls);
config.set("Game", "UnlockCamera", cfgUnlockCamera);
config.set("Game", "UnlockCursor", cfgUnlockCursor);
}
// ---- Patch ----
void patch(wk::Exe& exe, int gameVersion)
{
if (cfgEnableAllControls)
{
wk::Patch patch(exe.Offset(0x001C5D26), 4);
patch.write(0x9090016A); // CWnd::EnableWindow(bEnable) -> CWnd::EnableWindow(TRUE)
}
if (cfgUnlockCamera)
{
wk::Patch::nops(exe.Offset(0x00142A89), 2); // X- axis
wk::Patch::nops(exe.Offset(0x00142A91), 2); // X+ axis
wk::Patch::nops(exe.Offset(0x00142AA7), 3); // Y- axis
wk::Patch::nops(exe.Offset(0x00142A9C), 3); // Y+ axis
}
if (cfgUnlockCursor)
{
wk::Patch::nops(exe.Offset(0x00159EAD), 6); // X- axis 1
wk::Patch::nops(exe.Offset(0x00159A72), 6); // X- axis 2
wk::Patch::nops(exe.Offset(0x00159ECA), 6); // X+ axis 1
wk::Patch::nops(exe.Offset(0x00159A8F), 6); // X+ axis 2
wk::Patch::nops(exe.Offset(0x00159B00), 10); // Y- axis 1 cave
wk::Patch::nops(exe.Offset(0x00159F02), 10); // Y- axis 2 cave
wk::Patch::nops(exe.Offset(0x00159B19), 6); // Y- axis 1 island
wk::Patch::nops(exe.Offset(0x00159F1B), 6); // Y- axis 2 island
wk::Patch::nops(exe.Offset(0x00159AE5), 6); // Y+ axis 1
wk::Patch::nops(exe.Offset(0x00159EE7), 6); // Y+ axis 2
}
}
// ---- Main ----
int getVersion(DWORD timeDateStamp)
{
int id = wk::getGameID(timeDateStamp);
switch (id)
{
case wk::GAMEID_WA_3_8_CD:
return id;
default:
return 0;
}
}
BOOL WINAPI DllMain(HMODULE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
{
wk::Exe exe;
int version = getVersion(exe.FileHeader->TimeDateStamp);
if (version)
{
configure();
patch(exe, version);
}
else
{
MessageBox(NULL, "wkUnlimiter is incompatible with your game version. Please run the 3.8 CD release of "
"Worms Armageddon. Otherwise, you can delete the module to remove this warning.", "wkUnlimiter",
MB_ICONWARNING);
}
}
break;
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}

View File

@ -0,0 +1,39 @@
#include "wkConfig.h"
#include <stdio.h>
namespace wk
{
Config::Config(LPCSTR fileName)
{
GetModuleFileName(NULL, _filePath, MAX_PATH);
char* sepIdx = strrchr(_filePath, '\\') + 1;
strcpy_s(sepIdx, MAX_PATH - (int)(sepIdx - _filePath), fileName);
}
void Config::get(LPCSTR category, LPCSTR key, BOOL& result, UINT fallback) const
{
result = GetPrivateProfileInt(category, key, fallback, _filePath);
}
void Config::get(LPCSTR category, LPCSTR key, UINT& result, UINT fallback) const
{
result = GetPrivateProfileInt(category, key, fallback, _filePath);
}
void Config::get(LPCSTR category, LPCSTR key, LPSTR result, INT resultLength, LPCSTR fallback) const
{
GetPrivateProfileString(category, key, fallback, result, resultLength, _filePath);
}
void Config::set(LPCSTR category, LPCSTR key, UINT value) const
{
CHAR buffer[32];
sprintf_s(buffer, "%d", value);
WritePrivateProfileString(category, key, buffer, _filePath);
}
void Config::set(LPCSTR category, LPCSTR key, LPCSTR value) const
{
WritePrivateProfileString(category, key, value, _filePath);
}
}

View File

@ -0,0 +1,20 @@
#pragma once
#include <Windows.h>
namespace wk
{
class Config
{
public:
Config(LPCSTR fileName);
void get(LPCSTR category, LPCSTR key, BOOL& result, UINT fallback) const;
void get(LPCSTR category, LPCSTR key, UINT& result, UINT fallback) const;
void get(LPCSTR category, LPCSTR key, LPSTR result, INT resultLength, LPCSTR fallback = NULL) const;
void set(LPCSTR category, LPCSTR key, UINT value) const;
void set(LPCSTR category, LPCSTR key, LPCSTR value) const;
private:
CHAR _filePath[MAX_PATH];
};
}

View File

@ -0,0 +1,103 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{cded4b7c-91df-45d3-9704-db8750bdaf5b}</ProjectGuid>
<RootNamespace>wkUnlimiter</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<OutDir>bin\$(Configuration)\</OutDir>
<IntDir>obj\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>bin\$(Configuration)\</OutDir>
<IntDir>obj\$(Configuration)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;WKUNLIMITER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(ProjectDir)..\WormKitTools\include\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;WKUNLIMITER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(ProjectDir)..\WormKitTools\include\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="wkConfig.cpp" />
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="wkConfig.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WormKitTools\FrontendKitLib.vcxproj">
<Project>{068a8647-0a66-4e39-983b-43aceac5c937}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="wkConfig.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="wkConfig.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>