Ludeon Forums

RimWorld => Mods => Help => Topic started by: TheRedOne on September 03, 2015, 12:51:50 AM

Title: How do I overwrite internal behavior? (modify classes)
Post by: TheRedOne on September 03, 2015, 12:51:50 AM
Not too long ago, I made a forum post that wished for a mod to have outfits affect weapons, too. After some time however, I though I can do that mod myself.

After browsing the source code of Rimworld for some time, I found the class which I need to change for that. So I know what I need to change and I guess I will figure out how to change it. My question is how do I make Rimworld load my class instead of its own or how do I overwrite Rimworld's class?

I made a simple mod folder with my Assembly in it, but of course it is not loading my class, because I do not know how to call my class instead.

Could someone please point me in the right direction?
Title: Re: How do I overwrite internal behavior? (modify classes)
Post by: 1000101 on September 03, 2015, 02:11:46 AM
You need to hook your class in whatever is going to use it.  Generally this is done via xml.  Look at the xml and for tags which have "class" in the name.  eg, "thingClass", "compClass", etc.  This is where you need to put your class to be used.

For RimWorld and Verse classes, you don't need to specify the namespace but for a mod you do.  ie, <thingClass>myNamespace.myClass</thingClass>
Title: Re: How do I overwrite internal behavior? (modify classes)
Post by: TheRedOne on September 03, 2015, 03:18:35 AM
Thanks for the reply! However, I am still stuck.

The class I'd like to replace is OutfitDatabase and I wrote an xml for my mod so far like this:

<?xml version="1.0" encoding="utf-8" ?>
<MainTabDefs>
<MainTabDef>
<defName>RedOutfit</defName>
<description>Configure what each colonist is allowed to wear and which weapons to carry.</description>
<compClass>RedOutfit.RedOutfitDatabase</compClass>
<windowClass>MainTabWindow_Outfits</windowClass>
<order>31</order>
</MainTabDef>
</MainTabDefs>


Though, Rimworld gives me "Found no usable data when trying to get Verse.ThingDefs from file RedOutfit.xml". So in my unknowing state of being, I thought I should change <compClass>RedOutfit.RedOutfitDatabase</compClass> to <thingClass>RedOutfit.RedOutfitDatabase</thingClass>. Though, this changed nothing.

PS: I joined Slack, too
Title: Re: How do I overwrite internal behavior? (modify classes)
Post by: 1000101 on September 03, 2015, 03:31:51 AM
You can't just add tags willy-nilly.  You need to apply the tags properly.  MainTabDef doesn't contain any "comps."

You're going to need a tool like IlSpy or dotPeek to examine the game assemblies and determine what you need to do and how to do it.
Title: Re: How do I overwrite internal behavior? (modify classes)
Post by: TheRedOne on September 03, 2015, 04:07:59 AM
For others. We had a discussion on slack and tried several approaches, but it seems like to outfit system can not be replaced, because the relevant classes are sealed which prevents from custom classes to extend them.

I gave up on that idea (for now?). If someone else finds a solution to our problem, I'd be glad to hear about it.
Title: Re: How do I overwrite internal behavior? (modify classes)
Post by: 1000101 on September 03, 2015, 05:02:29 AM
Instead of replacing OutfitDatabase, use reflection to add/remove outfits from the database and change the filters on the outfits.