mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-08 22:13:30 +08:00
work in progress
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection.Emit;
|
||||
using BepInEx.Configuration;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
@@ -8,10 +9,11 @@ namespace UniverseGenTweaks;
|
||||
|
||||
public class MoreSettings
|
||||
{
|
||||
private static float _minDist = 2f;
|
||||
private static float _minStep = 2f;
|
||||
private static float _maxStep = 3.2f;
|
||||
private static float _flatten = 0.18f;
|
||||
public static ConfigEntry<int> MaxStarCount;
|
||||
private static double _minDist = 2;
|
||||
private static double _minStep = 2;
|
||||
private static double _maxStep = 3.2;
|
||||
private static double _flatten = 0.18;
|
||||
|
||||
private static Text _minDistTitle;
|
||||
private static Text _minStepTitle;
|
||||
@@ -53,9 +55,9 @@ public class MoreSettings
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(UIGalaxySelect), nameof(UIGalaxySelect._OnInit))]
|
||||
private static void PatchGalaxyUI_OnInit(UIGalaxySelect __instance)
|
||||
private static void UIGalaxySelect__OnInit_Postfix(UIGalaxySelect __instance)
|
||||
{
|
||||
__instance.starCountSlider.maxValue = UniverseGenTweaks.MaxStarCount;
|
||||
__instance.starCountSlider.maxValue = MaxStarCount.Value;
|
||||
|
||||
CreateSliderWithText(__instance.starCountSlider, out _minDistTitle, out _minDistSlider, out _minDistText);
|
||||
CreateSliderWithText(__instance.starCountSlider, out _minStepTitle, out _minStepSlider, out _minStepText);
|
||||
@@ -65,22 +67,22 @@ public class MoreSettings
|
||||
_minDistTitle.name = "min-dist";
|
||||
_minDistSlider.minValue = 10f;
|
||||
_minDistSlider.maxValue = 50f;
|
||||
_minDistSlider.value = _minDist * 10f;
|
||||
_minDistSlider.value = (float)(_minDist * 10.0);
|
||||
|
||||
_minStepTitle.name = "min-step";
|
||||
_minStepSlider.minValue = 10f;
|
||||
_minStepSlider.maxValue = _maxStep * 10f - 1f;
|
||||
_minStepSlider.value = _minStep * 10f;
|
||||
_minStepSlider.maxValue = (float)(_maxStep * 10.0 - 1.0);
|
||||
_minStepSlider.value = (float)(_minStep * 10.0);
|
||||
|
||||
_maxStepTitle.name = "max-step";
|
||||
_maxStepSlider.minValue = _minStep * 10f + 1f;
|
||||
_maxStepSlider.minValue = (float)(_minStep * 10.0 + 1.0);
|
||||
_maxStepSlider.maxValue = 100f;
|
||||
_maxStepSlider.value = _maxStep * 10f;
|
||||
_maxStepSlider.value = (float)(_maxStep * 10.0);
|
||||
|
||||
_flattenTitle.name = "flatten";
|
||||
_flattenSlider.minValue = 1f;
|
||||
_flattenSlider.maxValue = 50f;
|
||||
_flattenSlider.value = _flatten * 50f;
|
||||
_flattenSlider.value = (float)(_flatten * 50.0);
|
||||
|
||||
TransformDeltaY(_minDistTitle.transform, -0.3573f);
|
||||
TransformDeltaY(_minStepTitle.transform, -0.3573f * 2);
|
||||
@@ -94,7 +96,7 @@ public class MoreSettings
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(UIGalaxySelect), nameof(UIGalaxySelect._OnOpen))]
|
||||
private static void PatchGalaxyUI_OnOpen(UIGalaxySelect __instance)
|
||||
private static void UIGalaxySelect__OnOpen_Prefix()
|
||||
{
|
||||
_minDistTitle.text = "恒星最小距离".Translate();
|
||||
_minStepTitle.text = "步进最小距离".Translate();
|
||||
@@ -108,24 +110,24 @@ public class MoreSettings
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(UIGalaxySelect), nameof(UIGalaxySelect._OnRegEvent))]
|
||||
private static void PatchGalaxyUI_OnRegEvent(UIGalaxySelect __instance)
|
||||
private static void UIGalaxySelect__OnRegEvent_Postfix(UIGalaxySelect __instance)
|
||||
{
|
||||
_minDistSlider.onValueChanged.RemoveAllListeners();
|
||||
_minDistSlider.onValueChanged.AddListener(val =>
|
||||
{
|
||||
var newVal = Mathf.Round(val) / 10f;
|
||||
var newVal = Mathf.Round(val) / 10.0;
|
||||
if (newVal.Equals(_minDist)) return;
|
||||
_minDist = newVal;
|
||||
_minDistText.text = _minDist.ToString();
|
||||
if (_minStep < _minDist)
|
||||
{
|
||||
_minStep = _minDist;
|
||||
_minStepSlider.value = _minStep * 10f;
|
||||
_minStepSlider.value = (float)(_minStep * 10.0);
|
||||
_minStepText.text = _minStep.ToString();
|
||||
if (_maxStep < _minStep)
|
||||
{
|
||||
_maxStep = _minStep;
|
||||
_maxStepSlider.value = _maxStep * 10f;
|
||||
_maxStepSlider.value = (float)(_maxStep * 10.0);
|
||||
_maxStepText.text = _maxStep.ToString();
|
||||
}
|
||||
}
|
||||
@@ -134,27 +136,27 @@ public class MoreSettings
|
||||
_minStepSlider.onValueChanged.RemoveAllListeners();
|
||||
_minStepSlider.onValueChanged.AddListener(val =>
|
||||
{
|
||||
var newVal = Mathf.Round(val) / 10f;
|
||||
var newVal = Mathf.Round(val) / 10.0;
|
||||
if (newVal.Equals(_minStep)) return;
|
||||
_minStep = newVal;
|
||||
_maxStepSlider.minValue = newVal * 10f;
|
||||
_maxStepSlider.minValue = (float)(newVal * 10.0);
|
||||
_minStepText.text = _minStep.ToString();
|
||||
__instance.SetStarmapGalaxy();
|
||||
});
|
||||
_maxStepSlider.onValueChanged.RemoveAllListeners();
|
||||
_maxStepSlider.onValueChanged.AddListener(val =>
|
||||
{
|
||||
var newVal = Mathf.Round(val) / 10f;
|
||||
var newVal = Mathf.Round(val) / 10.0;
|
||||
if (newVal.Equals(_maxStep)) return;
|
||||
_maxStep = newVal;
|
||||
_minStepSlider.maxValue = newVal * 10f;
|
||||
_minStepSlider.maxValue = (float)(newVal * 10.0);
|
||||
_maxStepText.text = _maxStep.ToString();
|
||||
__instance.SetStarmapGalaxy();
|
||||
});
|
||||
_flattenSlider.onValueChanged.RemoveAllListeners();
|
||||
_flattenSlider.onValueChanged.AddListener(val =>
|
||||
{
|
||||
var newVal = Mathf.Round(val) / 50f;
|
||||
var newVal = Mathf.Round(val) / 50.0;
|
||||
if (newVal.Equals(_flatten)) return;
|
||||
_flatten = newVal;
|
||||
_flattenText.text = _flatten.ToString();
|
||||
@@ -164,80 +166,75 @@ public class MoreSettings
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(UIGalaxySelect), nameof(UIGalaxySelect._OnUnregEvent))]
|
||||
private static void PatchGalaxyUI_OnUnregEvent(UIGalaxySelect __instance)
|
||||
private static void UIGalaxySelect__OnUnregEvent_Postfix()
|
||||
{
|
||||
_minDistSlider.onValueChanged.RemoveAllListeners();
|
||||
_minStepSlider.onValueChanged.RemoveAllListeners();
|
||||
_maxStepSlider.onValueChanged.RemoveAllListeners();
|
||||
_flattenSlider.onValueChanged.RemoveAllListeners();
|
||||
}
|
||||
|
||||
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(UIGalaxySelect), nameof(UIGalaxySelect.OnStarCountSliderValueChange))]
|
||||
static IEnumerable<CodeInstruction> PatchStarCountOnValueChange(IEnumerable<CodeInstruction> instructions)
|
||||
private static IEnumerable<CodeInstruction> UIGalaxySelect_OnStarCountSliderValueChange_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
foreach (var instruction in instructions)
|
||||
{
|
||||
if (instruction.opcode == OpCodes.Ldc_I4_S && instruction.OperandIs(80))
|
||||
{
|
||||
yield return new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(UniverseGenTweaks), nameof(UniverseGenTweaks.MaxStarCount)));
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return instruction;
|
||||
}
|
||||
}
|
||||
// Increase hard-coded maxium star count from 80 to MaxStarCount.Value
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(ci => ci.opcode == OpCodes.Ldc_I4_S && ci.OperandIs(80))
|
||||
).Set(OpCodes.Ldsfld, AccessTools.Field(typeof(MoreSettings), nameof(MoreSettings.MaxStarCount))).Insert(
|
||||
new CodeInstruction(OpCodes.Call, AccessTools.PropertyGetter(typeof(ConfigEntry<int>), nameof(ConfigEntry<int>.Value)))
|
||||
);
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(GalaxyData), MethodType.Constructor)]
|
||||
static bool PatchGalaxyData(GalaxyData __instance)
|
||||
private static IEnumerable<CodeInstruction> GalaxyData_Constructor_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
__instance.astrosData = new AstroData[(UniverseGenTweaks.MaxStarCount + 1) * 100];
|
||||
return false;
|
||||
// 25600 -> (MaxStarCount.Value + 1) * 100
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(ci => ci.opcode == OpCodes.Ldc_I4 && ci.OperandIs(25600))
|
||||
).Set(OpCodes.Ldfld, AccessTools.Field(typeof(MoreSettings), nameof(MoreSettings.MaxStarCount))).Insert(
|
||||
new CodeInstruction(OpCodes.Call, AccessTools.PropertyGetter(typeof(ConfigEntry<int>), nameof(ConfigEntry<int>.Value))),
|
||||
new CodeInstruction(OpCodes.Ldc_I4_1),
|
||||
new CodeInstruction(OpCodes.Add),
|
||||
new CodeInstruction(OpCodes.Ldc_I4_S, 100),
|
||||
new CodeInstruction(OpCodes.Mul)
|
||||
);
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(UniverseGen), nameof(UniverseGen.CreateGalaxy))]
|
||||
static IEnumerable<CodeInstruction> PatchCreateGalaxy(IEnumerable<CodeInstruction> instructions)
|
||||
private static IEnumerable<CodeInstruction> UniverseGen_CreateGalaxy_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
foreach (var instruction in instructions)
|
||||
{
|
||||
if (instruction.opcode == OpCodes.Call &&
|
||||
instruction.OperandIs(AccessTools.Method(typeof(UniverseGen), nameof(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(MoreSettings), nameof(_minDist)));
|
||||
yield return new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(MoreSettings), nameof(_minStep)));
|
||||
yield return new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(MoreSettings), nameof(_maxStep)));
|
||||
yield return new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(MoreSettings), nameof(_flatten)));
|
||||
}
|
||||
yield return instruction;
|
||||
}
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Call, AccessTools.Method(typeof(UniverseGen), nameof(UniverseGen.GenerateTempPoses)))
|
||||
).Advance(-4).RemoveInstructions(4).Insert(
|
||||
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(MoreSettings), nameof(_minDist))),
|
||||
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(MoreSettings), nameof(_minStep))),
|
||||
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(MoreSettings), nameof(_maxStep))),
|
||||
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(MoreSettings), nameof(_flatten)))
|
||||
);
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
/* Patch `rand() * (maxStepLen - minStepLen) + minDist` to `rand() * (maxStepLen - minStepLen) + minStepLen`,
|
||||
this should be a bugged line in original game code. */
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(UniverseGen), nameof(UniverseGen.RandomPoses))]
|
||||
static IEnumerable<CodeInstruction> PatchUniverGenRandomPoses(IEnumerable<CodeInstruction> instructions)
|
||||
static IEnumerable<CodeInstruction> UniverseGen_RandomPoses_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var lastIsMul = false;
|
||||
foreach (var instruction in instructions)
|
||||
{
|
||||
if (lastIsMul && instruction.opcode == OpCodes.Ldarg_2)
|
||||
{
|
||||
lastIsMul = false;
|
||||
yield return new CodeInstruction(OpCodes.Ldarg_3);
|
||||
continue;
|
||||
}
|
||||
lastIsMul = instruction.opcode == OpCodes.Mul;
|
||||
yield return instruction;
|
||||
}
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Mul),
|
||||
new CodeMatch(OpCodes.Ldarg_2)
|
||||
);
|
||||
matcher.Repeat(m => m.Advance(1).SetInstructionAndAdvance(new CodeInstruction(OpCodes.Ldarg_3)));
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,17 +10,15 @@ public class UniverseGenTweaks : BaseUnityPlugin
|
||||
BepInEx.Logging.Logger.CreateLogSource(PluginInfo.PLUGIN_NAME);
|
||||
|
||||
private bool _moreSettings = true;
|
||||
public static int MaxStarCount = 128;
|
||||
private bool _epicDifficulty = true;
|
||||
public static float OilMultiplier = 0.5f;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_moreSettings = Config.Bind("MoreSettings", "Enabled", _moreSettings, "Enable more settings on Universe Generation").Value;
|
||||
MaxStarCount = Config.Bind("MoreSettings", "MaxStarCount", MaxStarCount,
|
||||
MoreSettings.MaxStarCount = Config.Bind("MoreSettings", "MaxStarCount", 128,
|
||||
new ConfigDescription("(32 ~ 1024)\nMaximum star count for Universe Generation, enable MoreSettings.Enabled to take effect",
|
||||
new AcceptableValueRange<int>(32, 1024), new {}))
|
||||
.Value;
|
||||
new AcceptableValueRange<int>(32, 1024), new {}));
|
||||
_epicDifficulty = Config.Bind("EpicDifficulty", "Enabled", _epicDifficulty, "Enable Epic difficulty").Value;
|
||||
OilMultiplier = Config.Bind("EpicDifficulty", "OilMultiplier", OilMultiplier,
|
||||
new ConfigDescription("Multiplier relative to the Very-Hard difficulty multiplier",
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<AssemblyName>UniverseGenTweaks</AssemblyName>
|
||||
<BepInExPluginGuid>org.soardev.universegentweaks</BepInExPluginGuid>
|
||||
<Description>DSP MOD - UniverseGenTweaks</Description>
|
||||
<Version>1.1.0</Version>
|
||||
<Version>1.2.0</Version>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<LangVersion>latest</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "UniverseGenTweaks",
|
||||
"version_number": "1.1.0",
|
||||
"version_number": "1.2.0",
|
||||
"website_url": "https://github.com/soarqin/DSP_Mods/tree/master/UniverseGenTweaks",
|
||||
"description": "Universe Generation Tweaks / 宇宙生成参数调节",
|
||||
"dependencies": [
|
||||
|
||||
Reference in New Issue
Block a user