How stackboom/lunahook works
Project Type and Purpose
• LunaHook is a native C++ hooking library and host application for extracting and processing in-game text (for translation).
• It consists of two main deliverables:
a. The “LunaHook” injection module (DLL) that you inject into a target (32-bit or 64-bit) game process.
b. The “LunaHost” process (GUI/CLI) that receives extracted text, manages plugins, and forwards text to translators or other extensions.
Top-Level Components
• LunaHook (injectable module):
• Core hooking engine (MinHook, YY-Thunks)
• Engine backends (engine32/, engine64/, enginecollection32.cpp, enginecollection64.cpp) for dozens of game scripting systems (KiriKiri, Ren’Py, Unity/Mono, Unreal, PPSSPP, etc.)
• Utilities (util/ subfolders: disassembler, dynamic SJIS codec, memory debugger, string filters, etc.)
• Hook control and finder (hookfinder.cc, enginecontrol.cpp)
• Resource files and language headers (Lang/)
• LunaHost (host process):
• GUI application (Qt-based): main window, plugin manager, config helper, text thread, HTTP helper
• Plugins (GUI/Plugin/extensions/): translation wrappers (Google, DeepL, Bing, Systran, Papago), filters (regex, markup, repeat removal), dev tools, network interceptors, clipboard helpers, etc.
• CLI and DLL host modes (LunaHostCLI.cpp, LunaHostDll.cpp)
• Build & Packaging:
• CMakeLists.txt at root plus subfolder CMake files
• build.py and .bat scripts for 32/64-bit builds, XP compatibility
• Third-party libs under libs/ (MinHook, YY-Thunks, nlohmann/json, yapi.hpp)
Core Interactions and Data Flow
• Injection & Hooking:
1. User launches LunaHost or triggers injection via plugin.
2. LunaHook DLL is injected into the game process (Win32 or x64).
3. Hook engine identifies the game’s scripting engine (via enginefinder) and loads the corresponding backend.
4. When the game calls text-rendering or text-loading APIs, the hook intercepts those calls, extracts text buffers.
• IPC to Host:
• Extracted text is packaged (possibly JSON via nlohmann/json) and sent over an IPC channel (e.g., named pipe or shared memory) to the LunaHost process.
• LunaHost’s textthread.cpp listens for incoming messages.
• Plugin Pipeline:
• LunaHost receives raw text → pushes it into a locked queue → Plugin Manager invokes each enabled extension in series.
• Extensions can transform text (filters), send to external translation APIs (HTTP), modify formatting, copy to clipboard, or display in dev tools.
• UI Rendering & User Action:
• Processed text is displayed in the GUI window.
• User actions (enable/disable plugin, copy, manual edit) flow back through the host, not directly into the game.
Architectural Patterns & Principles
• Modular Backends: Each game engine backend is its own component (source & header pair) loaded conditionally.
• Plugin Architecture: Host uses Qt plugin system to load extensions at runtime, enabling ease of adding new translation or filter modules.
• Separation of Concerns:
• Hook DLL isolates low-level process memory manipulation and instruction patching.
• Host process handles all user-facing logic and external network calls.
• Cross-Architecture Support: Two build targets for 32-bit and 64-bit, but most code is shared via enginecollection files and conditional compilation.