diff --git a/UXAssist/Common/Util.cs b/UXAssist/Common/Util.cs new file mode 100644 index 0000000..94a1bf3 --- /dev/null +++ b/UXAssist/Common/Util.cs @@ -0,0 +1,24 @@ +using System.IO; +using System.Reflection; +using UnityEngine; + +namespace UXAssist.Common; + +public static class Util +{ + public static Texture2D LoadTexture(string path) + { + var fileData = System.IO.File.ReadAllBytes(path); + var tex = new Texture2D(2, 2); + tex.LoadImage(fileData); + return tex; + } + + public static Sprite LoadSprite(string path) + { + var tex = LoadTexture(path); + return Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f)); + } + + public static string PluginFolder => Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); +} \ No newline at end of file diff --git a/UXAssist/FactoryPatch.cs b/UXAssist/FactoryPatch.cs index d2e14ba..be4b772 100644 --- a/UXAssist/FactoryPatch.cs +++ b/UXAssist/FactoryPatch.cs @@ -8,7 +8,6 @@ using BepInEx.Configuration; using CommonAPI.Systems; using HarmonyLib; using UnityEngine; -using UnityEngine.EventSystems; using UXAssist.Common; namespace UXAssist; @@ -1600,7 +1599,6 @@ public static class FactoryPatch private static Harmony _persistPatch; private static bool _initialized; private static bool _loaded; - private static AssetBundle _bundle; private static long _clusterSeedKey; private static readonly int[] DarkFogItemIds = [5201, 5206, 5202, 5204, 5203, 5205]; private static readonly int[] DarkFogItemExchangeRate = [20, 60, 30, 30, 30, 10]; @@ -1639,8 +1637,7 @@ public static class FactoryPatch private static void AddBeltSignalProtos() { if (!_initialized || _loaded) return; - var pluginfolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); - _bundle = AssetBundle.LoadFromFile($"{pluginfolder}/uxassist.assetbundle"); + var pluginfolder = Util.PluginFolder; var signals = LDB._signals; SignalProto[] protos = [ @@ -1649,8 +1646,8 @@ public static class FactoryPatch ID = 301, Name = "存储单元", GridIndex = 3601, - IconPath = "Assets/memory.png", - _iconSprite = _bundle.LoadAsset("Assets/memory.png"), + IconPath = "assets/memory.png", + _iconSprite = Util.LoadSprite($"{pluginfolder}/assets/memory.png"), SID = "" }, new SignalProto @@ -1658,8 +1655,8 @@ public static class FactoryPatch ID = 302, Name = "能量碎片", GridIndex = 3602, - IconPath = "Assets/energy-fragment.png", - _iconSprite = _bundle.LoadAsset("Assets/energy-fragment.png"), + IconPath = "assets/energy-fragment.png", + _iconSprite = Util.LoadSprite($"{pluginfolder}/assets/energy-fragment.png"), SID = "" }, new SignalProto @@ -1667,8 +1664,8 @@ public static class FactoryPatch ID = 303, Name = "硅基神经元", GridIndex = 3603, - IconPath = "Assets/silicon-neuron.png", - _iconSprite = _bundle.LoadAsset("Assets/silicon-neuron.png"), + IconPath = "assets/silicon-neuron.png", + _iconSprite = Util.LoadSprite($"{pluginfolder}/assets/silicon-neuron.png"), SID = "" }, new SignalProto @@ -1677,7 +1674,7 @@ public static class FactoryPatch Name = "负熵奇点", GridIndex = 3604, IconPath = "Assets/negentropy.png", - _iconSprite = _bundle.LoadAsset("Assets/negentropy.png"), + _iconSprite = Util.LoadSprite($"{pluginfolder}/assets/negentropy.png"), SID = "" }, new SignalProto @@ -1685,8 +1682,8 @@ public static class FactoryPatch ID = 305, Name = "物质重组器", GridIndex = 3605, - IconPath = "Assets/reassembler.png", - _iconSprite = _bundle.LoadAsset("Assets/reassembler.png"), + IconPath = "assets/reassembler.png", + _iconSprite = Util.LoadSprite($"{pluginfolder}/assets/reassembler.png"), SID = "" }, new SignalProto @@ -1694,8 +1691,8 @@ public static class FactoryPatch ID = 306, Name = "虚粒子", GridIndex = 3606, - IconPath = "Assets/virtual-particle.png", - _iconSprite = _bundle.LoadAsset("Assets/virtual-particle.png"), + IconPath = "assets/virtual-particle.png", + _iconSprite = Util.LoadSprite($"{pluginfolder}/assets/virtual-particle.png"), SID = "" }, ]; @@ -1729,8 +1726,6 @@ public static class FactoryPatch signals.dataIndices[signals.dataArray[index].ID] = index; } - _bundle.Unload(true); - _bundle = null; _loaded = false; } diff --git a/UXAssist/GamePatch.cs b/UXAssist/GamePatch.cs index 5000da3..e409cf3 100644 --- a/UXAssist/GamePatch.cs +++ b/UXAssist/GamePatch.cs @@ -18,6 +18,7 @@ public static class GamePatch public static ConfigEntry EnableWindowResizeEnabled; public static ConfigEntry LoadLastWindowRectEnabled; + public static ConfigEntry MouseCursorScaleUpMultiplier; // public static ConfigEntry AutoSaveOptEnabled; public static ConfigEntry ConvertSavesFromPeaceEnabled; public static ConfigEntry LastWindowRect; @@ -29,7 +30,7 @@ public static class GamePatch { // Get profile name from command line arguments, and set window title accordingly var args = Environment.GetCommandLineArgs(); - for (var i = 0; i < args.Length; i++) + for (var i = 0; i < args.Length - 1; i++) { if (args[i] != "--doorstop-target") continue; var arg = args[i + 1]; @@ -52,6 +53,10 @@ public static class GamePatch EnableWindowResizeEnabled.SettingChanged += (_, _) => EnableWindowResize.Enable(EnableWindowResizeEnabled.Value); LoadLastWindowRectEnabled.SettingChanged += (_, _) => LoadLastWindowRect.Enable(LoadLastWindowRectEnabled.Value); + MouseCursorScaleUpMultiplier.SettingChanged += (_, _) => + { + MouseCursorScaleUp.Enable(MouseCursorScaleUpMultiplier.Value > 1); + }; // AutoSaveOptEnabled.SettingChanged += (_, _) => AutoSaveOpt.Enable(AutoSaveOptEnabled.Value); ConvertSavesFromPeaceEnabled.SettingChanged += (_, _) => ConvertSavesFromPeace.Enable(ConvertSavesFromPeaceEnabled.Value); ProfileBasedSaveFolderEnabled.SettingChanged += (_, _) => @@ -64,6 +69,7 @@ public static class GamePatch }; EnableWindowResize.Enable(EnableWindowResizeEnabled.Value); LoadLastWindowRect.Enable(LoadLastWindowRectEnabled.Value); + MouseCursorScaleUp.Enable(MouseCursorScaleUpMultiplier.Value > 1); // AutoSaveOpt.Enable(AutoSaveOptEnabled.Value); ConvertSavesFromPeace.Enable(ConvertSavesFromPeaceEnabled.Value); _gamePatch ??= Harmony.CreateAndPatchAll(typeof(GamePatch)); @@ -73,6 +79,7 @@ public static class GamePatch { LoadLastWindowRect.Enable(false); EnableWindowResize.Enable(false); + MouseCursorScaleUp.Enable(false); // AutoSaveOpt.Enable(false); ConvertSavesFromPeace.Enable(false); _gamePatch?.UnpatchSelf(); @@ -488,4 +495,89 @@ public static class GamePatch _needConvert = false; } } + + private static class MouseCursorScaleUp + { + private static Harmony _patch; + + public static void Enable(bool on) + { + if (on) + { + _patch ??= Harmony.CreateAndPatchAll(typeof(MouseCursorScaleUp)); + if (!UICursor.loaded) return; + UICursor.loaded = false; + UICursor.LoadCursors(); + return; + } + + _patch?.UnpatchSelf(); + _patch = null; + if (!UICursor.loaded) return; + UICursor.loaded = false; + UICursor.LoadCursors(); + } + + [HarmonyTranspiler] + [HarmonyPatch(typeof(UICursor), nameof(UICursor.LoadCursors))] + private static IEnumerable UICursor_LoadCursors_Transpiler(IEnumerable instructions, ILGenerator generator) + { + var matcher = new CodeMatcher(instructions, generator); + matcher.Start().MatchForward(false, + new CodeMatch(OpCodes.Ldc_I4_1), + new CodeMatch(OpCodes.Stsfld, AccessTools.Field(typeof(UICursor), nameof(UICursor.loaded))) + ).InsertAndAdvance( + Transpilers.EmitDelegate(() => + { + var multiplier = MouseCursorScaleUpMultiplier.Value; + if (multiplier <= 1) return; + for (var i = 0; i < UICursor.cursorTexs.Length; i++) + { + var cursor = UICursor.cursorTexs[i]; + if (cursor == null) continue; + UICursor.cursorTexs[i] = ResizeTexture2D(cursor, cursor.width * multiplier, cursor.height * multiplier); + } + + for (var i = UICursor.cursorHots.Length - 1; i >= 0; i--) + { + UICursor.cursorHots[i] = new Vector2(UICursor.cursorHots[i].x * multiplier, UICursor.cursorHots[i].y * multiplier); + } + }) + ).MatchForward(false, + new CodeMatch(OpCodes.Ldc_I4_0), + new CodeMatch(OpCodes.Call, AccessTools.Method(typeof(Cursor), nameof(Cursor.SetCursor), [typeof(Texture2D), typeof(Vector2), typeof(CursorMode)])) + ).SetInstruction(new CodeInstruction(OpCodes.Ldc_I4_1)); + return matcher.InstructionEnumeration(); + + Texture2D ResizeTexture2D(Texture2D texture2D, int targetWidth, int targetHeight) + { + var oldActive = RenderTexture.active; + var rt = new RenderTexture(targetWidth, targetHeight, 32) + { + antiAliasing = 8 + }; + RenderTexture.active = rt; + Graphics.Blit(texture2D, rt); + rt.ResolveAntiAliasedSurface(); + var result = new Texture2D(targetWidth, targetHeight, texture2D.format, texture2D.mipmapCount > 1); + result.ReadPixels(new Rect(0, 0, targetWidth, targetHeight), 0, 0); + result.Apply(); + RenderTexture.active = oldActive; + rt.Release(); + return result; + } + } + + [HarmonyTranspiler] + [HarmonyPatch(typeof(UICursor), nameof(UICursor.cursorIndexApply), MethodType.Setter)] + private static IEnumerable UICursor_set_cursorIndexApply_Transpiler(IEnumerable instructions, ILGenerator generator) + { + var matcher = new CodeMatcher(instructions, generator); + matcher.Start().MatchForward(false, + new CodeMatch(OpCodes.Ldc_I4_0), + new CodeMatch(OpCodes.Call, AccessTools.Method(typeof(Cursor), nameof(Cursor.SetCursor), [typeof(Texture2D), typeof(Vector2), typeof(CursorMode)])) + ).SetInstruction(new CodeInstruction(OpCodes.Ldc_I4_1)); + return matcher.InstructionEnumeration(); + } + } } \ No newline at end of file diff --git a/UXAssist/TechPatch.cs b/UXAssist/TechPatch.cs index db2cb69..21750b4 100644 --- a/UXAssist/TechPatch.cs +++ b/UXAssist/TechPatch.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Reflection.Emit; using BepInEx.Configuration; using HarmonyLib; diff --git a/UXAssist/UI/MyCheckbox.cs b/UXAssist/UI/MyCheckbox.cs index 3066e59..974e786 100644 --- a/UXAssist/UI/MyCheckbox.cs +++ b/UXAssist/UI/MyCheckbox.cs @@ -1,6 +1,5 @@ using System; using BepInEx.Configuration; -using UITools; using UnityEngine; using UnityEngine.UI; diff --git a/UXAssist/UIConfigWindow.cs b/UXAssist/UIConfigWindow.cs index f5c680f..8a09422 100644 --- a/UXAssist/UIConfigWindow.cs +++ b/UXAssist/UIConfigWindow.cs @@ -1,5 +1,4 @@ -using System; -using UnityEngine; +using UnityEngine; using UXAssist.UI; using UXAssist.Common; @@ -21,6 +20,7 @@ public static class UIConfigWindow I18N.Add("Tech/Combat", "Tech/Combat", "科研/战斗"); I18N.Add("Enable game window resize", "Enable game window resize (maximum box and thick frame)", "可调整游戏窗口大小(可最大化和拖动边框)"); I18N.Add("Remeber window position and size on last exit", "Remeber window position and size on last exit", "记住上次退出时的窗口位置和大小"); + I18N.Add("Mouse cursor scale up", "Mouse cursor scale up", "鼠标指针放大"); /* I18N.Add("Better auto-save mechanism", "Better auto-save mechanism", "更好的自动存档机制"); I18N.Add("Better auto-save mechanism tips", "Auto saves are stored in 'Save\\AutoSaves' folder, filenames are combined with cluster address and date-time", "自动存档会以星区地址和日期时间组合为文件名存储在'Save\\AutoSaves'文件夹中"); @@ -110,6 +110,11 @@ public static class UIConfigWindow wnd.AddCheckBox(x, y, tab1, GamePatch.EnableWindowResizeEnabled, "Enable game window resize"); y += 36f; wnd.AddCheckBox(x, y, tab1, GamePatch.LoadLastWindowRectEnabled, "Remeber window position and size on last exit"); + y += 36f; + var txt = wnd.AddText2(x, y, tab1, "Mouse cursor scale up", 15, "text-mouse-cursor-scale-up"); + x += txt.preferredWidth + 5f; + wnd.AddSlider(x, y + 6f, tab1, GamePatch.MouseCursorScaleUpMultiplier, [1, 2, 3, 4], "0x", 100f); + x = 0f; /* y += 30f; wnd.AddCheckBox(x, y, tab1, GamePatch.AutoSaveOptEnabled, "Better auto-save mechanism"); diff --git a/UXAssist/UXAssist.cs b/UXAssist/UXAssist.cs index 93ff7a4..dd04a0c 100644 --- a/UXAssist/UXAssist.cs +++ b/UXAssist/UXAssist.cs @@ -67,6 +67,8 @@ public class UXAssist : BaseUnityPlugin, IModCanSave "Load last window position and size when game starts"); GamePatch.LastWindowRect = Config.Bind("Game", "LastWindowRect", new Vector4(0f, 0f, 0f, 0f), "Last window position and size"); + GamePatch.MouseCursorScaleUpMultiplier = Config.Bind("Game", "MouseCursorScaleUpMultiplier", 1, + "Mouse cursor scale up multiplier"); GamePatch.ProfileBasedSaveFolderEnabled = Config.Bind("Game", "ProfileBasedSaveFolder", false, "Profile-based save folder"); GamePatch.DefaultProfileName = Config.Bind("Game", "DefaultProfileName", "Default", diff --git a/UXAssist/UXAssist.csproj b/UXAssist/UXAssist.csproj index ed6a2a2..37f9246 100644 --- a/UXAssist/UXAssist.csproj +++ b/UXAssist/UXAssist.csproj @@ -26,6 +26,6 @@ - + diff --git a/UXAssist/package/plugins/assets/cursor/cursor-ban.png b/UXAssist/package/plugins/assets/cursor/cursor-ban.png new file mode 100644 index 0000000..57dd883 Binary files /dev/null and b/UXAssist/package/plugins/assets/cursor/cursor-ban.png differ diff --git a/UXAssist/package/plugins/assets/cursor/cursor-blank.png b/UXAssist/package/plugins/assets/cursor/cursor-blank.png new file mode 100644 index 0000000..566a3c1 Binary files /dev/null and b/UXAssist/package/plugins/assets/cursor/cursor-blank.png differ diff --git a/UXAssist/package/plugins/assets/cursor/cursor-delete.png b/UXAssist/package/plugins/assets/cursor/cursor-delete.png new file mode 100644 index 0000000..c9f8c90 Binary files /dev/null and b/UXAssist/package/plugins/assets/cursor/cursor-delete.png differ diff --git a/UXAssist/package/plugins/assets/cursor/cursor-downgrade.png b/UXAssist/package/plugins/assets/cursor/cursor-downgrade.png new file mode 100644 index 0000000..47321d6 Binary files /dev/null and b/UXAssist/package/plugins/assets/cursor/cursor-downgrade.png differ diff --git a/UXAssist/package/plugins/assets/cursor/cursor-dyson-node-create.png b/UXAssist/package/plugins/assets/cursor/cursor-dyson-node-create.png new file mode 100644 index 0000000..d038f4a Binary files /dev/null and b/UXAssist/package/plugins/assets/cursor/cursor-dyson-node-create.png differ diff --git a/UXAssist/package/plugins/assets/cursor/cursor-eraser.png b/UXAssist/package/plugins/assets/cursor/cursor-eraser.png new file mode 100644 index 0000000..557ddae Binary files /dev/null and b/UXAssist/package/plugins/assets/cursor/cursor-eraser.png differ diff --git a/UXAssist/package/plugins/assets/cursor/cursor-eyedropper.png b/UXAssist/package/plugins/assets/cursor/cursor-eyedropper.png new file mode 100644 index 0000000..bee0df2 Binary files /dev/null and b/UXAssist/package/plugins/assets/cursor/cursor-eyedropper.png differ diff --git a/UXAssist/package/plugins/assets/cursor/cursor-painter.png b/UXAssist/package/plugins/assets/cursor/cursor-painter.png new file mode 100644 index 0000000..8995063 Binary files /dev/null and b/UXAssist/package/plugins/assets/cursor/cursor-painter.png differ diff --git a/UXAssist/package/plugins/assets/cursor/cursor-reform.png b/UXAssist/package/plugins/assets/cursor/cursor-reform.png new file mode 100644 index 0000000..fea86e3 Binary files /dev/null and b/UXAssist/package/plugins/assets/cursor/cursor-reform.png differ diff --git a/UXAssist/package/plugins/assets/cursor/cursor-remove.png b/UXAssist/package/plugins/assets/cursor/cursor-remove.png new file mode 100644 index 0000000..d284fe3 Binary files /dev/null and b/UXAssist/package/plugins/assets/cursor/cursor-remove.png differ diff --git a/UXAssist/package/plugins/assets/cursor/cursor-target-a.png b/UXAssist/package/plugins/assets/cursor/cursor-target-a.png new file mode 100644 index 0000000..62ec11c Binary files /dev/null and b/UXAssist/package/plugins/assets/cursor/cursor-target-a.png differ diff --git a/UXAssist/package/plugins/assets/cursor/cursor-target-b.png b/UXAssist/package/plugins/assets/cursor/cursor-target-b.png new file mode 100644 index 0000000..61ee760 Binary files /dev/null and b/UXAssist/package/plugins/assets/cursor/cursor-target-b.png differ diff --git a/UXAssist/package/plugins/assets/cursor/cursor-target-in.png b/UXAssist/package/plugins/assets/cursor/cursor-target-in.png new file mode 100644 index 0000000..bbdf341 Binary files /dev/null and b/UXAssist/package/plugins/assets/cursor/cursor-target-in.png differ diff --git a/UXAssist/package/plugins/assets/cursor/cursor-target-out.png b/UXAssist/package/plugins/assets/cursor/cursor-target-out.png new file mode 100644 index 0000000..033518c Binary files /dev/null and b/UXAssist/package/plugins/assets/cursor/cursor-target-out.png differ diff --git a/UXAssist/package/plugins/assets/cursor/cursor-transfer.png b/UXAssist/package/plugins/assets/cursor/cursor-transfer.png new file mode 100644 index 0000000..e6894e0 Binary files /dev/null and b/UXAssist/package/plugins/assets/cursor/cursor-transfer.png differ diff --git a/UXAssist/package/plugins/assets/cursor/cursor-upgrade.png b/UXAssist/package/plugins/assets/cursor/cursor-upgrade.png new file mode 100644 index 0000000..e03c5e2 Binary files /dev/null and b/UXAssist/package/plugins/assets/cursor/cursor-upgrade.png differ diff --git a/UXAssist/package/plugins/assets/cursor/cursor.png b/UXAssist/package/plugins/assets/cursor/cursor.png new file mode 100644 index 0000000..bba66a0 Binary files /dev/null and b/UXAssist/package/plugins/assets/cursor/cursor.png differ diff --git a/UXAssist/package/plugins/assets/signal/energy-fragment.png b/UXAssist/package/plugins/assets/signal/energy-fragment.png new file mode 100644 index 0000000..c6318c5 Binary files /dev/null and b/UXAssist/package/plugins/assets/signal/energy-fragment.png differ diff --git a/UXAssist/package/plugins/assets/signal/memory.png b/UXAssist/package/plugins/assets/signal/memory.png new file mode 100644 index 0000000..faf28e4 Binary files /dev/null and b/UXAssist/package/plugins/assets/signal/memory.png differ diff --git a/UXAssist/package/plugins/assets/signal/negentropy.png b/UXAssist/package/plugins/assets/signal/negentropy.png new file mode 100644 index 0000000..8574f38 Binary files /dev/null and b/UXAssist/package/plugins/assets/signal/negentropy.png differ diff --git a/UXAssist/package/plugins/assets/signal/reassembler.png b/UXAssist/package/plugins/assets/signal/reassembler.png new file mode 100644 index 0000000..b845f7e Binary files /dev/null and b/UXAssist/package/plugins/assets/signal/reassembler.png differ diff --git a/UXAssist/package/plugins/assets/signal/silicon-neuron.png b/UXAssist/package/plugins/assets/signal/silicon-neuron.png new file mode 100644 index 0000000..b3df372 Binary files /dev/null and b/UXAssist/package/plugins/assets/signal/silicon-neuron.png differ diff --git a/UXAssist/package/plugins/assets/signal/virtual-particle.png b/UXAssist/package/plugins/assets/signal/virtual-particle.png new file mode 100644 index 0000000..7275611 Binary files /dev/null and b/UXAssist/package/plugins/assets/signal/virtual-particle.png differ diff --git a/UXAssist/package/uxassist.assetbundle b/UXAssist/package/uxassist.assetbundle deleted file mode 100644 index ab0a448..0000000 Binary files a/UXAssist/package/uxassist.assetbundle and /dev/null differ