1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2025-12-08 22:13:30 +08:00
This commit is contained in:
2024-01-03 19:26:31 +08:00
parent 9bdf25c407
commit 4fee747fdd
4 changed files with 202 additions and 70 deletions

View File

@@ -32,7 +32,7 @@ public class MoreSettings
private static Text _minStepText;
private static Text _maxStepText;
private static Text _flattenText;
private static Harmony _harmony;
private static Harmony _patch, _permanentPatch;
private static double _gameMinDist = 2;
private static double _gameMinStep = 2;
@@ -46,6 +46,9 @@ public class MoreSettings
I18N.Add("步进最大距离", "Step Distance Max", "步进最大距离");
I18N.Add("扁平度", "Flatness", "扁平度");
I18N.Apply();
_permanentPatch ??= Harmony.CreateAndPatchAll(typeof(PermanentPatch));
Enabled.SettingChanged += (_, _) => Enable(Enabled.Value);
Enable(Enabled.Value);
}
@@ -53,17 +56,20 @@ public class MoreSettings
public static void Uninit()
{
Enable(false);
_permanentPatch?.UnpatchSelf();
_permanentPatch = null;
}
private static void Enable(bool on)
{
if (on)
{
_harmony ??= Harmony.CreateAndPatchAll(typeof(MoreSettings));
_patch ??= Harmony.CreateAndPatchAll(typeof(MoreSettings));
return;
}
_harmony?.UnpatchSelf();
_harmony = null;
_patch?.UnpatchSelf();
_patch = null;
}
private static void CreateSliderWithText(Slider orig, out Text title, out Slider slider, out Text text, out Localizer loc)
@@ -218,74 +224,88 @@ public class MoreSettings
return matcher.InstructionEnumeration();
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(GalaxyData), MethodType.Constructor)]
private static IEnumerable<CodeInstruction> GalaxyData_Constructor_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
private static class PermanentPatch
{
// 25700 -> (MaxStarCount.Value + 1) * 100
var matcher = new CodeMatcher(instructions, generator);
matcher.MatchForward(false,
new CodeMatch(ci => ci.opcode == OpCodes.Ldc_I4 && ci.OperandIs(25700))
);
matcher.Repeat(m => m.SetAndAdvance(OpCodes.Ldsfld, 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();
}
private static void ResetSettings()
{
_gameMinDist = 2;
_gameMinStep = 2;
_gameMaxStep = 3.2;
_gameFlatten = 0.18;
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(SectorModel), nameof(SectorModel.CreateGalaxyAstroBuffer))]
[HarmonyPatch(typeof(SpaceColliderLogic), nameof(SpaceColliderLogic.UpdateCollidersPose))]
private static IEnumerable<CodeInstruction> SectorModel_CreateGalaxyAstroBuffer_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
// 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))
);
matcher.Repeat(m => m.SetAndAdvance(OpCodes.Ldsfld, 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();
}
[HarmonyPrefix]
[HarmonyPatch(typeof(GameData), nameof(GameData.Import))]
private static void GameData_Import_Prefix(GameData __instance)
{
ResetSettings();
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(UniverseGen), nameof(UniverseGen.CreateGalaxy))]
private static IEnumerable<CodeInstruction> UniverseGen_CreateGalaxy_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
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(_gameMinDist))),
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)))
);
return matcher.InstructionEnumeration();
}
[HarmonyPrefix]
[HarmonyPatch(typeof(GameData), nameof(GameData.SetForNewGame))]
private static void GameData_SetForNewGame_Prefix(GameData __instance)
{
if (Enabled.Value) return;
ResetSettings();
}
/* 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> UniverseGen_RandomPoses_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
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();
[HarmonyTranspiler]
[HarmonyPatch(typeof(GalaxyData), MethodType.Constructor)]
private static IEnumerable<CodeInstruction> GalaxyData_Constructor_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
// 25700 -> 102500
var matcher = new CodeMatcher(instructions, generator);
matcher.MatchForward(false,
new CodeMatch(ci => ci.opcode == OpCodes.Ldc_I4 && ci.OperandIs(25700))
);
matcher.Repeat(m => m.SetAndAdvance(OpCodes.Ldc_I4, 102500));
return matcher.InstructionEnumeration();
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(SectorModel), nameof(SectorModel.CreateGalaxyAstroBuffer))]
[HarmonyPatch(typeof(SpaceColliderLogic), nameof(SpaceColliderLogic.UpdateCollidersPose))]
private static IEnumerable<CodeInstruction> SectorModel_CreateGalaxyAstroBuffer_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
// 25600 -> 102500
var matcher = new CodeMatcher(instructions, generator);
matcher.MatchForward(false,
new CodeMatch(ci => ci.opcode == OpCodes.Ldc_I4 && ci.OperandIs(25600))
);
matcher.Repeat(m => m.SetAndAdvance(OpCodes.Ldc_I4, 102500));
return matcher.InstructionEnumeration();
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(UniverseGen), nameof(UniverseGen.CreateGalaxy))]
private static IEnumerable<CodeInstruction> UniverseGen_CreateGalaxy_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
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(_gameMinDist))),
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)))
);
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> UniverseGen_RandomPoses_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
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();
}
}
[HarmonyPrefix]
@@ -665,6 +685,110 @@ public class MoreSettings
__instance.propertyMultiplierText.text = "元数据生成倍率".Translate() + " " + gameDesc.propertyMultiplier.ToString("0%");
return false;
}
[HarmonyPrefix]
[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
{
< -0.1f => -0.2f,
< 0.25f => 0f,
< 0.75f => 0.5f,
< 1.5f => 0.75f,
< 2.5f => 0.875f,
_ => 1.125f
};
var initialLevelScore = __instance.initialLevel * 0.8f;
var initialGrowthScore = __instance.initialGrowth switch
{
< 0.15f => 0f,
< 0.3f => 0.25f,
< 0.65f => 0.5f,
< 0.8f => 0.75f,
< 1.15f => 1f,
< 1.65f => 1.25f,
< 2.15f => 1.5f,
< 2.65f => 1.75f,
< 3.15f => 2f,
< 3.65f => 2.25f,
_ => 2.5f
};
var initialColonizeScore = __instance.initialColonize switch
{
< 0.15f => 0f,
< 0.3f => 0.25f,
< 0.65f => 0.5f,
< 0.8f => 0.75f,
< 1.15f => 1f,
< 1.65f => 1.25f,
< 2.15f => 1.5f,
< 2.65f => 1.75f,
< 3.15f => 2f,
< 3.65f => 2.25f,
_ => 2.5f
};
var maxDensityScore = __instance.maxDensity - 1f;
var growthSpeedFactorScore = __instance.growthSpeedFactor switch
{
< 0.35f => 0.3f,
< 0.75f => 0.7f,
< 1.5f => 1f,
< 2.5f => 1.2f,
< 3.5f => 1.5f,
< 4.5f => 1.6f,
< 5.5f => 1.8f,
_ => 2f
};
var powerThreatFactorScore = __instance.powerThreatFactor switch
{
< 0.05f => 0.125f,
< 0.15f => 0.3f,
< 0.25f => 0.6f,
< 0.55f => 0.8f,
< 1.15f => 1f,
< 2.15f => 1.2f,
< 5.15f => 1.5f,
< 8.15f => 1.8f,
< 10.15f => 2f,
< 15.15f => 2.5f,
_ => 3f
};
var battleThreatFactorScore = __instance.battleThreatFactor switch
{
< 0.05f => 0.125f,
< 0.15f => 0.3f,
< 0.25f => 0.6f,
< 0.55f => 0.8f,
< 1.15f => 1f,
< 2.15f => 1.2f,
< 5.15f => 1.5f,
< 8.15f => 1.8f,
< 10.15f => 2f,
< 15.15f => 2.5f,
_ => 3f
};
var battleExpFactorScore = __instance.battleExpFactor switch
{
< 0.05f => 0f,
< 0.15f => 1f,
< 0.25f => 3f,
< 0.55f => 6f,
< 1.15f => 10f,
< 2.15f => 12f,
< 5.15f => 14f,
< 8.15f => 16f,
< 10.15f => 18f,
< 15.15f => 19f,
_ => 20f
};
var score1 = aggressivenessScore < 0f ? 0f : 0.25f + aggressivenessScore * (powerThreatFactorScore * 0.5f + battleThreatFactorScore * 0.5f);
var score2 = 0.375f + 0.625f * ((initialLevelScore + battleExpFactorScore) / 10f);
var score3 = 0.375f + 0.625f * ((initialColonizeScore * 0.6f + initialGrowthScore * 0.4f * (initialColonizeScore * 0.75f + 0.25f)) * 0.6f + growthSpeedFactorScore * 0.4f * (initialColonizeScore * 0.8f + 0.2f) + maxDensityScore * 0.29f * (initialColonizeScore * 0.5f + 0.5f));
__result = (int)(score1 * score2 * score3 * 10000f + 0.5f) / 10000f;
return false;
}
#endregion
#region ModSave

View File

@@ -4,6 +4,9 @@
#### 宇宙生成参数调节
## Changelog
* 1.2.6
+ Fix possible crash or wrong stars data when loading save file with changed generation settings but with `Enable more settings on UniverseGen` disabled on config window.
+ Larger maximum value in combat settings (except `Aggressiveness` and `Max Density`).
* 1.2.5
+ Thanks to [kremnev8](https://github.com/kremnev8)'s work on new version of [DSPModSave](https://dsp.thunderstore.io/package/CommonAPI/DSPModSave/), universe generation options are stored in save file now.
+ Fix text display issue on new game screen
@@ -32,6 +35,7 @@
* 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.
+ Larger maximum value in combat settings (except `Aggressiveness` and `Max Density`).
* Epic difficulty
* 0.01x resources and 0.25x oils (very hard difficulty has 0.5x oils).
* Same oil mining speed as very hard difficuly
@@ -41,6 +45,9 @@
* High luminosity for birth star
## 更新日志
* 1.2.6
+ 修复了在存档中更改了生成参数但是在配置面板中禁用了`启用更多宇宙生成设置`时可能崩溃或者星系数据错误的问题
+ 在星系生成时的战斗设置面板上提升了各选项的最大值(`黑雾攻击性``最大黑雾密度`除外`)
* 1.2.5
+ 感谢[kremnev8](https://github.com/kremnev8)对[DSPModSave](https://dsp.thunderstore.io/package/CommonAPI/DSPModSave/)的更新,现在宇宙生成选项会被保存到存档中
+ 修复新建游戏界面文本显示问题
@@ -69,6 +76,7 @@
* 生成宇宙时提供更多选项
+可以在配置文件中设置最大恒星数(默认128, 最多1024)
- 注意: 大量恒星会导致宇宙视图出现性能问题
+ 在星系生成时的战斗设置面板上提升了各选项的最大值(`黑雾攻击性`和`最大黑雾密度`除外`)
* 史诗难度
* 资源0.01倍油井储量0.25倍(极难是0.5倍)
* 采油速度和极难相同

View File

@@ -6,7 +6,7 @@
<AssemblyName>UniverseGenTweaks</AssemblyName>
<BepInExPluginGuid>org.soardev.universegentweaks</BepInExPluginGuid>
<Description>DSP MOD - UniverseGenTweaks</Description>
<Version>1.2.5</Version>
<Version>1.2.6</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.5",
"version_number": "1.2.6",
"website_url": "https://github.com/soarqin/DSP_Mods/tree/master/UniverseGenTweaks",
"description": "Universe Generation Tweaks / 宇宙生成参数调节",
"dependencies": [