Difference between revisions of "Modding Tutorials/Application Startup"

From RimWorld Wiki
Jump to navigation Jump to search
(Created page with "{{DISPLAYTITLE:Application Startup}} {{BackToTutorials}} {{:Modding_Tutorials/Under_Review}} This guide explains the application startup sequence of RimWorld. This can be us...")
 
Line 15: Line 15:
 
|-
 
|-
 
| class="TutorialCodeTable-description" | '''1'''
 
| class="TutorialCodeTable-description" | '''1'''
| class="TutorialCodeTable-description" | '''Build Mod List'''
+
| class="TutorialCodeTable-description" | '''Load mod config data''' (the list of active mod)
 
| <source lang="xml">
 
| <source lang="xml">
Verse.LoadedModManager.LoadAllActiveMods()
+
Verse.ModsConfig constructor
 
</source>
 
</source>
 
|-
 
|-
 
| class="TutorialCodeTable-description" | '''2'''
 
| class="TutorialCodeTable-description" | '''2'''
| class="TutorialCodeTable-description" | '''Load mod load folders'''
+
| class="TutorialCodeTable-description" | '''Build mod list from mod folders'''
 
| <source lang="xml">
 
| <source lang="xml">
Verse.LoadedModManager.LoadModContent();
+
Verse.ModLister.RebuildModList();
 
</source>
 
</source>
 
|-
 
|-
 
| class="TutorialCodeTable-description" | '''3'''
 
| class="TutorialCodeTable-description" | '''3'''
| class="TutorialCodeTable-description" | '''Load all mod assemblies in mod list order'''
+
| class="TutorialCodeTable-description" | '''Initialize mods'''
 
| <source lang="xml">
 
| <source lang="xml">
 +
Verse.LoadedModManager.InitializeMods()
 
</source>
 
</source>
 
|-
 
|-
 
| class="TutorialCodeTable-description" | '''4'''
 
| class="TutorialCodeTable-description" | '''4'''
| class="TutorialCodeTable-description" | '''Instantiate Mod subclasses'''
+
| class="TutorialCodeTable-description" | '''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)
 
| <source lang="xml">
 
| <source lang="xml">
 +
Verse.LoadedModManager.LoadModContent()
 
Verse.LoadedModManager.CreateModClasses()
 
Verse.LoadedModManager.CreateModClasses()
 
</source>
 
</source>
Line 52: Line 54:
 
| class="TutorialCodeTable-description" | '''Load translation keys from Defs (very rarely used)'''
 
| class="TutorialCodeTable-description" | '''Load translation keys from Defs (very rarely used)'''
 
| <source lang="xml">
 
| <source lang="xml">
 +
Verse.TKeySystem.Parse()
 
</source>
 
</source>
 
|-
 
|-
Line 69: Line 72:
 
| class="TutorialCodeTable-description" | '''Register Def inheritance (Name and ParentName)'''
 
| class="TutorialCodeTable-description" | '''Register Def inheritance (Name and ParentName)'''
 
| <source lang="xml">
 
| <source lang="xml">
Verse.LoadedModManager.ParseAndProcessXML()
+
Verse.XmlInheritance.TryRegister()
 
</source>
 
</source>
 
|-
 
|-
Line 75: Line 78:
 
| class="TutorialCodeTable-description" | '''Apply Def inheritance'''
 
| class="TutorialCodeTable-description" | '''Apply Def inheritance'''
 
| <source lang="xml">
 
| <source lang="xml">
 +
Verse.LoadedModManager.ParseAndProcessXML()
 
</source>
 
</source>
 
|-
 
|-
Line 80: Line 84:
 
| class="TutorialCodeTable-description" | '''Load Defs from XML into Def classes. References to other Defs are registered and not resolved until step 20'''
 
| class="TutorialCodeTable-description" | '''Load Defs from XML into Def classes. References to other Defs are registered and not resolved until step 20'''
 
| <source lang="xml">
 
| <source lang="xml">
 +
Verse.LoadedModManager.ParseAndProcessXML()
 
</source>
 
</source>
 
|-
 
|-
Line 85: Line 90:
 
| class="TutorialCodeTable-description" | '''Warn if any patches failed'''
 
| class="TutorialCodeTable-description" | '''Warn if any patches failed'''
 
| <source lang="xml">
 
| <source lang="xml">
 +
Verse.LoadedModManager.ClearCachedPatches()
 
</source>
 
</source>
 
|-
 
|-
Line 96: Line 102:
 
| class="TutorialCodeTable-description" | '''Store Defs into <code>DefDatabase</code>'''
 
| class="TutorialCodeTable-description" | '''Store Defs into <code>DefDatabase</code>'''
 
| <source lang="xml">
 
| <source lang="xml">
Verse.PlayDataLoader.DoPlayLoad()
+
Verse.GenGeneric.InvokeStaticMethodOnGenericType() -> AddAllInMods
 
</source>
 
</source>
 
|-
 
|-
Line 190: Line 196:
 
| class="TutorialCodeTable-description" | '''Load audio files from mods'''
 
| class="TutorialCodeTable-description" | '''Load audio files from mods'''
 
| <source lang="xml">
 
| <source lang="xml">
 +
Verse.LoadedModManager.LoadModContent() -> Verse.ModContentPack.ReloadContent() -> VerseModContentPack.ReloadContentInt()
 
</source>
 
</source>
 
|-
 
|-
Line 195: Line 202:
 
| class="TutorialCodeTable-description" | '''Load textures from mods'''
 
| class="TutorialCodeTable-description" | '''Load textures from mods'''
 
| <source lang="xml">
 
| <source lang="xml">
 +
Verse.LoadedModManager.LoadModContent() -> Verse.ModContentPack.ReloadContent() -> VerseModContentPack.ReloadContentInt()
 
</source>
 
</source>
 
|-
 
|-
Line 200: Line 208:
 
| class="TutorialCodeTable-description" | '''Load strings from mods'''
 
| class="TutorialCodeTable-description" | '''Load strings from mods'''
 
| <source lang="xml">
 
| <source lang="xml">
 +
Verse.LoadedModManager.LoadModContent() -> Verse.ModContentPack.ReloadContent() -> VerseModContentPack.ReloadContentInt()
 
</source>
 
</source>
 
|-
 
|-
Line 205: Line 214:
 
| class="TutorialCodeTable-description" | '''Load asset bundles from mods'''
 
| class="TutorialCodeTable-description" | '''Load asset bundles from mods'''
 
| <source lang="xml">
 
| <source lang="xml">
 +
Verse.LoadedModManager.LoadModContent() -> Verse.ModContentPack.ReloadContent() -> VerseModContentPack.ReloadContentInt()
 
</source>
 
</source>
 
|-
 
|-

Revision as of 00:37, 29 August 2023

Modding Tutorials

?
Under Review
This tutorial or guide is currently undergoing review and should not be considered ready to use.

This guide explains the application startup sequence of RimWorld. This can 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.

Application Load

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

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