Hi all,
I'm trying to replace ImpactSomething in Verse.Projectile with my own method. I'm using Harmony. Here's my code:
using Verse;
using Harmony;
using RimWorld;
using System.Linq;
using System;
using System.Reflection;
using UnityEngine;
using System.Collections.Generic;
namespace NoFriendlyFire
{
[StaticConstructorOnStartup]
class Main
{
static Main()
{
Log.Message("Patching");
var harmony = HarmonyInstance.Create("venner.io.nofriendlyfire");
harmony.PatchAll(Assembly.GetExecutingAssembly());
}
}
[HarmonyPatch(typeof(Verse.Projectile), "ImpactSomething")]
public static class NoFriendlyFirePatch
{
// Harmony stuff
static void Prefix()
{
Log.Message("This works for some reason, but it's not what I need.");
}
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
Log.Message("Replacing method");
MethodBase from = typeof(Verse.Projectile).GetMethod("ImpactSomething", AccessTools.all);
MethodBase to = typeof(NoFriendlyFirePatch).GetMethod("ImpactSomethingElse", AccessTools.all);
return instructions.MethodReplacer(from, to);
}
// NoFriendlyFire method
static void ImpactSomethingElse()
{
Log.Message("I would appreciate it if you actually worked");
}
}
}
It does not work. There's no errors. The "Patching" and "Replacing method" appear in console when the game is opened. "This works for some reason, but it's not what I need." appears when a projectile hits a pawn. "I would appreciate it if you actually worked" does not appear at all. Why is this? I've searched all over GitHub for a solution to this problem with no avail.