-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b099127
Showing
5 changed files
with
300 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
#pragma once | ||
#include <Windows.h> | ||
|
||
class CPatch | ||
{ | ||
public: | ||
inline static void Patch(void* address, void* data, int size) | ||
{ | ||
unsigned long protect[2]; | ||
VirtualProtect(address, size, PAGE_EXECUTE_READWRITE, &protect[0]); | ||
memcpy(address, data, size); | ||
VirtualProtect(address, size, protect[0], &protect[1]); | ||
} | ||
|
||
inline static void Patch2(int address, void* data, int size) | ||
{ | ||
unsigned long protect[2]; | ||
VirtualProtect((void *)address, size, PAGE_EXECUTE_READWRITE, &protect[0]); | ||
memcpy((void *)address, data, size); | ||
VirtualProtect((void *)address, size, protect[0], &protect[1]); | ||
} | ||
|
||
inline static void Unprotect(int address, int size) | ||
{ | ||
unsigned long protect[2]; | ||
VirtualProtect((void *)address, size, PAGE_EXECUTE_READWRITE, &protect[0]); | ||
} | ||
inline static void Nop(int address, int size) | ||
{ | ||
unsigned long protect[2]; | ||
VirtualProtect((void *)address, size, PAGE_EXECUTE_READWRITE, &protect[0]); | ||
memset((void *)address, 0x90, size); | ||
VirtualProtect((void *)address, size, protect[0], &protect[1]); | ||
} | ||
inline static void FillWithZeroes(int address, int size) | ||
{ | ||
unsigned long protect[2]; | ||
VirtualProtect((void *)address, size, PAGE_EXECUTE_READWRITE, &protect[0]); | ||
memset((void *)address, 0x00, size); | ||
VirtualProtect((void *)address, size, protect[0], &protect[1]); | ||
} | ||
inline static void RedirectCall(int address, void *func) | ||
{ | ||
int temp = 0xE8; | ||
Patch((void *)address, &temp, 1); | ||
temp = (int)func - ((int)address + 5); | ||
Patch((void *)((int)address + 1), &temp, 4); | ||
} | ||
inline static void RedirectJump(int address, void *func) | ||
{ | ||
int temp = 0xE9; | ||
Patch((void *)address, &temp, 1); | ||
temp = (int)func - ((int)address + 5); | ||
Patch((void *)((int)address + 1), &temp, 4); | ||
} | ||
inline static void SetChar(int address, char value) | ||
{ | ||
Patch((void *)address, &value, 1); | ||
} | ||
inline static void SetUChar(int address, unsigned char value) | ||
{ | ||
Patch((void *)address, &value, 1); | ||
} | ||
inline static void SetShort(int address, short value) | ||
{ | ||
Patch((void *)address, &value, 2); | ||
} | ||
inline static void SetUShort(int address, unsigned short value) | ||
{ | ||
Patch((void *)address, &value, 2); | ||
} | ||
inline static void SetInt(int address, int value) | ||
{ | ||
Patch((void *)address, &value, 4); | ||
} | ||
inline static void SetUInt(int address, unsigned int value) | ||
{ | ||
Patch((void *)address, &value, 4); | ||
} | ||
inline static void SetUIntWithCheck(int address, unsigned int value, unsigned int expectedValue) | ||
{ | ||
if (*(unsigned int *)address == expectedValue) | ||
Patch((void *)address, &value, 4); | ||
} | ||
inline static void SetFloat(int address, float value) | ||
{ | ||
Patch((void *)address, &value, 4); | ||
} | ||
inline static void SetDouble(int address, double value) | ||
{ | ||
Patch((void *)address, &value, 8); | ||
} | ||
inline static void SetPointer(int address, void *value) | ||
{ | ||
Patch((void *)address, &value, 4); | ||
} | ||
|
||
inline static void AdjustPointer(int address, void *value, DWORD offset, DWORD end) | ||
{ | ||
int result; | ||
if((DWORD)*(DWORD*)address >= offset && (DWORD)*(DWORD*)address <= end) { | ||
result = (DWORD)value + (DWORD)*(DWORD*)address - (DWORD)offset; | ||
Patch((void *)address, &result, 4); | ||
} else { | ||
address = address + 1; | ||
if((DWORD)*(DWORD*)address >= offset && (DWORD)*(DWORD*)address <= end) { | ||
result = (DWORD)value + (DWORD)*(DWORD*)address - (DWORD)offset; | ||
Patch((void *)address, &result, 4); | ||
} else { | ||
address = address + 1; | ||
if((DWORD)*(DWORD*)address >= offset && (DWORD)*(DWORD*)address <= end) { | ||
result = (DWORD)value + (DWORD)*(DWORD*)address - (DWORD)offset; | ||
Patch((void *)address, &result, 4); | ||
} else { | ||
address = address + 1; | ||
if((DWORD)*(DWORD*)address >= offset && (DWORD)*(DWORD*)address <= end) { | ||
result = (DWORD)value + (DWORD)*(DWORD*)address - (DWORD)offset; | ||
Patch((void *)address, &result, 4); | ||
} else { | ||
address = address + 1; | ||
if((DWORD)*(DWORD*)address >= offset && (DWORD)*(DWORD*)address <= end) { | ||
result = (DWORD)value + (DWORD)*(DWORD*)address - (DWORD)offset; | ||
Patch((void *)address, &result, 4); | ||
} else { | ||
address = address + 1; | ||
if((DWORD)*(DWORD*)address >= offset && (DWORD)*(DWORD*)address <= end) { | ||
result = (DWORD)value + (DWORD)*(DWORD*)address - (DWORD)offset; | ||
Patch((void *)address, &result, 4); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
inline static bool FileExists(const TCHAR *fileName) | ||
{ | ||
DWORD fileAttr; | ||
fileAttr = GetFileAttributes(fileName); | ||
if (0xFFFFFFFF == fileAttr && GetLastError()==ERROR_FILE_NOT_FOUND) | ||
return false; | ||
return true; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup Label="ProjectConfigurations"> | ||
<ProjectConfiguration Include="Release|Win32"> | ||
<Configuration>Release</Configuration> | ||
<Platform>Win32</Platform> | ||
</ProjectConfiguration> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClInclude Include="CPatch.h" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClCompile Include="dllmain.cpp" /> | ||
</ItemGroup> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>{AB0FB32B-95D2-4DDC-8D9E-F9EE99CC16DD}</ProjectGuid> | ||
<RootNamespace>MafiaDebugPatch</RootNamespace> | ||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion> | ||
</PropertyGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | ||
<ConfigurationType>DynamicLibrary</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<PlatformToolset>v140</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)'=='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)'=='Release|Win32'"> | ||
<TargetExt>.asi</TargetExt> | ||
<OutDir>$(SolutionDir)\$(Configuration)\</OutDir> | ||
</PropertyGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>MaxSpeed</Optimization> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<SDLCheck>true</SDLCheck> | ||
</ClCompile> | ||
<Link> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||
<ImportGroup Label="ExtensionTargets"> | ||
</ImportGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?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;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;hm;inl;inc;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> | ||
<ClInclude Include="CPatch.h"> | ||
<Filter>Header Files</Filter> | ||
</ClInclude> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClCompile Include="dllmain.cpp"> | ||
<Filter>Source Files</Filter> | ||
</ClCompile> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Mafia.DebugPatch | ||
2016.10.13 | ||
created by JaGoTu | ||
An asi patch that makes Mafia print all debugging messages in game. | ||
|
||
Currently only supports v1.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
2016.10.13 | ||
created by JaGoTu | ||
An asi patch that makes Mafia print all debugging messages in game. | ||
Currently only supports v1.2 | ||
*/ | ||
|
||
#include "CPatch.h" | ||
|
||
void Init(); | ||
void script_command_hook(); | ||
|
||
|
||
|
||
|
||
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { | ||
if (ul_reason_for_call == DLL_PROCESS_ATTACH) { | ||
Init(); | ||
} | ||
return TRUE; | ||
} | ||
|
||
void Init() | ||
{ | ||
CPatch::SetUChar(0x4637F0, 0x10); //debug_text is a function with one string parameter, not garbage | ||
CPatch::SetUChar(0x462CF9, 0x7F); //String length is now max 127, not 48 | ||
CPatch::RedirectCall(0x46D3F9, *script_command_hook); //Redirect command processing | ||
|
||
} | ||
|
||
|
||
void __declspec(naked)script_command_hook() { | ||
static void* sub_47BE10 = (void*)0x47BE10; | ||
static void* PrintMafiaString = (void*)0x5F9D50; | ||
static int unk_6BF980 = 0x6BF980; | ||
_asm { | ||
mov eax, [ecx + 4]; | ||
mov ecx, [esp + 4]; | ||
lea eax, [eax + ecx * 8]; | ||
|
||
PUSHAD; | ||
PUSHFD; | ||
mov eax, [eax] | ||
cmp eax, 0x38; | ||
jnz NotDebug; | ||
|
||
mov edx, [ebp + 1Ch]; | ||
mov ecx, esi; | ||
push edx; | ||
call sub_47BE10; | ||
mov eax, [eax + 4]; | ||
mov esi, unk_6BF980; | ||
mov ecx, esi; | ||
|
||
push 0xFF0000; //DEBUG TEXT COLOR | ||
push eax; | ||
call PrintMafiaString; | ||
|
||
NotDebug: | ||
POPFD; | ||
POPAD; | ||
retn 4; | ||
} | ||
} |