This commit is contained in:
Hash Borgir 2024-04-10 16:09:25 -06:00
commit 54c085f7fb
15 changed files with 1156 additions and 0 deletions

33
.gitignore vendored Normal file
View File

@ -0,0 +1,33 @@
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
.vs/
spdlog/
template/

50
D2Constants.h Normal file
View File

@ -0,0 +1,50 @@
#pragma once
#ifndef _D2CONSTANTS_H
#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. *
* *
*---------------------------------------------------------------------------*
* *
* 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
};
// end of file ---------------------------------------------------------------
#endif

56
D2DataTables.h Normal file
View File

@ -0,0 +1,56 @@
#pragma once
#ifndef _D2DATATABLES_H
#define _D2DATATABLES_H
#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. *
* *
*---------------------------------------------------------------------------*
* *
* 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 *
* *
*****************************************************************************/
struct D2MonstatsTXT;
/****************************************************************************
* *
* DEFINITIONS *
* *
*****************************************************************************/
struct D2MonstatsTXT
{
//...
};
// end of file --------------------------------------------------------------
#pragma pack()
#endif

62
D2PacketDef.h Normal file
View File

@ -0,0 +1,62 @@
#pragma once
#ifndef _D2PACKETDEF_H
#define _D2PACKETDEF_H
#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. *
* *
*---------------------------------------------------------------------------*
* *
* 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 *
* *
*****************************************************************************/
struct D2GSPacketClt01;
struct D2GSPacketClt02;
struct D2GSPacketClt03;
struct D2GSPacketSrv01;
struct D2GSPacketSrv02;
struct D2GSPacketSrv03;
/****************************************************************************
* *
* DEFINITIONS *
* *
*****************************************************************************/
struct D2GSPacketClt01
{
//...
};
// end of file --------------------------------------------------------------
#pragma pack()
#endif

157
D2Patch.h Normal file
View File

@ -0,0 +1,157 @@
#pragma once
#ifndef _D2PATCH_H
#define _D2PATCH_H
#include "D2PatchConst.h"
#include <iostream>
#include <iomanip>
#include <sstream>
#include <windows.h>
#include <string>
#include <vector>
#include <map>
#include <fstream>
#include <algorithm>
// Function to read settings from D2Mod.ini file
int ReadSettingFromIni(const char* section, const char* key, BYTE defaultValue) {
return GetPrivateProfileInt(section, key, defaultValue, "D2Mod.ini");
}
// Function to calculate relative offset (D2COMMON base address is 0x6F600000)
DWORD calculateRelativeOffsetD2Common(DWORD offset) {
return offset - 0x6F600000;
}
// Function to calculate relative offset (D2COMMON base address is 0x6F600000)
DWORD calculateRelativeOffsetD2Client(DWORD offset) {
return offset - 0x6FAA0000;
}
// Define settings from D2Mod.ini
BYTE leftBorder = ReadSettingFromIni("CharmZone", "leftBorder", 0x00);
BYTE rightBorder = ReadSettingFromIni("CharmZone", "rightBorder", 0x10);
BYTE topBorder = ReadSettingFromIni("CharmZone", "topBorder", 0x0C);
BYTE bottomBorder = ReadSettingFromIni("CharmZone", "bottomBorder", 0x10);
// Function to reverse the bytes of a hexadecimal number
uint32_t reverseHexBytes(uint32_t hexNumber) {
uint32_t reversedHex = 0;
// Reverse the bytes
reversedHex |= (hexNumber & 0x000000FF) << 24; // Move the last byte to the first byte
reversedHex |= (hexNumber & 0x0000FF00) << 8; // Move the second last byte to the second byte
reversedHex |= (hexNumber & 0x00FF0000) >> 8; // Move the second byte to the second last byte
reversedHex |= (hexNumber & 0xFF000000) >> 24; // Move the first byte to the last byte
return reversedHex;
}
static const DLLPatchStrc gptTemplatePatches[] =
{
{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F65FEF4), (DWORD)PATCH_JMP, FALSE, 0x01},
{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F65FEF5), (DWORD)reverseHexBytes(0x77D60200), FALSE, 0x00},
// Patching TEST EAX, EAX at address 0x6F68D570
{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D570), (DWORD)(0xC085), FALSE, 0x00},
// Patching JNE SHORT 6F68D577 at address 0x6F68D572
{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D572), (DWORD)(0x0375), FALSE, 0x00},
// Patching RETN 8 at address 0x6F68D574
{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D574), (DWORD)(0x0008C2), FALSE, 0x00},
// Patching MOV EAX,DWORD PTR SS:[ESP+4] at address 0x6F68D577
{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D577), (DWORD)(0x04E4448B), FALSE, 0x00},
// Patching MOV EAX,DWORD PTR DS:[EAX+2C] at address 0x6F68D57B
{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D57B), (DWORD)(0x2C408B), FALSE, 0x00},
// Patching CMP DWORD PTR DS:[EAX+0C],leftBorder at address 0x6F68D57E
{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D57E), (DWORD)(0x0C7883), FALSE, 0x0},
{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D581), (DWORD)leftBorder, FALSE, 0x01},
// Patching JB SHORT 6F68D59E at address 0x6F68D582
{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D582), (DWORD)(0x1A72), FALSE, 0x0},
// Patching CMP DWORD PTR DS:[EAX+0C],rightBorder at address 0x6F68D584
{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D584), (DWORD)(0x0C7883), FALSE, 0x0},
{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D587), (DWORD)rightBorder, FALSE, 0x01},
// Patching JA SHORT 6F68D59E at address 0x6F68D588
{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D588), (DWORD)(0x1477), FALSE, 0x0},
// Patching CMP DWORD PTR DS:[EAX+10],topBorder at address 0x6F68D58A
{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D58A), (DWORD)(0x107883), FALSE, 0x0},
{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D58D), (DWORD)topBorder, FALSE, 0x01},
// Patching JB SHORT 6F68D59E at address 0x6F68D58E
{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D58E), (DWORD)(0x0E72), FALSE, 0x0},
// Patching CMP DWORD PTR DS:[EAX+10],bottomBorder at address 0x6F68D590
{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D590), (DWORD)(0x107883), FALSE, 0x0},
{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D593), (DWORD)bottomBorder, FALSE, 0x01},
// Patching JA SHORT 6F68D59E at address 0x6F68D594
{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D594), (DWORD)(0x0877), FALSE, 0x0},
// Patching MOV EAX,1 at address 0x6F68D596
{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D596), (DWORD)reverseHexBytes(0xB8010000), FALSE, 0x0},
{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D59A), (DWORD)(0x00), FALSE, 0x1},
// Patching RETN 8 at address 0x6F68D59B
{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D59B), (DWORD)(0x0008C2), FALSE, 0x0},
// Patching XOR EAX,EAX at address 0x6F68D59E
{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D59E), (DWORD)(0xC031), FALSE, 0x0},
// Patching RETN 8 at address 0x6F68D5A0
{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D5A0), (DWORD)(0x0008C2), FALSE, 0x0},
//// Patching TEST EAX, EAX at address 0x6F68D570
//{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D570), (DWORD)(0x85C0), FALSE, 0x00},
//// Patching JNE SHORT 6F68D577 at address 0x6F68D572
//{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D572), (DWORD)(0x7503), FALSE, 0x00},
//// Patching RETN 8 at address 0x6F68D574
//{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D574), (DWORD)(0xC20800), FALSE, 0x00},
//// Patching MOV EAX,DWORD PTR SS:[ESP+4] at address 0x6F68D577
//{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D577), (DWORD)reverseHexBytes(0x8B44E404), FALSE, 0x00},
//// Patching MOV EAX,DWORD PTR DS:[EAX+2C] at address 0x6F68D57B
//{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D57B), (DWORD)(0x8B402C), FALSE, 0x00},
//// Patching CMP DWORD PTR DS:[EAX+0C],leftBorder at address 0x6F68D57E
//{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D57E), (DWORD)(0x83780C), FALSE, 0x0},
//{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D581), (DWORD)leftBorder, FALSE, 0x01},
//// Patching JB SHORT 6F68D59E at address 0x6F68D582
//{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D582), (DWORD)(0x721A), FALSE, 0x0},
//// Patching CMP DWORD PTR DS:[EAX+0C],rightBorder at address 0x6F68D584
//{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D584), (DWORD)(0x83780C), FALSE, 0x0},
//{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D587), (DWORD)rightBorder, FALSE, 0x01},
//// Patching JA SHORT 6F68D59E at address 0x6F68D588
//{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D588), (DWORD)(0x7714), FALSE, 0x0},
//// Patching CMP DWORD PTR DS:[EAX+10],topBorder at address 0x6F68D58A
//{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D58A), (DWORD)(0x837810), FALSE, 0x0},
//{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D58D), (DWORD)topBorder, FALSE, 0x01},
//// Patching JB SHORT 6F68D59E at address 0x6F68D58E
//{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D58E), (DWORD)(0x720E), FALSE, 0x0},
//// Patching CMP DWORD PTR DS:[EAX+10],bottomBorder at address 0x6F68D590
//{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D590), (DWORD)(0x837810), FALSE, 0x0},
//{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D593), (DWORD)bottomBorder, FALSE, 0x01},
//// Patching JA SHORT 6F68D59E at address 0x6F68D594
//{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D594), (DWORD)(0x7708), FALSE, 0x0},
//// Patching MOV EAX,1 at address 0x6F68D596
//{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D596), (DWORD)reverseHexBytes(0xB8010000), FALSE, 0x0},
//// Patching RETN 8 at address 0x6F68D59B
//{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D59B), (DWORD)(0xC20800), FALSE, 0x0},
//// Patching XOR EAX,EAX at address 0x6F68D59E
//{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D59E), (DWORD)(0x31C0), FALSE, 0x0},
//// Patching RETN 8 at address 0x6F68D5A0
//{D2DLL_D2COMMON, calculateRelativeOffsetD2Common(0x6F68D5A0), (DWORD)(0xC20800), FALSE, 0x0},
//{D2DLL_D2CLIENT, calculateRelativeOffsetD2Client(0x6FAE118F), (DWORD)PATCH_JMP, FALSE, 0x00},
//{D2DLL_D2CLIENT, calculateRelativeOffsetD2Client(0x6FAE1190), (DWORD)0x6CB30800, FALSE, 0x00},
//{D2DLL_D2CLIENT, calculateRelativeOffsetD2Client(0x6FAE1194), (DWORD)0x90, FALSE, 0x03},
//{D2DLL_D2CLIENT, calculateRelativeOffsetD2Client(0x6FB6C500), (DWORD)customD2ClientASM, TRUE, 0x00},
{D2DLL_INVALID} // this must be the last entry in the array!
};
#endif // _D2PATCH_H

45
D2PatchConst.h Normal file
View File

@ -0,0 +1,45 @@
#pragma once
#ifndef _D2PATCHCONST_H
#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. *
* *
*---------------------------------------------------------------------------*
* *
* 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
#endif

69
D2Ptrs.h Normal file
View File

@ -0,0 +1,69 @@
#pragma once
#ifndef _D2PTRS_H
#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. *
* *
*---------------------------------------------------------------------------*
* *
* 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); ///
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/********************************************************************************
* *
* D2GAME.DLL POINTERS *
* *
*********************************************************************************/
/********************************************************************************
* *
* D2CLIENT.DLL POINTERS *
* *
*********************************************************************************/
/********************************************************************************
* *
* D2COMMON.DLL POINTERS *
* *
*********************************************************************************/
// end of file -----------------------------------------------------------------
#endif

63
D2Structs.h Normal file
View File

@ -0,0 +1,63 @@
#pragma once
#ifndef _D2STRUCTS_H
#define _D2STRUCTS_H
#include "D2DataTables.h"
#include "D2PacketDef.h"
#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. *
* *
*---------------------------------------------------------------------------*
* *
* 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 *
* *
*****************************************************************************/
struct D2GameStrc;
struct D2UnitStrc;
/****************************************************************************
* *
* DEFINITIONS *
* *
*****************************************************************************/
struct D2GameStrc
{
//...
};
struct D2UnitStrc
{
//0xF0
};
// end of file --------------------------------------------------------------
#pragma pack()
#endif

20
D2Template.sln Normal file
View File

@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual C++ Express 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "template", "template\template.vcxproj", "{B7848D7C-A05C-4DED-A363-B9555FF791A1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B7848D7C-A05C-4DED-A363-B9555FF791A1}.Debug|Win32.ActiveCfg = Debug|Win32
{B7848D7C-A05C-4DED-A363-B9555FF791A1}.Debug|Win32.Build.0 = Debug|Win32
{B7848D7C-A05C-4DED-A363-B9555FF791A1}.Release|Win32.ActiveCfg = Release|Win32
{B7848D7C-A05C-4DED-A363-B9555FF791A1}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

44
D2Vars.h Normal file
View File

@ -0,0 +1,44 @@
#ifdef _D2VARS_H
#define VAR(Type, Name) Type Name;
#else
#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. *
* *
*---------------------------------------------------------------------------*
* *
* 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)
VAR(void*, SampleVariable2)
VAR(char, SampleVariable3[256])
const DWORD D2Client_SkillDescCaptureValue_Return = (0x7343D + DLLBASE_D2CLIENT);
const DWORD D2Client_SkillDescFix_Return = (0x734A1 + DLLBASE_D2CLIENT);
const DWORD D2Client_SkillDescFix_testZero_Return = (0x73472 + DLLBASE_D2CLIENT);
// end of file ---------------------------------------------------------------
#undef _D2VARS_H

175
DLLmain.cpp Normal file
View File

@ -0,0 +1,175 @@
#define _D2VARS_H
#include "DLLmain.h"
#include "D2Patch.h"
#include <windows.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. *
* *
*---------------------------------------------------------------------------*
* *
* 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);
}
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;
}
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;
}
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;
}
int __stdcall DllAttach()
{
D2TEMPLATE_GetDebugPrivilege();
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;
}
D2TEMPLATE_ApplyPatch(hGame, gptTemplatePatches);
CloseHandle(hGame);
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;
}

131
DLLmain.h Normal file
View File

@ -0,0 +1,131 @@
/****************************************************************************
* *
* 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 *
* *
*****************************************************************************/
#define WIN32_LEAN_AND_MEAN
#define _CRT_SECURE_NO_DEPRECATE
#define _WIN32_WINNT 0x600
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#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"
#include "D2Ptrs.h"
#include "D2Vars.h"
#include "TemplateIncludes.h"
struct DLLBaseStrc
{
char* szName;
DWORD dwAddress;
};
struct DLLPatchStrc
{
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
};
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},
};
void __fastcall D2TEMPLATE_FatalError(char* szMessage);

201
LICENSE Normal file
View File

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
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.

15
README.md Normal file
View File

@ -0,0 +1,15 @@
# D2Template
D2Template is an open source community project that was developed in order to help modders getting started into advanced code editing on Diablo II. The library provides a basic and simple codebase, ready to be injected in-game, allowing you to quickly inject your own code, without the need to learn stuff like memory patching.
## What does the template include?
To start off, a patcher. This is pretty much the basic of basics, as you need to inject your code into the game at some point, right? You do not need to get into complicated memory patching coding, the template does it for you. Then you have some various utility files, for pointers importing from the game's library, variables declaration, etc.
## What do I need to use this template?
The template was created and compiled with Visual Studio 2012, so it is better if you get Visual Studio 2012 (or just Visual C++ 2012). It is in theory possible to get the template to work with any other IDE but you will not get any support on this from me. Tutorials/Modified templates for other IDE are welcome.
## What should I know before using this template?
First of all, get started with the basics of C/C++. Get used to the syntax, practice by creating basic programs, get at least a basic knowledge of the language. Next, get used with the IDE you're going to use to work with this template. And finally, basic ASM knowledge can also help you a lot.

35
TemplateIncludes.h Normal file
View File

@ -0,0 +1,35 @@
#pragma once
#ifndef _TEMPLATEINCLUDES_H
#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. *
* *
*---------------------------------------------------------------------------*
* *
* https://github.com/olivier-verville/D2Template *
* *
* This file is where you include new headers in your codebase *
* *
*****************************************************************************/
//#include "MyOwnSourceHeader1.h"
//#include "MyOwnSourceHeader2.h"
//#include "MyOwnSourceHeader3.h"
// end of file --------------------------------------------------------------
#endif