# riccochicco/ninjaripper architecture

> Architecture diagram of the GitHub repository riccochicco/ninjaripper, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/riccochicco/ninjaripper
- Repository: https://github.com/riccochicco/ninjaripper

## Overview

##### Project Type and Purpose
- Ninja Ripper is a native, desktop C++ utility for extracting (“ripping”) 3D meshes, textures, and shaders from running DirectX games.
- It consists of two main user‐facing parts:
- Ripper GUI (Windows executable) that launches or injects into a DirectX8/9/11 game and configures ripping modes.
- 3ds Max Importer (MaxScript) that reads the .rip output files and reconstructs models inside 3ds Max.

##### High-Level File Structure Analysis
- Top-level:
- Common – shared C++ headers/registry handling.
- DXSDK – bundled DirectX headers & libs for DX7/8/9/11 build targets.
- MaxScript – importer script (.ms) for 3ds Max.
- Tools/D3DWrapper – source for wrapper DLL that replaces d3d9.dll/d3d11.dll.
- injector – standalone injector tool to load intruder.dll into any running process.
- README.md – describes features and usage.

##### Insights from README
- Describes three modes:
- “No Wrapper” – GUI launches game with intruder.dll loaded via standard Windows DLL search.
- “D3DX Wrapper” – GUI copies a proxy d3d#.dll into game folder; when game loads DirectX it loads this wrapper, which in turn loads intruder.dll.
- “Injector” – a separate EXE that injects intruder.dll into an already‐running process.
- Output (.rip, texture files, shaders) go into user‐specified folder.
- Importer for 3ds Max reads .rip files, reconstructs geometry and UVs.

##### Main Components
a. Ripper GUI
– Windows Forms or MFC app
– Reads/Writes registry for config
– Presents UI fields (Exe path, Args, Wrapper mode, Output dir)
– Launches game process or copies wrapper DLL or launches injector
b. Wrapper DLL (d3d8.dll / d3d9.dll / d3d11.dll)
– Placed next to game .exe
– Acts as proxy: loads real DirectX, loads intruder.dll
c. Injector Tool
– Standalone EXE that injects intruder.dll into any process via CreateRemoteThread or similar
d. Intruder DLL
– Entry point: DllMain initializes hooking manager (Common/KHookMgr)
– Per-API submodules (intruder/dx8, intruder/dx9, intruder/dx11) hook key D3D functions (e.g., IDirect3DDevice9::DrawIndexedPrimitive)
– Capture calls: extract vertex buffers, index buffers, texture & shader data
– Save extracted data to disk (.rip, texture files)
e. Output Directory
– Receives .rip container files plus auxiliary textures/shaders
f. 3ds Max Importer (MaxScript)
– Reads .rip files, parses embedded binary data, rebuilds mesh, UVs, optionally weights
– Runs inside 3ds Max as a script plugin

##### Relationships and Data Flows
- User starts Ripper GUI → selects DirectX mode → GUI writes config to registry
- GUI either:
1. Launches game with intruder.dll in PATH (“No Wrapper” mode),
2. Copies wrapper DLL to game folder then closes (“Wrapper” mode),
3. Or launches injector tool to attach intruder.dll to a running process.
- Game process loads wrapper or intruder.dll → intruder hooks D3D API
- During rendering, hooked D3D calls trigger extraction routines
- Extracted data flows to file system → .rip + textures/shaders
- User switches to 3ds Max → runs MaxScript importer → reads .rip → creates scene graph & meshes

##### Architectural Patterns & Principles
- Plugin/Hooking Pattern: intruder.dll plugins into host via shared hooking manager.
- Proxy/Wrapping: wrapper DLL forwards all calls to real D3D DLL after hooking.
- Modular Subsystems: separate code for DX8/DX9/DX11 to isolate API‐specific logic.
- Shared Utility Layer: Common directory handles registry, logging, hook management.

##### Key Technologies & Frameworks
- C++ / Win32 / Visual Studio solution and project files (.sln, .vcxproj).
- DirectX SDK 7, 8, 9, 11 headers/libs.
- Windows registry API for config storage.
- CreateRemoteThread or Detours‐style inline hooking techniques.
- MaxScript for 3ds Max importer.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top Layer: Control & Injection Components
    subgraph "Control & Injection" 
        direction TB
        GUI("Ripper GUI"):::control
        Wrapper("Wrapper DLL (d3d#.dll)"):::injection
        Injector("Injector Tool"):::control
        README["README.md"]:::doc
    end

    %% Middle Layer: Game Process & Intrusion
    subgraph "Game Process" 
        direction TB
        GameExe("Game Executable"):::process
        RealDX["Real DirectX Runtime"]:::process
        subgraph "Intruder DLL" 
            direction TB
            IntruderCore("Intruder Core Engine"):::injection
            CommonMod("Common Module"):::injection
            DX8("DX8 Submodule"):::injection
            DX9("DX9 Submodule"):::injection
            DX11("DX11 Submodule"):::injection
        end
    end

    %% Bottom Layer: Output & Importer
    subgraph "Data & Import" 
        direction TB
        Output("Output Folder (.rip, textures, shaders)"):::data
        Importer("3ds Max Importer"):::data
    end

    %% Connections: GUI flows
    GUI -->|"Launch Game (No Wrapper)"| GameExe
    GUI -->|"Copy Wrapper DLL"| Wrapper
    GUI -->|"Launch Injector"| Injector

    Wrapper -->|"Loaded as d3d#.dll"| GameExe
    Injector -->|"Inject intruder.dll"| GameExe

    %% Game loading Intruder and DirectX
    GameExe -->|"Loads Wrapper or intruder.dll"| IntruderCore
    GameExe -->|"Loads DirectX"| RealDX

    %% Intruder hooks into DirectX calls
    IntruderCore -->|"Init Hook Manager"| CommonMod
    IntruderCore -->|"Hook DX8 APIs"| DX8
    IntruderCore -->|"Hook DX9 APIs"| DX9
    IntruderCore -->|"Hook DX11 APIs"| DX11

    %% Data extraction to file system
    DX8 -->|"Save .rip and textures"| Output
    DX9 -->|"Save .rip and textures"| Output
    DX11 -->|"Save .rip and textures"| Output

    %% Import into 3ds Max
    Output -->|"Read .rip files"| Importer

    %% Additional connections
    GUI -->|"Guidance & Usage"| README

    %% Click Events
    click GUI "https://github.com/riccochicco/ninjaripper/blob/master/intruder/Debug/NinjaRipper.exe"
    click Wrapper "https://github.com/riccochicco/ninjaripper/tree/master/Tools/D3DWrapper/"
    click Injector "https://github.com/riccochicco/ninjaripper/tree/master/injector/"
    click IntruderCore "https://github.com/riccochicco/ninjaripper/blob/master/intruder/intruder.cpp"
    click CommonMod "https://github.com/riccochicco/ninjaripper/tree/master/intruder/common/"
    click DX8 "https://github.com/riccochicco/ninjaripper/tree/master/intruder/dx8/"
    click DX9 "https://github.com/riccochicco/ninjaripper/tree/master/intruder/dx9/"
    click DX11 "https://github.com/riccochicco/ninjaripper/tree/master/intruder/dx11/"
    click Output "https://github.com/riccochicco/ninjaripper/blob/master/Common/registry.cpp"
    click Importer "https://github.com/riccochicco/ninjaripper/blob/master/MaxScript/ninja_ripper_1.3.ms"
    click README "https://github.com/riccochicco/ninjaripper/blob/master/README.md"

    %% Styles
    classDef control fill:#D6EAF8,stroke:#2980B9,color:#154360
    classDef injection fill:#F5B041,stroke:#B9770E,color:#7E5109
    classDef data fill:#ABEBC6,stroke:#239B56,color:#1D8348
    classDef process fill:#FAD7A0,stroke:#D35400,color:#7D6608
    classDef doc fill:#E5E7E9,stroke:#7B7D7D,color:#1C2833
```
