static IEnumerable <CodeInstruction> CheckRun_Transpiler(IEnumerable <CodeInstruction> instructions) { BetterStaminaPlugin.DebugTranspilerLog($"######## CheckRun_Transpiler START ########"); var codes = new List <CodeInstruction>(instructions); for (var i = 0; i < codes.Count; i++) { CodeInstruction instr = codes[i]; BetterStaminaPlugin.DebugTranspilerLog($"{i} {instr}"); if (instr.opcode == OpCodes.Call) { String instrString = instr.ToString(); if (instrString.Contains("Mathf::Lerp")) // Looking for this line: float drain = this.m_runStaminaDrain * Mathf.Lerp(1f, 0.5f, this.m_skills.GetSkillFactor(Skills.SkillType.Run)); { int insertIndex = i; BetterStaminaPlugin.DebugTranspilerLog($">>> Deleting instruction {insertIndex} {codes[insertIndex].ToString()}:"); codes.RemoveAt(i); BetterStaminaPlugin.DebugTranspilerLog($">>> Inserting instruction at {insertIndex}:"); BetterStaminaPlugin.DebugTranspilerLog($"Old: { codes[insertIndex].ToString()}"); codes.Insert(insertIndex, new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(SkillPatches), "GetRunStaminaSkillFactor"))); BetterStaminaPlugin.DebugTranspilerLog($"New: { codes[insertIndex].ToString()}"); BetterStaminaPlugin.DebugTranspilerLog($">>> Inserting instruction at {insertIndex}:"); BetterStaminaPlugin.DebugTranspilerLog($"Old: { codes[insertIndex].ToString()}"); codes.Insert(insertIndex, new CodeInstruction(OpCodes.Ldarg_0)); BetterStaminaPlugin.DebugTranspilerLog($"New: { codes[insertIndex].ToString()}"); break; } } } BetterStaminaPlugin.DebugTranspilerLog($""); BetterStaminaPlugin.DebugTranspilerLog($"#############################################################"); BetterStaminaPlugin.DebugTranspilerLog($"######## MODIFIED INSTRUCTIONS - {codes.Count} ########"); BetterStaminaPlugin.DebugTranspilerLog($"#############################################################"); BetterStaminaPlugin.DebugTranspilerLog($""); for (var i = 0; i < codes.Count; i++) { CodeInstruction instr = codes[i]; BetterStaminaPlugin.DebugTranspilerLog($"{i} {instr}"); } BetterStaminaPlugin.DebugTranspilerLog($"######## CheckRun_Transpiler END ########"); BetterStaminaPlugin.DebugTranspilerLog($""); return(codes); }
static IEnumerable <CodeInstruction> OnSwimming_Transpiler(IEnumerable <CodeInstruction> instructions) { BetterStaminaPlugin.DebugTranspilerLog($"######## OnSwimming_Transpiler START ########"); var codes = new List <CodeInstruction>(instructions); for (var i = 0; i < codes.Count; i++) { CodeInstruction instr = codes[i]; BetterStaminaPlugin.DebugTranspilerLog($"{i} {instr}"); if (instr.opcode == OpCodes.Call) { String instrString = instr.ToString(); if (instrString.Contains("Mathf::Lerp")) { int insertIndex = i; BetterStaminaPlugin.DebugTranspilerLog($">>> Deleting instruction {insertIndex} {codes[insertIndex].ToString()}:"); codes.RemoveAt(i); BetterStaminaPlugin.DebugTranspilerLog($">>> Inserting instruction at {insertIndex}:"); BetterStaminaPlugin.DebugTranspilerLog($"Old: { codes[insertIndex].ToString()}"); codes.Insert(insertIndex, new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(SkillPatches), "GetSwimmingStaminaDrain"))); BetterStaminaPlugin.DebugTranspilerLog($"New: { codes[insertIndex].ToString()}"); BetterStaminaPlugin.DebugTranspilerLog($">>> Inserting instruction at {insertIndex}:"); BetterStaminaPlugin.DebugTranspilerLog($"Old: { codes[insertIndex].ToString()}"); codes.Insert(insertIndex, new CodeInstruction(OpCodes.Ldarg_0)); BetterStaminaPlugin.DebugTranspilerLog($"New: { codes[insertIndex].ToString()}"); break; } } } BetterStaminaPlugin.DebugTranspilerLog($""); BetterStaminaPlugin.DebugTranspilerLog($"#############################################################"); BetterStaminaPlugin.DebugTranspilerLog($"######## MODIFIED INSTRUCTIONS - {codes.Count} ########"); BetterStaminaPlugin.DebugTranspilerLog($"#############################################################"); BetterStaminaPlugin.DebugTranspilerLog($""); for (var i = 0; i < codes.Count; i++) { CodeInstruction instr = codes[i]; BetterStaminaPlugin.DebugTranspilerLog($"{i} {instr}"); } BetterStaminaPlugin.DebugTranspilerLog($"######## OnSwimming_Transpiler END ########"); BetterStaminaPlugin.DebugTranspilerLog($""); return(codes); }
static IEnumerable <CodeInstruction> PlayerAttackInput_Transpiler(IEnumerable <CodeInstruction> instructions) { BetterStaminaPlugin.DebugTranspilerLog($"######## PlayerAttackInput_Patch START ########"); var codes = new List <CodeInstruction>(instructions); for (var i = 0; i < codes.Count; i++) { CodeInstruction instr = codes[i]; BetterStaminaPlugin.DebugTranspilerLog($"{i} {instr}"); if (instr.opcode == OpCodes.Callvirt) { String instrString = instr.ToString(); if (instrString.Contains("UseStamina")) // Looking for this line: this.UseStamina(currentWeapon.m_shared.m_holdStaminaDrain * dt); { int foundCorrectUseStaminaIndex = -1; for (var j = i - 1; j >= i - 5; j--) // Verify that this UseStamina() call uses m_holdStaminaDrain by checking for it being loaded on the stack within last 5 instructions { BetterStaminaPlugin.DebugTranspilerLog($"^{j} {codes[j].ToString()}"); if (codes[j].opcode == OpCodes.Ldfld) { instrString = codes[j].ToString(); if (instrString.Contains("holdStaminaDrain")) { BetterStaminaPlugin.DebugTranspilerLog($">>> Found load holdStaminaDrain instruction at {j}:"); foundCorrectUseStaminaIndex = j; break; } } } if (foundCorrectUseStaminaIndex >= 0) { int insertIndex = foundCorrectUseStaminaIndex + 1; BetterStaminaPlugin.DebugTranspilerLog($">>> Inserting instruction at {insertIndex}:"); BetterStaminaPlugin.DebugTranspilerLog($"Old: { codes[insertIndex].ToString()}"); codes.Insert(insertIndex, new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(SkillPatches), "GetUpdatedHoldBowStaminaDrain"))); BetterStaminaPlugin.DebugTranspilerLog($"New: { codes[insertIndex].ToString()}"); BetterStaminaPlugin.DebugTranspilerLog($">>> Inserting instruction at {insertIndex}:"); BetterStaminaPlugin.DebugTranspilerLog($"Old: { codes[insertIndex].ToString()}"); codes.Insert(insertIndex, new CodeInstruction(OpCodes.Ldarg_0)); BetterStaminaPlugin.DebugTranspilerLog($"New: { codes[insertIndex].ToString()}"); break; } } } } BetterStaminaPlugin.DebugTranspilerLog($""); BetterStaminaPlugin.DebugTranspilerLog($"#############################################################"); BetterStaminaPlugin.DebugTranspilerLog($"######## MODIFIED INSTRUCTIONS - {codes.Count} ########"); BetterStaminaPlugin.DebugTranspilerLog($"#############################################################"); BetterStaminaPlugin.DebugTranspilerLog($""); for (var i = 0; i < codes.Count; i++) { CodeInstruction instr = codes[i]; BetterStaminaPlugin.DebugTranspilerLog($"{i} {instr}"); } BetterStaminaPlugin.DebugTranspilerLog($"######## PlayerAttackInput_Patch END ########"); BetterStaminaPlugin.DebugTranspilerLog($""); return(codes); }