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

UniverseGenTweaks 1.2.10

This commit is contained in:
2025-09-15 14:25:39 +08:00
parent 688b50344c
commit 8446fba0e4
5 changed files with 156 additions and 78 deletions

View File

@@ -3,6 +3,9 @@
## Changelog
* 1.2.10
* Fix issues which cause universe settings not applied on staring a new game or loading game (again).
* Reset star distance/flatten settings on entering galaxy creation screen.
* 1.2.9
* Fix some issues that universe settings not applied on staring a new game or loading game.
* Always show Black hole/Neutron star on preview galaxy map while creating new game.
@@ -43,6 +46,9 @@
## 更新日志
* 1.2.10
* (再次)修复新建游戏或加载存档时宇宙设置没有应用的问题
* 进入宇宙创建界面时重置星系间距/扁平度设置
* 1.2.9
* 修复了一些在新建游戏或加载存档时宇宙设置没有应用的问题
* 在新建游戏时的星系预览图中始终显示黑洞/中子星

View File

@@ -12,12 +12,23 @@ namespace UniverseGenTweaks;
public class MoreSettings
{
const double DEFAULT_MIN_DIST = 2;
const double DEFAULT_MIN_STEP = 2;
const double DEFAULT_MAX_STEP = 3.2;
const double DEFAULT_FLATTEN = 0.18;
public static ConfigEntry<bool> Enabled;
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 double _minDist = DEFAULT_MIN_DIST;
private static double _minStep = DEFAULT_MIN_STEP;
private static double _maxStep = DEFAULT_MAX_STEP;
private static double _flatten = DEFAULT_FLATTEN;
private static double _gameMinDist = DEFAULT_MIN_DIST;
private static double _gameMinStep = DEFAULT_MIN_STEP;
private static double _gameMaxStep = DEFAULT_MAX_STEP;
private static double _gameFlatten = DEFAULT_FLATTEN;
private static Text _minDistTitle;
private static Text _minStepTitle;
@@ -33,11 +44,6 @@ public class MoreSettings
private static Text _flattenText;
private static Harmony _patch, _permanentPatch;
private static double _gameMinDist = 2;
private static double _gameMinStep = 2;
private static double _gameMaxStep = 3.2;
private static double _gameFlatten = 0.18;
public static void Init()
{
I18N.Add("恒星最小距离", "Star Distance Min", "恒星最小距离");
@@ -87,6 +93,33 @@ public class MoreSettings
((RectTransform)trans).anchoredPosition3D = pos;
}
private static void UpdateSliderControls()
{
_minDistSlider.minValue = 10f;
_minDistSlider.maxValue = 50f;
_minDistSlider.value = (float)(_minDist * 10.0);
_minStepTitle.name = "min-step";
_minStepSlider.minValue = (float)(_minDist * 10.0);
_minStepSlider.maxValue = (float)(_maxStep * 10.0);
_minStepSlider.value = (float)(_minStep * 10.0);
_maxStepTitle.name = "max-step";
_maxStepSlider.minValue = (float)(_minStep * 10.0);
_maxStepSlider.maxValue = 100f;
_maxStepSlider.value = (float)(_maxStep * 10.0);
_flattenTitle.name = "flatten";
_flattenSlider.minValue = 1f;
_flattenSlider.maxValue = 50f;
_flattenSlider.value = (float)(_flatten * 50.0);
_minDistText.text = _minDist.ToString();
_minStepText.text = _minStep.ToString();
_maxStepText.text = _maxStep.ToString();
_flattenText.text = _flatten.ToString();
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UIGalaxySelect), nameof(UIGalaxySelect._OnCreate))]
private static void UIGalaxySelect__OnCreate_Postfix(UIGalaxySelect __instance)
@@ -108,12 +141,12 @@ public class MoreSettings
_minDistSlider.value = (float)(_minDist * 10.0);
_minStepTitle.name = "min-step";
_minStepSlider.minValue = 10f;
_minStepSlider.maxValue = (float)(_maxStep * 10.0 - 1.0);
_minStepSlider.minValue = (float)(_minDist * 10.0);
_minStepSlider.maxValue = (float)(_maxStep * 10.0);
_minStepSlider.value = (float)(_minStep * 10.0);
_maxStepTitle.name = "max-step";
_maxStepSlider.minValue = (float)(_minStep * 10.0 + 1.0);
_maxStepSlider.minValue = (float)(_minStep * 10.0);
_maxStepSlider.maxValue = 100f;
_maxStepSlider.value = (float)(_maxStep * 10.0);
@@ -137,15 +170,12 @@ public class MoreSettings
[HarmonyPatch(typeof(UIGalaxySelect), nameof(UIGalaxySelect._OnOpen))]
private static void UIGalaxySelect__OnOpen_Prefix()
{
_gameMinDist = _minDist;
_gameMinStep = _minStep;
_gameMaxStep = _maxStep;
_gameFlatten = _flatten;
_minDist = DEFAULT_MIN_DIST;
_minStep = DEFAULT_MIN_STEP;
_maxStep = DEFAULT_MAX_STEP;
_flatten = DEFAULT_FLATTEN;
_minDistText.text = _minDist.ToString();
_minStepText.text = _minStep.ToString();
_maxStepText.text = _maxStep.ToString();
_flattenText.text = _flatten.ToString();
UpdateSliderControls();
}
[HarmonyPostfix]
@@ -157,20 +187,21 @@ public class MoreSettings
{
var newVal = Mathf.Round(val) / 10.0;
if (newVal.Equals(_minDist)) return;
_minDist = _gameMinDist = newVal;
_minDist = newVal;
_minDistText.text = _minDist.ToString();
if (_minStep < _minDist)
{
_minStep = _gameMinStep = _minDist;
_minStep = _minDist;
_minStepSlider.value = (float)(_minStep * 10.0);
_minStepText.text = _minStep.ToString();
if (_maxStep < _minStep)
{
_maxStep = _gameMaxStep = _minStep;
_maxStep = _minStep;
_maxStepSlider.value = (float)(_maxStep * 10.0);
_maxStepText.text = _maxStep.ToString();
}
}
_minStepSlider.minValue = (float)(_minDist * 10.0);
__instance.SetStarmapGalaxy();
});
_minStepSlider.onValueChanged.RemoveAllListeners();
@@ -178,7 +209,7 @@ public class MoreSettings
{
var newVal = Mathf.Round(val) / 10.0;
if (newVal.Equals(_minStep)) return;
_minStep = _gameMinStep = newVal;
_minStep = newVal;
_maxStepSlider.minValue = (float)(newVal * 10.0);
_minStepText.text = _minStep.ToString();
__instance.SetStarmapGalaxy();
@@ -188,7 +219,7 @@ public class MoreSettings
{
var newVal = Mathf.Round(val) / 10.0;
if (newVal.Equals(_maxStep)) return;
_maxStep = _gameMaxStep = newVal;
_maxStep = newVal;
_minStepSlider.maxValue = (float)(newVal * 10.0);
_maxStepText.text = _maxStep.ToString();
__instance.SetStarmapGalaxy();
@@ -198,7 +229,7 @@ public class MoreSettings
{
var newVal = Mathf.Round(val) / 50.0;
if (newVal.Equals(_flatten)) return;
_flatten = _gameFlatten = newVal;
_flatten = newVal;
_flattenText.text = _flatten.ToString();
__instance.SetStarmapGalaxy();
});
@@ -230,20 +261,31 @@ public class MoreSettings
private static class PermanentPatch
{
public static void ResetSettings()
[HarmonyPrefix]
[HarmonyPatch(typeof(GameMain), nameof(GameMain.Start))]
private static void GameMain_Start_Prefix()
{
_gameMinDist = 2;
_gameMinStep = 2;
_gameMaxStep = 3.2;
_gameFlatten = 0.18;
_gameMinDist = DEFAULT_MIN_DIST;
_gameMinStep = DEFAULT_MIN_STEP;
_gameMaxStep = DEFAULT_MAX_STEP;
_gameFlatten = DEFAULT_FLATTEN;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(GameData), nameof(GameData.SetForNewGame))]
private static void GameData_SetForNewGame_Prefix(GameData __instance)
[HarmonyPatch(typeof(GameData), nameof(GameData.NewGame))]
private static void GameData_NewGame_Prefix()
{
if (Enabled.Value) return;
ResetSettings();
if (!Enabled.Value) return;
_gameMinDist = _minDist;
_gameMinStep = _minStep;
_gameMaxStep = _maxStep;
_gameFlatten = _flatten;
_minDist = DEFAULT_MIN_DIST;
_minStep = DEFAULT_MIN_STEP;
_maxStep = DEFAULT_MAX_STEP;
_flatten = DEFAULT_FLATTEN;
}
[HarmonyTranspiler]
@@ -278,14 +320,26 @@ public class MoreSettings
private static IEnumerable<CodeInstruction> UniverseGen_CreateGalaxy_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
var matcher = new CodeMatcher(instructions, generator);
var b0 = generator.DefineLabel();
var b1 = generator.DefineLabel();
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(_gameMinDist))),
).Advance(-4).RemoveInstructions(4).InsertAndAdvance(
new CodeInstruction(OpCodes.Call, AccessTools.PropertyGetter(typeof(UIRoot), nameof(UIRoot.instance))),
new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(UIRoot), nameof(UIRoot.galaxySelect))),
new CodeInstruction(OpCodes.Callvirt, AccessTools.PropertyGetter(typeof(ManualBehaviour), nameof(ManualBehaviour.active))),
new CodeInstruction(OpCodes.Brfalse, b0),
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))),
new CodeInstruction(OpCodes.Br, b1),
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(MoreSettings), nameof(_gameMinDist))).WithLabels(b0),
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(MoreSettings), nameof(_gameMinStep))),
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(MoreSettings), nameof(_gameMaxStep))),
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(MoreSettings), nameof(_gameFlatten)))
);
matcher.Labels.Add(b1);
return matcher.InstructionEnumeration();
}
@@ -320,8 +374,9 @@ public class MoreSettings
new CodeInstruction(OpCodes.Stloc, local1)
).Advance(3).Insert(
new CodeInstruction(OpCodes.Ldloc, local1),
Transpilers.EmitDelegate(bool (UIVirtualStarmap.StarNode starNode) => {
return starNode.starData.type switch
Transpilers.EmitDelegate(bool (UIVirtualStarmap.StarNode starNode) =>
{
return starNode?.starData?.type switch
{
EStarType.NeutronStar or EStarType.BlackHole => true,
_ => false,
@@ -331,6 +386,30 @@ public class MoreSettings
);
return matcher.InstructionEnumeration();
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(UIGalaxySelect), nameof(UIGalaxySelect.UpdateUIDisplay))]
private static IEnumerable<CodeInstruction> UIGalaxySelect_UpdateUIDisplay_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
var matcher = new CodeMatcher(instructions, generator);
Label? b1 = null;
matcher.MatchForward(false,
new CodeMatch(OpCodes.Ldc_I4_0),
new CodeMatch(ci => ci.IsStloc()),
new CodeMatch(ci => ci.Branches(out b1)),
new CodeMatch(ci => ci.IsLdloc()),
new CodeMatch(ci => ci.IsLdloc()),
new CodeMatch(OpCodes.Ldelem_Ref),
new CodeMatch(ci => ci.IsStloc()),
new CodeMatch(ci => ci.IsLdloc())
).Advance(7);
var instr = matcher.InstructionAt(0);
matcher.Insert(
instr,
new CodeInstruction(OpCodes.Brfalse, b1!)
);
return matcher.InstructionEnumeration();
}
}
#region CombatSettings
@@ -702,7 +781,7 @@ public class MoreSettings
}
[HarmonyPrefix]
[HarmonyPatch(typeof(CombatSettings),nameof(CombatSettings.difficulty), MethodType.Getter)]
[HarmonyPatch(typeof(CombatSettings), nameof(CombatSettings.difficulty), MethodType.Getter)]
private static bool CombatSettings_difficulty_Getter_Prefix(CombatSettings __instance, ref float __result)
{
var aggressivenessScore = __instance.aggressiveness switch
@@ -823,11 +902,5 @@ public class MoreSettings
_gameFlatten = r.ReadDouble();
}
public static void IntoOtherSave()
{
// Skip prologue demo save
if (DSPGame.IsMenuDemo && DSPGame.LoadDemoIndex == -99) return;
PermanentPatch.ResetSettings();
}
#endregion
}

View File

@@ -82,7 +82,6 @@ public class UniverseGenTweaks : BaseUnityPlugin, IModCanSave
public void IntoOtherSave()
{
MoreSettings.IntoOtherSave();
}
#endregion
}

View File

@@ -6,7 +6,7 @@
<AssemblyName>UniverseGenTweaks</AssemblyName>
<BepInExPluginGuid>org.soardev.universegentweaks</BepInExPluginGuid>
<Description>DSP MOD - UniverseGenTweaks</Description>
<Version>1.2.9</Version>
<Version>1.2.10</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
<RestoreAdditionalProjectSources>https://nuget.bepinex.dev/v3/index.json</RestoreAdditionalProjectSources>

View File

@@ -1,6 +1,6 @@
{
"name": "UniverseGenTweaks",
"version_number": "1.2.9",
"version_number": "1.2.10",
"website_url": "https://github.com/soarqin/DSP_Mods/tree/master/UniverseGenTweaks",
"description": "Universe Generation Tweaks / 宇宙生成参数调节",
"dependencies": [