Difference between revisions of "Modding Tutorials/Application Startup"
(Created page with "{{DISPLAYTITLE:Application Startup}} {{BackToTutorials}} {{:Modding_Tutorials/Under_Review}} This guide explains the application startup sequence of RimWorld. This can be us...") |
|||
(3 intermediate revisions by 2 users not shown) | |||
Line 2: | Line 2: | ||
{{BackToTutorials}} | {{BackToTutorials}} | ||
− | + | This guide explains the application startup sequence of RimWorld. | |
− | This guide | + | == WARNING == |
+ | |||
+ | 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 [https://discord.gg/rimworld the RimWorld Discord]. | ||
== Application Load == | == Application Load == | ||
Line 15: | Line 17: | ||
|- | |- | ||
| class="TutorialCodeTable-description" | '''1''' | | class="TutorialCodeTable-description" | '''1''' | ||
− | | class="TutorialCodeTable-description" | ''' | + | | class="TutorialCodeTable-description" | '''Load mod config data''' (the list of active mod) |
| <source lang="xml"> | | <source lang="xml"> | ||
− | Verse. | + | Verse.ModsConfig constructor |
</source> | </source> | ||
|- | |- | ||
| class="TutorialCodeTable-description" | '''2''' | | class="TutorialCodeTable-description" | '''2''' | ||
− | | class="TutorialCodeTable-description" | ''' | + | | class="TutorialCodeTable-description" | '''Build mod list from mod folders''' |
| <source lang="xml"> | | <source lang="xml"> | ||
− | Verse. | + | Verse.ModLister.RebuildModList(); |
</source> | </source> | ||
|- | |- | ||
| class="TutorialCodeTable-description" | '''3''' | | class="TutorialCodeTable-description" | '''3''' | ||
− | | class="TutorialCodeTable-description" | ''' | + | | 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" | ''' | + | | 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 56: | ||
| 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 74: | ||
| 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. | + | Verse.XmlInheritance.TryRegister() |
</source> | </source> | ||
|- | |- | ||
Line 75: | Line 80: | ||
| 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 86: | ||
| 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 92: | ||
| 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 104: | ||
| 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. | + | Verse.GenGeneric.InvokeStaticMethodOnGenericType() -> AddAllInMods |
</source> | </source> | ||
|- | |- | ||
Line 190: | Line 198: | ||
| 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 204: | ||
| 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 210: | ||
| 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 216: | ||
| 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> | ||
|- | |- | ||
Line 244: | Line 256: | ||
The data in this guide was compiled using and cross-referenced with the [https://discord.com/channels/214523379766525963/215496692047413249/959362775933673472 writeup on Discord] by [https://steamcommunity.com/id/legodude17/myworkshopfiles/ legodude17]. | The data in this guide was compiled using and cross-referenced with the [https://discord.com/channels/214523379766525963/215496692047413249/959362775933673472 writeup on Discord] by [https://steamcommunity.com/id/legodude17/myworkshopfiles/ legodude17]. | ||
+ | |||
+ | [[Category:Modding tutorials]] |
Latest revision as of 22:17, 10 February 2024
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.