diff --git a/D2Constants.h b/D2Constants.h index 671cffc..cddef7f 100644 --- a/D2Constants.h +++ b/D2Constants.h @@ -4,46 +4,46 @@ #define _D2CONSTANTS_H /**************************************************************************** -* * -* D2Constants.h * -* Copyright (C) Olivier Verville * -* * -* Licensed under the Apache License, Version 2.0 (the "License"); * -* you may not use this file except in compliance with the License. * -* You may obtain a copy of the License at * -* * -* http://www.apache.org/licenses/LICENSE-2.0 * -* * -* Unless required by applicable law or agreed to in writing, software * -* distributed under the License is distributed on an "AS IS" BASIS, * -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* -* See the License for the specific language governing permissions and * -* limitations under the License. * -* * +* * +* D2Constants.h * +* Copyright (C) Olivier Verville * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* +* See the License for the specific language governing permissions and * +* limitations under the License. * +* * *---------------------------------------------------------------------------* -* * -* https://github.com/olivier-verville/D2Template * -* * -* This file is meant to declare various constant data. As you add more * -* custom code to your library, you will be using many constant values * -* used by the game's internal code. Unit types are a good example. * -* Declaring constants allows you to assign a name to these constants * -* which are more convenient to use in your source code. * -* * -* Another advantage is smaller impact in cases where these values would * -* need to change. Rather than revising every single piece of code using * -* this value, you only need to change your constant's value * -* * +* * +* https://github.com/olivier-verville/D2Template * +* * +* This file is meant to declare various constant data. As you add more * +* custom code to your library, you will be using many constant values * +* used by the game's internal code. Unit types are a good example. * +* Declaring constants allows you to assign a name to these constants * +* which are more convenient to use in your source code. * +* * +* Another advantage is smaller impact in cases where these values would * +* need to change. Rather than revising every single piece of code using * +* this value, you only need to change your constant's value * +* * *****************************************************************************/ enum D2C_UnitTypes { - UNIT_PLAYER, // 0 - Players - UNIT_MONSTER, // 1 - Monsters - UNIT_OBJECT, // 2 - Objects - UNIT_MISSILE, // 3 - Missiles - UNIT_ITEM, // 4 - Items - UNIT_TILE // 5 - Tiles + UNIT_PLAYER, // 0 - Players + UNIT_MONSTER, // 1 - Monsters + UNIT_OBJECT, // 2 - Objects + UNIT_MISSILE, // 3 - Missiles + UNIT_ITEM, // 4 - Items + UNIT_TILE // 5 - Tiles }; // end of file --------------------------------------------------------------- diff --git a/D2DataTables.h b/D2DataTables.h index a38e4d7..71f0457 100644 --- a/D2DataTables.h +++ b/D2DataTables.h @@ -6,49 +6,49 @@ #pragma pack(1) /**************************************************************************** -* * -* D2DataTables.h * -* Copyright (C) Olivier Verville * -* * -* Licensed under the Apache License, Version 2.0 (the "License"); * -* you may not use this file except in compliance with the License. * -* You may obtain a copy of the License at * -* * -* http://www.apache.org/licenses/LICENSE-2.0 * -* * -* Unless required by applicable law or agreed to in writing, software * -* distributed under the License is distributed on an "AS IS" BASIS, * -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* -* See the License for the specific language governing permissions and * -* limitations under the License. * -* * +* * +* D2DataTables.h * +* Copyright (C) Olivier Verville * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* +* See the License for the specific language governing permissions and * +* limitations under the License. * +* * *---------------------------------------------------------------------------* -* * -* https://github.com/olivier-verville/D2Template * -* * -* This file is an expansion of D2Structs.h, meant to be used to declare * -* structs representing the record of a data table once loaded in memory * -* by the game, such as Monstats.txt or Charstats.txt * -* * +* * +* https://github.com/olivier-verville/D2Template * +* * +* This file is an expansion of D2Structs.h, meant to be used to declare * +* structs representing the record of a data table once loaded in memory * +* by the game, such as Monstats.txt or Charstats.txt * +* * *****************************************************************************/ /**************************************************************************** -* * -* DECLARATIONS * -* * +* * +* DECLARATIONS * +* * *****************************************************************************/ struct D2MonstatsTXT; /**************************************************************************** -* * -* DEFINITIONS * -* * +* * +* DEFINITIONS * +* * *****************************************************************************/ struct D2MonstatsTXT { - //... + //... }; // end of file -------------------------------------------------------------- diff --git a/D2PacketDef.h b/D2PacketDef.h index 3158fef..6acfd82 100644 --- a/D2PacketDef.h +++ b/D2PacketDef.h @@ -6,36 +6,36 @@ #pragma pack(1) /**************************************************************************** -* * -* D2PacketDef.h * -* Copyright (C) Olivier Verville * -* * -* Licensed under the Apache License, Version 2.0 (the "License"); * -* you may not use this file except in compliance with the License. * -* You may obtain a copy of the License at * -* * -* http://www.apache.org/licenses/LICENSE-2.0 * -* * -* Unless required by applicable law or agreed to in writing, software * -* distributed under the License is distributed on an "AS IS" BASIS, * -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* -* See the License for the specific language governing permissions and * -* limitations under the License. * -* * +* * +* D2PacketDef.h * +* Copyright (C) Olivier Verville * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* +* See the License for the specific language governing permissions and * +* limitations under the License. * +* * *---------------------------------------------------------------------------* -* * -* https://github.com/olivier-verville/D2Template * -* * -* This file is an expansion of D2Structs.h, meant to be used to declare * -* structs representing network data packets used by the game to * -* handle communications between the server and the client * -* * +* * +* https://github.com/olivier-verville/D2Template * +* * +* This file is an expansion of D2Structs.h, meant to be used to declare * +* structs representing network data packets used by the game to * +* handle communications between the server and the client * +* * *****************************************************************************/ /**************************************************************************** -* * -* DECLARATIONS * -* * +* * +* DECLARATIONS * +* * *****************************************************************************/ struct D2GSPacketClt01; @@ -47,14 +47,14 @@ struct D2GSPacketSrv02; struct D2GSPacketSrv03; /**************************************************************************** -* * -* DEFINITIONS * -* * +* * +* DEFINITIONS * +* * *****************************************************************************/ struct D2GSPacketClt01 { - //... + //... }; // end of file -------------------------------------------------------------- diff --git a/D2Patch.h b/D2Patch.h index 74c22ea..6ce1051 100644 --- a/D2Patch.h +++ b/D2Patch.h @@ -6,40 +6,40 @@ #include "D2PatchConst.h" /**************************************************************************** -* * -* D2Patch.h * -* Copyright (C) Olivier Verville * -* * -* Licensed under the Apache License, Version 2.0 (the "License"); * -* you may not use this file except in compliance with the License. * -* You may obtain a copy of the License at * -* * -* http://www.apache.org/licenses/LICENSE-2.0 * -* * -* Unless required by applicable law or agreed to in writing, software * -* distributed under the License is distributed on an "AS IS" BASIS, * -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* -* See the License for the specific language governing permissions and * -* limitations under the License. * -* * +* * +* D2Patch.h * +* Copyright (C) Olivier Verville * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* +* See the License for the specific language governing permissions and * +* limitations under the License. * +* * *---------------------------------------------------------------------------* -* * -* https://github.com/olivier-verville/D2Template * -* * -* This file is where you declare all your patches, in order to inject * -* your own code into the game. Each patch should be declared in the * -* array, in order to be handled by D2Template's patcher * -* * +* * +* https://github.com/olivier-verville/D2Template * +* * +* This file is where you declare all your patches, in order to inject * +* your own code into the game. Each patch should be declared in the * +* array, in order to be handled by D2Template's patcher * +* * *****************************************************************************/ static const DLLPatchStrc gptTemplatePatches[] = { - /* - All your patches should be added here - Keep it organized to save yourself some headache - */ - - {D2DLL_INVALID} // this must be the last entry in the array! + /* + All your patches should be added here + Keep it organized to save yourself some headache + */ + + {D2DLL_INVALID} // this must be the last entry in the array! }; // end of file -------------------------------------------------------------- diff --git a/D2PatchConst.h b/D2PatchConst.h index 5939986..f8c5c54 100644 --- a/D2PatchConst.h +++ b/D2PatchConst.h @@ -4,42 +4,42 @@ #define _D2PATCHCONST_H /**************************************************************************** -* * -* D2PatchConst.h * -* Copyright (C) Olivier Verville * -* * -* Licensed under the Apache License, Version 2.0 (the "License"); * -* you may not use this file except in compliance with the License. * -* You may obtain a copy of the License at * -* * -* http://www.apache.org/licenses/LICENSE-2.0 * -* * -* Unless required by applicable law or agreed to in writing, software * -* distributed under the License is distributed on an "AS IS" BASIS, * -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* -* See the License for the specific language governing permissions and * -* limitations under the License. * -* * +* * +* D2PatchConst.h * +* Copyright (C) Olivier Verville * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* +* See the License for the specific language governing permissions and * +* limitations under the License. * +* * *---------------------------------------------------------------------------* -* * -* https://github.com/olivier-verville/D2Template * -* * -* This file defines various expressions to simplify the declaration of * -* patches in D2Patch.h, and you shouldn't modify this file unless you * -* know what you're doing. * -* * +* * +* https://github.com/olivier-verville/D2Template * +* * +* This file defines various expressions to simplify the declaration of * +* patches in D2Patch.h, and you shouldn't modify this file unless you * +* know what you're doing. * +* * *****************************************************************************/ -#define PATCH_JMP 0x000000E9 -#define PATCH_CALL 0x000000E8 -#define PATCH_RETN 0x000000C3 -#define PATCH_RETN4 0x000004C2 -#define PATCH_RETN8 0x000008C2 -#define PATCH_RETN0C 0x00000CC2 -#define PATCH_RETN10 0x000010C2 -#define PATCH_RETN14 0x000014C2 -#define PATCH_RETN18 0x000018C2 -#define PATCH_RETN1C 0x00001CC2 -#define PATCH_NOPBLOCK 0x90909090 +#define PATCH_JMP 0x000000E9 +#define PATCH_CALL 0x000000E8 +#define PATCH_RETN 0x000000C3 +#define PATCH_RETN4 0x000004C2 +#define PATCH_RETN8 0x000008C2 +#define PATCH_RETN0C 0x00000CC2 +#define PATCH_RETN10 0x000010C2 +#define PATCH_RETN14 0x000014C2 +#define PATCH_RETN18 0x000018C2 +#define PATCH_RETN1C 0x00001CC2 +#define PATCH_NOPBLOCK 0x90909090 #endif \ No newline at end of file diff --git a/D2Ptrs.h b/D2Ptrs.h index e316b9f..c17e4cc 100644 --- a/D2Ptrs.h +++ b/D2Ptrs.h @@ -4,63 +4,63 @@ #define _D2PTRS_H /**************************************************************************** -* * -* D2Ptrs.h * -* * -* Licensed under the Apache License, Version 2.0 (the "License"); * -* you may not use this file except in compliance with the License. * -* You may obtain a copy of the License at * -* * -* http://www.apache.org/licenses/LICENSE-2.0 * -* * -* Unless required by applicable law or agreed to in writing, software * -* distributed under the License is distributed on an "AS IS" BASIS, * -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* -* See the License for the specific language governing permissions and * -* limitations under the License. * -* * +* * +* D2Ptrs.h * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* +* See the License for the specific language governing permissions and * +* limitations under the License. * +* * *---------------------------------------------------------------------------* -* * -* https://github.com/olivier-verville/D2Template * -* * -* This file is used to declare pointers, be it function or variable * -* pointers, from the game's libraries. * -* * -* It is recommended that you keep this file organized by which dll the * -* pointer is imported from, what type of pointer it is, etc. Ordering * -* them by address can also end up being very useful * -* * +* * +* https://github.com/olivier-verville/D2Template * +* * +* This file is used to declare pointers, be it function or variable * +* pointers, from the game's libraries. * +* * +* It is recommended that you keep this file organized by which dll the * +* pointer is imported from, what type of pointer it is, etc. Ordering * +* them by address can also end up being very useful * +* * *****************************************************************************/ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// These are the macros used by the template core to declare /// -// pointers. Do not touch unless you know what you're doing /// -// /// -#define D2FUNC(DLL, NAME, RETURN, CONV, ARGS, OFFSET) typedef RETURN (##CONV##* DLL##_##NAME##_t ) ARGS; static DLL##_##NAME##_t DLL##_##NAME = (DLL##_##NAME##_t )( DLLBASE_##DLL + OFFSET); /// -#define D2VAR(DLL, NAME, TYPE, OFFSET) typedef TYPE DLL##_##NAME##_vt; static DLL##_##NAME##_vt * DLL##_##NAME = (DLL##_##NAME##_vt *)( DLLBASE_##DLL + OFFSET); /// -#define D2PTR(DLL, NAME, OFFSET) static DWORD NAME = (DLLBASE_##DLL + OFFSET); /// +// These are the macros used by the template core to declare /// +// pointers. Do not touch unless you know what you're doing /// +// /// +#define D2FUNC(DLL, NAME, RETURN, CONV, ARGS, OFFSET) typedef RETURN (##CONV##* DLL##_##NAME##_t ) ARGS; static DLL##_##NAME##_t DLL##_##NAME = (DLL##_##NAME##_t )( DLLBASE_##DLL + OFFSET); /// +#define D2VAR(DLL, NAME, TYPE, OFFSET) typedef TYPE DLL##_##NAME##_vt; static DLL##_##NAME##_vt * DLL##_##NAME = (DLL##_##NAME##_vt *)( DLLBASE_##DLL + OFFSET); /// +#define D2PTR(DLL, NAME, OFFSET) static DWORD NAME = (DLLBASE_##DLL + OFFSET); /// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /******************************************************************************** -* * -* D2GAME.DLL POINTERS * -* * +* * +* D2GAME.DLL POINTERS * +* * *********************************************************************************/ /******************************************************************************** -* * -* D2CLIENT.DLL POINTERS * -* * +* * +* D2CLIENT.DLL POINTERS * +* * *********************************************************************************/ /******************************************************************************** -* * -* D2COMMON.DLL POINTERS * -* * +* * +* D2COMMON.DLL POINTERS * +* * *********************************************************************************/ diff --git a/D2Structs.h b/D2Structs.h index c0781c0..9696d16 100644 --- a/D2Structs.h +++ b/D2Structs.h @@ -8,54 +8,54 @@ #pragma pack(1) /**************************************************************************** -* * -* D2Structs.h * -* * -* Licensed under the Apache License, Version 2.0 (the "License"); * -* you may not use this file except in compliance with the License. * -* You may obtain a copy of the License at * -* * -* http://www.apache.org/licenses/LICENSE-2.0 * -* * -* Unless required by applicable law or agreed to in writing, software * -* distributed under the License is distributed on an "AS IS" BASIS, * -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* -* See the License for the specific language governing permissions and * -* limitations under the License. * -* * +* * +* D2Structs.h * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* +* See the License for the specific language governing permissions and * +* limitations under the License. * +* * *---------------------------------------------------------------------------* -* * -* https://github.com/olivier-verville/D2Template * -* * -* This file is used to declare data structures used by the game to * -* represent various entities, such as the data structure representing * -* a unit entity, or a game entity * -* * +* * +* https://github.com/olivier-verville/D2Template * +* * +* This file is used to declare data structures used by the game to * +* represent various entities, such as the data structure representing * +* a unit entity, or a game entity * +* * *****************************************************************************/ /**************************************************************************** -* * -* DECLARATIONS * -* * +* * +* DECLARATIONS * +* * *****************************************************************************/ struct D2GameStrc; struct D2UnitStrc; /**************************************************************************** -* * -* DEFINITIONS * -* * +* * +* DEFINITIONS * +* * *****************************************************************************/ struct D2GameStrc { - //... + //... }; struct D2UnitStrc { - //... + //... }; // end of file -------------------------------------------------------------- diff --git a/D2Vars.h b/D2Vars.h index a43905c..8a7812b 100644 --- a/D2Vars.h +++ b/D2Vars.h @@ -1,32 +1,32 @@ #ifdef _D2VARS_H -#define VAR(Type, Name) Type Name; +#define VAR(Type, Name) Type Name; #else -#define VAR(Type, Name) extern Type Name; +#define VAR(Type, Name) extern Type Name; #endif /**************************************************************************** -* * -* D2Vars.h * -* * -* Licensed under the Apache License, Version 2.0 (the "License"); * -* you may not use this file except in compliance with the License. * -* You may obtain a copy of the License at * -* * -* http://www.apache.org/licenses/LICENSE-2.0 * -* * -* Unless required by applicable law or agreed to in writing, software * -* distributed under the License is distributed on an "AS IS" BASIS, * -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* -* See the License for the specific language governing permissions and * -* limitations under the License. * -* * +* * +* D2Vars.h * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* +* See the License for the specific language governing permissions and * +* limitations under the License. * +* * *---------------------------------------------------------------------------* -* * -* https://github.com/olivier-verville/D2Template * -* * -* This file is used to declare your own global variables to use * -* within your code. These variables can be used anywhere in your code * -* * +* * +* https://github.com/olivier-verville/D2Template * +* * +* This file is used to declare your own global variables to use * +* within your code. These variables can be used anywhere in your code * +* * *****************************************************************************/ VAR(DWORD, SampleVariable1) diff --git a/DLLmain.cpp b/DLLmain.cpp index 2d6eeab..4e415d7 100644 --- a/DLLmain.cpp +++ b/DLLmain.cpp @@ -4,170 +4,170 @@ #include "D2Patch.h" /**************************************************************************** -* * -* DLLmain.h * -* * -* Licensed under the Apache License, Version 2.0 (the "License"); * -* you may not use this file except in compliance with the License. * -* You may obtain a copy of the License at * -* * -* http://www.apache.org/licenses/LICENSE-2.0 * -* * -* Unless required by applicable law or agreed to in writing, software * -* distributed under the License is distributed on an "AS IS" BASIS, * -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* -* See the License for the specific language governing permissions and * -* limitations under the License. * -* * +* * +* DLLmain.h * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* +* See the License for the specific language governing permissions and * +* limitations under the License. * +* * *---------------------------------------------------------------------------* -* * -* https://github.com/olivier-verville/D2Template * -* * -* D2Template core file, do not modify unless you know what you're doing * -* * +* * +* https://github.com/olivier-verville/D2Template * +* * +* D2Template core file, do not modify unless you know what you're doing * +* * *****************************************************************************/ void __fastcall D2TEMPLATE_FatalError(char* szMessage) { - MessageBoxA(NULL, szMessage, "D2Template", MB_OK | MB_ICONERROR); - TerminateProcess(GetCurrentProcess(), -1); + MessageBoxA(NULL, szMessage, "D2Template", MB_OK | MB_ICONERROR); + TerminateProcess(GetCurrentProcess(), -1); } BOOL __fastcall D2TEMPLATE_ApplyPatch(void* hGame, const DLLPatchStrc* hPatch) { - while (hPatch->nDLL != D2DLL_INVALID) - { - int nReturn = 0; - int nDLL = hPatch->nDLL; - if (nDLL < 0 || nDLL >= D2DLL_INVALID) return FALSE; - - DWORD dwAddress = hPatch->dwAddress; - if (!dwAddress) return FALSE; - - DWORD dwBaseAddress = gptDllFiles[nDLL].dwAddress; - if (!dwBaseAddress) return FALSE; - - dwAddress += dwBaseAddress; - - DWORD dwData = hPatch->dwData; - if (hPatch->bRelative){ dwData = dwData - (dwAddress + sizeof(dwData)); } - - void* hAddress = (void*)dwAddress; - DWORD dwOldPage; - - if (hPatch->nPatchSize > 0) - { - BYTE Buffer[1024]; - - for (size_t i = 0; i < hPatch->nPatchSize; i++) - Buffer[i] = (BYTE)dwData; - - VirtualProtect(hAddress, hPatch->nPatchSize, PAGE_EXECUTE_READWRITE, &dwOldPage); - nReturn = WriteProcessMemory(hGame, hAddress, &Buffer, hPatch->nPatchSize, 0); - VirtualProtect(hAddress, hPatch->nPatchSize, dwOldPage, 0); - } - - else - { - VirtualProtect(hAddress, sizeof(dwData), PAGE_EXECUTE_READWRITE, &dwOldPage); - nReturn = WriteProcessMemory(hGame, hAddress, &dwData, sizeof(dwData), 0); - VirtualProtect(hAddress, sizeof(dwData), dwOldPage, 0); - } - - if (nReturn == 0) return FALSE; - - hPatch++; - } - - return TRUE; + while (hPatch->nDLL != D2DLL_INVALID) + { + int nReturn = 0; + int nDLL = hPatch->nDLL; + if (nDLL < 0 || nDLL >= D2DLL_INVALID) return FALSE; + + DWORD dwAddress = hPatch->dwAddress; + if (!dwAddress) return FALSE; + + DWORD dwBaseAddress = gptDllFiles[nDLL].dwAddress; + if (!dwBaseAddress) return FALSE; + + dwAddress += dwBaseAddress; + + DWORD dwData = hPatch->dwData; + if (hPatch->bRelative){ dwData = dwData - (dwAddress + sizeof(dwData)); } + + void* hAddress = (void*)dwAddress; + DWORD dwOldPage; + + if (hPatch->nPatchSize > 0) + { + BYTE Buffer[1024]; + + for (size_t i = 0; i < hPatch->nPatchSize; i++) + Buffer[i] = (BYTE)dwData; + + VirtualProtect(hAddress, hPatch->nPatchSize, PAGE_EXECUTE_READWRITE, &dwOldPage); + nReturn = WriteProcessMemory(hGame, hAddress, &Buffer, hPatch->nPatchSize, 0); + VirtualProtect(hAddress, hPatch->nPatchSize, dwOldPage, 0); + } + + else + { + VirtualProtect(hAddress, sizeof(dwData), PAGE_EXECUTE_READWRITE, &dwOldPage); + nReturn = WriteProcessMemory(hGame, hAddress, &dwData, sizeof(dwData), 0); + VirtualProtect(hAddress, sizeof(dwData), dwOldPage, 0); + } + + if (nReturn == 0) return FALSE; + + hPatch++; + } + + return TRUE; } BOOL __fastcall D2TEMPLATE_LoadModules() { - for (int i = 0; i < D2DLL_INVALID; i++) - { - DLLBaseStrc* hDllFile = &gptDllFiles[i]; - - void* hModule = GetModuleHandle(hDllFile->szName); - if (!hModule) - { - hModule = LoadLibrary(hDllFile->szName); - } - - hDllFile->dwAddress = (DWORD)hModule; - } - - return TRUE; + for (int i = 0; i < D2DLL_INVALID; i++) + { + DLLBaseStrc* hDllFile = &gptDllFiles[i]; + + void* hModule = GetModuleHandle(hDllFile->szName); + if (!hModule) + { + hModule = LoadLibrary(hDllFile->szName); + } + + hDllFile->dwAddress = (DWORD)hModule; + } + + return TRUE; } int __fastcall D2TEMPLATE_GetDebugPrivilege() { - void* hToken; - LUID luid; - TOKEN_PRIVILEGES tokenPrivileges; - - if (OpenProcessToken(GetCurrentProcess(),TOKEN_ALL_ACCESS,&hToken) == 0) - { - D2TEMPLATE_FatalError("OpenProcessToken Failed"); - return 0; - } - - if (LookupPrivilegeValue(0,SE_DEBUG_NAME,&luid) == 0) - { - D2TEMPLATE_FatalError("LookupPrivilegeValue Failed"); - CloseHandle(hToken); - return 0; - } - - tokenPrivileges.PrivilegeCount = 1; - tokenPrivileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; - tokenPrivileges.Privileges[0].Luid = luid; - if (AdjustTokenPrivileges(hToken,0,&tokenPrivileges,sizeof(tokenPrivileges),0,0) == 0) - { - D2TEMPLATE_FatalError("AdjustTokenPrivileges Failed"); - CloseHandle(hToken); - return 0; - } - - CloseHandle(hToken); - return 1; + void* hToken; + LUID luid; + TOKEN_PRIVILEGES tokenPrivileges; + + if (OpenProcessToken(GetCurrentProcess(),TOKEN_ALL_ACCESS,&hToken) == 0) + { + D2TEMPLATE_FatalError("OpenProcessToken Failed"); + return 0; + } + + if (LookupPrivilegeValue(0,SE_DEBUG_NAME,&luid) == 0) + { + D2TEMPLATE_FatalError("LookupPrivilegeValue Failed"); + CloseHandle(hToken); + return 0; + } + + tokenPrivileges.PrivilegeCount = 1; + tokenPrivileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; + tokenPrivileges.Privileges[0].Luid = luid; + if (AdjustTokenPrivileges(hToken,0,&tokenPrivileges,sizeof(tokenPrivileges),0,0) == 0) + { + D2TEMPLATE_FatalError("AdjustTokenPrivileges Failed"); + CloseHandle(hToken); + return 0; + } + + CloseHandle(hToken); + return 1; } int __stdcall DllAttach() { - D2TEMPLATE_GetDebugPrivilege(); + D2TEMPLATE_GetDebugPrivilege(); - void* hGame = OpenProcess(PROCESS_ALL_ACCESS, 0, GetCurrentProcessId()); - if (!hGame) - { - D2TEMPLATE_FatalError("Failed to retrieve process"); - return 0; - } + void* hGame = OpenProcess(PROCESS_ALL_ACCESS, 0, GetCurrentProcessId()); + if (!hGame) + { + D2TEMPLATE_FatalError("Failed to retrieve process"); + return 0; + } - if (!D2TEMPLATE_LoadModules()) - { - D2TEMPLATE_FatalError("Failed to load modules"); - CloseHandle(hGame); - return 0; - } + if (!D2TEMPLATE_LoadModules()) + { + D2TEMPLATE_FatalError("Failed to load modules"); + CloseHandle(hGame); + return 0; + } - D2TEMPLATE_ApplyPatch(hGame, gptTemplatePatches); + D2TEMPLATE_ApplyPatch(hGame, gptTemplatePatches); - CloseHandle(hGame); + CloseHandle(hGame); - return 1; + return 1; } int __stdcall DllMain(HINSTANCE hModule, DWORD dwReason, void* lpReserved) { - switch (dwReason) - { - case DLL_PROCESS_ATTACH: - { - if (!DllAttach()) D2TEMPLATE_FatalError("Couldn't attach to Diablo II"); - break; - } - } - - return TRUE; + switch (dwReason) + { + case DLL_PROCESS_ATTACH: + { + if (!DllAttach()) D2TEMPLATE_FatalError("Couldn't attach to Diablo II"); + break; + } + } + + return TRUE; } \ No newline at end of file diff --git a/DLLmain.h b/DLLmain.h index 9a5c683..79cf3e6 100644 --- a/DLLmain.h +++ b/DLLmain.h @@ -1,25 +1,25 @@ /**************************************************************************** -* * -* DLLmain.h * -* * -* Licensed under the Apache License, Version 2.0 (the "License"); * -* you may not use this file except in compliance with the License. * -* You may obtain a copy of the License at * -* * -* http://www.apache.org/licenses/LICENSE-2.0 * -* * -* Unless required by applicable law or agreed to in writing, software * -* distributed under the License is distributed on an "AS IS" BASIS, * -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* -* See the License for the specific language governing permissions and * -* limitations under the License. * -* * +* * +* DLLmain.h * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* +* See the License for the specific language governing permissions and * +* limitations under the License. * +* * *---------------------------------------------------------------------------* -* * -* https://github.com/olivier-verville/D2Template * -* * -* D2Template core file, do not modify unless you know what you're doing * -* * +* * +* https://github.com/olivier-verville/D2Template * +* * +* D2Template core file, do not modify unless you know what you're doing * +* * *****************************************************************************/ #define WIN32_LEAN_AND_MEAN @@ -30,28 +30,28 @@ #include #include -#define DLLBASE_BNCLIENT (DWORD)LoadLibraryA("Bnclient.dll") -#define DLLBASE_D2CLIENT (DWORD)LoadLibraryA("D2Client.dll") -#define DLLBASE_D2CMP (DWORD)LoadLibraryA("D2CMP.dll") -#define DLLBASE_D2COMMON (DWORD)LoadLibraryA("D2Common.dll") -#define DLLBASE_D2DDRAW (DWORD)LoadLibraryA("D2DDraw.dll") -#define DLLBASE_D2DIRECT3D (DWORD)LoadLibraryA("D2Direct3D.dll") -#define DLLBASE_D2GAME (DWORD)LoadLibraryA("D2Game.dll") -#define DLLBASE_D2GDI (DWORD)LoadLibraryA("D2Gdi.dll") -#define DLLBASE_D2GFX (DWORD)LoadLibraryA("D2Gfx.dll") -#define DLLBASE_D2GLIDE (DWORD)LoadLibraryA("D2Glide.dll") -#define DLLBASE_D2LANG (DWORD)LoadLibraryA("D2Lang.dll") -#define DLLBASE_D2LAUNCH (DWORD)LoadLibraryA("D2Launch.dll") -#define DLLBASE_D2MCPCLIENT (DWORD)LoadLibraryA("D2MCPClient.dll") -#define DLLBASE_D2MULTI (DWORD)LoadLibraryA("D2Multi.dll") -#define DLLBASE_D2NET (DWORD)LoadLibraryA("D2Net.dll") -#define DLLBASE_D2SOUND (DWORD)LoadLibraryA("D2Sound.dll") -#define DLLBASE_D2WIN (DWORD)LoadLibraryA("D2Win.dll") -#define DLLBASE_FOG (DWORD)LoadLibraryA("Fog.dll") -#define DLLBASE_STORM (DWORD)LoadLibraryA("Storm.dll") -#define DLLBASE_IJL11 (DWORD)LoadLibraryA("ijl11.dll") -#define DLLBASE_BINKW32 (DWORD)LoadLibraryA("binkw32.dll") -#define DLLBASE_SMACKW32 (DWORD)LoadLibraryA("SmackW32.dll") +#define DLLBASE_BNCLIENT (DWORD)LoadLibraryA("Bnclient.dll") +#define DLLBASE_D2CLIENT (DWORD)LoadLibraryA("D2Client.dll") +#define DLLBASE_D2CMP (DWORD)LoadLibraryA("D2CMP.dll") +#define DLLBASE_D2COMMON (DWORD)LoadLibraryA("D2Common.dll") +#define DLLBASE_D2DDRAW (DWORD)LoadLibraryA("D2DDraw.dll") +#define DLLBASE_D2DIRECT3D (DWORD)LoadLibraryA("D2Direct3D.dll") +#define DLLBASE_D2GAME (DWORD)LoadLibraryA("D2Game.dll") +#define DLLBASE_D2GDI (DWORD)LoadLibraryA("D2Gdi.dll") +#define DLLBASE_D2GFX (DWORD)LoadLibraryA("D2Gfx.dll") +#define DLLBASE_D2GLIDE (DWORD)LoadLibraryA("D2Glide.dll") +#define DLLBASE_D2LANG (DWORD)LoadLibraryA("D2Lang.dll") +#define DLLBASE_D2LAUNCH (DWORD)LoadLibraryA("D2Launch.dll") +#define DLLBASE_D2MCPCLIENT (DWORD)LoadLibraryA("D2MCPClient.dll") +#define DLLBASE_D2MULTI (DWORD)LoadLibraryA("D2Multi.dll") +#define DLLBASE_D2NET (DWORD)LoadLibraryA("D2Net.dll") +#define DLLBASE_D2SOUND (DWORD)LoadLibraryA("D2Sound.dll") +#define DLLBASE_D2WIN (DWORD)LoadLibraryA("D2Win.dll") +#define DLLBASE_FOG (DWORD)LoadLibraryA("Fog.dll") +#define DLLBASE_STORM (DWORD)LoadLibraryA("Storm.dll") +#define DLLBASE_IJL11 (DWORD)LoadLibraryA("ijl11.dll") +#define DLLBASE_BINKW32 (DWORD)LoadLibraryA("binkw32.dll") +#define DLLBASE_SMACKW32 (DWORD)LoadLibraryA("SmackW32.dll") #include "D2Constants.h" #include "D2Structs.h" @@ -62,70 +62,70 @@ struct DLLBaseStrc { - char* szName; - DWORD dwAddress; + char* szName; + DWORD dwAddress; }; struct DLLPatchStrc { - int nDLL; - DWORD dwAddress; - DWORD dwData; - BOOL bRelative; - size_t nPatchSize; + int nDLL; + DWORD dwAddress; + DWORD dwData; + BOOL bRelative; + size_t nPatchSize; }; enum D2TEMPLATE_DLL_FILES { - D2DLL_BINKW32, - D2DLL_BNCLIENT, - D2DLL_D2CLIENT, - D2DLL_D2CMP, - D2DLL_D2COMMON, - D2DLL_D2DDRAW, - D2DLL_D2DIRECT3D, - D2DLL_D2GAME, - D2DLL_D2GDI, - D2DLL_D2GFX, - D2DLL_D2GLIDE, - D2DLL_D2LANG, - D2DLL_D2LAUNCH, - D2DLL_D2MCPCLIENT, - D2DLL_D2MULTI, - D2DLL_D2NET, - D2DLL_D2SOUND, - D2DLL_D2WIN, - D2DLL_FOG, - D2DLL_IJL11, - D2DLL_SMACKW32, - D2DLL_STORM, - D2DLL_INVALID + D2DLL_BINKW32, + D2DLL_BNCLIENT, + D2DLL_D2CLIENT, + D2DLL_D2CMP, + D2DLL_D2COMMON, + D2DLL_D2DDRAW, + D2DLL_D2DIRECT3D, + D2DLL_D2GAME, + D2DLL_D2GDI, + D2DLL_D2GFX, + D2DLL_D2GLIDE, + D2DLL_D2LANG, + D2DLL_D2LAUNCH, + D2DLL_D2MCPCLIENT, + D2DLL_D2MULTI, + D2DLL_D2NET, + D2DLL_D2SOUND, + D2DLL_D2WIN, + D2DLL_FOG, + D2DLL_IJL11, + D2DLL_SMACKW32, + D2DLL_STORM, + D2DLL_INVALID }; static DLLBaseStrc gptDllFiles [] = { - {"Binkw32.dll", NULL}, - {"BnClient.dll", NULL}, - {"D2Client.dll", NULL}, - {"D2CMP.dll", NULL}, - {"D2Common.dll", NULL}, - {"D2DDraw.dll", NULL}, - {"D2Direct3D.dll", NULL}, - {"D2Game.dll", NULL}, - {"D2Gdi.dll", NULL}, - {"D2Gfx.dll", NULL}, - {"D2Glide.dll", NULL}, - {"D2Lang.dll", NULL}, - {"D2Launch.dll", NULL}, - {"D2MCPClient.dll", NULL}, - {"D2Multi.dll", NULL}, - {"D2Net.dll", NULL}, - {"D2Sound.dll", NULL}, - {"D2Win.dll", NULL}, - {"Fog.dll", NULL}, - {"Ijl11.dll", NULL}, - {"SmackW32.dll", NULL}, - {"Storm.dll", NULL}, + {"Binkw32.dll", NULL}, + {"BnClient.dll", NULL}, + {"D2Client.dll", NULL}, + {"D2CMP.dll", NULL}, + {"D2Common.dll", NULL}, + {"D2DDraw.dll", NULL}, + {"D2Direct3D.dll", NULL}, + {"D2Game.dll", NULL}, + {"D2Gdi.dll", NULL}, + {"D2Gfx.dll", NULL}, + {"D2Glide.dll", NULL}, + {"D2Lang.dll", NULL}, + {"D2Launch.dll", NULL}, + {"D2MCPClient.dll", NULL}, + {"D2Multi.dll", NULL}, + {"D2Net.dll", NULL}, + {"D2Sound.dll", NULL}, + {"D2Win.dll", NULL}, + {"Fog.dll", NULL}, + {"Ijl11.dll", NULL}, + {"SmackW32.dll", NULL}, + {"Storm.dll", NULL}, }; void __fastcall D2TEMPLATE_FatalError(char* szMessage); \ No newline at end of file diff --git a/TemplateIncludes.h b/TemplateIncludes.h index c7f034f..7cb9af7 100644 --- a/TemplateIncludes.h +++ b/TemplateIncludes.h @@ -4,27 +4,27 @@ #define _TEMPLATEINCLUDES_H /**************************************************************************** -* * -* DLLmain.h * -* * -* Licensed under the Apache License, Version 2.0 (the "License"); * -* you may not use this file except in compliance with the License. * -* You may obtain a copy of the License at * -* * -* http://www.apache.org/licenses/LICENSE-2.0 * -* * -* Unless required by applicable law or agreed to in writing, software * -* distributed under the License is distributed on an "AS IS" BASIS, * -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* -* See the License for the specific language governing permissions and * -* limitations under the License. * -* * +* * +* DLLmain.h * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* +* See the License for the specific language governing permissions and * +* limitations under the License. * +* * *---------------------------------------------------------------------------* -* * -* https://github.com/olivier-verville/D2Template * -* * -* This file is where you include new headers in your codebase * -* * +* * +* https://github.com/olivier-verville/D2Template * +* * +* This file is where you include new headers in your codebase * +* * *****************************************************************************/ //#include "MyOwnSourceHeader1.h"