1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2025-12-09 03:33:29 +08:00

Work in progress

This commit is contained in:
2024-09-02 12:12:44 +08:00
parent 0dafd8a763
commit d52bc630ba
32 changed files with 139 additions and 23 deletions

24
UXAssist/Common/Util.cs Normal file
View File

@@ -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);
}

View File

@@ -8,7 +8,6 @@ using BepInEx.Configuration;
using CommonAPI.Systems; using CommonAPI.Systems;
using HarmonyLib; using HarmonyLib;
using UnityEngine; using UnityEngine;
using UnityEngine.EventSystems;
using UXAssist.Common; using UXAssist.Common;
namespace UXAssist; namespace UXAssist;
@@ -1600,7 +1599,6 @@ public static class FactoryPatch
private static Harmony _persistPatch; private static Harmony _persistPatch;
private static bool _initialized; private static bool _initialized;
private static bool _loaded; private static bool _loaded;
private static AssetBundle _bundle;
private static long _clusterSeedKey; private static long _clusterSeedKey;
private static readonly int[] DarkFogItemIds = [5201, 5206, 5202, 5204, 5203, 5205]; private static readonly int[] DarkFogItemIds = [5201, 5206, 5202, 5204, 5203, 5205];
private static readonly int[] DarkFogItemExchangeRate = [20, 60, 30, 30, 30, 10]; private static readonly int[] DarkFogItemExchangeRate = [20, 60, 30, 30, 30, 10];
@@ -1639,8 +1637,7 @@ public static class FactoryPatch
private static void AddBeltSignalProtos() private static void AddBeltSignalProtos()
{ {
if (!_initialized || _loaded) return; if (!_initialized || _loaded) return;
var pluginfolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var pluginfolder = Util.PluginFolder;
_bundle = AssetBundle.LoadFromFile($"{pluginfolder}/uxassist.assetbundle");
var signals = LDB._signals; var signals = LDB._signals;
SignalProto[] protos = SignalProto[] protos =
[ [
@@ -1649,8 +1646,8 @@ public static class FactoryPatch
ID = 301, ID = 301,
Name = "存储单元", Name = "存储单元",
GridIndex = 3601, GridIndex = 3601,
IconPath = "Assets/memory.png", IconPath = "assets/memory.png",
_iconSprite = _bundle.LoadAsset<Sprite>("Assets/memory.png"), _iconSprite = Util.LoadSprite($"{pluginfolder}/assets/memory.png"),
SID = "" SID = ""
}, },
new SignalProto new SignalProto
@@ -1658,8 +1655,8 @@ public static class FactoryPatch
ID = 302, ID = 302,
Name = "能量碎片", Name = "能量碎片",
GridIndex = 3602, GridIndex = 3602,
IconPath = "Assets/energy-fragment.png", IconPath = "assets/energy-fragment.png",
_iconSprite = _bundle.LoadAsset<Sprite>("Assets/energy-fragment.png"), _iconSprite = Util.LoadSprite($"{pluginfolder}/assets/energy-fragment.png"),
SID = "" SID = ""
}, },
new SignalProto new SignalProto
@@ -1667,8 +1664,8 @@ public static class FactoryPatch
ID = 303, ID = 303,
Name = "硅基神经元", Name = "硅基神经元",
GridIndex = 3603, GridIndex = 3603,
IconPath = "Assets/silicon-neuron.png", IconPath = "assets/silicon-neuron.png",
_iconSprite = _bundle.LoadAsset<Sprite>("Assets/silicon-neuron.png"), _iconSprite = Util.LoadSprite($"{pluginfolder}/assets/silicon-neuron.png"),
SID = "" SID = ""
}, },
new SignalProto new SignalProto
@@ -1677,7 +1674,7 @@ public static class FactoryPatch
Name = "负熵奇点", Name = "负熵奇点",
GridIndex = 3604, GridIndex = 3604,
IconPath = "Assets/negentropy.png", IconPath = "Assets/negentropy.png",
_iconSprite = _bundle.LoadAsset<Sprite>("Assets/negentropy.png"), _iconSprite = Util.LoadSprite($"{pluginfolder}/assets/negentropy.png"),
SID = "" SID = ""
}, },
new SignalProto new SignalProto
@@ -1685,8 +1682,8 @@ public static class FactoryPatch
ID = 305, ID = 305,
Name = "物质重组器", Name = "物质重组器",
GridIndex = 3605, GridIndex = 3605,
IconPath = "Assets/reassembler.png", IconPath = "assets/reassembler.png",
_iconSprite = _bundle.LoadAsset<Sprite>("Assets/reassembler.png"), _iconSprite = Util.LoadSprite($"{pluginfolder}/assets/reassembler.png"),
SID = "" SID = ""
}, },
new SignalProto new SignalProto
@@ -1694,8 +1691,8 @@ public static class FactoryPatch
ID = 306, ID = 306,
Name = "虚粒子", Name = "虚粒子",
GridIndex = 3606, GridIndex = 3606,
IconPath = "Assets/virtual-particle.png", IconPath = "assets/virtual-particle.png",
_iconSprite = _bundle.LoadAsset<Sprite>("Assets/virtual-particle.png"), _iconSprite = Util.LoadSprite($"{pluginfolder}/assets/virtual-particle.png"),
SID = "" SID = ""
}, },
]; ];
@@ -1729,8 +1726,6 @@ public static class FactoryPatch
signals.dataIndices[signals.dataArray[index].ID] = index; signals.dataIndices[signals.dataArray[index].ID] = index;
} }
_bundle.Unload(true);
_bundle = null;
_loaded = false; _loaded = false;
} }

View File

@@ -18,6 +18,7 @@ public static class GamePatch
public static ConfigEntry<bool> EnableWindowResizeEnabled; public static ConfigEntry<bool> EnableWindowResizeEnabled;
public static ConfigEntry<bool> LoadLastWindowRectEnabled; public static ConfigEntry<bool> LoadLastWindowRectEnabled;
public static ConfigEntry<int> MouseCursorScaleUpMultiplier;
// public static ConfigEntry<bool> AutoSaveOptEnabled; // public static ConfigEntry<bool> AutoSaveOptEnabled;
public static ConfigEntry<bool> ConvertSavesFromPeaceEnabled; public static ConfigEntry<bool> ConvertSavesFromPeaceEnabled;
public static ConfigEntry<Vector4> LastWindowRect; public static ConfigEntry<Vector4> LastWindowRect;
@@ -29,7 +30,7 @@ public static class GamePatch
{ {
// Get profile name from command line arguments, and set window title accordingly // Get profile name from command line arguments, and set window title accordingly
var args = Environment.GetCommandLineArgs(); 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; if (args[i] != "--doorstop-target") continue;
var arg = args[i + 1]; var arg = args[i + 1];
@@ -52,6 +53,10 @@ public static class GamePatch
EnableWindowResizeEnabled.SettingChanged += (_, _) => EnableWindowResize.Enable(EnableWindowResizeEnabled.Value); EnableWindowResizeEnabled.SettingChanged += (_, _) => EnableWindowResize.Enable(EnableWindowResizeEnabled.Value);
LoadLastWindowRectEnabled.SettingChanged += (_, _) => LoadLastWindowRect.Enable(LoadLastWindowRectEnabled.Value); LoadLastWindowRectEnabled.SettingChanged += (_, _) => LoadLastWindowRect.Enable(LoadLastWindowRectEnabled.Value);
MouseCursorScaleUpMultiplier.SettingChanged += (_, _) =>
{
MouseCursorScaleUp.Enable(MouseCursorScaleUpMultiplier.Value > 1);
};
// AutoSaveOptEnabled.SettingChanged += (_, _) => AutoSaveOpt.Enable(AutoSaveOptEnabled.Value); // AutoSaveOptEnabled.SettingChanged += (_, _) => AutoSaveOpt.Enable(AutoSaveOptEnabled.Value);
ConvertSavesFromPeaceEnabled.SettingChanged += (_, _) => ConvertSavesFromPeace.Enable(ConvertSavesFromPeaceEnabled.Value); ConvertSavesFromPeaceEnabled.SettingChanged += (_, _) => ConvertSavesFromPeace.Enable(ConvertSavesFromPeaceEnabled.Value);
ProfileBasedSaveFolderEnabled.SettingChanged += (_, _) => ProfileBasedSaveFolderEnabled.SettingChanged += (_, _) =>
@@ -64,6 +69,7 @@ public static class GamePatch
}; };
EnableWindowResize.Enable(EnableWindowResizeEnabled.Value); EnableWindowResize.Enable(EnableWindowResizeEnabled.Value);
LoadLastWindowRect.Enable(LoadLastWindowRectEnabled.Value); LoadLastWindowRect.Enable(LoadLastWindowRectEnabled.Value);
MouseCursorScaleUp.Enable(MouseCursorScaleUpMultiplier.Value > 1);
// AutoSaveOpt.Enable(AutoSaveOptEnabled.Value); // AutoSaveOpt.Enable(AutoSaveOptEnabled.Value);
ConvertSavesFromPeace.Enable(ConvertSavesFromPeaceEnabled.Value); ConvertSavesFromPeace.Enable(ConvertSavesFromPeaceEnabled.Value);
_gamePatch ??= Harmony.CreateAndPatchAll(typeof(GamePatch)); _gamePatch ??= Harmony.CreateAndPatchAll(typeof(GamePatch));
@@ -73,6 +79,7 @@ public static class GamePatch
{ {
LoadLastWindowRect.Enable(false); LoadLastWindowRect.Enable(false);
EnableWindowResize.Enable(false); EnableWindowResize.Enable(false);
MouseCursorScaleUp.Enable(false);
// AutoSaveOpt.Enable(false); // AutoSaveOpt.Enable(false);
ConvertSavesFromPeace.Enable(false); ConvertSavesFromPeace.Enable(false);
_gamePatch?.UnpatchSelf(); _gamePatch?.UnpatchSelf();
@@ -488,4 +495,89 @@ public static class GamePatch
_needConvert = false; _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<CodeInstruction> UICursor_LoadCursors_Transpiler(IEnumerable<CodeInstruction> 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<CodeInstruction> UICursor_set_cursorIndexApply_Transpiler(IEnumerable<CodeInstruction> 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();
}
}
} }

View File

@@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit; using System.Reflection.Emit;
using BepInEx.Configuration; using BepInEx.Configuration;
using HarmonyLib; using HarmonyLib;

View File

@@ -1,6 +1,5 @@
using System; using System;
using BepInEx.Configuration; using BepInEx.Configuration;
using UITools;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;

View File

@@ -1,5 +1,4 @@
using System; using UnityEngine;
using UnityEngine;
using UXAssist.UI; using UXAssist.UI;
using UXAssist.Common; using UXAssist.Common;
@@ -21,6 +20,7 @@ public static class UIConfigWindow
I18N.Add("Tech/Combat", "Tech/Combat", "科研/战斗"); I18N.Add("Tech/Combat", "Tech/Combat", "科研/战斗");
I18N.Add("Enable game window resize", "Enable game window resize (maximum box and thick frame)", "可调整游戏窗口大小(可最大化和拖动边框)"); 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("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", "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'文件夹中"); 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"); wnd.AddCheckBox(x, y, tab1, GamePatch.EnableWindowResizeEnabled, "Enable game window resize");
y += 36f; y += 36f;
wnd.AddCheckBox(x, y, tab1, GamePatch.LoadLastWindowRectEnabled, "Remeber window position and size on last exit"); 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; y += 30f;
wnd.AddCheckBox(x, y, tab1, GamePatch.AutoSaveOptEnabled, "Better auto-save mechanism"); wnd.AddCheckBox(x, y, tab1, GamePatch.AutoSaveOptEnabled, "Better auto-save mechanism");

View File

@@ -67,6 +67,8 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
"Load last window position and size when game starts"); "Load last window position and size when game starts");
GamePatch.LastWindowRect = Config.Bind("Game", "LastWindowRect", new Vector4(0f, 0f, 0f, 0f), GamePatch.LastWindowRect = Config.Bind("Game", "LastWindowRect", new Vector4(0f, 0f, 0f, 0f),
"Last window position and size"); "Last window position and size");
GamePatch.MouseCursorScaleUpMultiplier = Config.Bind("Game", "MouseCursorScaleUpMultiplier", 1,
"Mouse cursor scale up multiplier");
GamePatch.ProfileBasedSaveFolderEnabled = Config.Bind("Game", "ProfileBasedSaveFolder", false, GamePatch.ProfileBasedSaveFolderEnabled = Config.Bind("Game", "ProfileBasedSaveFolder", false,
"Profile-based save folder"); "Profile-based save folder");
GamePatch.DefaultProfileName = Config.Bind("Game", "DefaultProfileName", "Default", GamePatch.DefaultProfileName = Config.Bind("Game", "DefaultProfileName", "Default",

View File

@@ -26,6 +26,6 @@
</ItemGroup> </ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(Configuration)' == 'Release'"> <Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(Configuration)' == 'Release'">
<Exec Command="del /F /Q package\$(ProjectName)-$(Version).zip&#xA;powershell Compress-Archive -Force -DestinationPath 'package/$(ProjectName)-$(Version).zip' -Path '$(TargetPath)', package/icon.png, package/manifest.json, package/uxassist.assetbundle, README.md, CHANGELOG.md" /> <Exec Command="del /F /Q package\$(ProjectName)-$(Version).zip&#xA;copy /y &quot;$(TargetPath)&quot; package\plugins\&#xA;powershell Compress-Archive -Force -DestinationPath 'package/$(ProjectName)-$(Version).zip' -Path package/plugins, package/icon.png, package/manifest.json, README.md, CHANGELOG.md" />
</Target> </Target>
</Project> </Project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 634 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 597 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB