Application Startup

From RimWorld Wiki
Jump to navigation Jump to search

Modding Tutorials

This guide explains the application startup sequence of RimWorld.

WARNING[edit]

This guide is intended to be used to reference the order in which data is loaded in order to diagnose issues with mod code running too early or too late. You should not Harmony patch any of these referenced methods in order to do custom loading, there are many above-board methods for ensuring data and setup is done at the correct time, so those should be used instead. If you have any questions regarding application load issues, please make use of online resources such as the #mod-development channel on the RimWorld Discord.

Application Load[edit]

The root method that begins the application load process is Verse.PlayDataLoader.LoadAllPlayData(bool), which is called by Verse.Root.Start().

# Description Code Location
1 Load mod config data (the list of active mod)
Verse.ModsConfig constructor
2 Build mod list from mod folders
Verse.ModLister.RebuildModList();
3 Initialize mods
Verse.LoadedModManager.InitializeMods()
4 Load mod assemblies (also create Mod subclass instances) (also queues up loading for audio, graphics, strings, and asset bundles, which doesn't execute until steps 30-33)
Verse.LoadedModManager.LoadModContent()
Verse.LoadedModManager.CreateModClasses()
5 Load and parse Def XML files
Verse.LoadedModManager.LoadModXML()
6 Combine all the Def files into a single XML document
Verse.LoadedModManager.CombineIntoUnifiedXML()
7 Load translation keys from Defs (very rarely used)
Verse.TKeySystem.Parse()
8 Load and error check patches
Verse.LoadedModManager.ErrorCheckPatches()
9 Apply XML PatchOperations
Verse.LoadedModManager.ApplyPatches()
10 Register Def inheritance (Name and ParentName)
Verse.XmlInheritance.TryRegister()
11 Apply Def inheritance
Verse.LoadedModManager.ParseAndProcessXML()
12 Load Defs from XML into Def classes. References to other Defs are registered and not resolved until step 20
Verse.LoadedModManager.ParseAndProcessXML()
13 Warn if any patches failed
Verse.LoadedModManager.ClearCachedPatches()
14 Load Language metadata
Verse.LanguageDatabase.InitAllMetadata()
15 Store Defs into DefDatabase
Verse.GenGeneric.InvokeStaticMethodOnGenericType() -> AddAllInMods
16 Store Defs into DefOf classes
RimWorld.DefOfHelper.RebindAllDefOfs(true)
17 Build translation key mappings
Verse.TKeySystem.BuildMappings()
18 Inject DefInjected translations (first round)
Verse.LanguageDatabase.activeLanguage.InjectIntoData_BeforeImpliedDefs()
19 Generate implied defs (Blueprints, Meat, Frames, Techprints, Corpses, Stone terrain, Recipes from recipeMakers, Neurotrainers)
Verse.DefGenerator.GenerateImpliedDefs_PreResolve();
20 Resolve cross references (goes through cross-reference registrations and replace them with direct references to their actual Defs
Verse.DirectXmlCrossRefLoader.ResolveAllWantedCrossReferences()
21 Store Defs into DefOf fields (again, will error if Def is not found this time)
RimWorld.DefOfHelper.RebindAllDefOfs(false)
22 Reload player knowledge database (Learning Helper entries)
RimWorld.PlayerKnowledgeDatabase.ReloadAndRebind()
RimWorld.LessonAutoActivator.Reset();
23 Reset all static data
Verse.LoadedModManager.DoPlayLoad()
24 Resolve references (calls ResolveReferences on all Defs), specifically in order: ThingCategoryDefs, RecipeDefs, all other defs, ThingDefs
Verse.DefDatabase<ThingCategoryDef>.ResolveAllReferences(true, true)
Verse.DefDatabase<RecipeDef>.ResolveAllReferences(true, true)
Verse.GenGeneric.InvokeStaticMethodOnGenericType() -> ResolveAllReferences
Verse.DefDatabase<ThingDef>.ResolveAllReferences()
25 Generate implied defs (Key bindings)
RimWorld.DefGenerator.GenerateImpliedDefs_PostResolve()
26 Reset more static data, and make sure smoothing is set up properly
Verse.LoadedModManager.DoPlayLoad()
27 If in Dev mode, log all config errors
Verse.GenGeneric.InvokeStaticMethodOnGenericType() -> ErrorCheckAllDefs
28 Load KeyBindings
Verse.KeyPrefs.Init()
29 Assign short hashes
Verse.ShortHashGiver.GiveAllShortHashes()
30 Load audio files from mods
Verse.LoadedModManager.LoadModContent() -> Verse.ModContentPack.ReloadContent() -> VerseModContentPack.ReloadContentInt()
31 Load textures from mods
Verse.LoadedModManager.LoadModContent() -> Verse.ModContentPack.ReloadContent() -> VerseModContentPack.ReloadContentInt()
32 Load strings from mods
Verse.LoadedModManager.LoadModContent() -> Verse.ModContentPack.ReloadContent() -> VerseModContentPack.ReloadContentInt()
33 Load asset bundles from mods
Verse.LoadedModManager.LoadModContent() -> Verse.ModContentPack.ReloadContent() -> VerseModContentPack.ReloadContentInt()
34 Load PawnBios (backer pawns and name-in-game lists)
RimWorld.SolidBioDatabase.LoadAllBios()
35 Inject DefInjected translations, including in backstories, and error if there's a translation for a Def that isn't present
Verse.LanguageDatabase.activeLanguage.InjectIntoData_AfterImpliedDefs()
36 Call all StaticConstructorOnStartup classes
Verse.StaticConstructorOnStartupUtility.CallAll()
37 Bake static atlases (building damage and minified overlays such as the crate and bag textures)
Verse.GlobalTextureAtlasManager.BakeStaticAtlases()
38 Force garbage collection
RimWorld.IO.AbstractFilesystem.ClearAllCache()
System.GC.Collect(int.MaxValue, GCCollectionMode.Forced)

Sources[edit]

The data in this guide was compiled using and cross-referenced with the writeup on Discord by legodude17.