diff --git a/CheatEnabler/CheatEnabler.csproj b/CheatEnabler/CheatEnabler.csproj index 8749cdf..ce2bdab 100644 --- a/CheatEnabler/CheatEnabler.csproj +++ b/CheatEnabler/CheatEnabler.csproj @@ -12,7 +12,6 @@ - diff --git a/CompressSave/CompressSave.csproj b/CompressSave/CompressSave.csproj index e7a972c..b897000 100644 --- a/CompressSave/CompressSave.csproj +++ b/CompressSave/CompressSave.csproj @@ -11,7 +11,6 @@ - diff --git a/CompressSave/LZ4Wrap/LZ4DecompressionStream.cs b/CompressSave/LZ4Wrap/LZ4DecompressionStream.cs index 3f21985..d5b3d9f 100644 --- a/CompressSave/LZ4Wrap/LZ4DecompressionStream.cs +++ b/CompressSave/LZ4Wrap/LZ4DecompressionStream.cs @@ -99,12 +99,12 @@ class LZ4DecompressionStream : Stream if (buffSize <= 0) return readlen; var rt = LZ4API.DecompressUpdateEx(dctx, dcmpBuffer, 0, dcmpBuffer.Capacity, srcBuffer, srcBuffer.Position,buffSize, null); - if (rt.expect < 0) throw new Exception(rt.expect.ToString()); - if (rt.expect == 0) decompressFinish = true; + if (rt.Expect < 0) throw new Exception(rt.Expect.ToString()); + if (rt.Expect == 0) decompressFinish = true; - srcBuffer.Position += (int)rt.readLen; + srcBuffer.Position += (int)rt.ReadLen; dcmpBuffer.Position = 0; - dcmpBuffer.Length = (int)rt.writeLen; + dcmpBuffer.Length = (int)rt.WriteLen; } readPos += readlen; return readlen; @@ -118,12 +118,12 @@ class LZ4DecompressionStream : Stream if (buffSize <= 0) return -1; var rt = LZ4API.DecompressUpdateEx(dctx, dcmpBuffer, 0, dcmpBuffer.Capacity, srcBuffer, srcBuffer.Position, buffSize, null); - if (rt.expect < 0) throw new Exception(rt.expect.ToString()); - if (rt.expect == 0) decompressFinish = true; + if (rt.Expect < 0) throw new Exception(rt.Expect.ToString()); + if (rt.Expect == 0) decompressFinish = true; - srcBuffer.Position += (int)rt.readLen; + srcBuffer.Position += (int)rt.ReadLen; dcmpBuffer.Position = 0; - dcmpBuffer.Length = (int)rt.writeLen; + dcmpBuffer.Length = (int)rt.WriteLen; } return dcmpBuffer.Buffer[dcmpBuffer.Position]; } diff --git a/CompressSave/LZ4Wrap/LZ4Wrap.cs b/CompressSave/LZ4Wrap/LZ4Wrap.cs index 73dba15..fceeeb4 100644 --- a/CompressSave/LZ4Wrap/LZ4Wrap.cs +++ b/CompressSave/LZ4Wrap/LZ4Wrap.cs @@ -7,14 +7,15 @@ namespace CompressSave.LZ4Wrap; public struct DecompressStatus { - public long writeLen; - public long readLen; - public long expect; + public long WriteLen; + public long ReadLen; + public long Expect; } public static class LZ4API { public static readonly bool Avaliable; + static LZ4API() { Avaliable = true; @@ -24,17 +25,21 @@ public static class LZ4API { if (!string.IsNullOrEmpty(assemblyPath)) { - root = Path.GetDirectoryName(assemblyPath); + root = Path.GetDirectoryName(assemblyPath) ?? string.Empty; } + var map = new Dictionary> { - { "LZ4.dll" ,new List{ - "LZ4.dll", - "X64/LZ4.dll", - "BepInEx/scripts/x64/LZ4.dll", - Path.Combine(root,"X64/LZ4.dll"), - Path.Combine(root,"LZ4.dll") - } }, + { + "LZ4.dll", new List + { + "LZ4.dll", + "X64/LZ4.dll", + "BepInEx/scripts/x64/LZ4.dll", + Path.Combine(root, "X64/LZ4.dll"), + Path.Combine(root, "LZ4.dll") + } + }, }; typeof(LZ4API).ResolveDynDllImports(map); } @@ -42,68 +47,74 @@ public static class LZ4API { Avaliable = false; Console.WriteLine($"Error: {e}"); - return; } } - public delegate long _CalCompressOutBufferSize(long inBufferSize); + public delegate long CalCompressOutBufferSizeFunc(long inBufferSize); - [DynDllImport(libraryName: "LZ4.dll")] - public static _CalCompressOutBufferSize CalCompressOutBufferSize; + [DynDllImport(libraryName: "LZ4.dll")] public static CalCompressOutBufferSizeFunc CalCompressOutBufferSize; - [DynDllImport(libraryName: "LZ4.dll")] - public static _CompressBegin CompressBegin; - public delegate long _CompressBegin(out IntPtr ctx, byte[] outBuff, long outCapacity, byte[] dictBuffer = null, long dictSize = 0); + [DynDllImport(libraryName: "LZ4.dll")] public static CompressBeginFunc CompressBegin; - [DynDllImport(libraryName: "LZ4.dll")] - public static _CompressUpdate CompressUpdate; - public unsafe delegate long _CompressUpdate(IntPtr ctx, byte* dstBuffer, long dstCapacity, byte* srcBuffer, long srcSize); + public delegate long CompressBeginFunc(out IntPtr ctx, byte[] outBuff, long outCapacity, byte[] dictBuffer = null, + long dictSize = 0); - public unsafe static long CompressUpdateEx(IntPtr ctx, byte[] dstBuffer, long dstOffset, byte[] srcBuffer, long srcOffset, long srcLen) + [DynDllImport(libraryName: "LZ4.dll")] private static CompressUpdateFunc CompressUpdate = null; + + private unsafe delegate long CompressUpdateFunc(IntPtr ctx, byte* dstBuffer, long dstCapacity, byte* srcBuffer, + long srcSize); + + public static unsafe long CompressUpdateEx(IntPtr ctx, byte[] dstBuffer, long dstOffset, byte[] srcBuffer, + long srcOffset, long srcLen) { fixed (byte* pdst = dstBuffer, psrc = srcBuffer) { - return CompressUpdate(ctx, pdst + dstOffset, dstBuffer.Length - dstOffset, psrc + srcOffset, srcLen - srcOffset); + return CompressUpdate(ctx, pdst + dstOffset, dstBuffer.Length - dstOffset, psrc + srcOffset, + srcLen - srcOffset); } } - [DynDllImport(libraryName: "LZ4.dll")] - public static _FreeCompressContext FreeCompressContext; - public delegate void _FreeCompressContext(IntPtr ctx); + [DynDllImport(libraryName: "LZ4.dll")] public static FreeCompressContextFunc FreeCompressContext; - [DynDllImport(libraryName: "LZ4.dll")] - public static _CompressEnd CompressEnd; - public delegate long _CompressEnd(IntPtr ctx, byte[] dstBuffer, long dstCapacity); + public delegate void FreeCompressContextFunc(IntPtr ctx); - [DynDllImport(libraryName: "LZ4.dll")] - public static _DecompressEnd DecompressEnd; - public delegate long _DecompressEnd(IntPtr dctx); + [DynDllImport(libraryName: "LZ4.dll")] public static CompressEndFunc CompressEnd; - [DynDllImport(libraryName: "LZ4.dll")] - unsafe static _DecompressUpdate DecompressUpdate = null; - public unsafe delegate long _DecompressUpdate(IntPtr dctx, byte* dstBuffer, ref long dstCapacity, byte* srcBuffer, ref long srcSize, byte* dict, long dictSize); - public unsafe static DecompressStatus DecompressUpdateEx(IntPtr dctx, byte[] dstBuffer, int dstOffset, int dstCount, byte[] srcBuffer, long srcOffset, long count, byte[] dict) + public delegate long CompressEndFunc(IntPtr ctx, byte[] dstBuffer, long dstCapacity); + + [DynDllImport(libraryName: "LZ4.dll")] public static DecompressEndFunc DecompressEnd; + + public delegate long DecompressEndFunc(IntPtr dctx); + + [DynDllImport(libraryName: "LZ4.dll")] private static DecompressUpdateFunc DecompressUpdate = null; + + private unsafe delegate long DecompressUpdateFunc(IntPtr dctx, byte* dstBuffer, ref long dstCapacity, byte* srcBuffer, + ref long srcSize, byte* dict, long dictSize); + + public static unsafe DecompressStatus DecompressUpdateEx(IntPtr dctx, byte[] dstBuffer, int dstOffset, int dstCount, + byte[] srcBuffer, long srcOffset, long count, byte[] dict) { long dstLen = Math.Min(dstCount, dstBuffer.Length - dstOffset); - long errCode = 0; + long errCode; fixed (byte* pdst = dstBuffer, psrc = srcBuffer, pdict = dict) { - errCode = DecompressUpdate(dctx, pdst + dstOffset, ref dstLen, psrc + srcOffset, ref count, pdict, dict == null ? 0 : dict.Length); + errCode = DecompressUpdate(dctx, pdst + dstOffset, ref dstLen, psrc + srcOffset, ref count, pdict, + dict?.Length ?? 0); } + return new DecompressStatus { - expect = errCode, - readLen = count, - writeLen = dstLen, + Expect = errCode, + ReadLen = count, + WriteLen = dstLen, }; } - [DynDllImport(libraryName: "LZ4.dll")] - public static _DecompressBegin DecompressBegin; - public delegate long _DecompressBegin(ref IntPtr pdctx, byte[] inBuffer, ref int inBufferSize, out int blockSize); + [DynDllImport(libraryName: "LZ4.dll")] public static DecompressBeginFunc DecompressBegin; - public delegate void _ResetDecompresssCTX(IntPtr dctx); + public delegate long DecompressBeginFunc(ref IntPtr pdctx, byte[] inBuffer, ref int inBufferSize, out int blockSize); - [DynDllImport(libraryName: "LZ4.dll")] - public static _ResetDecompresssCTX ResetDecompresssCTX; + public delegate void ResetDecompresssCtxFunc(IntPtr dctx); + + [DynDllImport(libraryName: "LZ4.dll")] public static ResetDecompresssCtxFunc ResetDecompresssCTX; } \ No newline at end of file diff --git a/DSP_Mods.sln b/DSP_Mods.sln index 2b12884..cbb0748 100644 --- a/DSP_Mods.sln +++ b/DSP_Mods.sln @@ -12,6 +12,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CompressSave", "CompressSav EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OCBatchBuild", "OCBatchBuild\OCBatchBuild.csproj", "{E8FB30A0-29BF-4CF0-8E08-9784962A8656}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniverseGenTweaks", "UniverseGenTweaks\UniverseGenTweaks.csproj", "{9534694E-14F0-4498-852D-BBB3FCA986CD}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -42,5 +44,9 @@ Global {E8FB30A0-29BF-4CF0-8E08-9784962A8656}.Debug|Any CPU.Build.0 = Debug|Any CPU {E8FB30A0-29BF-4CF0-8E08-9784962A8656}.Release|Any CPU.ActiveCfg = Release|Any CPU {E8FB30A0-29BF-4CF0-8E08-9784962A8656}.Release|Any CPU.Build.0 = Release|Any CPU + {9534694E-14F0-4498-852D-BBB3FCA986CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9534694E-14F0-4498-852D-BBB3FCA986CD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9534694E-14F0-4498-852D-BBB3FCA986CD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9534694E-14F0-4498-852D-BBB3FCA986CD}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/Dustbin/Dustbin.csproj b/Dustbin/Dustbin.csproj index 16efe3c..f133024 100644 --- a/Dustbin/Dustbin.csproj +++ b/Dustbin/Dustbin.csproj @@ -12,7 +12,6 @@ - diff --git a/HideTips/HideTips.csproj b/HideTips/HideTips.csproj index b6a6e57..20167b8 100644 --- a/HideTips/HideTips.csproj +++ b/HideTips/HideTips.csproj @@ -11,7 +11,6 @@ - diff --git a/LogisticMiner/LogisticMiner.csproj b/LogisticMiner/LogisticMiner.csproj index 923d84d..1c4cf45 100644 --- a/LogisticMiner/LogisticMiner.csproj +++ b/LogisticMiner/LogisticMiner.csproj @@ -11,7 +11,6 @@ - diff --git a/README.md b/README.md index 792afbf..2e8bb09 100644 --- a/README.md +++ b/README.md @@ -27,5 +27,10 @@ Storages can destroy incoming items while capacity limited to zero # [OrbitalCollectorBatchBuild](OCBatchBuild) -Batch build Orbital Collectors +Batch build Orbital Collectors 轨道采集器快速批量建造 + +# [UniverseGenTweaks](UniverseGenTweaks) + +Universe Generator Tweak +宇宙生成参数调节 diff --git a/UniverseGenTweaks/README.md b/UniverseGenTweaks/README.md new file mode 100644 index 0000000..385cc5d --- /dev/null +++ b/UniverseGenTweaks/README.md @@ -0,0 +1,12 @@ +# UniverseGenTweak + +#### Universe Generator Tweak +#### 宇宙生成参数调节 + +## Usage +* More options on universe creation +* Can set maximum star count in config file. + +## 使用说明 +* 生成宇宙时提供更多选项 +* 可以在配置文件中设置最大恒星数 diff --git a/UniverseGenTweaks/UniverseGenTweaks.cs b/UniverseGenTweaks/UniverseGenTweaks.cs new file mode 100644 index 0000000..0137eab --- /dev/null +++ b/UniverseGenTweaks/UniverseGenTweaks.cs @@ -0,0 +1,195 @@ +using System.Collections.Generic; +using System.Reflection.Emit; +using BepInEx; +using BepInEx.Configuration; +using HarmonyLib; +using UnityEngine; +using UnityEngine.UI; + +namespace UniverseGenTweaks; + +[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)] +public class UniverseGenTweaks : BaseUnityPlugin +{ + private new static readonly BepInEx.Logging.ManualLogSource Logger = + BepInEx.Logging.Logger.CreateLogSource(PluginInfo.PLUGIN_NAME); + + private bool _cfgEnabled = true; + private static int _maxStarCount = 64; + private static float _minDist = 2f; + private static float _maxDist = 3.2f; + private static float _flatten = 0.18f; + + private static Text _minDistTitle; + private static Text _maxDistTitle; + private static Text _flattenTitle; + private static Slider _minDistSlider; + private static Slider _maxDistSlider; + private static Slider _flattenSlider; + private static Text _minDistText; + private static Text _maxDistText; + private static Text _flattenText; + + private void Awake() + { + _cfgEnabled = Config.Bind("General", "Enabled", _cfgEnabled, "enable/disable this plugin").Value; + _maxStarCount = Config.Bind("General", "MaxStarCount", _maxStarCount, + new ConfigDescription("Maximum star count for galaxy creation", + new AcceptableValueRange(32, 1024), new {})) + .Value; + Harmony.CreateAndPatchAll(typeof(UniverseGenTweaks)); + } + + private static void createSliderWithText(Slider orig, out Text title, out Slider slider, out Text text) + { + var origText = orig.transform.parent.GetComponent(); + title = Object.Instantiate(origText, origText.transform.parent); + slider = title.transform.FindChildRecur("Slider").GetComponent(); + text = slider.transform.FindChildRecur("Text").GetComponent(); + } + + private static void transformDeltaY(Transform trans, float delta) + { + var pos = trans.position; + pos.y += delta; + trans.position = pos; + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(UIGalaxySelect), "_OnInit")] + private static void PatchGalaxyUI_OnInit(UIGalaxySelect __instance) + { + __instance.starCountSlider.maxValue = _maxStarCount; + + createSliderWithText(__instance.starCountSlider, out _minDistTitle, out _minDistSlider, out _minDistText); + createSliderWithText(__instance.starCountSlider, out _maxDistTitle, out _maxDistSlider, out _maxDistText); + createSliderWithText(__instance.starCountSlider, out _flattenTitle, out _flattenSlider, out _flattenText); + + _minDistTitle.name = "min-dist"; + _minDistSlider.minValue = 10f; + _minDistSlider.maxValue = _maxDist * 10f; + _minDistSlider.value = _minDist * 10f; + + _maxDistTitle.name = "max-dist"; + _maxDistSlider.minValue = _minDist * 10f; + _maxDistSlider.maxValue = 100f; + _maxDistSlider.value = _maxDist * 10f; + + _flattenTitle.name = "flatten"; + _flattenSlider.minValue = 1f; + _flattenSlider.maxValue = 50f; + _flattenSlider.value = _flatten * 50f; + + transformDeltaY(_minDistTitle.transform, -0.3573f); + transformDeltaY(_maxDistTitle.transform, -0.3573f * 2); + transformDeltaY(_flattenTitle.transform, -0.3573f * 3); + transformDeltaY(__instance.resourceMultiplierSlider.transform.parent, -0.3573f * 3); + transformDeltaY(__instance.sandboxToggle.transform.parent, -0.3573f * 3); + transformDeltaY(__instance.propertyMultiplierText.transform, -0.3573f * 3); + transformDeltaY(__instance.addrText.transform.parent, -0.3573f * 3); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(UIGalaxySelect), "_OnOpen")] + private static void PatchGalaxyUI_OnOpen(UIGalaxySelect __instance) + { + if (Localization.language == Language.zhCN) + { + _minDistTitle.text = "恒星/步进距离"; + _maxDistTitle.text = "步进最大距离"; + _flattenTitle.text = "扁平度"; + } + else + { + _minDistTitle.text = "Star/Step Distance"; + _maxDistTitle.text = "Step Distance Max"; + _flattenTitle.text = "Flatten"; + } + _minDistText.text = _minDist.ToString(); + _maxDistText.text = _maxDist.ToString(); + _flattenText.text = _flatten.ToString(); + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(UIGalaxySelect), "_OnRegEvent")] + private static void PatchGalaxyUI_OnRegEvent(UIGalaxySelect __instance) + { + _minDistSlider.onValueChanged.RemoveAllListeners(); + _minDistSlider.onValueChanged.AddListener(val => + { + var newVal = val / 10f; + if (newVal.Equals(_minDist)) return; + _minDist = newVal; + _maxDistSlider.minValue = newVal * 10f; + _minDistText.text = _minDist.ToString(); + __instance.SetStarmapGalaxy(); + }); + _maxDistSlider.onValueChanged.RemoveAllListeners(); + _maxDistSlider.onValueChanged.AddListener(val => + { + var newVal = val / 10f; + if (newVal.Equals(_maxDist)) return; + _maxDist = newVal; + _minDistSlider.maxValue = newVal * 10f; + _maxDistText.text = _maxDist.ToString(); + __instance.SetStarmapGalaxy(); + }); + _flattenSlider.onValueChanged.RemoveAllListeners(); + _flattenSlider.onValueChanged.AddListener(val => + { + var newVal = val / 50f; + if (newVal.Equals(_maxDist)) return; + _flatten = newVal; + _flattenText.text = _flatten.ToString(); + __instance.SetStarmapGalaxy(); + }); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(GalaxyData), MethodType.Constructor)] + static bool PatchGalaxyData(GalaxyData __instance) + { + __instance.astrosData = new AstroData[(_maxStarCount + 1) * 100]; + return false; + } + + [HarmonyTranspiler] + [HarmonyPatch(typeof(UniverseGen), "CreateGalaxy")] + static IEnumerable PatchCreateGalaxy(IEnumerable instructions) + { + foreach (var instruction in instructions) + { + if (instruction.opcode == OpCodes.Call && + instruction.OperandIs(AccessTools.Method(typeof(UniverseGen), "GenerateTempPoses"))) + { + var pop = new CodeInstruction(OpCodes.Pop); + yield return pop; + yield return pop; + yield return pop; + yield return pop; + yield return new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(UniverseGenTweaks), "_minDist")); + yield return new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(UniverseGenTweaks), "_minDist")); + yield return new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(UniverseGenTweaks), "_maxDist")); + yield return new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(UniverseGenTweaks), "_flatten")); + } + yield return instruction; + } + } + + [HarmonyTranspiler] + [HarmonyPatch(typeof(UIGalaxySelect), "OnStarCountSliderValueChange")] + static IEnumerable PatchStarCountOnValueChange(IEnumerable instructions) + { + foreach (var instruction in instructions) + { + if (instruction.opcode == OpCodes.Ldc_I4_S && instruction.OperandIs(80)) + { + yield return new CodeInstruction(OpCodes.Ldc_I4, _maxStarCount); + } + else + { + yield return instruction; + } + } + } +} \ No newline at end of file diff --git a/UniverseGenTweaks/UniverseGenTweaks.csproj b/UniverseGenTweaks/UniverseGenTweaks.csproj new file mode 100644 index 0000000..5465dcc --- /dev/null +++ b/UniverseGenTweaks/UniverseGenTweaks.csproj @@ -0,0 +1,27 @@ + + + + netstandard2.0 + UniverseGenTweaks + org.soardev.universegentweaks + DSP MOD - UniverseGenTweaks + 1.0.0 + true + latest + + + + + + + + + + + + + + + + + diff --git a/UniverseGenTweaks/package/icon.png b/UniverseGenTweaks/package/icon.png new file mode 100644 index 0000000..645e026 Binary files /dev/null and b/UniverseGenTweaks/package/icon.png differ diff --git a/UniverseGenTweaks/package/manifest.json b/UniverseGenTweaks/package/manifest.json new file mode 100644 index 0000000..f3febba --- /dev/null +++ b/UniverseGenTweaks/package/manifest.json @@ -0,0 +1,9 @@ +{ + "name": "UniverseGenTweaks", + "version_number": "1.0.0", + "website_url": "https://github.com/soarqin/DSP_Mods/tree/master/UniverseGenTweaks", + "description": "#### Universe Generator Tweaks / 宇宙生成参数调节", + "dependencies": [ + "xiaoye97-BepInEx-5.4.17" + ] +}