How do I overwrite internal behavior? (modify classes)

Started by TheRedOne, September 03, 2015, 12:51:50 AM

Previous topic - Next topic

TheRedOne

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?

1000101

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>
(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

TheRedOne

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

1000101

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.
(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

TheRedOne

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.

1000101

Instead of replacing OutfitDatabase, use reflection to add/remove outfits from the database and change the filters on the outfits.
(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