RimWorld

RimWorld

Trade Price Fix
Fixed a little icompatability with 1-2-3 Perosnalites M2
Your transpiler was a little too crude and not compatible with other mods changing that method, so I went over it a little and changed it to this:

using System.Collections.Generic; using System.Linq; using System.Reflection.Emit; using HarmonyLib; using RimWorld; using Verse; namespace TradePriceFix { [HarmonyPatch(typeof(Tradeable), "InitPriceDataIfNeeded")] public static partial class Tradeable_InitPriceDataIfNeededPatch { [HarmonyTranspiler] private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { List<CodeInstruction> codes = new List<CodeInstruction>(instructions); bool foundEnd = false; bool foundStart = false; int idxEnd = 0; int idxStart = 0; for (int i = codes.Count<CodeInstruction>() - 1; i > 0; i--) { if (!foundStart && codes.opcode == OpCodes.Stfld && codes.opcode == OpCodes.Ldfld && codes.LoadsField(AccessTools.Field(typeof(Tradeable), "pricePlayerBuy")) && codes.opcode == OpCodes.Ldarg_0)
{
foundStart = true;
idxStart = i;
}
if (!foundEnd && codes.opcode == OpCodes.Ldarg_0 && codes.opcode == OpCodes.Ldfld && codes.LoadsField(AccessTools.Field(typeof(Tradeable), "pricePlayerSell")) && codes.opcode == OpCodes.Ldarg_0)
{
foundEnd = true;
idxEnd = i - 2;
break;
}
}
//Log.Message($"idxEnd = {idxEnd},idxStart = {idxStart}, count = {idxStart + 1 - idxEnd}");
codes.RemoveRange(idxEnd, idxStart + 1 - idxEnd);
return codes.AsEnumerable<CodeInstruction>();
}
}
}
Last edited by Spürgelwürg; 13 Aug, 2023 @ 2:59pm
< >
Showing 1-1 of 1 comments
Spürgelwürg 14 Aug, 2023 @ 2:03am 
From what I've seen, UnCap TradePriceImprovement should also be now compatible with this change.
< >
Showing 1-1 of 1 comments
Per page: 1530 50