Skip to content

Commit 1b5d1d0

Browse files
committed
Structuring and Cleanup
1 parent 8b7fb20 commit 1b5d1d0

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

DSP_AssemblerUI/AssemblerSpeedUI/AssemblerSpeedUIMod.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using HarmonyLib;
44
using System;
55
using System.Collections.Generic;
6+
using System.Diagnostics;
67
using System.Linq;
78
using System.Reflection;
89
using System.Reflection.Emit;
@@ -19,6 +20,7 @@ namespace DSP_AssemblerUI.AssemblerSpeedUI
1920
[BepInPlugin("dsp.assemblerUI.speedMod", "Assembler UI Speed Info Mod", "1.0.0.0")]
2021
public class AssemblerSpeedUIMod : BaseUnityPlugin
2122
{
23+
#region Main Plugin
2224
public new static ManualLogSource Logger;
2325

2426
internal void Awake()
@@ -31,8 +33,14 @@ internal void Awake()
3133
Harmony.CreateAndPatchAll(typeof(AssemblerSpeedUIMod));
3234
}
3335

36+
[Conditional("DEBUG")]
37+
static void DebugLog(string logMessage)
38+
{
39+
Logger.LogDebug(logMessage);
40+
}
41+
#endregion
3442

35-
43+
#region Patcher
3644
internal class ItemSpeedInfoLabel
3745
{
3846
public GameObject gameObject;
@@ -134,9 +142,9 @@ public static void AddSpeedLabel(string id, int num, int ofNum)
134142
public static void PositionSpeedLabel(GameObject gameObject, int num, int ofNum)
135143
{
136144

137-
Logger.LogDebug($"OgPosition:{gameObject.transform.localPosition}");
145+
DebugLog($"OgPosition:{gameObject.transform.localPosition}");
138146
Vector3 shiftVector = getPosShift(num, ofNum);
139-
Logger.LogDebug($"ShiftedBy:{shiftVector}");
147+
DebugLog($"ShiftedBy:{shiftVector}");
140148

141149
gameObject.transform.localPosition = ogPos.Value + shiftVector;
142150
}
@@ -164,15 +172,15 @@ public static void UpdateSpeedLabels(float baseSpeed, int[] productCounts)
164172
[HarmonyTranspiler, HarmonyPatch(typeof(UIAssemblerWindow), "_OnUpdate")]
165173
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
166174
{
167-
Logger.LogDebug("UiTextTranspiler started!");
175+
DebugLog("UiTextTranspiler started!");
168176
CodeMatcher matcher = new CodeMatcher(instructions);
169177
//find -->
170178
//ldloc.s 18
171179
//ldloc.s 19
172180
//mul
173181
//stloc.s 18
174182
//<-- endFind
175-
Logger.LogDebug($"UiTextTranspiler Matcher Codes Count: {matcher.Instructions().Count}, Matcher Pos: {matcher.Pos}!");
183+
DebugLog($"UiTextTranspiler Matcher Codes Count: {matcher.Instructions().Count}, Matcher Pos: {matcher.Pos}!");
176184
matcher.MatchForward(
177185
true,
178186
new CodeMatch(i => i.opcode == OpCodes.Ldloc_S && i.operand is LocalBuilder lb && lb.LocalIndex == 18),
@@ -181,15 +189,15 @@ public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructio
181189
new CodeMatch(i => i.opcode == OpCodes.Stloc_S && i.operand is LocalBuilder lb && lb.LocalIndex == 18)
182190
);
183191

184-
Logger.LogDebug($"UiTextTranspiler Matcher Codes Count: {matcher.Instructions().Count}, Matcher Pos: {matcher.Pos}!");
192+
DebugLog($"UiTextTranspiler Matcher Codes Count: {matcher.Instructions().Count}, Matcher Pos: {matcher.Pos}!");
185193
matcher.Advance(1); //move from last match to next element
186194
//insert-->
187195
//ldloc.s 18
188196
//ldloca.s 0 //AssemblerComponent local var
189197
//ldfld int32[] AssemblerComponent::productCounts
190198
//call update
191199
//<-- endInsert
192-
Logger.LogDebug($"UiTextTranspiler Matcher Codes Count: {matcher.Instructions().Count}, Matcher Pos: {matcher.Pos}!");
200+
DebugLog($"UiTextTranspiler Matcher Codes Count: {matcher.Instructions().Count}, Matcher Pos: {matcher.Pos}!");
193201
matcher.InsertAndAdvance(
194202
new CodeInstruction(OpCodes.Ldloc_S, (byte)18),
195203
new CodeInstruction(OpCodes.Ldloca_S, (byte)0),
@@ -199,5 +207,6 @@ public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructio
199207

200208
return matcher.InstructionEnumeration();
201209
}
210+
#endregion
202211
}
203212
}

0 commit comments

Comments
 (0)