How jayveer/gcx works
Project type and purpose
• Gcx is a native C++ command-line tool for decompiling GCX binary script files used by Metal Gear Solid games (MGS3+ and MGS4).
• It reads GCX files, optionally exports embedded resources, applies a dictionary for hashed strings, formats output, and emits Game Command Language (GCL) scripts.
File structure
Top-level artifacts:
• main.cpp – entry point
• gcx.sln/vcxproj – Visual Studio solution and project files
• .gitignore, README.md
Modular directories:
• interface/cli – parses command-line options, presents usage, invokes core logic
• decompiler – core GCX parsing and bytecode→GCL translation
• dictionary – loads and queries a commands.txt dictionary for resolving hashed identifiers
• indentation – post-processing formatter for pretty-printing decompiled scripts
• mgs/common – shared utilities (file I/O, hash algorithms) and game-specific constants (strcode, game parameters)
• mgs/script – high-level orchestration of decompilation for specific game versions (gcx.cpp/h)
README insights
• Describes supported game versions, default modes, options (-MGS3, ‑MGS4, ‑res).
• Explains GCL structure, resource extraction, hash algorithm, encoding (EUC-JP, UTF-8).
• Mentions optional use of dictionary and formatting fixes as TODOs.
• GCX Parser & Decompiler (decompiler module) – green
• Script Orchestrator (mgs/script/gcx) – light green
• Game-Specific Logic (mgs/common/game, strcode) – teal
3. Dictionary Service (dictionary module) – yellow
4. Formatter (indentation module) – orange
5. File I/O & Utilities (mgs/common/fileutil) – gray
6. Output Sink – terminal/stdout files (decompiled .gcl, resource folders) – white
1. User → CLI Layer: command-line args (-mgs3/-mgs4, ‑res, input path)
2. CLI Layer → Core Engine: invokes Decompile(input, options)
3. Core Engine → File I/O: read raw GCX file
4. Core Engine → Game-Specific Logic: apply hash decoding, version constants
5. Core Engine → Dictionary Service: lookup hashed commands/strings (optional)
6. Core Engine → Script Orchestrator: assemble decompiled tokens into GCL AST
7. Script Orchestrator → Formatter: pretty-print AST to text
8. Formatter → Output Sink: write .gcl script
9. Core Engine → Output Sink (if ‑res): export binary resources
c. Architectural patterns and principles:
• Layered architecture – CLI → Core → Output
• Single Responsibility per module (parsing, dictionary, formatting)
• Plug-in style extensibility for game versions (mgs/script + flags)
• Clear separation of concerns: parsing vs. formatting vs. resource extraction
d. Key technologies/frameworks:
• C++17 (or later) – core language
• Visual Studio solution/project (.sln, .vcxproj) – build system
• Standard Library for I/O, file handling
Essential details
• Dictionary file as an external dependency
• Two output channels: decompiled script and binary resources
• Encoding differences (EUC-JP vs. UTF-8) as a note on the Script Orchestrator