Skip to content

Commit 965304f

Browse files
committed
Create UIPlanetShieldDetailPatches.cs
1 parent c8a7a0a commit 965304f

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Reflection.Emit;
4+
using HarmonyLib;
5+
6+
namespace ProjectGenesis.Patches
7+
{
8+
/// <summary>
9+
/// 护盾填充度显示由四舍五入调整为截断
10+
/// </summary>
11+
public static class UIPlanetShieldDetailPatches
12+
{
13+
[HarmonyTranspiler]
14+
[HarmonyPatch(typeof(UIPlanetShieldDetail), nameof(UIPlanetShieldDetail.Refresh))]
15+
[HarmonyPatch(typeof(UIZS_PlanetaryShieldInfo), nameof(UIZS_PlanetaryShieldInfo.Refresh))]
16+
[HarmonyPatch(typeof(UIFieldGeneratorWindow), nameof(UIFieldGeneratorWindow.Refresh))]
17+
public static IEnumerable<CodeInstruction> Refresh_Transpiler(IEnumerable<CodeInstruction> instructions)
18+
{
19+
var matcher = new CodeMatcher(instructions);
20+
21+
while (true)
22+
{
23+
matcher.MatchForward(true, new CodeMatch(OpCodes.Ldstr, "0.00%"), new CodeMatch(OpCodes.Call));
24+
25+
if (matcher.IsInvalid) break;
26+
27+
matcher.SetAndAdvance(OpCodes.Call, AccessTools.Method(typeof(UIPlanetShieldDetailPatches), nameof(TruncatePercent)));
28+
}
29+
30+
return matcher.InstructionEnumeration();
31+
}
32+
33+
public static string TruncatePercent(ref double value, string format)
34+
{
35+
var truncated = Math.Truncate(value * 10000.0) / 100.0;
36+
return truncated.ToString("0.00") + "%";
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)