Editing Modding Tutorials/Modifying classes

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 15: Line 15:
 
=Adding behaviour to the Hediff class=
 
=Adding behaviour to the Hediff class=
 
HediffWithComps also support comps. HediffComps are different from [[Modding Tutorials/ThingComp|ThingComp]]s, but their general use is the same.
 
HediffWithComps also support comps. HediffComps are different from [[Modding Tutorials/ThingComp|ThingComp]]s, but their general use is the same.
 
=Using Harmony to override a non-overridden method=
 
You can't. Harmony can only patch methods which are actually implemented. You can't patch what isn't there.
 
 
Alternatives:
 
* [[Modding_Tutorials/Modifying_classes#Patching_the_base_class_of_a_subclass|Patch the base]] class instead, then check for the instance.
 
* [[Modding_Tutorials/Modifying_classes#Adding_fields_or_methods_to_classes|Subclass]], and then replace it wherever it's created with Harmony.
 
 
=Patching the base class of a subclass=
 
[[Modding Tutorials/Harmony|Harmony]] can only patch methods that actually have IL code. What you can do is patch the parent class. Let your patch take the __instance of the parent and pattern match.
 
<source lang="csharp">
 
if (!(__instance is SubClass))
 
    return;
 
</source>
 
 
[[Category:Modding tutorials]][[Category:Modding]]
 

Please note that all contributions to RimWorld Wiki are considered to be released under the CC BY-SA 3.0 (see RimWorld Wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)

Template used on this page:

This page is a member of 1 hidden category: