What is Polymod?
Polymod is an atomic modding framework for Haxe games. It provides a complete system for:- Loading mods from filesystem or ZIP archives
- Replacing game assets transparently
- Merging data files intelligently
- Sandboxing scripts securely
- Managing mod dependencies and versioning
Polymod on GitHub
Polymod is open source and maintained by Lars Doucet
How FNF Uses Polymod
Friday Night Funkin’ integrates Polymod through thePolymodHandler class:
Mod Folder Structure
Polymod scans the mods directory for valid mods:Mod Root Location
The mod folder location varies by build configuration:- Release Builds
- Development
Mods are in the
mods/ folder next to the executable.Asset Replacement
How It Works
When the game requests an asset, Polymod intercepts the request:- Check if any loaded mod has a replacement for that path
- If yes, return the mod’s version
- If no, return the base game’s version
Example
1
Game requests asset
2
Polymod checks mods
Looks for
images/newgrounds_logo.png in loaded mods, in order:3
Returns mod asset
Returns the custom logo from
testing123 instead of the base game’s.Asset Types
Polymod supports all OpenFL asset types:IMAGE- PNG, JPG, GIFAUDIO_MUSIC- OGG, MP3 (long tracks)AUDIO_SOUND- OGG, MP3 (short effects)TEXT- TXT, JSON, XML, CSVBINARY- Any other file type
Asset Merging
Merge vs Replace
Instead of replacing entire files, you can merge your changes:- Replace
- Merge
Normal asset path:Result: Completely replaces the base game’s
introText.txtParse Rules
Polymod needs to know how to parse files for merging:Supported Merge Formats
LINES
Text files treated as arrays of lines. Append mode adds lines to the end.
PLAINTEXT
Raw text concatenation. Useful for scripts.
JSON
Deep object merging. Properties from mods override base game properties.
CSV
Row-based appending. New rows added to the end.
XML
Node-based merging. Matching nodes get merged or appended.
Merge Example: Intro Text
TheintroMod example demonstrates text merging:
- Base Game
- Mod File
- Result
data/introText.txt:
Version Management
API Version
Mods declare compatibility viaapi_version:
_polymod_meta.json
Version Rule Syntax
Polymod uses semantic versioning rules:>=0.8.0- At least version 0.8.0<0.9.0- Less than version 0.9.0>=0.8.0 <0.9.0- Between 0.8.0 and 0.9.01.2.3- Exactly version 1.2.3
Script Integration
Scripted Classes
Polymod can load HScript classes and register them:.hxc files to define classes that extend base classes.
Import Management
Polymod handles imports automatically:Import Aliases
Some classes are aliased for compatibility or security:Blacklisting
Dangerous classes are blacklisted:Scripts attempting to use blacklisted classes will fail with an error.
File System Support
ZIP File System
Polymod can load mods from ZIP archives:- Folders - Extracted mod folders
- ZIP files - Single
.zipfiles in the mods folder
Auto Scanning
WithautoScan: true, Polymod automatically detects:
- New mods added to the folder
- ZIP files alongside folder mods
- Changes to mod metadata
Framework Parameters
FNF configures OpenFL-specific parameters:Ignored Files
Certain files are ignored when loading mods:_polymod_meta.json(metadata, not an asset)_polymod_icon.png(icon, not an asset)_polymod_pack.txt(pack definition).DS_Store(macOS metadata)
Hot Reloading
During development, reload mods without restarting:Mod Management
Scanning Mods
Loading Specific Mods
- All Mods
- Enabled Mods
- Specific IDs
- No Mods
Load Order
Mods are loaded in the order specified in thedirs array:
baseModloads firstskinModloads second, can overridebaseModtweakModloads last, can override both previous mods
Error Handling
Polymod reports errors via callback:- Missing metadata - No
_polymod_meta.json - Invalid version -
api_versionincompatible - Parse error - Malformed JSON/XML/script
- Missing dependency - Required mod not loaded
Advanced Techniques
Custom Merge Logic
You can specify merge behavior per file:Conditional Asset Loading
Load different assets based on conditions:MyModule.hxc
Multi-Mod Compatibility
Design mods to work together:Dynamic Asset Replacement
Modify assets at runtime:Performance Considerations
Asset Caching
Asset Caching
Polymod caches asset lookups. First access is slower, subsequent accesses are fast.
Script Compilation
Script Compilation
HScript files are compiled once on load. Avoid reloading unless necessary.
Merge Operations
Merge Operations
Text merging is fast. JSON/XML merging can be slower for large files.
ZIP vs Folders
ZIP vs Folders
ZIP files have slight overhead. Folders are faster for development.
Debugging Tips
Enable Debug Logging
Compile withFEATURE_DEBUG_FUNCTIONS to see detailed mod info:
Check Loaded Mods
Verify Asset Sources
Check which mod provided an asset:Next Steps
Scripting Guide
Master HScript for advanced mod functionality
Creating Mods
Build your own mods from scratch
Modding Overview
Return to the modding overview
