How flenarndev/engine-level works
1. What this repo is
- Engine-Level is a native F4SE plugin for Fallout 4 / Fallout Cascadia.
- It sits inside the game process and extends or alters engine behavior at runtime, rather than acting as an external app.
2. Core boundary
- The main architectural boundary is between:
- the game engine/F4SE runtime, and
- the plugin’s feature modules under src/.
- The plugin consumes engine events, hooks game functions, and exposes script-facing APIs back into the game.
3. Bootstrap and composition
- src/main.cpp is the entry point that likely wires the whole plugin together.
- From there, initialization fans out into shared hook setup, subsystem registration, script registration, and patch application.
- This is a classic “single plugin binary, multiple feature modules” layout.
4. Shared infrastructure layer
- src/Shared contains cross-cutting code used by most subsystems:
- Hooks for detouring/interception,
- InputWatcher for player input state,
- helper utilities like NPCFileUtils, PerkHelpers, SharedFunctions, and shared declarations.
- This layer is the glue between low-level engine interaction and higher-level gameplay features.
5. Gameplay systems
- src/Systems holds the main feature areas:
- AmmoSwitch
- Dialogue
- ItemDegradation
- LockLevels
- Skills
- These are the likely “business logic” modules of the plugin, each focused on one gameplay mechanic or rule set.
6. Event-driven integration
- src/Events contains handlers for game lifecycle and gameplay events:
- menu open/close,
- cell load,
- hit events,
- harvest,
- script init,
- load game,
- animation graph,
- level increase.
- These events are the main input stream from the engine into the plugin’s systems, allowing feature modules to react to game state changes.
7. UI/menu boundary
- src/Menus defines custom or extended menus such as:
- dialogue,
- examine/confirm flows,
- level-up,
- Pip-Boy tabs,
- text input.
- This indicates the plugin doesn’t only alter backend logic; it also injects or modifies UI flows that the player interacts with.
8. Script exposure layer
- src/Scripts provides game-script-facing APIs in two forms:
- ObScript/console-style commands under src/Scripts/ObScript
- Papyrus functions under src/Scripts/Papyrus
- Examples like ToggleMarkers, GetBaseObject, SavePlayerFace, and Skills_Papyrus suggest this repo exposes engine features to mod scripts and in-game scripting systems.
9. Papyrus manager
- src/Papyrus/Manager.cpp and .h form the registration/coordination point for Papyrus-native functions.
- This is the bridge between the scripting runtime and the C++ gameplay systems.
10. Persistence and save-state
- src/Serialization handles save/load persistence for plugin state.
- In a plugin like this, serialization is the mechanism that keeps custom gameplay state consistent across saves, loads, and session transitions.
11. Low-level patching
- src/Patches contains direct engine/game behavior changes such as:
- Sprint
- MoonRotation
- LoadEditorIDs
- TESObjectREFR
- These patches are the most invasive layer: they modify engine behavior when hooks or events are not enough.
12. Data flow at a high level
- The usual path is:
- engine/F4SE runtime starts the plugin,
- hooks and patches are installed,
- engine events and UI events enter the plugin,
- systems process them,
- script APIs expose controlled entry points back to the game,
- serialization preserves state across load/save boundaries.
- This makes the architecture event-driven, runtime-patched, and feature-modular.
13. Technology and build context
- The project is built with XMake and depends on CommonLibF4 for Fallout 4 engine access.
- src/detourXS suggests function detouring support for runtime hooks.
- This is a native C++ mod/plugin codebase, not a standalone application.
14. How to diagram it
- A good architecture diagram would place the game/F4SE runtime at the center boundary, with arrows into:
- Shared hook/infrastructure
- Event handlers
- Gameplay systems
- UI menus
- Script APIs
- Serialization
- Patches
- The key idea is that these are not separate services; they are cooperating modules inside one injected runtime plugin.
Main entry points: main.cpp Plugin entry · Hooks.cpp Hooks · SharedFunctions.cpp Shared utils · Skills.cpp Skills
Components 20
Runtime Boundary
Game engine and F4SE host environment
- Game + F4SE · Fallout 4 / Fallout Cascadia process with F4SE plugin loading
- CommonLibF4 · External engine access library used by the plugin
lib/commonlibf4 - detourXS · Function detouring support for hooks and patches
src/detourXS - XMake · Build configuration and project generation
xmake.lua
Plugin Core
Bootstrap and shared infrastructure inside the injected module
- Plugin entry · Entry point that wires initialization and module setup
src/main.cpp - Hooks · Shared detours and function interception setup
src/Shared/Hooks.cpp - Input watcher · Tracks player input state for gameplay features
src/Shared/InputWatcher.cpp - Shared utils · Cross-cutting helpers and declarations used by multiple systems
src/Shared/SharedFunctions.cpp
Gameplay Systems
Main feature modules that implement gameplay rules
- Ammo switch · Ammo selection and switching behavior
src/Systems/AmmoSwitch.cpp - Dialogue · Dialogue-related gameplay logic
src/Systems/Dialogue.cpp - Item degradation · Weapon and armor degradation rules
src/Systems/ItemDegradation.cpp - Lock levels · Lock difficulty and level logic
src/Systems/LockLevels.cpp - Skills · Skill progression and related rules
src/Systems/Skills.cpp
Integration
Events, menus, scripting, and persistence bridges
- Events · Lifecycle and gameplay event handlers
- Menus · Custom and extended in-game menus
- Papyrus manager · Registers and coordinates Papyrus-native functions
src/Papyrus/Manager.cpp - Serialization · Persists plugin state across save/load boundaries
src/Serialization/Serialization.cpp - Patches · Direct engine behavior modifications and fixes
src/Patches/Patches.h - OBScript APIs · Console-style commands exposed to scripts and commands
src/Scripts/ObScript.h - Papyrus APIs · Papyrus-facing functions exposed by the plugin
src/Scripts/Papyrus.h
Connections 27
- Game + F4SE → Plugin entry: loads · The game process loads the plugin entry point
- Plugin entry → Hooks: initializes · Bootstrap sets up shared hooks
- Plugin entry → Events: registers · Bootstrap wires engine event handlers
- Plugin entry → Menus: registers · Bootstrap installs UI/menu integrations
- Plugin entry → Papyrus manager: registers · Bootstrap connects Papyrus-native functions
- Plugin entry → Serialization: enables · Bootstrap enables persistent plugin state
- Plugin entry → Patches: applies · Bootstrap activates runtime patches
- Hooks → detourXS: uses · Shared hook layer relies on detouring support
- Hooks → Shared utils: depends on · Hook logic shares common helpers and declarations
- Input watcher → Shared utils: uses · Input tracking relies on shared declarations
- Events → Ammo switch: drives · Engine events trigger gameplay systems
- Events → Dialogue: drives · Engine events trigger gameplay systems
- Events → Item degradation: drives · Engine events trigger gameplay systems
- Events → Lock levels: drives · Engine events trigger gameplay systems
- Events → Skills: drives · Engine events trigger gameplay systems
- Menus → Dialogue: extends · UI flows support dialogue behavior
- Menus → Skills: extends · Level-up and related UI connect to skills
- Papyrus manager → Papyrus APIs: exposes · Manager publishes Papyrus functions
- Papyrus manager → Skills: bridges · Script functions reach gameplay logic
- Papyrus APIs → Skills: calls · Papyrus functions operate on skill systems
- OBScript APIs → Shared utils: uses · Console commands reuse shared helpers
- OBScript APIs → Item degradation: controls · Commands toggle degradation-related behavior
- Serialization → Shared utils: persists · Save/load logic preserves shared plugin state
- Patches → Game + F4SE: modifies · Patches alter engine behavior at runtime
- Patches → Hooks: cooperates with · Patches and hooks jointly intercept engine behavior
- CommonLibF4 → Plugin entry: supports · Engine access library underpins the plugin code
- XMake → Plugin entry: builds · Build system produces the plugin binary