XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFE.SpaceEngineers.AgentBridge

【SpaceEngineer】AI调试插件

公开
关注 0 Fork 0 Star 0
UTF-8
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<CodeInstruction> ReplaceMaximum(IEnumerable<CodeInstruction> instructions)
        {
            var result = new List<CodeInstruction>(); 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;
        }
    }
}