[Solved]New Modder - How to execute logic on a pawn every tick (or alternatives)

Started by Verdiss, August 30, 2019, 09:54:15 PM

Previous topic - Next topic

Verdiss

I'm new to Rimworld modding as of this morning, so I'm still finding my around the particulars of how the code works.

My goal: increase the speed at which pawns naturally age by some factor (i.e. a pawn ages 10 years in 1 game year).

The code that controls aging is in Verse.Pawn_AgeTracker.AgeTick(). This is called by Verse.Pawn.Tick(). The absolute best case scenario for my mod is a direct edit to the AgeTick() method to allow it to increase ageBiologicalTicksInt by more than one at a time, as well as correcting the birthday logic to account for the multiple ticks at a time. Is there a way that I can directly overwrite a method of a class in the Core assembly?

If not, what are my alternatives for executing code every tick? Do I need to have a thing to get into the tick system, or can my code run divorced from a thing? Are there other ways of scheduling code, like a hidden incident that fires every n time? And, if I can't overwrite the method, I will need access to a collection of colonists to be able to tell them to age up, is there a variable or method that will give me such a collection (this last one I'm just too lazy to dig around more to find out)?

K

Harmony exists for exactly this reason: https://github.com/pardeike/Harmony

Harmony has fairly good documentation, but the gist of it is that it allows you to run code before or after a method in the RimWorld core is executed, and if you're feeling adventurous, you can even cut into the execution of a method directly. It should be more than capable of accomplishing what you want to do.

Verdiss

Thanks, K, I should have done my reading on Harmony looks like. What a wonderfully useful looking tool!

Edit: It genuinely took me all of 30 minutes with Harmony. Some... issues arose, but I'm sure it's nothing too bad.