Caves of Qud

Caves of Qud

Harmony Injector
 This topic has been pinned, so it's probably important
namkazt  [developer] 20 Jan, 2019 @ 10:07am
Example Transpiler Mod
Target is TinkeringScreen class with ApplyModification method we will change
GO.ModIntProperty("nMods", 1, false); to
GO.ModIntProperty("nMods", 0, false);

1, Create new .cs file

2, put those content
using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Reflection; using UnityEngine; using Harmony; using GameObject = XRL.World.GameObject; using Event = XRL.World.Event; using XRL.Core; using System.Linq; using XRL.UI; using XRL.World.Parts; using System.Reflection.Emit; namespace YourModName { [HarmonyPatch(typeof(TinkeringScreen))] [HarmonyPatch("ApplyModification", new Type[] { typeof(GameObject), typeof(IModification), typeof(bool) })] // because this is method overloading so i need set exactly all parameters type class Patch_TinkeringScreen_ApplyModification { static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator) { // init our IL codes of current method var codes = new List<CodeInstruction>(instructions); // find injection point for (int i = 0; i < codes.Count - 1; i++) { // find location of "nMods" string in parameters if (codes.opcode == OpCodes.Ldstr && codes.operand == "nMods")
{
// change from 1 to 0
codes.opcode = OpCodes.Ldc_I4_0;
break;
}
}
return codes.AsEnumerable();
}
}
}
Last edited by namkazt; 20 Jan, 2019 @ 10:08am