# dosinabox/g2_classic architecture

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

- Interactive diagram: https://gitdiagram.com/dosinabox/g2_classic
- Repository: https://github.com/dosinabox/g2_classic

## Overview

This project is a modification and scripting overhaul for Gothic 2 Classic. It’s not a traditional full‐stack web app or a stand-alone tool, but rather a game mod composed of a very large collection of scripts that affect game AI, dialogs, spells, items, and story events. There is also a dedicated section for the game menu (PrjMENU) and additional support directories for DLLs, configuration (ini), installer scripts (nsi), and patch files to fix or adjust certain behaviors in the original game engine. The project is compiled by the Gothic Sourcer tool (version 3.16) using the main solution file (Gothic_2_Classic.gsc).

##### Main Components
- Game Script Module (PrjGothic):
– Contains several sub-modules such as AI (with further subdivisions by Human, Magic, Monster, etc.), Items, Story (including dialogs, events, NPC, etc.), and internal helper scripts.
– Represent this module as the “Core Game Logic” or “Gameplay Scripting” layer.
- Game Menu Module (PrjMENU):
– Contains source code and scripts for the in-game menu and interface modifications.
- Configuration and Patching (src directory):
– Contains DLL code (src/dll), ini configurations (src/ini), NSIS installer scripts (src/nsi), and patch files (src/patch) that apply fixes/fixes for particular issues within the game engine.
- Build/Compilation Process:
– The primary entry point is Gothic_2_Classic.gsc which is compiled using the Gothic Sourcer. Represent this as the “Build Pipeline / Compiler” node.

##### Relationships and Interactions
- The Build Pipeline (Gothic Sourcer) compiles the scripts from both the PrjGothic (core game logic) and PrjMENU (menu interface) directories.
- Patches and configuration files (under src) provide necessary fixes and integrations before the game is run. They adjust and improve both the engine’s behavior (e.g., collision fixes, sound management) and script execution.
- There is a dependency flow: source scripts → Gothic Sourcer (compilation) → integrated mod (game engine run-time) → patched configurations/DLL enhancements.

##### Architectural Patterns and Relevant Technologies
- Modularity: The project is divided into discrete components (AI, Menu, Items, Story, etc.) which likely follow a modular pattern. Each major script category can be seen as an independent service or plugin for the game engine.
- Separation of Concerns: Game logic (PrjGothic) is separate from user interface modifications (PrjMENU), and further separated from the configuration/patch layer (src).
- External Tool Integration: Gothic Sourcer is a critical external dependency required for script compilation.
- File Organization as a “Folder-as-Module” pattern: The deep file tree shows each new category in its own folder, allowing you to map out several modules that will interact during game runtime.
- The use of patch files indicates that the design also implements a “layer on top” concept where the mod’s changes “override” or “patch” the default game behaviors.

##### Additional Notes
- Layering and modularity since separating each major area in the game (AI, Menu, Patching) facilitates understanding of the interactions.
- To capture the deep hierarchical tree inside PrjGothic by grouping similar components (e.g., group all “Dialogue” related scripts and represent them as one submodule within “Story”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top Layer: Build Pipeline / Compiler
    subgraph "Build Pipeline"
        EntryPoint["Gothic_2_Classic.gsc"]:::entrypoint
        GSCompiler["Gothic Sourcer Compiler"]:::compiler
        EntryPoint -->|"entry"| GSCompiler
    end

    %% Middle Layer: Modules
    subgraph "Script Modules"
        subgraph "Game Logic Module (PrjGothic)"
            CL_AI["AI (Human,Magic,Monster)"]:::logic
            CL_Items["Items"]:::logic
            CL_Story["Story (Dialogs,Events,NPC)"]:::logic
        end
        subgraph "Menu Module (PrjMENU)"
            Menu["Menu Scripts"]:::menu
        end
    end

    %% Right Side: Configuration & Patching Module
    subgraph "Configuration & Patching (src)"
        DLL["DLL Code"]:::config
        INI["INI Configurations"]:::config
        NSIS["NSIS Installer Scripts"]:::config
        Patch["Patch Files"]:::config
    end

    %% Intermediate: Compiled Mod Integration Layer
    ModIntegration["Compiled Scripts (Mod Integration)"]:::runtime

    %% Bottom Layer: Original Game Engine
    Engine["Gothic 2 Game Engine"]:::engine

    %% Arrows: Compilation Process from Modules to Compiler
    CL_AI -->|"compile"| GSCompiler
    CL_Items -->|"compile"| GSCompiler
    CL_Story -->|"compile"| GSCompiler
    Menu -->|"compile"| GSCompiler

    %% Arrow: Build output flows to Compiled Mod Integration Layer
    GSCompiler -->|"build-output"| ModIntegration

    %% Arrow: Mod Integration injected into Game Engine
    ModIntegration -->|"integrate"| Engine

    %% Arrows: Configuration and Patching applied to Game Engine
    DLL -->|"patch"| Engine
    INI -->|"configure"| Engine
    NSIS -->|"install"| Engine
    Patch -->|"override"| Engine

    %% Click Events
    click CL_AI "https://github.com/dosinabox/g2_classic/tree/master/PrjGothic/AI"
    click CL_Items "https://github.com/dosinabox/g2_classic/tree/master/PrjGothic/Items"
    click CL_Story "https://github.com/dosinabox/g2_classic/tree/master/PrjGothic/Story"
    click Menu "https://github.com/dosinabox/g2_classic/tree/master/PrjMENU"
    click EntryPoint "https://github.com/dosinabox/g2_classic/blob/master/Gothic_2_Classic.gsc"
    click DLL "https://github.com/dosinabox/g2_classic/tree/master/src/dll"
    click INI "https://github.com/dosinabox/g2_classic/tree/master/src/ini"
    click NSIS "https://github.com/dosinabox/g2_classic/tree/master/src/nsi"
    click Patch "https://github.com/dosinabox/g2_classic/tree/master/src/patch"
    click GSCompiler "https://github.com/dosinabox/g2_classic/blob/master/Gothic_2_Classic.gsc"
    click ModIntegration "https://github.com/dosinabox/g2_classic/tree/master/PrjGothic"

    %% Styles
    classDef compiler fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef entrypoint fill:#FFA500,stroke:#333,stroke-width:2px;
    classDef logic fill:#66CCFF,stroke:#333,stroke-width:2px;
    classDef menu fill:#CC99FF,stroke:#333,stroke-width:2px;
    classDef config fill:#99FF99,stroke:#333,stroke-width:2px;
    classDef runtime fill:#FF6666,stroke:#333,stroke-width:2px;
    classDef engine fill:#CCCCCC,stroke:#333,stroke-width:2px;
```
