Skip to main content

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 the PolymodHandler class:

Mod Folder Structure

Polymod scans the mods directory for valid mods:

Mod Root Location

The mod folder location varies by build configuration:
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:
  1. Check if any loaded mod has a replacement for that path
  2. If yes, return the mod’s version
  3. 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, GIF
  • AUDIO_MUSIC - OGG, MP3 (long tracks)
  • AUDIO_SOUND - OGG, MP3 (short effects)
  • TEXT - TXT, JSON, XML, CSV
  • BINARY - Any other file type

Asset Merging

Merge vs Replace

Instead of replacing entire files, you can merge your changes:
Normal asset path:
Result: Completely replaces the base game’s introText.txt

Parse 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

The introMod example demonstrates text merging:
data/introText.txt:

Version Management

API Version

Mods declare compatibility via api_version:
_polymod_meta.json
The game checks this against its version rule:

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.0
  • 1.2.3 - Exactly version 1.2.3
Mods with incompatible api_version will not load and will show an error.

Script Integration

Scripted Classes

Polymod can load HScript classes and register them:
This allows .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:
This allows distributing mods as:
  • Folders - Extracted mod folders
  • ZIP files - Single .zip files in the mods folder

Auto Scanning

With autoScan: 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:
This maps OpenFL asset libraries to filesystem paths.

Ignored Files

Certain files are ignored when loading mods:
Default ignored files include:
  • _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:
Hot reloading is a development feature. It requires debug builds and may cause instability.

Mod Management

Scanning Mods

Loading Specific Mods

Loads every detected mod.

Load Order

Mods are loaded in the order specified in the dirs array:
  • baseMod loads first
  • skinMod loads second, can override baseMod
  • tweakMod loads last, can override both previous mods
Later mods take priority. If multiple mods replace the same asset, the last one wins.

Error Handling

Polymod reports errors via callback:
Common errors:
  • Missing metadata - No _polymod_meta.json
  • Invalid version - api_version incompatible
  • 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

Polymod caches asset lookups. First access is slower, subsequent accesses are fast.
HScript files are compiled once on load. Avoid reloading unless necessary.
Text merging is fast. JSON/XML merging can be slower for large files.
ZIP files have slight overhead. Folders are faster for development.

Debugging Tips

Enable Debug Logging

Compile with FEATURE_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