mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-09 01:33:33 +08:00
UniverseGenTweaks 1.1.0
This commit is contained in:
186
UniverseGenTweaks/EpicDifficulty.cs
Normal file
186
UniverseGenTweaks/EpicDifficulty.cs
Normal file
@@ -0,0 +1,186 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection.Emit;
|
||||
using HarmonyLib;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace UniverseGenTweaks;
|
||||
|
||||
public class EpicDifficulty
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
I18N.Add("究极少", "Micro", "究极少");
|
||||
I18N.Add("史诗难度", "Epic Difficulty !!", "史诗难度 !!");
|
||||
Harmony.CreateAndPatchAll(typeof(EpicDifficulty));
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(UIGalaxySelect), nameof(UIGalaxySelect._OnInit))]
|
||||
private static void PatchGalaxyUI_OnInit(UIGalaxySelect __instance)
|
||||
{
|
||||
__instance.resourceMultiplierSlider.maxValue = 10f;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(UIGalaxySelect), nameof(UIGalaxySelect.OnResourceMultiplierValueChange))]
|
||||
private static bool UIGalaxySelect_OnResourceMultiplierValueChange_Prefix(UIGalaxySelect __instance, float val)
|
||||
{
|
||||
float value = __instance.resourceMultiplierSlider.value;
|
||||
if (value < 0.5f)
|
||||
{
|
||||
__instance.gameDesc.resourceMultiplier = 0.01f;
|
||||
}
|
||||
else if (value < 1.5f)
|
||||
{
|
||||
__instance.gameDesc.resourceMultiplier = 0.1f;
|
||||
}
|
||||
else if (value < 2.5f)
|
||||
{
|
||||
__instance.gameDesc.resourceMultiplier = 0.5f;
|
||||
}
|
||||
else if (value < 3.5f)
|
||||
{
|
||||
__instance.gameDesc.resourceMultiplier = 0.8f;
|
||||
}
|
||||
else if (value < 4.5f)
|
||||
{
|
||||
__instance.gameDesc.resourceMultiplier = 1f;
|
||||
}
|
||||
else if (value < 5.5f)
|
||||
{
|
||||
__instance.gameDesc.resourceMultiplier = 1.5f;
|
||||
}
|
||||
else if (value < 6.5f)
|
||||
{
|
||||
__instance.gameDesc.resourceMultiplier = 2f;
|
||||
}
|
||||
else if (value < 7.5f)
|
||||
{
|
||||
__instance.gameDesc.resourceMultiplier = 3f;
|
||||
}
|
||||
else if (value < 8.5f)
|
||||
{
|
||||
__instance.gameDesc.resourceMultiplier = 5f;
|
||||
}
|
||||
else if (value < 9.5f)
|
||||
{
|
||||
__instance.gameDesc.resourceMultiplier = 8f;
|
||||
}
|
||||
else
|
||||
{
|
||||
__instance.gameDesc.resourceMultiplier = 100f;
|
||||
}
|
||||
__instance.UpdateParametersUIDisplay();
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(UIGalaxySelect), nameof(UIGalaxySelect.UpdateParametersUIDisplay))]
|
||||
private static bool UIGalaxySelect_UpdateParametersUIDisplay_Prefix(UIGalaxySelect __instance)
|
||||
{
|
||||
float resourceMultiplier = __instance.gameDesc.resourceMultiplier;
|
||||
string text = "";
|
||||
if (resourceMultiplier < 0.04f)
|
||||
{
|
||||
__instance.resourceMultiplierSlider.value = 0f;
|
||||
}
|
||||
else if (resourceMultiplier < 0.11f)
|
||||
{
|
||||
__instance.resourceMultiplierSlider.value = 1f;
|
||||
}
|
||||
else if (resourceMultiplier < 0.51f)
|
||||
{
|
||||
__instance.resourceMultiplierSlider.value = 2f;
|
||||
}
|
||||
else if (resourceMultiplier < 0.81f)
|
||||
{
|
||||
__instance.resourceMultiplierSlider.value = 3f;
|
||||
}
|
||||
else if (resourceMultiplier < 1.01f)
|
||||
{
|
||||
__instance.resourceMultiplierSlider.value = 4f;
|
||||
}
|
||||
else if (resourceMultiplier < 1.51f)
|
||||
{
|
||||
__instance.resourceMultiplierSlider.value = 5f;
|
||||
}
|
||||
else if (resourceMultiplier < 2.01f)
|
||||
{
|
||||
__instance.resourceMultiplierSlider.value = 6f;
|
||||
}
|
||||
else if (resourceMultiplier < 3.01f)
|
||||
{
|
||||
__instance.resourceMultiplierSlider.value = 7f;
|
||||
}
|
||||
else if (resourceMultiplier < 5.01f)
|
||||
{
|
||||
__instance.resourceMultiplierSlider.value = 8f;
|
||||
}
|
||||
else if (resourceMultiplier < 8.01f)
|
||||
{
|
||||
__instance.resourceMultiplierSlider.value = 9f;
|
||||
}
|
||||
else
|
||||
{
|
||||
__instance.resourceMultiplierSlider.value = 10f;
|
||||
}
|
||||
if (resourceMultiplier < 100f && resourceMultiplier > 0.1f)
|
||||
{
|
||||
text = resourceMultiplier.ToString() + "x";
|
||||
}
|
||||
else if (resourceMultiplier >= 100f)
|
||||
{
|
||||
text = "无限".Translate();
|
||||
}
|
||||
else if (resourceMultiplier < 0.04f)
|
||||
{
|
||||
text = "究极少".Translate();
|
||||
}
|
||||
else if (resourceMultiplier < 0.11f)
|
||||
{
|
||||
text = "极少".Translate();
|
||||
}
|
||||
__instance.resourceMultiplierText.text = text;
|
||||
__instance.propertyMultiplierText.text = "元数据生成倍率".Translate() + " " + __instance.gameDesc.propertyMultiplier.ToString("P0");
|
||||
__instance.addrText.text = __instance.gameDesc.clusterString;
|
||||
var showDifficultTip = resourceMultiplier < 0.11f && !__instance.gameDesc.isSandboxMode;
|
||||
__instance.difficultTipGroup.SetActive(showDifficultTip);
|
||||
if (showDifficultTip)
|
||||
{
|
||||
if (resourceMultiplier < 0.04f)
|
||||
{
|
||||
__instance.difficultTipGroup.transform.Find("difficult-tip-text").GetComponent<Text>().text = "史诗难度".Translate();
|
||||
}
|
||||
else
|
||||
{
|
||||
__instance.difficultTipGroup.transform.Find("difficult-tip-text").GetComponent<Text>().text = "非常困难".Translate();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(GameDesc), "get_oilAmountMultiplier")]
|
||||
private static IEnumerable<CodeInstruction> GameDesc_get_oilAmountMultiplier_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
if (Math.Abs(UniverseGenTweaks.OilMultiplier - 1f) > 0.00001f)
|
||||
{
|
||||
var label1 = generator.DefineLabel();
|
||||
matcher.Start().InsertAndAdvance(
|
||||
new CodeInstruction(OpCodes.Ldarg_0),
|
||||
new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(GameDesc), nameof(GameDesc.resourceMultiplier))),
|
||||
new CodeInstruction(OpCodes.Ldc_R4, 0.05f),
|
||||
new CodeInstruction(OpCodes.Ble_S, label1)
|
||||
).End().Advance(1).Insert(
|
||||
new CodeInstruction(OpCodes.Ldc_R4, 0.5f * UniverseGenTweaks.OilMultiplier).WithLabels(label1),
|
||||
new CodeInstruction(OpCodes.Ret)
|
||||
);
|
||||
}
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
}
|
||||
61
UniverseGenTweaks/I18N.cs
Normal file
61
UniverseGenTweaks/I18N.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
|
||||
namespace UniverseGenTweaks;
|
||||
|
||||
public class I18N
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
Harmony.CreateAndPatchAll(typeof(I18N));
|
||||
}
|
||||
private static int _nextID = 0;
|
||||
private static readonly List<StringProto> StringsToAdd = new();
|
||||
public static void Add(string key, string enus, string zhcn = null, string frfr = null)
|
||||
{
|
||||
var strings = LDB._strings;
|
||||
while (_nextID <= 12000)
|
||||
{
|
||||
if (!strings.dataIndices.ContainsKey(_nextID))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
_nextID++;
|
||||
}
|
||||
var strProto = new StringProto
|
||||
{
|
||||
Name = key,
|
||||
ID = _nextID,
|
||||
SID = "",
|
||||
ENUS = enus,
|
||||
ZHCN = string.IsNullOrEmpty(zhcn) ? enus : zhcn,
|
||||
FRFR = string.IsNullOrEmpty(frfr) ? enus : frfr
|
||||
};
|
||||
StringsToAdd.Add(strProto);
|
||||
_nextID++;
|
||||
}
|
||||
|
||||
private static bool _initialized = false;
|
||||
[HarmonyPostfix, HarmonyPriority(Priority.Last), HarmonyPatch(typeof(VFPreload), "InvokeOnLoadWorkEnded")]
|
||||
private static void VFPreload_InvokeOnLoadWorkEnded_Postfix()
|
||||
{
|
||||
if (_initialized) return;
|
||||
_initialized = true;
|
||||
if (StringsToAdd.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var strings = LDB._strings;
|
||||
var index = strings.dataArray.Length;
|
||||
strings.dataArray = strings.dataArray.Concat(StringsToAdd).ToArray();
|
||||
StringsToAdd.Clear();
|
||||
var newIndex = strings.dataArray.Length;
|
||||
for (; index < newIndex; index++)
|
||||
{
|
||||
strings.dataIndices[strings.dataArray[index].ID] = index;
|
||||
strings.nameIndices[strings.dataArray[index].Name] = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
243
UniverseGenTweaks/MoreSettings.cs
Normal file
243
UniverseGenTweaks/MoreSettings.cs
Normal file
@@ -0,0 +1,243 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Reflection.Emit;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
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;
|
||||
|
||||
private static Text _minDistTitle;
|
||||
private static Text _minStepTitle;
|
||||
private static Text _maxStepTitle;
|
||||
private static Text _flattenTitle;
|
||||
private static Slider _minDistSlider;
|
||||
private static Slider _minStepSlider;
|
||||
private static Slider _maxStepSlider;
|
||||
private static Slider _flattenSlider;
|
||||
private static Text _minDistText;
|
||||
private static Text _minStepText;
|
||||
private static Text _maxStepText;
|
||||
private static Text _flattenText;
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
I18N.Add("恒星最小距离", "Star Distance Min", "恒星最小距离");
|
||||
I18N.Add("步进最小距离", "Step Distance Min", "步进最小距离");
|
||||
I18N.Add("步进最大距离", "Step Distance Max", "步进最大距离");
|
||||
I18N.Add("扁平度", "Flatness", "扁平度");
|
||||
Harmony.CreateAndPatchAll(typeof(MoreSettings));
|
||||
}
|
||||
|
||||
private static void CreateSliderWithText(Slider orig, out Text title, out Slider slider, out Text text)
|
||||
{
|
||||
var origText = orig.transform.parent.GetComponent<Text>();
|
||||
title = Object.Instantiate(origText, origText.transform.parent);
|
||||
slider = title.transform.FindChildRecur("Slider").GetComponent<Slider>();
|
||||
text = slider.transform.FindChildRecur("Text").GetComponent<Text>();
|
||||
}
|
||||
|
||||
private static void TransformDeltaY(Transform trans, float delta)
|
||||
{
|
||||
var pos = trans.position;
|
||||
pos.y += delta;
|
||||
trans.position = pos;
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(UIGalaxySelect), nameof(UIGalaxySelect._OnInit))]
|
||||
private static void PatchGalaxyUI_OnInit(UIGalaxySelect __instance)
|
||||
{
|
||||
__instance.starCountSlider.maxValue = UniverseGenTweaks.MaxStarCount;
|
||||
|
||||
CreateSliderWithText(__instance.starCountSlider, out _minDistTitle, out _minDistSlider, out _minDistText);
|
||||
CreateSliderWithText(__instance.starCountSlider, out _minStepTitle, out _minStepSlider, out _minStepText);
|
||||
CreateSliderWithText(__instance.starCountSlider, out _maxStepTitle, out _maxStepSlider, out _maxStepText);
|
||||
CreateSliderWithText(__instance.starCountSlider, out _flattenTitle, out _flattenSlider, out _flattenText);
|
||||
|
||||
_minDistTitle.name = "min-dist";
|
||||
_minDistSlider.minValue = 10f;
|
||||
_minDistSlider.maxValue = 50f;
|
||||
_minDistSlider.value = _minDist * 10f;
|
||||
|
||||
_minStepTitle.name = "min-step";
|
||||
_minStepSlider.minValue = 10f;
|
||||
_minStepSlider.maxValue = _maxStep * 10f - 1f;
|
||||
_minStepSlider.value = _minStep * 10f;
|
||||
|
||||
_maxStepTitle.name = "max-step";
|
||||
_maxStepSlider.minValue = _minStep * 10f + 1f;
|
||||
_maxStepSlider.maxValue = 100f;
|
||||
_maxStepSlider.value = _maxStep * 10f;
|
||||
|
||||
_flattenTitle.name = "flatten";
|
||||
_flattenSlider.minValue = 1f;
|
||||
_flattenSlider.maxValue = 50f;
|
||||
_flattenSlider.value = _flatten * 50f;
|
||||
|
||||
TransformDeltaY(_minDistTitle.transform, -0.3573f);
|
||||
TransformDeltaY(_minStepTitle.transform, -0.3573f * 2);
|
||||
TransformDeltaY(_maxStepTitle.transform, -0.3573f * 3);
|
||||
TransformDeltaY(_flattenTitle.transform, -0.3573f * 4);
|
||||
TransformDeltaY(__instance.resourceMultiplierSlider.transform.parent, -0.3573f * 4);
|
||||
TransformDeltaY(__instance.sandboxToggle.transform.parent, -0.3573f * 4);
|
||||
TransformDeltaY(__instance.propertyMultiplierText.transform, -0.3573f * 4);
|
||||
TransformDeltaY(__instance.addrText.transform.parent, -0.3573f * 4);
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(UIGalaxySelect), nameof(UIGalaxySelect._OnOpen))]
|
||||
private static void PatchGalaxyUI_OnOpen(UIGalaxySelect __instance)
|
||||
{
|
||||
_minDistTitle.text = "恒星最小距离".Translate();
|
||||
_minStepTitle.text = "步进最小距离".Translate();
|
||||
_maxStepTitle.text = "步进最大距离".Translate();
|
||||
_flattenTitle.text = "扁平度".Translate();
|
||||
_minDistText.text = _minDist.ToString();
|
||||
_minStepText.text = _minStep.ToString();
|
||||
_maxStepText.text = _maxStep.ToString();
|
||||
_flattenText.text = _flatten.ToString();
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(UIGalaxySelect), nameof(UIGalaxySelect._OnRegEvent))]
|
||||
private static void PatchGalaxyUI_OnRegEvent(UIGalaxySelect __instance)
|
||||
{
|
||||
_minDistSlider.onValueChanged.RemoveAllListeners();
|
||||
_minDistSlider.onValueChanged.AddListener(val =>
|
||||
{
|
||||
var newVal = Mathf.Round(val) / 10f;
|
||||
if (newVal.Equals(_minDist)) return;
|
||||
_minDist = newVal;
|
||||
_minDistText.text = _minDist.ToString();
|
||||
if (_minStep < _minDist)
|
||||
{
|
||||
_minStep = _minDist;
|
||||
_minStepSlider.value = _minStep * 10f;
|
||||
_minStepText.text = _minStep.ToString();
|
||||
if (_maxStep < _minStep)
|
||||
{
|
||||
_maxStep = _minStep;
|
||||
_maxStepSlider.value = _maxStep * 10f;
|
||||
_maxStepText.text = _maxStep.ToString();
|
||||
}
|
||||
}
|
||||
__instance.SetStarmapGalaxy();
|
||||
});
|
||||
_minStepSlider.onValueChanged.RemoveAllListeners();
|
||||
_minStepSlider.onValueChanged.AddListener(val =>
|
||||
{
|
||||
var newVal = Mathf.Round(val) / 10f;
|
||||
if (newVal.Equals(_minStep)) return;
|
||||
_minStep = newVal;
|
||||
_maxStepSlider.minValue = newVal * 10f;
|
||||
_minStepText.text = _minStep.ToString();
|
||||
__instance.SetStarmapGalaxy();
|
||||
});
|
||||
_maxStepSlider.onValueChanged.RemoveAllListeners();
|
||||
_maxStepSlider.onValueChanged.AddListener(val =>
|
||||
{
|
||||
var newVal = Mathf.Round(val) / 10f;
|
||||
if (newVal.Equals(_maxStep)) return;
|
||||
_maxStep = newVal;
|
||||
_minStepSlider.maxValue = newVal * 10f;
|
||||
_maxStepText.text = _maxStep.ToString();
|
||||
__instance.SetStarmapGalaxy();
|
||||
});
|
||||
_flattenSlider.onValueChanged.RemoveAllListeners();
|
||||
_flattenSlider.onValueChanged.AddListener(val =>
|
||||
{
|
||||
var newVal = Mathf.Round(val) / 50f;
|
||||
if (newVal.Equals(_flatten)) return;
|
||||
_flatten = newVal;
|
||||
_flattenText.text = _flatten.ToString();
|
||||
__instance.SetStarmapGalaxy();
|
||||
});
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(UIGalaxySelect), nameof(UIGalaxySelect._OnUnregEvent))]
|
||||
private static void PatchGalaxyUI_OnUnregEvent(UIGalaxySelect __instance)
|
||||
{
|
||||
_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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(GalaxyData), MethodType.Constructor)]
|
||||
static bool PatchGalaxyData(GalaxyData __instance)
|
||||
{
|
||||
__instance.astrosData = new AstroData[(UniverseGenTweaks.MaxStarCount + 1) * 100];
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(UniverseGen), nameof(UniverseGen.CreateGalaxy))]
|
||||
static IEnumerable<CodeInstruction> PatchCreateGalaxy(IEnumerable<CodeInstruction> instructions)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +1,36 @@
|
||||
# UniverseGenTweak
|
||||
|
||||
#### Universe Generator Tweak
|
||||
#### Universe Generation Tweak
|
||||
#### 宇宙生成参数调节
|
||||
|
||||
## Usage
|
||||
* More options on universe creation
|
||||
* Can set maximum star count(128 by default, up to 1024) in config file.
|
||||
* Note: there is performance issue on galaxy view with large amount of stars.
|
||||
## Changelog
|
||||
* 1.1.0
|
||||
+ Add epic difficulty
|
||||
+ `More options` and `Epic difficulty` can be enabled individually now.
|
||||
+ Fix a crash while setting `Star Distance Min` to larger than `Step Distance Min`.
|
||||
* 1.0.0
|
||||
+ Initial release
|
||||
|
||||
## 使用说明
|
||||
* 生成宇宙时提供更多选项
|
||||
* 可以在配置文件中设置最大恒星数(默认128, 最多1024)
|
||||
* 注意: 大量恒星会导致宇宙视图出现性能问题
|
||||
## Features
|
||||
1. More options on universe generation
|
||||
* Can set maximum star count(128 by default, up to 1024) in config file.
|
||||
+ Note: there is performance issue on galaxy view with large amount of stars.
|
||||
2. Epic difficulty
|
||||
* 0.01x resources and 0.25x oils (very hard difficulty has 0.5x oils).
|
||||
* Same oil mining speed as very hard difficuly
|
||||
|
||||
## 更新日志
|
||||
* 1.1.0
|
||||
+ 增加史诗难度
|
||||
+ `更多选项`和`史诗难度`现在可以单独启用
|
||||
+ 修复了将`恒星最小距离`设置为大于`步进最小距离`时崩溃的问题
|
||||
* 1.0.0
|
||||
+ 初始版本
|
||||
|
||||
## 功能
|
||||
1. 生成宇宙时提供更多选项
|
||||
* 可以在配置文件中设置最大恒星数(默认128, 最多1024)
|
||||
+ 注意: 大量恒星会导致宇宙视图出现性能问题
|
||||
2. 史诗难度
|
||||
* 资源0.01倍,油井储量0.25倍(极难是0.5倍)
|
||||
* 采油速度和极难相同
|
||||
|
||||
@@ -1,249 +1,42 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Reflection.Emit;
|
||||
using BepInEx;
|
||||
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 =
|
||||
public new static readonly BepInEx.Logging.ManualLogSource Logger =
|
||||
BepInEx.Logging.Logger.CreateLogSource(PluginInfo.PLUGIN_NAME);
|
||||
|
||||
private bool _cfgEnabled = true;
|
||||
private static int _maxStarCount = 128;
|
||||
private static float _minDist = 2f;
|
||||
private static float _minStep = 2f;
|
||||
private static float _maxStep = 3.2f;
|
||||
private static float _flatten = 0.18f;
|
||||
|
||||
private static Text _minDistTitle;
|
||||
private static Text _minStepTitle;
|
||||
private static Text _maxStepTitle;
|
||||
private static Text _flattenTitle;
|
||||
private static Slider _minDistSlider;
|
||||
private static Slider _minStepSlider;
|
||||
private static Slider _maxStepSlider;
|
||||
private static Slider _flattenSlider;
|
||||
private static Text _minDistText;
|
||||
private static Text _minStepText;
|
||||
private static Text _maxStepText;
|
||||
private static Text _flattenText;
|
||||
private bool _moreSettings = true;
|
||||
public static int MaxStarCount = 128;
|
||||
private bool _epicDifficulty = true;
|
||||
public static float OilMultiplier = 0.5f;
|
||||
|
||||
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",
|
||||
_moreSettings = Config.Bind("MoreSettings", "Enabled", _moreSettings, "Enable more settings on Universe Generation").Value;
|
||||
MaxStarCount = Config.Bind("MoreSettings", "MaxStarCount", MaxStarCount,
|
||||
new ConfigDescription("(32 ~ 1024)\nMaximum star count for Universe Generation, enable MoreSettings.Enabled to take effect",
|
||||
new AcceptableValueRange<int>(32, 1024), new {}))
|
||||
.Value;
|
||||
Harmony.CreateAndPatchAll(typeof(UniverseGenTweaks));
|
||||
}
|
||||
_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",
|
||||
new AcceptableValueRange<float>(0.1f, 1f), new {}))
|
||||
.Value;
|
||||
|
||||
private static void CreateSliderWithText(Slider orig, out Text title, out Slider slider, out Text text)
|
||||
{
|
||||
var origText = orig.transform.parent.GetComponent<Text>();
|
||||
title = Object.Instantiate(origText, origText.transform.parent);
|
||||
slider = title.transform.FindChildRecur("Slider").GetComponent<Slider>();
|
||||
text = slider.transform.FindChildRecur("Text").GetComponent<Text>();
|
||||
}
|
||||
|
||||
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 _minStepTitle, out _minStepSlider, out _minStepText);
|
||||
CreateSliderWithText(__instance.starCountSlider, out _maxStepTitle, out _maxStepSlider, out _maxStepText);
|
||||
CreateSliderWithText(__instance.starCountSlider, out _flattenTitle, out _flattenSlider, out _flattenText);
|
||||
|
||||
_minDistTitle.name = "min-dist";
|
||||
_minDistSlider.minValue = 10f;
|
||||
_minDistSlider.maxValue = 50f;
|
||||
_minDistSlider.value = _minDist * 10f;
|
||||
|
||||
_minStepTitle.name = "min-step";
|
||||
_minStepSlider.minValue = 10f;
|
||||
_minStepSlider.maxValue = _maxStep * 10f - 1f;
|
||||
_minStepSlider.value = _minStep * 10f;
|
||||
|
||||
_maxStepTitle.name = "max-step";
|
||||
_maxStepSlider.minValue = _minStep * 10f + 1f;
|
||||
_maxStepSlider.maxValue = 100f;
|
||||
_maxStepSlider.value = _maxStep * 10f;
|
||||
|
||||
_flattenTitle.name = "flatten";
|
||||
_flattenSlider.minValue = 1f;
|
||||
_flattenSlider.maxValue = 50f;
|
||||
_flattenSlider.value = _flatten * 50f;
|
||||
|
||||
TransformDeltaY(_minDistTitle.transform, -0.3573f);
|
||||
TransformDeltaY(_minStepTitle.transform, -0.3573f * 2);
|
||||
TransformDeltaY(_maxStepTitle.transform, -0.3573f * 3);
|
||||
TransformDeltaY(_flattenTitle.transform, -0.3573f * 4);
|
||||
TransformDeltaY(__instance.resourceMultiplierSlider.transform.parent, -0.3573f * 4);
|
||||
TransformDeltaY(__instance.sandboxToggle.transform.parent, -0.3573f * 4);
|
||||
TransformDeltaY(__instance.propertyMultiplierText.transform, -0.3573f * 4);
|
||||
TransformDeltaY(__instance.addrText.transform.parent, -0.3573f * 4);
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(UIGalaxySelect), "_OnOpen")]
|
||||
private static void PatchGalaxyUI_OnOpen(UIGalaxySelect __instance)
|
||||
{
|
||||
if (Localization.language == Language.zhCN)
|
||||
I18N.Init();
|
||||
if (_moreSettings)
|
||||
{
|
||||
_minDistTitle.text = "恒星最小距离";
|
||||
_minStepTitle.text = "步进最小距离";
|
||||
_maxStepTitle.text = "步进最大距离";
|
||||
_flattenTitle.text = "扁平度";
|
||||
MoreSettings.Init();
|
||||
}
|
||||
else
|
||||
{
|
||||
_minDistTitle.text = "Star Distance Min";
|
||||
_minStepTitle.text = "Step Distance Min";
|
||||
_maxStepTitle.text = "Step Distance Max";
|
||||
_flattenTitle.text = "Flatten";
|
||||
}
|
||||
_minDistText.text = _minDist.ToString(CultureInfo.InvariantCulture);
|
||||
_minStepText.text = _minStep.ToString(CultureInfo.InvariantCulture);
|
||||
_maxStepText.text = _maxStep.ToString(CultureInfo.InvariantCulture);
|
||||
_flattenText.text = _flatten.ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(UIGalaxySelect), "_OnRegEvent")]
|
||||
private static void PatchGalaxyUI_OnRegEvent(UIGalaxySelect __instance)
|
||||
{
|
||||
_minDistSlider.onValueChanged.RemoveAllListeners();
|
||||
_minDistSlider.onValueChanged.AddListener(val =>
|
||||
if (_epicDifficulty)
|
||||
{
|
||||
var newVal = Mathf.Round(val) / 10f;
|
||||
if (newVal.Equals(_minDist)) return;
|
||||
_minDist = newVal;
|
||||
_minDistText.text = _minDist.ToString(CultureInfo.InvariantCulture);
|
||||
__instance.SetStarmapGalaxy();
|
||||
});
|
||||
_minStepSlider.onValueChanged.RemoveAllListeners();
|
||||
_minStepSlider.onValueChanged.AddListener(val =>
|
||||
{
|
||||
var newVal = Mathf.Round(val) / 10f;
|
||||
if (newVal.Equals(_minStep)) return;
|
||||
_minStep = newVal;
|
||||
_maxStepSlider.minValue = newVal * 10f;
|
||||
_minStepText.text = _minStep.ToString(CultureInfo.InvariantCulture);
|
||||
__instance.SetStarmapGalaxy();
|
||||
});
|
||||
_maxStepSlider.onValueChanged.RemoveAllListeners();
|
||||
_maxStepSlider.onValueChanged.AddListener(val =>
|
||||
{
|
||||
var newVal = Mathf.Round(val) / 10f;
|
||||
if (newVal.Equals(_maxStep)) return;
|
||||
_maxStep = newVal;
|
||||
_minStepSlider.maxValue = newVal * 10f;
|
||||
_maxStepText.text = _maxStep.ToString(CultureInfo.InvariantCulture);
|
||||
__instance.SetStarmapGalaxy();
|
||||
});
|
||||
_flattenSlider.onValueChanged.RemoveAllListeners();
|
||||
_flattenSlider.onValueChanged.AddListener(val =>
|
||||
{
|
||||
var newVal = Mathf.Round(val) / 50f;
|
||||
if (newVal.Equals(_flatten)) return;
|
||||
_flatten = newVal;
|
||||
_flattenText.text = _flatten.ToString(CultureInfo.InvariantCulture);
|
||||
__instance.SetStarmapGalaxy();
|
||||
});
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(UIGalaxySelect), "_OnUnregEvent")]
|
||||
private static void PatchGalaxyUI_OnUnregEvent(UIGalaxySelect __instance)
|
||||
{
|
||||
_minDistSlider.onValueChanged.RemoveAllListeners();
|
||||
_minStepSlider.onValueChanged.RemoveAllListeners();
|
||||
_maxStepSlider.onValueChanged.RemoveAllListeners();
|
||||
_flattenSlider.onValueChanged.RemoveAllListeners();
|
||||
}
|
||||
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(UIGalaxySelect), "OnStarCountSliderValueChange")]
|
||||
static IEnumerable<CodeInstruction> PatchStarCountOnValueChange(IEnumerable<CodeInstruction> instructions)
|
||||
{
|
||||
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), "_maxStarCount"));
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return instruction;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[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<CodeInstruction> PatchCreateGalaxy(IEnumerable<CodeInstruction> 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), "_minStep"));
|
||||
yield return new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(UniverseGenTweaks), "_maxStep"));
|
||||
yield return new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(UniverseGenTweaks), "_flatten"));
|
||||
}
|
||||
yield return instruction;
|
||||
}
|
||||
}
|
||||
|
||||
/* Patch `rand() * (maxStepLen - minStepLen) + minDist` to `rand() * (maxStepLen - minStepLen) + minStepLen`,
|
||||
this should be a bugged line in original game code. */
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(UniverseGen), "RandomPoses")]
|
||||
static IEnumerable<CodeInstruction> PatchUniverGenRandomPoses(IEnumerable<CodeInstruction> instructions)
|
||||
{
|
||||
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;
|
||||
EpicDifficulty.Init();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
<AssemblyName>UniverseGenTweaks</AssemblyName>
|
||||
<BepInExPluginGuid>org.soardev.universegentweaks</BepInExPluginGuid>
|
||||
<Description>DSP MOD - UniverseGenTweaks</Description>
|
||||
<Version>1.0.0</Version>
|
||||
<Version>1.1.0</Version>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<LangVersion>latest</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "UniverseGenTweaks",
|
||||
"version_number": "1.0.0",
|
||||
"version_number": "1.1.0",
|
||||
"website_url": "https://github.com/soarqin/DSP_Mods/tree/master/UniverseGenTweaks",
|
||||
"description": "Universe Generator Tweaks / 宇宙生成参数调节",
|
||||
"description": "Universe Generation Tweaks / 宇宙生成参数调节",
|
||||
"dependencies": [
|
||||
"xiaoye97-BepInEx-5.4.17"
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user