Hello, I only have experience on modding with XML but for this new idea I have I need to do some stuff in C#, basically since I want to suffer I want to make a colony of vegans, it would be ok to roleplay it but I want it to have real consequences and my pawns to get a big debuff if an animal is butchered (and other things but lets focus on this one), looking through the assemblies I see that these lines are in the Verse.Corpse
public override IEnumerable<Thing> ButcherProducts(Pawn butcher, float efficiency)
{
foreach (Thing thing in this.InnerPawn.ButcherProducts(butcher, efficiency))
{
yield return thing;
}
IEnumerator<Thing> enumerator = null;
if (this.InnerPawn.RaceProps.BloodDef != null)
{
FilthMaker.TryMakeFilth(butcher.Position, butcher.Map, this.InnerPawn.RaceProps.BloodDef, this.InnerPawn.LabelIndefinite(), 1, FilthSourceFlags.None);
}
if (this.InnerPawn.RaceProps.Humanlike)
{
if (butcher.needs.mood != null)
{
butcher.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOf.ButcheredHumanlikeCorpse, null);
}
foreach (Pawn pawn in butcher.Map.mapPawns.SpawnedPawnsInFaction(butcher.Faction))
{
if (pawn != butcher && pawn.needs != null && pawn.needs.mood != null && pawn.needs.mood.thoughts != null)
{
pawn.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOf.KnowButcheredHumanlikeCorpse, null);
}
}
TaleRecorder.RecordTale(TaleDefOf.ButcheredHumanlikeCorpse, new object[]
{
butcher
});
}
yield break;
yield break;
I assume it would be enough to add this
if (this.InnerPawn.RaceProps.Animal)
{
if (butcher.needs.mood != null)
{
butcher.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOf.ButcheredAnimal, null);
}
foreach (Pawn pawn in butcher.Map.mapPawns.SpawnedPawnsInFaction(butcher.Faction))
{
if (pawn != butcher && pawn.needs != null && pawn.needs.mood != null && pawn.needs.mood.thoughts != null)
{
pawn.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOf.KnowButcheredAnimal, null);
}
}
TaleRecorder.RecordTale(TaleDefOf.ButcheredAnimal, new object[]
{
}
But how can I do this? I have searched for tutorials but can't find anything.
use harmony code injection.
you can inject custom code directly, but should not do it.
Lookup https://harmony.pardeike.net/articles/intro.html
for further details
Thanks for answering, unfortunately I have read that documentation whole multiple times and still can't make it work, I get the basics but don't know how to do it, could I get a small example of how to inject a new if? Or maybe some other mod that does it so I could study their source code?
Take a look at
https://github.com/Khaligufzel/RimStory/tree/master/Source/Harmony
(I'm currently working at a 1.2 version of this)
Note: mod uses HugsLib!
Another C# example project, but without harmony patching
https://github.com/HaploX1/ExampleDllMod
You have to tweak a few things to set it up for RW1.1+
see https://gist.github.com/pardeike/08ff826bf40ee60452f02d85e59f32ff
Check the wiki as well
https://rimworldwiki.com/wiki/Modding_Tutorials
Hope this helps
Chers,
m1st4x
This collection might be interesting!
https://github.com/Lanilor/Simple-Mods-Collection