Skip to content

Commit

Permalink
Update 2.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Awbugl committed Jan 14, 2023
1 parent aa402a1 commit 2250950
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 35 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,25 @@ Construct Real Universe. Then leave a GenesisBook.
![img.png](https://assets.awbugl.top/dsp-genesisbook/3.jpg)
![img.png](https://assets.awbugl.top/dsp-genesisbook/4.jpg)

### 不兼容的MOD | Incompatible MODs

+ [TheyComeFromVoid](https://dsp.thunderstore.io/package/ckcz123/TheyComeFromVoid/)
+ [GalacticScale](https://dsp.thunderstore.io/package/Galactic_Scale/GalacticScale)


- 加载以上MOD时,不会加载本MOD。
- When loading the above MOD, this MOD will not be loaded.

### 最近更新介绍 | Recent update

- v2.4.2
+ 修复了与`BlueprintTweaks` mod的兼容性问题
+ 确定与`TheyComeFromVoid``GalacticScale`不兼容且无法修复,在加载上述mod时不会加载本mod

+ Fixed compatibility with `BlueprintTweaks` mod
+ Explicitly incompatible with `TheyComeFromVoid` and `GalacticScale`, will not load when loading the above mods


- v2.4.1
+ 修复了二氧化碳还原配方需求错误的问题
+ 移除了戈壁星球的硝酸海洋(仅在新存档生效)
Expand Down Expand Up @@ -126,6 +143,11 @@ Construct Real Universe. Then leave a GenesisBook.
<details>
<summary>展开查看</summary>

- v2.4.2
+ 修复了与`BlueprintTweaks` mod的兼容性问题
+ 确定与`TheyComeFromVoid``GalacticScale`不兼容且无法修复,在加载上述mod时不会加载本mod


- v2.4.1
+ 修复了二氧化碳还原配方需求错误的问题
+ 移除了戈壁星球的硝酸海洋(仅在新存档生效)
Expand Down Expand Up @@ -389,6 +411,11 @@ free to communicate with us.
<details>
<summary>Details</summary>

- v2.4.2
+ Fixed compatibility with `BlueprintTweaks` mod
+ Explicitly incompatible with `TheyComeFromVoid` and `GalacticScale`, will not load when loading the above mods


- v2.4.1
+ Fixed the problem that the carbon dioxide reduction formula requirement was wrong
+ Removed the nitric acid ocean of Gobi planet (only effective in new archives)
Expand Down
15 changes: 9 additions & 6 deletions src/Patches/PlanetGasPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace ProjectGenesis.Patches
public static class PlanetGasPatches
{
private static readonly FieldInfo StationComponent_IsCollector_Field = AccessTools.Field(typeof(StationComponent), "isCollector");
private static readonly FieldInfo PlanetData_GasInfo_Field = AccessTools.Field(typeof(PlanetData), "gasItems");
private static readonly FieldInfo PlanetData_GasItems_Field = AccessTools.Field(typeof(PlanetData), "gasItems");

[HarmonyPatch(typeof(UIPlanetDetail), "OnPlanetDataSet")]
[HarmonyTranspiler]
Expand Down Expand Up @@ -53,10 +53,12 @@ public static IEnumerable<CodeInstruction> PlanetGen_SetPlanetTheme_Transpiler(I
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> BuildTool_Blueprint_DetermineActive_Transpiler(IEnumerable<CodeInstruction> instructions)
{
if (ProjectGenesis.BlueprintTweaksInstalled) return instructions;

var matcher = new CodeMatcher(instructions).MatchForward(true, new CodeMatch(OpCodes.Ldarg_0),
new CodeMatch(OpCodes.Ldfld,
AccessTools.Field(typeof(BuildTool), nameof(BuildTool.planet))),
new CodeMatch(OpCodes.Ldfld, PlanetData_GasInfo_Field));
new CodeMatch(OpCodes.Ldfld, PlanetData_GasItems_Field));

matcher.SetOperandAndAdvance(AccessTools.Field(typeof(PlanetData), "type"));
matcher.InsertAndAdvance(new CodeInstruction(OpCodes.Ldc_I4_5));
Expand All @@ -76,12 +78,14 @@ public static IEnumerable<CodeInstruction> BuildTool_Blueprint_DetermineActive_T
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> PlayerController_OpenBlueprintMode_Transpiler(IEnumerable<CodeInstruction> instructions)
{
if (ProjectGenesis.BlueprintTweaksInstalled) return instructions;

var matcher = new CodeMatcher(instructions).MatchForward(true, new CodeMatch(OpCodes.Ldarg_0),
new CodeMatch(OpCodes.Ldfld,
AccessTools.Field(typeof(PlayerController), "gameData")),
new CodeMatch(OpCodes.Callvirt,
AccessTools.PropertyGetter(typeof(GameData), "localPlanet")),
new CodeMatch(OpCodes.Ldfld, PlanetData_GasInfo_Field));
new CodeMatch(OpCodes.Ldfld, PlanetData_GasItems_Field));

matcher.SetOperandAndAdvance(AccessTools.Field(typeof(PlanetData), "type"));

Expand Down Expand Up @@ -194,13 +198,12 @@ public static IEnumerable<CodeInstruction> SetOutputEntity_Transpiler(IEnumerabl
var label = matcher.Advance(2).Operand;
var is_S = matcher.Opcode == OpCodes.Brfalse_S;

matcher.Advance(1).InsertAndAdvance(new CodeInstruction(comp),
new CodeInstruction(OpCodes.Ldfld, StationComponent_IsCollector_Field),
matcher.Advance(1).InsertAndAdvance(new CodeInstruction(comp), new CodeInstruction(OpCodes.Ldfld, StationComponent_IsCollector_Field),
new CodeInstruction(is_S ? OpCodes.Brtrue_S : OpCodes.Brtrue, label));

return matcher.InstructionEnumeration();
}

[HarmonyPatch(typeof(StationComponent), "Init")]
[HarmonyPostfix]
public static void StationComponent_Init_Postfix(StationComponent __instance)
Expand Down
20 changes: 17 additions & 3 deletions src/ProjectGenesis.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -33,15 +34,19 @@ namespace ProjectGenesis
[BepInDependency(CommonAPIPlugin.GUID)]
[BepInDependency(LDBToolPlugin.MODGUID)]
[BepInDependency(NebulaModAPI.API_GUID)]
[BepInDependency(BlueprintTweaks_GUID, BepInDependency.DependencyFlags.SoftDependency)]
[BepInIncompatibility(GalacticScale_GUID)]
[BepInIncompatibility(DSPBattle_GUID)]

[CommonAPISubmoduleDependency(nameof(ProtoRegistry), nameof(CustomDescSystem), nameof(TabSystem), nameof(AssemblerRecipeSystem))]
public class ProjectGenesis : BaseUnityPlugin, IModCanSave, IMultiplayerModWithSettings
{
public const string MODGUID = "org.LoShin.GenesisBook";
public const string MODNAME = "GenesisBook";
public const string VERSION = "2.4.1";
public const string VERSION = "2.4.2";

public string Version => VERSION;

internal static ManualLogSource logger;

//无限堆叠开关(私货)
Expand All @@ -50,6 +55,11 @@ public class ProjectGenesis : BaseUnityPlugin, IModCanSave, IMultiplayerModWithS
private int[] TableID;
private Harmony Harmony;

internal static bool BlueprintTweaksInstalled;
private const string BlueprintTweaks_GUID = "org.kremnev8.plugin.BlueprintTweaks",
GalacticScale_GUID = "dsp.galactic-scale.2",
DSPBattle_GUID = "com.ckcz123.DSP_Battle";

public void Awake()
{
logger = Logger;
Expand All @@ -61,6 +71,10 @@ public void Awake()
resources.LoadAssetBundle("texpack");
ProtoRegistry.AddResource(resources);

Dictionary<string, PluginInfo> pluginInfos = BepInEx.Bootstrap.Chainloader.PluginInfos;

BlueprintTweaksInstalled = pluginInfos.ContainsKey(BlueprintTweaks_GUID);

TableID = new int[]
{
TabSystem.RegisterTab("org.LoShin.GenesisBook:org.LoShin.GenesisBookTab1",
Expand Down
61 changes: 35 additions & 26 deletions src/Utils/PlanetThemeUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.Linq;

// ReSharper disable LoopCanBePartlyConvertedToQuery

namespace ProjectGenesis.Utils
{
internal static class PlanetThemeUtils
Expand Down Expand Up @@ -35,7 +37,9 @@ internal static void AdjustPlanetThemeData()

foreach (var theme in LDB.themes.dataArray)
{
if (theme.ID == 1)
if (theme.PlanetType == EPlanetType.Gas) continue;

if (theme.Distribute == EThemeDistribute.Birth)
{
theme.RareVeins = new[] { 8 };
theme.RareSettings = new float[] { 1.0f, 0.5f, 0.0f, 0.4f };
Expand All @@ -48,40 +52,45 @@ internal static void AdjustPlanetThemeData()
? new float[] { theme.Wind * 0.7f }
: new float[] { theme.Wind * 0.7f, theme.Wind * 0.18f };
}
else if (theme.PlanetType != EPlanetType.Gas && theme.GasItems == null)
else if (theme.Wind == 0 || theme.GasItems == null)
{
theme.GasItems = Array.Empty<int>();
theme.GasSpeeds = Array.Empty<float>();
}

if (theme.VeinSpot.Length > 2)
{
ref var silicon = ref theme.VeinSpot[2];
AdjustVeins(theme);
}
}

if (silicon > 0)
{
silicon = 1 + silicon / 4;
theme.VeinCount[2] = 0.5f;
theme.VeinOpacity[2] = 0.5f;
}
}
private static void AdjustVeins(ThemeProto theme)
{
if (theme.VeinSpot.Length > 2)
{
ref var silicon = ref theme.VeinSpot[2];

if (theme.VeinSpot.Length > 5)
if (silicon > 0)
{
ref var coal = ref theme.VeinSpot[5];
silicon = 1 + silicon / 4;
theme.VeinCount[2] = 0.5f;
theme.VeinOpacity[2] = 0.5f;
}
}

if (theme.VeinSpot.Length > 5)
{
ref var coal = ref theme.VeinSpot[5];

if (!theme.GasItems.Contains(7019))
{
coal = 0;
theme.VeinCount[5] = 0f;
theme.VeinOpacity[5] = 0f;
}
else
{
coal += 1;
theme.VeinCount[5] *= 1.25f;
theme.VeinOpacity[5] *= 1.25f;
}
if (!theme.GasItems.Contains(7019))
{
coal = 0;
theme.VeinCount[5] = 0f;
theme.VeinOpacity[5] = 0f;
}
else
{
coal += 1;
theme.VeinCount[5] *= 1.25f;
theme.VeinOpacity[5] *= 1.25f;
}
}
}
Expand Down

0 comments on commit 2250950

Please sign in to comment.