Modding

From Crusader Kings II Wiki
Jump to: navigation, search

Modding, or creating mods, is the act of modifying the behavior of the base game (often referred as vanilla), either for personal use, or to release publicly to other players, for instance via the Steam Workshop.

As for all Paradox games, Crusader Kings II is moddable to a great extent.

Motivations of modders may vary widely: better translation to native language, more events or decisions, better map, major overhaul, etc.

Modding is not magic or heresy, anybody can learn to build a mod, and this guide is intended to lower the entry barriers to the world of CKII modding.

Yet, however good the documentation, there is still a learning curve to it, and it cannot replace the need to read some working vanilla code, and do lots of trial & error experimentations !

Guidelines[edit]

  • Create a mod for your modifications: use a personal mod even for small changes, and never modify directly game files in Steam CKII folder, as they may be overwritten without warning.
  • Use a good text editor (like Notepad++, with the CKII language file) to edit files and search into multiple files
  • Validate your mod with The Validator, it will save you a lot of pain and time troubleshooting crashes and bugs.
  • Minimize overwrites of vanilla files by adding separate files and loading from folders whenever possible, to improve mod compatibility and maintenance.
  • Use a proper merge tool, to merge between folders, and update modified vanilla files to a new vanilla patch.
  • Backup your work to avoid losing everything. In case of a modding team, consider using a source control system like GitHub to act as backup and also manage collaboration.
  • Use ANSI (Windows-1252) encoding for text files.
  • Indent properly to easily spot unclosed curly braced. Vanilla uses 1 tab for indentation rather than spaces.
  • Use comments starting with # character, to remember reasons for writing tricky stuff.

Mod structure[edit]

Mods are located in folder ~\Paradox Interactive\Crusader Kings II\mod, which must contain:

  • the .mod file, to tell the launcher what to do with the mod-folder.
  • the mod folder or zip containing the mod data. The mod data must have the same file and folder structure as if it was along with CK2game.exe in the game directory. Note that folder and file names are case sensitive on Mac and Linux.

The name of the .mod file must not contain any white-spaces, otherwise it will not auto-select when re-starting the launcher.

The content of the .mod file is:

Key Required? Effect Example
name Yes Defines the name that shows up in the launcher name = "My Mod"
path Yes Defines which folder is the mod's folder. It is relative to ~\Documents\Paradox Interactive\Crusader Kings II\ folder. path = "mod/MyMod"
user_dir No Tells the launcher to store saved games and temporary files in a specific folder. This can be useful for mods incompatible with vanilla saves (because of new titles, flags, religions, cultures, buildings, etc.), so that things don't get mixed up.

Warning: do not set user_dir for sub-mods of a main mod, as all user_dir of active mods are concatenated.

user_dir = "MyMod"
archive No Defines a zip-file instead of a folder. Alternative to path. It is relative to ~\Documents\Paradox Interactive\Crusader Kings II\ folder. This is the format used for mods downloaded from the Steam Workshop, but when uploading a mod to the workshop, path structure must be used instead. archive = "mod/mymod.zip"
replace_path No Tells the launcher to override everything in a folder, and load ONLY from the specified paths inside the mod. This is the only way to effectively remove stuff from vanilla, and is most often used for total conversion mods.

Notes:

  • replace_path works with folders, not files. To overwrite a file, just create a file with the same name in the mod.
  • To reduce mod size and improve mod compatibility, it is usually best to minimize the amount of folders that are replace_path.
  • replace_path is ignored when installing mod in the old Crusader Kings II\mod folder, hence why user mod folder must be used.
replace_path = "history"

replace_path = "history/characters"

dependencies No Tells the launcher that another mod has to be enabled. The other mod will be loaded first, allowing the 2nd mod to override some files (otherwise the 1st mod would win) dependencies = { "Another Mod" "Yet Another Mod" }
picture No Image under mod folder to serve as banner for Steam Workshop (will be displayed as 268px × 268px JPEG) picture = "MyMod.jpg"
tags No List of tags for Steam Workshop. tags = { "Tag1" "Tag 2" }

Below are some examples mod files, depending on the category of the mod:

Small mod[edit]

Small mods are the most common, and should neither use user_dir nor replace_path in order to keep compatibility with other small mods.

 name = "Small Mod"
 path = "mod/SmallMod"
 picture = "SmallMod.jpg"
 tags = { "Mods" "Small" }

Big mod[edit]

Overhaul mods typically use user_dir as saves wouldn't be loadable outside of the mod anyway. For total conversion mods, replace_path can be used to completely ignore vanilla directories that don't make sense in the context of the mod (history, flags, ...)

 name = "Big Mod"
 path = "mod/BigMod"
 user_dir = "BigMod"
 replace_path = "history/provinces" 
 picture = "BigMod.jpg"
 tags = { "Mods" "Big" }

Sub mod[edit]

Sub-mods of a main mod typically use dependencies to be able to override files from main mod.

 name = "Sub Mod"
 path = "mod/SubMod"
 dependencies = { "Main Mod" }
 picture = "SubMod.jpg"
 tags = { "Mods" "Main Mod" }

Game data[edit]

Game structure[edit]

The game data is composed of hierarchy of folders, containing game files.

A mod follows the same folder structure as the base game, so that when loading the game the engine will combine files from vanilla and mod(s). In most folders, the engine will load all the files within, which allows a mod to add new definitions (titles, religions, ...) without having to copy and modify vanilla files. To make use of this, it is important to understand how the scripts are loaded both at file level and definition level.

The behavior when loading a mod is the following:

  • Engine processes folders and files based on some hardcoded load order.
  • If current folder is defined as replace_path, all vanilla files in that folder will be ignored, and only mod files will be loaded (if any).
  • If the mod folder and vanilla folder both contain files with same names, vanilla files will be ignored and mod version will be used.
  • Inside a given folder, the order in which files are processed is usually alphanumerical on combined vanilla and mod file names, though some folders may have a different behavior.
  • When encountering more than once the same definition (title, religion, decision, ...), the duplicate definition may:
    • be ignored (first definition wins)
    • fully override the previous definition (last definition wins)
    • partially override the previous definition (definitions are merged/additive, which only makes sense if there is actually something to merge: hierarchy, list, etc.)
    • coexist/break both (in which case duplicate IDs must be avoided)

Below is a list of CKII game files and folders, with associated modding guide, and loading behavior.

For loading behavior, the cell colours highlight whether the behaviour is the expected one, strange or requiring some attention, or unexpected and to be avoided.

File/Folder What it contains How to mod Loading behavior
Crusader Kings II\common\
  • achievements.txt
  • defines.lua
  • defines.txt
  • hints.txt
  • region_colors.txt
  • static_modifiers.txt
  • technology.txt
General information
  • Defines Steam Achievements
  • POP, general, diplomatic, economic and military variables
  • Defines playable start- and end-date
  • Defines the displayed hints
  • RGB code for each region
  • All difficulty, rank and standard modifiers
  • Technology data

Defines




Static modifiers
Technology modding

N/A
Crusader Kings II\common\artifact_spawns\ Artifact modding
Crusader Kings II\common\artifacts\ Definitions of artifacts Artifact modding
Crusader Kings II\common\bookmarks\ Bookmarks are configured here (scenarios/start dates) Bookmark modding Merge, but chronological order of bookmarks is not kept. [This should be fixed with Conclave, TBC]
Crusader Kings II\common\buildings\ Buildings folder, all buildings are stored here. Building modding [?] Merge
Crusader Kings II\common\cb_types\ Casus Belli folder, all Casus-belli are stored here. Casus Belli modding [?] Merge
Crusader Kings II\common\combat_tactics\ Combat tactics definitions. Unit modding [?] Merge
Crusader Kings II\common\council_positions\ Conditions for an A.I. councillor to adopt a certain category of voting behavior. Councillor modding [?]
Crusader Kings II\common\council_voting\ A.I. rules for how councillors from a behavior category will vote Councillor modding [?]
Crusader Kings II\common\cultures\ Cultures folder, all cultures are stored here. Culture modding Merge. Since patch 2.4 cultures are merged like religions, and a new culture may be added to a vanilla culture_group via a separate file.
Crusader Kings II\common\death\ Death definitions Death modding
Crusader Kings II\common\death_text\ Flavor text for succession screen Death modding
Crusader Kings II\common\defines\ Defines. Defines [?] Merge. Entries in files override common/defines.lua values.
Crusader Kings II\common\disease\ Diseases definitions. Disease modding [?] Merge
Crusader Kings II\common\dynasties\ Dynasties folder, all dynasties are stored here. Dynasty modding. [?] Merge
Crusader Kings II\common\event_modifiers\ Event_modifiers folder, all event modifiers are stored here Modifiers [?] Merge
Crusader Kings II\common\execution_methods\ Execution methods Death modding [?]
Crusader Kings II\common\game_rules\ Game rules definitions Game rules modding Merge. The rules are displayed in UI based on order of files (alphanumerical on file name), then order of rules within the file.
Crusader Kings II\common\government_flavor\ Government naming definitions Government modding [?]
Crusader Kings II\common\governments\ Government definitions Government modding Merge. It is possible to define governments of the same government group in different files.
Crusader Kings II\common\graphicalculturetypes\ Graphicalculturetypes folder, all graphical culture types are stored here [?] Merge
Crusader Kings II\common\heir_text\ Flavor text for succession screen Death modding
Crusader Kings II\common\job_actions\ Defines councillors actions Councillor modding [?]
Crusader Kings II\common\job_titles\ Defines councillors titles Councillor modding [?]
Crusader Kings II\common\landed_titles\ Landed_titles folder, all landed titles are stored here. Title modding Merge. Merging behaviour is "complicated and might not have been designed that way intentionally"[1]
Crusader Kings II\common\laws\ Law modding Merge. A law with the same name as an existing law will append conditions to the allow section, but not the potential section.
Crusader Kings II\common\mercenaries\ Mercenaries folder, all mercenaries are stored here [?] Merge
Crusader Kings II\common\minor_titles\ Minor_titles folder, all minor (i.e. honorary) titles are stored here Minor title modding Alphanumerical, full override. Last minor title definition wins.
Crusader Kings II\common\modifier_definitions\ Defines dynamically defined modifiers, in particular special units modifiers. Unit modding [?] Merge
Crusader Kings II\common\nicknames\ Nicknames folder, all nicknames are stored here [?] Merge
Crusader Kings II\common\objectives\ Objectives folder, all objectives (i.e. ambitions, factions, and plots) are stored here. Objective modding [?] Merge
Crusader Kings II\common\on_actions\ On_actions folder, all on_actions are stored here Event modding Merge. Since patch 2.4 on_actions are merged, with new events being added to the previous list for a particular on_action, instead of replacing the list.
Crusader Kings II\common\opinion_modifiers\ Opinion modifiers folder, all opinion modifiers are stored here Modifiers [?] Merge
Crusader Kings II\common\province_setup\ Timeless information on provinces, duplicated from province history, used for loading saves. Map modding [?] Merge
Crusader Kings II\common\religion_modifiers\ Religion_modifiers folder, all religion modifiers are stored here. Modifiers [?] Merge
Crusader Kings II\common\religions\ Religions folder, all religions are stored here. Religion modding
Merge. Vanilla religions can be overridden, without needing to duplicate the whole religion group. Restrictions: need to define reformed religion before the non-reformed.
Crusader Kings II\common\religious_titles\ Religious_titles folder, all religious titles are stored here [?] Merge
Crusader Kings II\common\retinue_subunits\ Retinue subunits folder, all retinue subunits are stored here [?] Merge
Crusader Kings II\common\scripted_effects\ Scripted effects [?] Merge
Crusader Kings II\common\scripted_triggers\ Scripted triggers [?] Merge
Crusader Kings II\common\societies\ Definition of societies Society modding [?] Merge
Crusader Kings II\common\special_troops\ Special units definitions Unit modding [?] Merge
Crusader Kings II\common\stories\ Not used. N/A
Crusader Kings II\common\traits\ Traits folder, all traits are stored here. Trait modding Merge, but traits with same name will co-exist, and generated characters may get both versions of the trait at the same time. The last definition gets assigned to a character when using commands.
Crusader Kings II\common\trade_routes\ Trade route definitions. Trade route modding [?]
Crusader Kings II\common\triggered_modifiers\ Defines global modifiers that trigger under certain conditions Triggered modifiers [?] Merge
Crusader Kings II\connectui\ Appears to be leftover interface for the discontinued Paradox Connect service (used in older Clausewitz games CK2 is based on). Unusable
Crusader Kings II\decisions\ Decisions folder, all decisions are stored here Decision modding Merge, but override of decision by re-using same name does not work (breaks the decision effect, that does nothing)
Crusader Kings II\dlc\ Contains DLC information and zipped content files DLC files N/A
Crusader Kings II\eu4_converter\ Europa Universalis 4 Save Converter folder, all files related to the EUIV converter are stored here.

Note: vanilla files were moved inside /dlc/dlc030.zip

EU4 Converter modding [?]
Crusader Kings II\events\ Events folder, all events are stored here. Event modding [?] Merge
Crusader Kings II\gfx\
  • ambitions\
  • characters\
  • coats_of_arms\
  • cursors\
  • eurfonts\
  • event_pictures\
  • flags\
  • fonts\
  • FX\
  • interface\
  • loadingscreens\
  • mapitems\
  • models\
  • polishfonts\
  • titles\
  • traits\
Graphics folder, all graphics are stored here. Graphics modding

Graphics are mapped to a logical name (GFX_xxx) inside Crusader Kings II\interface\*.gfx files
Warning: a missing flag for a title in flags\ will cause wrong flags to appear for most titles, due to a shift.

Crusader Kings II\history\ Historical data for characters, titles, provinces and wars for the possible start dates. This is a likely the text export of an internal database, which is sometime mentioned in the patch notes[2]. History modding N/A
Crusader Kings II\history\characters\ Historical characters, optionally associated to a dynasty from \common\dynasties\ folder. Character modding [?] Merge. Duplicate character IDs break the character history and must be avoided.
Crusader Kings II\history\diplomacy\ Not used N/A N/A
Crusader Kings II\history\provinces\ History of provinces (holdings built, change of culture or religion) [?] Merge
Crusader Kings II\history\technology\ Initial technology of provinces, depending on the start date. Technology modding [?]
Crusader Kings II\history\titles\ History of titles (list of successive holders) Note: titles that should be deactivated at game start (ex: reformed religion heads) must have an history file that disables the title. [?] Merge
Crusader Kings II\history\wars\ Important on-going wars (attacker, defender, Casus Belli, war score, ...), usually for historical bookmarks. [?] Merge
Crusader Kings II\interface\
  • coats_of_arms.txt
  • coats_of_arms.gfx
  • generalstuff.gfx
Interface graphics Interface modding. Loading of *.gfx files is in alphanumerical order. Last spriteType definition loaded overrides previous ones with same name, if any (i.e. use zz_ file prefix to override vanilla sprites). Loading from gfx/interface/<religion_group> sub-folders is locked for mods.
Crusader Kings II\interface\portrait_offsets\ .txt files with external offsets for portrait frames Portrait modding
Crusader Kings II\interface\portrait_properties\ Dynamic rules to select portrait properties values Portrait modding [?]
Crusader Kings II\interface\portrait\ Definitions of spriteType and portraitType elements for portraits. Portrait modding Merge
Crusader Kings II\launcher\ Launcher graphics and configuration N/A
Crusader Kings II\localisation\ All text data for things like country names and event description, has options for other languages Localisation Full override. If duplicates are in different files, first file loaded wins (i.e. use 00_ file prefix to override vanilla keys). If in same file, last duplicate in file wins. Warning: files must end with .csv extension, or they will not be taken into account.
Crusader Kings II\localisation\customizable_localisation\ Custom localisation commands definitions Localisation#Custom_commands [?] Merge.
Crusader Kings II\map\
  • adjacencies.csv
  • default.map
  • definition.csv
  • geographical_region.txt
  • positions.txt
  • provinces.bmp
  • rivers.bmp
  • terrain.bmp
  • topology.bmp
  • trees.bmp
  • world_normal_height.bmp
Map settings, province shapes, continents, regions etc. Map modding N/A
Crusader Kings II\map\statics Map external frame size, and positions of fixed 3D map elements (wonders, etc.) Map modding
Crusader Kings II\map\terrain Map modding
Crusader Kings II\mod\ Dummy mod folder, do not store mods here, use local mod folder Mod file Breaks mods, as configurations like replace_path are ignored.
Crusader Kings II\music\ Music used by the game Music modding [?] All .txt files song elements are loaded.
Crusader Kings II\sound\ All sounds except music [?]
Crusader Kings II\tutorial\ Tutorial configuration [?]

Specific guides[edit]



Tools & utilities[edit]

These are utilities for modders. For player tools, see utilities.

Advanced tips[edit]

  • For the bigger mods using a source control management tool (Git, ...), it is handy to create a symbolic link between CKII mod folder and the working directory of the local repository, especially if the mod also has sub-mods. Note that you'll still need to copy the .mod file(s) manually, but they rarely change. Run the following command from the parent directory of main git folder, replacing:
    • <mod_path_name> by the value of path attribute from .mod file
    • <git_mod_folder> by the name of the sub-folder that contain mod data (folders common, decisions, events, etc...)
mklink /J "%HOMEDRIVE%%HOMEPATH%\Documents\Paradox Interactive\Crusader Kings II\mod\<mod_path_name>" ".\<git_mod_folder>"

External links[edit]

See also[edit]

References[edit]

  1. Forum:774248/page-14#post-19100145
  2. http://www.ckiiwiki.com/Patch_2.0#Database
Modding
Gfx/Sfx/localisation