RimWorld

RimWorld

Elite Bionics Framework
 This topic has been pinned, so it's probably important
Vectorial1024  [developer] 27 Feb, 2019 @ 2:13am
A Word for Fellow Modders
Hey there, fellow Modders,

Just gonna explain a bit of my mindset on and expectation of this mod.

I foresee and am confident that this mod will eventually become very popular, as evidenced by the (yet-to-come) very high visitor count and very high subscriber-visitor ratio.

Chill there, buddy. I am not boasting my mod. Hear me out.

In vanilla RimWorld, the max HP of a body part is defined in the Def, and is read directly from the Def XML into the executable. Theoretically, I could just end here, intercept the read request, and modify the value of the max HP as I wish.

But I couldn't.

After an update (0.18 or 0.19, can't be too wrong here), Tynan changed how the body of a pawn is defined. The most notable change is the consolidation of multiple "redundant" BodyPartDef into a single BodyPartDef, and also creating a new, "intermediate" class called BodyPartRecord. An example would be the consolidation of "left arm" and "right arm" pre-update BodyPartDef into a single post-update BodyPartDef "arm", and then adding two new BodyPartRecords, one labelled as "left arm", another "right arm". Both BodyPartRecords would point to the same (post-update) BodyPartDef "arm".

Here's the problem.

If I were to intercept requests at the BodyPartDef level and adjust the body part max HP, I will run into illogical situations. For example, suppose I were to apply a HediffComp of "+30 Max HP" onto the left arm of a colonist. If I simply intercept the read request at the BodyPartDef level then I would see that the right arm of the same colonist will also get the "+30 Max HP" effect, but not the Hediff. An implication would be that if both arms get the same HediffComp then the effect would be double-counted.

"Just check for which BodyPartRecord the game is calling!" You say. But it is impossible! If you can get your hands on a copy of RimWorld's underlying code, you will see that the C# function requesting body part max HP contains no parameters at all. That means, it is impossible for me to distinguish which BodyPartRecord the game is referring to when I am intercepting the request.

"Well, just add in one more parameter to that method!" My friend, that is not how programming works.

So what do I do?

I adopted an aggressive stance, added a new function under BodyPartDef that takes a BodyPartRecord as its only parameter, and patched all 14 occurences of the original function in RimWorld's code, verifying that everything still works.

But then again, I am not Tynan. I can't just overwrite everyone's copy of RimWorld to make sure my mod does not produce any errors. What I can do is to grab modders' attention by dumping an error message everytime the original function is called: yes, 1 call for 1 pawn in 1 tick. Do the math.

Eventually, users will ask modders to provide support for this mod because this mod is modifying something so fundamental that no one would have foreseen.

So dread it. Run from it. Destiny still arrives.

If you plan to make your mod's error-handing capability inclusive, then I suggest you incorporate this Framework to your mod in one way or another as soon as possible. This is simply practical matters; nothing personal.

That's all! Wish y'all a nice run on the Rim!
< >
Showing 1-12 of 12 comments
Razak 27 Feb, 2019 @ 10:35am 
Still have no idea why this was not done years ago :D

Changing bodypart hp is like the 3rd thing that came to my mind (after better hauling and larger table search radius :D)

So thanks for this! I just really hope that it will take off, as I am not well versed neither in C# nor in modding overall (wouldn't be all that against it but would need s1 to teach me as internet guides didn't really help :D)


So thanks a lot! :)
Jetharius 21 Jun, 2019 @ 3:58pm 
whats your stance on modders just including the assembly directly in their own modpacks versus requiring subscribers to sub here as a dependency. I know that would be bad practice as updates would not be automated, just wanted your stance on that scenario.
Vectorial1024  [developer] 21 Jun, 2019 @ 8:27pm 
If the modpack is on Steam, then add this framework to the Required Items. Then users will know they need to sub to this.

If the modpack is not on Steam, then just put the dll into the modpack. The features of this framework should be quite sufficient now, so I don't think I will need to work on it further. Safe to be included standalone.
Jetharius 22 Jun, 2019 @ 12:26am 
I understand the mechanics I wanted your take as the author. Would you be okay with just direct injection with credit versus dependency subscription?
Vectorial1024  [developer] 22 Jun, 2019 @ 3:07am 
Direct injection with credit is OK
(Still, dependency subscription is preferred, since it seems simpler to manage on the mod pack maker's side... idk?)
Jetharius 22 Jun, 2019 @ 3:15am 
I am the mod author, I just wanted your permission for a direct injection as a short term update option. The 2.0 version will have your mod as a initial dependency. Hal and I were worried that our 13k userbase would suffer a id.tenT error if we build in dependencies for your mod but didnt include the assembly natively, since I dont think steam will auto sub them...
Last edited by Jetharius; 22 Jun, 2019 @ 3:18am
Vectorial1024  [developer] 22 Jun, 2019 @ 3:41am 
Oh, I see. Just inject right away!
noj 19 Apr, 2020 @ 6:27am 
Seeing how hard-coded your transpilers are (counting calls), you might want to put [HarmonyPriority( Priority.First )] on them to make them more compatible with other transpilers.
(I had to lower the priority of one of my transpilers for my mod to not vomit the error message, as it was removing some calls and making your transpiler not work)
Vectorial1024  [developer] 19 Apr, 2020 @ 8:39am 
Originally posted by Jon:
Seeing how hard-coded your transpilers are (counting calls), you might want to put [HarmonyPriority( Priority.First )] on them to make them more compatible with other transpilers.
(I had to lower the priority of one of my transpilers for my mod to not vomit the error message, as it was removing some calls and making your transpiler not work)
Will look into it, thanks!
makoaluveaux 3 Nov, 2020 @ 11:50am 
EPOE works with this, right?
Vectorial1024  [developer] 4 Nov, 2020 @ 5:51am 
Originally posted by makoaluveaux:
EPOE works with this, right?

Well, EPOE won't crash with this, but afaik it does not make use of this either, so I guess you can say "yes it works"
bearhiderug 24 Feb, 2022 @ 9:12pm 
I stand by this mod.
< >
Showing 1-12 of 12 comments
Per page: 1530 50