D2MOO

repository·master·Indexed 41 days ago

https://github.com/thephrozenkeep/d2moo

A re-implementation of Diablo II designed as a toolset for modders to understand and patch game logic, primarily targeting version 1.10f. It provides a centralized code reference, a coordinate system conversion utility, and an experimental ImGui-based debugger.

Tokens
8.4K
Snippets
28
Records
40
Agent score
51%

What's inside D2MOO

  1. Replace D2Common.dll with D2MOO version

    master

    It is currently possible to build D2Common.dll and replace the original game file directly.

    Warning: This is not guaranteed to be bug-free. The recommended approach is to patch the specific functions (ordinals) you need. You can check the current status of patched ordinals in D2.Detours/patches/1.10f/D2Common.patch.cpp.

    Note: You CANNOT replace other game .dll files (like D2Game.dll) directly with those from D2MOO at this time.

  2. Convert between Game and Client coordinates

    master

    To transform between the logic-based Game coordinates and the pixel-based Client coordinates (assuming matching precision), use the following dimetric projection formulae:

    Game to Client:

    • clientX = (gameX - gameY) / 2
    • clientY = (gameX + gameY) / 4

    Client to Game:

    • gameX = 2 * clientY + clientX
    • gameY = 2 * clientY - clientX
  3. Understand Diablo II coordinate systems

    master

    Diablo II uses two primary coordinate systems: Game coordinates (aligned with tile axes) and Client coordinates (projected via dimetric projection).

    • Game coordinates: Used for game logic, collision, and pathfinding. They are represented at various precisions such as RoomX/Y, TilesX/Y, X/Y (subtiles), and PrecisionX/Y (fractional/fixed-point).
    • Client coordinates: Aligned with the screen axes and used for graphics/pixels. A single game coordinate 'square' appears as a diamond shape in client space.
    • Screen position: A separate system used for the GUI where the origin is the bottom-left, X faces right, and Y faces up.
  4. Understand Symbol Availability and Breakpoints

    master

    D2MOO does not patch every function by default. Consequently, source mapping and symbols (.pdb files) are only available for functions implemented by D2MOO.

    How to find patchable functions

    1. Locate the XXXXX.patch.cpp files in the D2.Detours.patches/1.10f directory.
    2. You can only set breakpoints via source code for functions explicitly marked with PatchAction::FunctionReplaceOriginalByPatch.

    Debugging original game code

    You can still set breakpoints in the original game .dlls, but you will not have source mapping. Note that two .dlls with the same name may be loaded: the original game version and the D2MOO version. Refer to the Patching.md guide for more details on how this works.

  5. How D2MOO patching works via D2.Detours

    master

    D2MOO uses a patching mechanism based on D2.Detours. Because Diablo II does not load all its .dll files at startup, D2.Detours is injected into the process to hook the LoadLibrary* functions.

    When a .dll load attempt occurs, the system completes the load and then patches all newly loaded .dlls before returning control to the process. This allows both the original and the patch .dlls to be loaded simultaneously, enabling them to call each other.

  6. Run D2MOO manually via D2.DetoursLauncher

    master

    Advanced users can launch Diablo II or D2SE using the D2.DetoursLauncher.

    Execution Patterns

    • Standard Launch: D2.DetoursLauncher [Path to Game.exe or D2SE.exe]. If the path is omitted, the launcher searches the registry, current working directory, and PATH.
    • Passing Arguments: To pass parameters to the game executable, use the -- separator. Example: D2.DetoursLauncher [Game.exe] -- -direct -txt -w.

    Patch Directory Configuration

    By default, the detours .dll expects patch .dlls to be located in the ./patch folder of the current working directory. You can override this location by setting the DIABLO2_PATCH environment variable.

    D2.DetoursLauncher [Game.exe] -- -direct -txt -w
  7. Use the experimental D2MOO Debugger

    master

    D2MOO includes an experimental visual debugger based on ImGui. To enable it, use one of the following two methods:

    1. Command Line Argument: Start the game with the -debug flag. If using the launcher, the syntax is: D2.DetoursLauncher -- -debug
    2. Environment Variable: Set the environment variable D2_DEBUGGER=1.
    D2.DetoursLauncher -- -debug
    # OR
    export D2_DEBUGGER=1
  8. Install dependencies for D2MOO

    master

    To build D2MOO, you must ensure the following dependencies are present:

    1. D2.Detours: This is a git submodule. You must initialize it using git submodule update --init or by cloning the repository recursively with git clone --recursive.
    2. CMake: The build system used for project configuration.
    3. C++ Compiler: A compiler capable of generating .DLL files on Windows (e.g., Visual C++).
    git submodule update --init
  9. Debug D2MOO in Visual Studio

    master

    If you generated a .sln file through CMake and are using a default Diablo II installation, debugging targets are pre-configured.

    Requirements

    • Game Location: D2 must be found via the Windows Registry/PATH, or explicitly set using the D2INSTALL or D2SE environment variables.
    • Subprocess Debugging: Since the project spawns the game (or D2SE) as a subprocess, it is recommended to install the Microsoft Child Process Debugging Power Tool extension. The project is configured to use this by default; you can verify this in Visual Studio under Debug > Other debug targets > Child process debugging settings.

    Troubleshooting

    If the executable is not found automatically, you must provide its path as a command argument in the project's debug properties.

  10. How to use the D2MOO Debugger

    master

    The D2MOO Debugger is an experimental feature. You can enable it by passing the -debug argument to the launcher or by setting an environment variable.

    Methods to enable debugging:

    1. CLI Argument: Pass -debug to the launcher (e.g., D2.DetoursLauncher -- -debug).
    2. Environment Variable: Set D2_DEBUGGER=1 in your environment.
    # Example using CLI argument
    D2.DetoursLauncher -- -debug
    
    # Example using environment variable
    export D2_DEBUGGER=1
  11. Install and build D2MOO using CMake presets

    master

    D2MOO requires the D2.Detours submodule, CMake, and a C++ compiler capable of generating .DLLs on Windows (such as Visual C++).

    To build the project, use CMake presets. You can replace DefaultGenerator with VS2022 or Ninja if using Visual Studio 2022. The generated Visual Studio solution will be located in out/build/VS20XX.

    # Ensure submodules are initialized
    git submodule update --init --recursive
    
    # Configure the CMake project
    cmake --preset DefaultGenerator
    
    # Build the release config
    cmake --build --preset DefaultGenerator --config Release
    
    # Install (Optional)
    cmake --build --preset DefaultGenerator --config Release --target install
  12. Build D2MOO without presets

    master

    If you prefer not to use presets, you can manually configure, build, and install the project using the following commands. Ensure you specify the architecture (e.g., -A Win32) and your desired build/install directories.

    # Configure the CMake project
    cmake -A Win32 -B YOU_BUILD_DIR
    
    # Build the release config
    cmake --build YOU_BUILD_DIR --config Release
    
    # Install
    cmake --install YOU_BUILD_DIR --config Release --prefix YOUR_INSTALL_FOLDER