mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-08 21:33:28 +08:00
more fixes to make sure nothing working wrong on game
This commit is contained in:
@@ -268,7 +268,7 @@ public static class WinApi
|
||||
|
||||
return result;
|
||||
|
||||
int CountBitsSet(ulong mask)
|
||||
static int CountBitsSet(ulong mask)
|
||||
{
|
||||
var count = 0;
|
||||
while (mask != 0)
|
||||
|
||||
@@ -358,7 +358,7 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
|
||||
}
|
||||
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(StarSimulator), "LateUpdate")]
|
||||
[HarmonyPatch(typeof(StarSimulator), nameof(StarSimulator.LateUpdate))]
|
||||
private static IEnumerable<CodeInstruction> StarSimulator_LateUpdate_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
@@ -384,7 +384,7 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
|
||||
}
|
||||
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(PlanetSimulator), "LateUpdate")]
|
||||
[HarmonyPatch(typeof(PlanetSimulator), nameof(PlanetSimulator.LateUpdate))]
|
||||
private static IEnumerable<CodeInstruction> PlanetSimulator_LateUpdate_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
// var vec = (NightlightEnabled ? GameMain.mainPlayer.transform.up : (Quaternion.Inverse(localPlanet.runtimeRotation) * (__instance.planetData.star.uPosition - __instance.planetData.uPosition).normalized));
|
||||
|
||||
@@ -19,8 +19,6 @@ public class GamePatch : PatchImpl<GamePatch>
|
||||
public static ConfigEntry<bool> EnableWindowResizeEnabled;
|
||||
public static ConfigEntry<bool> LoadLastWindowRectEnabled;
|
||||
|
||||
public static ConfigEntry<int> MouseCursorScaleUpMultiplier;
|
||||
|
||||
// public static ConfigEntry<bool> AutoSaveOptEnabled;
|
||||
public static ConfigEntry<bool> ConvertSavesFromPeaceEnabled;
|
||||
public static ConfigEntry<Vector4> LastWindowRect;
|
||||
@@ -87,11 +85,6 @@ public class GamePatch : PatchImpl<GamePatch>
|
||||
FixLastWindowRect();
|
||||
}
|
||||
};
|
||||
MouseCursorScaleUpMultiplier.SettingChanged += (_, _) =>
|
||||
{
|
||||
MouseCursorScaleUp.NeedReloadCursors = true;
|
||||
MouseCursorScaleUp.Enable(MouseCursorScaleUpMultiplier.Value > 1);
|
||||
};
|
||||
// AutoSaveOptEnabled.SettingChanged += (_, _) => AutoSaveOpt.Enable(AutoSaveOptEnabled.Value);
|
||||
ConvertSavesFromPeaceEnabled.SettingChanged += (_, _) => ConvertSavesFromPeace.Enable(ConvertSavesFromPeaceEnabled.Value);
|
||||
ProfileBasedSaveFolderEnabled.SettingChanged += (_, _) => RefreshSavePath();
|
||||
@@ -123,8 +116,6 @@ public class GamePatch : PatchImpl<GamePatch>
|
||||
}
|
||||
}
|
||||
EnableWindowResize.Enable(EnableWindowResizeEnabled.Value);
|
||||
MouseCursorScaleUp.NeedReloadCursors = false;
|
||||
MouseCursorScaleUp.Enable(MouseCursorScaleUpMultiplier.Value > 1);
|
||||
// AutoSaveOpt.Enable(AutoSaveOptEnabled.Value);
|
||||
ConvertSavesFromPeace.Enable(ConvertSavesFromPeaceEnabled.Value);
|
||||
Enable(true);
|
||||
@@ -136,8 +127,6 @@ public class GamePatch : PatchImpl<GamePatch>
|
||||
{
|
||||
Enable(false);
|
||||
EnableWindowResize.Enable(false);
|
||||
MouseCursorScaleUp.NeedReloadCursors = false;
|
||||
MouseCursorScaleUp.Enable(false);
|
||||
// AutoSaveOpt.Enable(false);
|
||||
ConvertSavesFromPeace.Enable(false);
|
||||
}
|
||||
@@ -160,7 +149,7 @@ public class GamePatch : PatchImpl<GamePatch>
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPriority(Priority.First)]
|
||||
[HarmonyPatch(typeof(GameConfig), "gameSaveFolder", MethodType.Getter)]
|
||||
[HarmonyPatch(typeof(GameConfig), nameof(GameConfig.gameSaveFolder), MethodType.Getter)]
|
||||
public static void GameConfig_gameSaveFolder_Postfix(ref string __result)
|
||||
{
|
||||
if (!ProfileBasedSaveFolderEnabled.Value || string.IsNullOrEmpty(WindowFunctions.ProfileName)) return;
|
||||
@@ -298,7 +287,7 @@ public class GamePatch : PatchImpl<GamePatch>
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
var label1 = generator.DefineLabel();
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Call, AccessTools.Method(typeof(Screen), nameof(Screen.SetResolution), [typeof(int), typeof(int), typeof(bool), typeof(int)]))
|
||||
new CodeMatch(OpCodes.Call, AccessTools.Method(typeof(Screen), nameof(Screen.SetResolution), [typeof(int), typeof(int), typeof(FullScreenMode), typeof(RefreshRate)]))
|
||||
).Advance(1).Labels.Add(label1);
|
||||
matcher.Start().Insert(
|
||||
Transpilers.EmitDelegate(() =>
|
||||
@@ -601,131 +590,4 @@ public class GamePatch : PatchImpl<GamePatch>
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[PatchSetCallbackFlag(PatchCallbackFlag.CallOnDisableAfterUnpatch)]
|
||||
private class MouseCursorScaleUp : PatchImpl<MouseCursorScaleUp>
|
||||
{
|
||||
public static bool NeedReloadCursors;
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
if (!NeedReloadCursors) return;
|
||||
if (!UICursor.loaded) return;
|
||||
UICursor.loaded = false;
|
||||
UICursor.LoadCursors();
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
if (!NeedReloadCursors) return;
|
||||
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.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldc_I4_S),
|
||||
new CodeMatch(OpCodes.Newarr)
|
||||
);
|
||||
var startPos = matcher.Pos;
|
||||
matcher.Advance(2).MatchForward(false,
|
||||
new CodeMatch(OpCodes.Stsfld, AccessTools.Field(typeof(UICursor), nameof(UICursor.cursorTexs)))
|
||||
);
|
||||
var endPos = matcher.Pos + 1;
|
||||
matcher.Start().Advance(startPos).RemoveInstructions(endPos - startPos);
|
||||
matcher.InsertAndAdvance(
|
||||
Transpilers.EmitDelegate(() =>
|
||||
{
|
||||
var pluginfolder = Util.PluginFolder;
|
||||
UICursor.cursorTexs =
|
||||
[
|
||||
Util.LoadTexture($"{pluginfolder}/assets/cursor/cursor.png"),
|
||||
Util.LoadTexture($"{pluginfolder}/assets/cursor/cursor-transfer.png"),
|
||||
Util.LoadTexture($"{pluginfolder}/assets/cursor/cursor-target-in.png"),
|
||||
Util.LoadTexture($"{pluginfolder}/assets/cursor/cursor-target-out.png"),
|
||||
Util.LoadTexture($"{pluginfolder}/assets/cursor/cursor-target-a.png"),
|
||||
Util.LoadTexture($"{pluginfolder}/assets/cursor/cursor-target-b.png"),
|
||||
Util.LoadTexture($"{pluginfolder}/assets/cursor/cursor-ban.png"),
|
||||
Util.LoadTexture($"{pluginfolder}/assets/cursor/cursor-delete.png"),
|
||||
Util.LoadTexture($"{pluginfolder}/assets/cursor/cursor-reform.png"),
|
||||
Util.LoadTexture($"{pluginfolder}/assets/cursor/cursor-dyson-node-create.png"),
|
||||
Util.LoadTexture($"{pluginfolder}/assets/cursor/cursor-painter.png"),
|
||||
Util.LoadTexture($"{pluginfolder}/assets/cursor/cursor-eyedropper.png"),
|
||||
Util.LoadTexture($"{pluginfolder}/assets/cursor/cursor-eraser.png"),
|
||||
Util.LoadTexture($"{pluginfolder}/assets/cursor/cursor-upgrade.png"),
|
||||
Util.LoadTexture($"{pluginfolder}/assets/cursor/cursor-downgrade.png"),
|
||||
Util.LoadTexture($"{pluginfolder}/assets/cursor/cursor-blank.png"),
|
||||
Util.LoadTexture($"{pluginfolder}/assets/cursor/cursor-remove.png")
|
||||
];
|
||||
})
|
||||
);
|
||||
*/
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Stsfld, AccessTools.Field(typeof(UICursor), nameof(UICursor.cursorHots))),
|
||||
new CodeMatch(OpCodes.Ldc_I4_1),
|
||||
new CodeMatch(OpCodes.Stsfld, AccessTools.Field(typeof(UICursor), nameof(UICursor.loaded)))
|
||||
).Advance(1).InsertAndAdvance(
|
||||
Transpilers.EmitDelegate(() =>
|
||||
{
|
||||
var multiplier = MouseCursorScaleUpMultiplier.Value;
|
||||
for (var i = 0; i < UICursor.cursorTexs.Length; i++)
|
||||
{
|
||||
var cursor = UICursor.cursorTexs[i];
|
||||
if (cursor == null) continue;
|
||||
var newWidth = 32 * multiplier;
|
||||
var newHeight = 32 * multiplier;
|
||||
if (cursor.width == newWidth && cursor.height == newHeight) continue;
|
||||
UICursor.cursorTexs[i] = ResizeTexture2D(cursor, newWidth, newHeight);
|
||||
}
|
||||
|
||||
if (multiplier <= 1) return;
|
||||
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, false);
|
||||
result.ReadPixels(new Rect(0, 0, targetWidth, targetHeight), 0, 0);
|
||||
result.filterMode = FilterMode.Trilinear;
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -850,7 +850,7 @@ public static class LogisticsPatch
|
||||
|
||||
var sliderBgPrefab = GameObject.Find("UI Root/Overlay Canvas/In Game/Windows/Station Window/storage-box-0/slider-bg");
|
||||
|
||||
_tipPrefab = Object.Instantiate(GameObject.Find("UI Root/Overlay Canvas/In Game/Scene UIs/Vein Marks/vein-tip-prefab"), _stationTipsRoot.transform);
|
||||
_tipPrefab = Object.Instantiate(GameObject.Find("UI Root/Overlay Canvas/In Game/Scene UIs/Vein Marks/vein-tips/vein-tip-prefab"), _stationTipsRoot.transform);
|
||||
_tipPrefab.name = "tipPrefab";
|
||||
Object.Destroy(_tipPrefab.GetComponent<UIVeinDetailNode>());
|
||||
var image = _tipPrefab.GetComponent<Image>();
|
||||
|
||||
@@ -41,29 +41,6 @@ public class PersistPatch : PatchImpl<PersistPatch>
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
// Patch to fix the issue that warning popup on VeinUtil upgraded to level 8000+
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(ABN_VeinsUtil), nameof(ABN_VeinsUtil.CheckValue))]
|
||||
private static IEnumerable<CodeInstruction> ABN_VeinsUtil_CheckValue_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldelem_R8),
|
||||
new CodeMatch(OpCodes.Conv_R4),
|
||||
new CodeMatch(OpCodes.Add),
|
||||
new CodeMatch(OpCodes.Stloc_1)
|
||||
);
|
||||
// loc1 = Mathf.Round(n * 1000f) / 1000f;
|
||||
matcher.Advance(3).Insert(
|
||||
new CodeInstruction(OpCodes.Ldc_R4, 1000f),
|
||||
new CodeInstruction(OpCodes.Mul),
|
||||
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Mathf), nameof(Mathf.Round))),
|
||||
new CodeInstruction(OpCodes.Ldc_R4, 1000f),
|
||||
new CodeInstruction(OpCodes.Div)
|
||||
);
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
// Bring popup tip window to top layer
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(UIButton), nameof(UIButton.LateUpdate))]
|
||||
|
||||
@@ -613,7 +613,7 @@ public abstract class MyWindowManager
|
||||
|
||||
/*
|
||||
//_Create -> _Init
|
||||
[HarmonyPostfix, HarmonyPatch(typeof(UIGame), "_OnCreate")]
|
||||
[HarmonyPostfix, HarmonyPatch(typeof(UIGame), nameof(UIGame._OnCreate))]
|
||||
public static void UIGame__OnCreate_Postfix()
|
||||
{
|
||||
}
|
||||
@@ -638,7 +638,7 @@ public abstract class MyWindowManager
|
||||
}
|
||||
|
||||
/*
|
||||
[HarmonyPostfix, HarmonyPatch(typeof(UIGame), "_OnFree")]
|
||||
[HarmonyPostfix, HarmonyPatch(typeof(UIGame), nameof(UIGame._OnFree))]
|
||||
public static void UIGame__OnFree_Postfix()
|
||||
{
|
||||
foreach (var win in Windows)
|
||||
|
||||
@@ -27,7 +27,6 @@ public static class UIConfigWindow
|
||||
I18N.Add("Tech/Combat/UI", "Tech/Combat/UI", "科研/战斗/UI");
|
||||
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("Scale up mouse cursor", "Scale up mouse cursor", "放大鼠标指针");
|
||||
/*
|
||||
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'文件夹中");
|
||||
@@ -294,6 +293,7 @@ public static class UIConfigWindow
|
||||
|
||||
private static void CreateUI(MyConfigWindow wnd, RectTransform trans)
|
||||
{
|
||||
UnityEngine.UI.Text txt;
|
||||
_windowTrans = trans;
|
||||
wnd.AddTabGroup(trans, "UXAssist", "tab-group-uxassist");
|
||||
var tab1 = wnd.AddTab(trans, "General");
|
||||
@@ -302,9 +302,6 @@ 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 + 2f, y, tab1, "Scale up mouse cursor", 15, "text-scale-up-mouse-cursor");
|
||||
wnd.AddSlider(x + txt.preferredWidth + 7f, y + 6f, tab1, GamePatch.MouseCursorScaleUpMultiplier, [1, 2, 3, 4], "0x", 100f);
|
||||
/*
|
||||
y += 30f;
|
||||
wnd.AddCheckBox(x, y, tab1, GamePatch.AutoSaveOptEnabled, "Better auto-save mechanism");
|
||||
|
||||
@@ -69,8 +69,6 @@ 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.ProfileBasedOptionEnabled = Config.Bind("Game", "ProfileBasedOption", false,
|
||||
|
||||
Reference in New Issue
Block a user