From db15c65961ecc04d2b954c42ca3fa4ddc7f37fd8 Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Tue, 7 Jul 2026 23:49:54 +0800 Subject: [PATCH] chore: remove BlueprintTweaks patch, the PR is merged as well --- UXAssist/ModsCompat/BlueprintTweaks.cs | 156 ------------------------- UXAssist/UXAssist.cs | 1 - 2 files changed, 157 deletions(-) delete mode 100644 UXAssist/ModsCompat/BlueprintTweaks.cs diff --git a/UXAssist/ModsCompat/BlueprintTweaks.cs b/UXAssist/ModsCompat/BlueprintTweaks.cs deleted file mode 100644 index 8a09530..0000000 --- a/UXAssist/ModsCompat/BlueprintTweaks.cs +++ /dev/null @@ -1,156 +0,0 @@ -using HarmonyLib; -using System; -using System.Collections.Generic; -using System.Reflection; -using System.Reflection.Emit; -using UnityEngine; -using UXAssist.Common.ModCompat; -using UXAssist.Functions; - -namespace UXAssist.ModsCompat; - -class BlueprintTweaks -{ - public const string BlueprintTweaksGuid = "org.kremnev8.plugin.BlueprintTweaks"; - private static FieldInfo selectObjIdsField; - private static Type classTypeBlueprintTweaksPlugin; - private static Type classTypeUIBuildingGridPatch2; - - public static bool Run(Harmony harmony) - { - if (!ModCompatHelper.TryGetLoadedPluginInfo(BlueprintTweaksGuid, out var pluginInfo)) return false; - if (!ModCompatHelper.TryGetPluginType(pluginInfo, "BlueprintTweaks.DragRemoveBuildTool", out var classTypeDragRemoveBuildTool)) return false; - if (ModCompatHelper.TryGetMethod(classTypeDragRemoveBuildTool, "DetermineMorePreviews", out _)) return true; - ModCompatHelper.TryGetPluginType(pluginInfo, "BlueprintTweaks.BlueprintTweaksPlugin", out classTypeBlueprintTweaksPlugin); - ModCompatHelper.TryGetPluginType(pluginInfo, "BlueprintTweaks.UIBuildingGridPatch2", out classTypeUIBuildingGridPatch2); - if (classTypeBlueprintTweaksPlugin == null || classTypeUIBuildingGridPatch2 == null) return false; - var UIBuildingGrid_Update = AccessTools.Method(typeof(UIBuildingGrid), nameof(UIBuildingGrid.Update)); - harmony.Patch(AccessTools.Method(classTypeUIBuildingGridPatch2, "UpdateGrid"), null, null, new HarmonyMethod(AccessTools.Method(typeof(BlueprintTweaks), nameof(PatchUpdateGrid)))); - selectObjIdsField = AccessTools.Field(classTypeDragRemoveBuildTool, "selectObjIds"); - harmony.Patch(AccessTools.Method(classTypeDragRemoveBuildTool, "DeterminePreviews"), - new HarmonyMethod(AccessTools.Method(typeof(BlueprintTweaks), nameof(PatchDeterminePreviews)))); - return true; - } - - private static readonly int zMin = Shader.PropertyToID("_ZMin"); - private static readonly int reformMode = Shader.PropertyToID("_ReformMode"); - - private static IEnumerable PatchUpdateGrid(IEnumerable instructions, ILGenerator generator) - { - var matcher = new CodeMatcher(instructions, generator); - matcher.MatchForward(false, - new CodeMatch(OpCodes.Ldsfld, AccessTools.Field(classTypeBlueprintTweaksPlugin, "tool")), - new CodeMatch(OpCodes.Ldfld), - new CodeMatch(ci => ci.opcode == OpCodes.Brfalse || ci.opcode == OpCodes.Brfalse_S) - ); - var label1 = generator.DefineLabel(); - matcher.Advance(2).Operand = label1; - matcher.Advance(1); - matcher.MatchForward(false, - new CodeMatch(OpCodes.Ldarg_0), - new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(UIBuildingGrid), nameof(UIBuildingGrid.blueprintMaterial))), - new CodeMatch(OpCodes.Ldsfld, AccessTools.Field(classTypeUIBuildingGridPatch2, "tintColor")), - new CodeMatch(OpCodes.Call), - new CodeMatch(OpCodes.Callvirt) - ).RemoveInstructions(5); - matcher.MatchForward(false, - new CodeMatch(OpCodes.Ldarg_0), - new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(UIBuildingGrid), nameof(UIBuildingGrid.blueprintMaterial))), - new CodeMatch(OpCodes.Ldsfld, AccessTools.Field(classTypeUIBuildingGridPatch2, "cursorGratBox")), - new CodeMatch(OpCodes.Ldsfld), - new CodeMatch(OpCodes.Ldfld), - new CodeMatch(OpCodes.Call), - new CodeMatch(OpCodes.Callvirt) - ).Advance(1).Operand = AccessTools.Field(typeof(UIBuildingGrid), nameof(UIBuildingGrid.material)); - matcher.Advance(6); - matcher.MatchForward(false, - new CodeMatch(OpCodes.Ldarg_0), - new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(UIBuildingGrid), nameof(UIBuildingGrid.blueprintMaterial))), - new CodeMatch(OpCodes.Ldsfld, AccessTools.Field(classTypeUIBuildingGridPatch2, "selectColor")), - new CodeMatch(OpCodes.Ldarg_0), - new CodeMatch(OpCodes.Ldfld), - new CodeMatch(OpCodes.Call), - new CodeMatch(OpCodes.Callvirt) - ).Advance(1).Operand = AccessTools.Field(typeof(UIBuildingGrid), nameof(UIBuildingGrid.material)); - matcher.Advance(1).Operand = AccessTools.Field(classTypeUIBuildingGridPatch2, "tintColor"); - matcher.Advance(5); - matcher.MatchForward(false, - new CodeMatch(OpCodes.Ldarg_0), - new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(UIBuildingGrid), nameof(UIBuildingGrid.blueprintMaterial))), - new CodeMatch(OpCodes.Ldsfld, AccessTools.Field(classTypeUIBuildingGridPatch2, "showDivideLine")), - new CodeMatch(OpCodes.Ldc_R4, 0f), - new CodeMatch(OpCodes.Callvirt) - ).RemoveInstructions(5); - matcher.InsertAndAdvance(new CodeInstruction(OpCodes.Ldarg_0), - Transpilers.EmitDelegate((UIBuildingGrid grid) => - { - grid.material.SetFloat(reformMode, 0f); - grid.material.SetFloat(zMin, -0.5f); - }) - ); - matcher.MatchForward(false, - new CodeMatch(OpCodes.Ldarg_0), - new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(UIBuildingGrid), nameof(UIBuildingGrid.blueprintGridRnd))), - new CodeMatch(OpCodes.Ldc_I4_1), - new CodeMatch(OpCodes.Callvirt), - new CodeMatch(ci => ci.opcode == OpCodes.Br || ci.opcode == OpCodes.Br_S) - ).RemoveInstructions(4).Set(OpCodes.Ret, null).Labels.Add(label1); - return matcher.InstructionEnumeration(); - } - - private static void PatchDeterminePreviews(object __instance) - { - var selectObjIds = (HashSet)selectObjIdsField.GetValue(__instance); - var buildTool = (BuildTool)__instance; - var factory = buildTool.factory; - HashSet extraObjIds = []; - foreach (var objId in selectObjIds) - { - var desc = buildTool.GetPrefabDesc(objId); - var isBelt = desc.isBelt; - var isInserter = desc.isInserter; - if (isInserter) continue; - if (isBelt) - { - var needCheck = false; - for (var j = 0; j < 2; j++) - { - factory.ReadObjectConn(objId, j, out _, out var connObjId, out _); - if (connObjId == 0 || FactoryFunctions.ObjectIsBeltOrInserter(factory, connObjId)) continue; - needCheck = true; - break; - } - if (needCheck) - { - for (var k = 0; k < 16; k++) - { - factory.ReadObjectConn(objId, k, out _, out var connObjId, out _); - if (connObjId != 0 && !selectObjIds.Contains(connObjId) && !extraObjIds.Contains(connObjId) && FactoryFunctions.ObjectIsBeltOrInserter(factory, connObjId)) - extraObjIds.Add(connObjId); - } - } - for (var m = 0; m < 4; m++) - { - factory.ReadObjectConn(objId, m, out _, out var connObjId, out _); - if (connObjId == 0 || !factory.ObjectIsBelt(connObjId) || selectObjIds.Contains(connObjId) || extraObjIds.Contains(connObjId)) continue; - for (var j = 0; j < 2; j++) - { - factory.ReadObjectConn(connObjId, j, out _, out var connObjId2, out _); - if (connObjId2 == 0 || selectObjIds.Contains(connObjId2) || extraObjIds.Contains(connObjId2) || FactoryFunctions.ObjectIsBeltOrInserter(factory, connObjId2)) continue; - extraObjIds.Add(connObjId); - break; - } - } - continue; - } - if (desc.addonType == EAddonType.Belt) continue; - for (var j = 0; j < 16; j++) - { - factory.ReadObjectConn(objId, j, out _, out var connObjId, out _); - if (connObjId != 0 && !selectObjIds.Contains(connObjId) && !extraObjIds.Contains(connObjId) && FactoryFunctions.ObjectIsBeltOrInserter(factory, connObjId)) - extraObjIds.Add(connObjId); - } - } - selectObjIds.UnionWith(extraObjIds); - } -} diff --git a/UXAssist/UXAssist.cs b/UXAssist/UXAssist.cs index bcf245a..f3a66d1 100644 --- a/UXAssist/UXAssist.cs +++ b/UXAssist/UXAssist.cs @@ -66,7 +66,6 @@ public class UXAssist : BaseUnityPlugin, IModCanSave UXAssist() { ModsCompat.PlanetVeinUtilization.Run(_harmony); - ModsCompat.BlueprintTweaks.Run(_harmony); ModsCompat.CommonAPIWrapper.Run(_harmony); }