using System; using System.Collections.Generic; using System.Reflection; using System.Reflection.Emit; using HarmonyLib; namespace XFE.SeAgent.Plugin.Performance { internal static class TexturePriorityUpdates { public static IEnumerable ReplaceMaximum(IEnumerable instructions) { var result = new List(); int matches = 0; foreach (var instruction in instructions) { if (instruction.opcode == OpCodes.Call && instruction.operand is MethodInfo method && method.DeclaringType == typeof(VRage.Utils.MyUtils) && method.Name == "InterlockedMax" && method.ReturnType == typeof(int)) { instruction.operand = AccessTools.Method(typeof(AtomicMaximum), nameof(AtomicMaximum.Update)); matches++; } result.Add(instruction); } // Keep both native guards, token lifetime, update frequency and priority // calculation unchanged; patch only the verified texture call site. if (matches != 1) throw new InvalidOperationException("Unsupported texture batch: expected one integer atomic maximum."); return result; } } }