Load Defs' XML on Demand

Started by Famous Shoes, April 19, 2015, 09:24:49 PM

Previous topic - Next topic

Famous Shoes

I'm trying to load Defs/FancyExtraDefs/FooBarDef.xml and put its contents into the DefDatabases, but only in certain conditions. I could have sworn this was covered in another post here, alas I cannot find it...

That is, how to:

  if (foo) {
    Fantastico.DefLoading("Defs/FancyExtraDefs/FooBarDef.xml");
    DefDatabase<ThingDef>.GetNamed("FooBar2"); // success...
    DefDatabase<ReceipeDef>.GetNamed("FooBar2Recipe"); // and victory!
  }


Pointers?

1000101

AFAIK, the xml will automatically be pulled into the dictionary by the core engine long before your mod code is ever even loaded let alone run.  By the time your code runs, it's already in the dictionary (and has been marked for removal).  After all the mods are loaded and their references have been checked, the core unloads unused assets.


Note:  I may be completely wrong, this is just what I have derived from logs and my own dll coding for RimWorld (see this thread)
(2*b)||!(2*b) - That is the question.
There are 10 kinds of people in this world - those that understand binary and those that don't.

Powered By

Famous Shoes

True enough for XML in standard directories. My aim is to throw the XML in other directories and then load it on demand. I'm trying to figure out a way to handle defs that should only be present when my mod and some other mod are present. Of course, I could work try to work backwards on this, i.e., let them load automatically then delete them, but the DefDatabases don't seem to have removal functionality.

1000101

#3
Well, I do know that if you have a corresponding class in your dll, it is automagically loaded (which is how the AdvancedRecipeDef works).

Take a look into RimWorld.Verse.DefDatabase class with IlSpy, specifically what AddAllInMods() is doing.
(2*b)||!(2*b) - That is the question.
There are 10 kinds of people in this world - those that understand binary and those that don't.

Powered By

Tynan

Adding and removing defs during play really isn't supported or recommended. It will break a *lot* of assumptions.

And you can definitely do whatever you're trying to do some other way. I recommend working out another way to do it.
Tynan Sylvester - @TynanSylvester - Tynan's Blog