Ludeon Forums

Ludeon Forums

  • December 04, 2020, 03:52:34 PM
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: How do I overwrite internal behavior? (modify classes)  (Read 1819 times)

TheRedOne

  • Muffalo
  • *
  • Posts: 15
  • Refugee
    • View Profile
How do I overwrite internal behavior? (modify classes)
« 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?
« Last Edit: September 03, 2015, 12:54:11 AM by TheRedOne »
Logged

1000101

  • Planetologist
  • ****
  • Posts: 1344
  • RimFortress Builder
    • View Profile
Re: How do I overwrite internal behavior? (modify classes)
« Reply #1 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>
Logged
(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

  • Muffalo
  • *
  • Posts: 15
  • Refugee
    • View Profile
Re: How do I overwrite internal behavior? (modify classes)
« Reply #2 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:

Code: [Select]
<?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
Logged

1000101

  • Planetologist
  • ****
  • Posts: 1344
  • RimFortress Builder
    • View Profile
Re: How do I overwrite internal behavior? (modify classes)
« Reply #3 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.
Logged
(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

  • Muffalo
  • *
  • Posts: 15
  • Refugee
    • View Profile
Re: How do I overwrite internal behavior? (modify classes)
« Reply #4 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.
Logged

1000101

  • Planetologist
  • ****
  • Posts: 1344
  • RimFortress Builder
    • View Profile
Re: How do I overwrite internal behavior? (modify classes)
« Reply #5 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.
Logged
(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