Skip to content

Commit

Permalink
Update Code
Browse files Browse the repository at this point in the history
  • Loading branch information
Awbugl committed Dec 25, 2022
1 parent 3ff7aa2 commit c440b3e
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 7 deletions.
2 changes: 2 additions & 0 deletions ProjectGenesis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<Compile Include="src\Patches\DisplayedTextPatches.cs" />
<Compile Include="src\Patches\FluidColorPatches.cs" />
<Compile Include="src\Patches\GridIndexExpandPatches.cs" />
<Compile Include="src\Patches\InitnalTechPatches.cs" />
<Compile Include="src\Patches\MegaAssemblerPatches.cs" />
<Compile Include="src\Patches\MegaPumpPatches.cs" />
<Compile Include="src\Patches\MultiProductionPatches.cs" />
Expand All @@ -111,6 +112,7 @@
<Compile Include="src\Utils\ItemData.cs" />
<Compile Include="src\Utils\JsonDataUtils.cs" />
<Compile Include="src\Utils\JsonHelper.cs" />
<Compile Include="src\Utils\LDBToolCacheUtils.cs" />
<Compile Include="src\Utils\MutliPlayerPacket.cs" />
<Compile Include="src\Utils\PrefabFixUtils.cs" />
<Compile Include="src\Utils\TranslateUtils.cs" />
Expand Down
2 changes: 2 additions & 0 deletions ProjectGenesis.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=LDB/@EntryIndexedValue">LDB</s:String></wpf:ResourceDictionary>
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ Reconstruct "Real Universe". Then leave a "GenesisBook".

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

- v2.2.10
+ 修复了复制未建成建筑时偶尔出现的报错

+ Fixed the error that occasionally occurred when copying the uncompleted building


- v2.2.9
+ 下调了量子芯片的科技需求
+ 调整了蓄电器和能量枢纽的输出功率与蓄电量
Expand All @@ -29,12 +35,6 @@ Reconstruct "Real Universe". Then leave a "GenesisBook".
correctly
+ Fixed the problem that the highlight color was displayed incorrectly when selecting the conveyor belt


- v2.2.8
+ 修改了部分配方的时间和产出(总产出不变)

+ Changed the time and output of some recipes (No change in total output)

----

<details>
Expand Down Expand Up @@ -114,6 +114,10 @@ Reconstruct "Real Universe". Then leave a "GenesisBook".
<details>
<summary>展开查看</summary>

- v2.2.10
+ 修复了复制未建成建筑时偶尔出现的报错


- v2.2.9
+ 下调了量子芯片的科技需求
+ 调整了蓄电器和能量枢纽的输出功率与蓄电量
Expand Down Expand Up @@ -327,6 +331,10 @@ free to communicate with us.
<details>
<summary>Details</summary>

- v2.2.10
+ Fixed the error that occasionally occurred when copying the uncompleted building


- v2.2.9
+ Adjusted the technology requirements of quantum chips
+ Adjusted the output power and storage capacity of capacitors and energy hubs
Expand Down
49 changes: 49 additions & 0 deletions src/Patches/InitnalTechPatches.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Reflection.Emit;
using HarmonyLib;

// ReSharper disable InconsistentNaming

namespace ProjectGenesis.Patches
{
public static class InitnalTechPatches
{
private static readonly List<int> InitnalTechs = new List<int>()
{
1,
1001,
1901,
1902,
1903,
1904,
1905
};

[HarmonyPatch(typeof(GameData), "SetForNewGame")]
[HarmonyPostfix]
public static void SetForNewGame(GameData __instance)
{
foreach (var tech in InitnalTechs) __instance.history.UnlockTech(tech);
}

[HarmonyPatch(typeof(UITechNode), "DoBuyoutTech")]
[HarmonyPatch(typeof(UITechNode), "DoStartTech")]
[HarmonyPatch(typeof(UITechNode), "OnPointerEnter")]
[HarmonyPatch(typeof(UITechNode), "OnPointerExit")]
[HarmonyPatch(typeof(UITechNode), "OnPointerDown")]
[HarmonyPatch(typeof(UITechNode), "OnOtherIconClick")]
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> UITechNode_Transpiler(IEnumerable<CodeInstruction> instructions)
{
var matcher = new CodeMatcher(instructions);
matcher.MatchForward(true, new CodeMatch(OpCodes.Ldarg_0),
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(UITechNode), nameof(UITechNode.techProto))),
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(Proto), nameof(Proto.ID))), new CodeMatch(OpCodes.Ldc_I4_1));

matcher.SetInstructionAndAdvance(Transpilers.EmitDelegate<Func<int, bool>>(id => InitnalTechs.Contains(id)));
matcher.SetOpcodeAndAdvance(OpCodes.Brfalse_S);
return matcher.InstructionEnumeration();
}
}
}
7 changes: 6 additions & 1 deletion src/ProjectGenesis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ public class ProjectGenesis : BaseUnityPlugin, IModCanSave, IMultiplayerModWithS
{
public const string MODGUID = "org.LoShin.GenesisBook";
internal const string MODNAME = "GenesisBook";
internal const string VERSION = "2.2.9";
internal const string VERSION = "2.2.10";

// ReSharper disable once MemberCanBePrivate.Global
internal static ManualLogSource logger;

//无限堆叠开关(私货)
private readonly bool StackSizeButton = false;

//清除LDB缓存
private readonly bool DebugMode = true;

private int[] TableID;

Expand Down Expand Up @@ -83,6 +86,8 @@ public void Awake()

foreach (var type in executingAssembly.GetTypes()) Harmony.PatchAll(type);

if (DebugMode) LDBToolCacheUtils.Clear();

LDBTool.PreAddDataAction += PreAddDataAction;
LDBTool.PostAddDataAction += PostAddDataAction;
}
Expand Down
20 changes: 20 additions & 0 deletions src/Utils/LDBToolCacheUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using BepInEx.Configuration;
using HarmonyLib;
using xiaoye97;

namespace ProjectGenesis.Utils
{
internal static class LDBToolCacheUtils
{
internal static void Clear()
{
ClearConfigFile("CustomID");
ClearConfigFile("CustomGridIndex");
ClearConfigFile("CustomStringZHCN");
ClearConfigFile("CustomStringENUS");
ClearConfigFile("CustomStringFRFR");
}

private static void ClearConfigFile(string name) => AccessTools.StaticFieldRefAccess<ConfigFile>(typeof(LDBTool), name).Clear();
}
}

0 comments on commit c440b3e

Please sign in to comment.