Skip to content

Commit f0334a2

Browse files
committed
Update v1.2.0 - planning speeds
Option to either display live or default device speed.
1 parent 3743f95 commit f0334a2

File tree

3 files changed

+76
-9
lines changed

3 files changed

+76
-9
lines changed

DSP_AssemblerUI/AssemblerSpeedUI/AssemblerSpeedUIMod.cs

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static class ModInfo
2323
public const string ModID = "dsp.assemblerUI.speedMod";
2424
public const string ModName = "Assembler UI Speed Info Mod";
2525
public const string majorVersion = "1";
26-
public const string minorVersion = "1";
26+
public const string minorVersion = "2";
2727
public const string hotfixVersion = "0";
2828
public const string buildVersion = "0";
2929
public const string VersionString = majorVersion + "." + minorVersion + "." + hotfixVersion + "." + buildVersion;
@@ -39,6 +39,7 @@ public class AssemblerSpeedUIMod : BaseUnityPlugin
3939

4040
public static ConfigEntry<bool> configEnableOutputSpeeds;
4141
public static ConfigEntry<bool> configEnableInputSpeeds;
42+
public static ConfigEntry<bool> configShowLiveSpeed;
4243

4344
internal void Awake()
4445
{
@@ -48,6 +49,7 @@ internal void Awake()
4849

4950
configEnableOutputSpeeds = Config.Bind("General", "EnableOutputSpeedInfo", true, "Enables the speed information below the output area in the Assembler Window.");
5051
configEnableInputSpeeds = Config.Bind("General", "EnableInputSpeedInfo", true, "Enables the speed information above the input area in the Assembler Window.");
52+
configShowLiveSpeed = Config.Bind("General", "ShowLiveSpeedInfo", true, "True: shows current speed of production building. False: shows regular recipe speed of production building.");
5153

5254
harmony = new Harmony(ModInfo.ModID);
5355
try
@@ -338,17 +340,61 @@ public static void UpdateSpeedLabels(float baseSpeed, int[] productCounts, int[]
338340

339341

340342
[HarmonyTranspiler, HarmonyPatch(typeof(UIAssemblerWindow), "_OnUpdate")]
341-
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
343+
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator codeGen)
342344
{
345+
//declare local variable to keep our calculation base speed in
346+
LocalBuilder baseSpeedValue = codeGen.DeclareLocal(typeof(float));
347+
baseSpeedValue.SetLocalSymInfo("baseSpeedValue");
348+
349+
//define label we later use for a branching instruction. label location is set separately
350+
Label noLiveData = codeGen.DefineLabel();
351+
343352
DebugLog("UiTextTranspiler started!");
344353
CodeMatcher matcher = new CodeMatcher(instructions);
354+
DebugLog($"UiTextTranspiler Matcher Codes Count: {matcher.Instructions().Count}, Matcher Pos: {matcher.Pos}!");
355+
356+
//find -->
357+
//ldc.r4 60
358+
//ldloc.s 17
359+
//div
360+
//stloc.s 18
361+
//<-- endFind
362+
matcher.MatchForward(
363+
true,
364+
new CodeMatch(i => i.opcode == OpCodes.Ldc_R4 && i.OperandIs(60f)),
365+
new CodeMatch(i => i.opcode == OpCodes.Ldloc_S && i.operand is LocalBuilder lb && lb.LocalIndex == 17),
366+
new CodeMatch(OpCodes.Div),
367+
new CodeMatch(i => i.opcode == OpCodes.Stloc_S && i.operand is LocalBuilder lb && lb.LocalIndex == 18)
368+
);
369+
matcher.Advance(1); //move from last match to next element
370+
371+
//insert-->
372+
//ldloc.s 18
373+
//ldloca.s 0 //AssemblerComponent local var
374+
//ldfld int32 AssemblerComponent::speed
375+
//conv.r4
376+
//ldc.r4 0.0001
377+
//mul
378+
//mul
379+
//stloc baseSpeedValue
380+
//<-- endInsert
381+
matcher.InsertAndAdvance(
382+
new CodeInstruction(OpCodes.Ldloc_S, (byte)18), //Load base speed without power
383+
new CodeInstruction(OpCodes.Ldloca_S, (byte)0),
384+
new CodeInstruction(OpCodes.Ldfld, typeof(AssemblerComponent).GetField("speed")),
385+
new CodeInstruction(OpCodes.Conv_R4),
386+
new CodeInstruction(OpCodes.Ldc_R4, 0.0001f),
387+
new CodeInstruction(OpCodes.Mul), //scale device speed to usable factor (0.0001 * speed)
388+
new CodeInstruction(OpCodes.Mul), //multiply base (mk2) speed with factor
389+
new CodeInstruction(OpCodes.Stloc_S, baseSpeedValue) //load value of config option
390+
);
391+
345392
//find -->
346393
//ldloc.s 18
347394
//ldloc.s 19
348395
//mul
349396
//stloc.s 18
350397
//<-- endFind
351-
DebugLog($"UiTextTranspiler Matcher Codes Count: {matcher.Instructions().Count}, Matcher Pos: {matcher.Pos}!");
352398
matcher.MatchForward(
353399
true,
354400
new CodeMatch(i => i.opcode == OpCodes.Ldloc_S && i.operand is LocalBuilder lb && lb.LocalIndex == 18),
@@ -359,17 +405,33 @@ public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructio
359405

360406
DebugLog($"UiTextTranspiler Matcher Codes Count: {matcher.Instructions().Count}, Matcher Pos: {matcher.Pos}!");
361407
matcher.Advance(1); //move from last match to next element
408+
409+
//Create code instruction with target label for Brfalse
410+
CodeInstruction labelledInstruction = new CodeInstruction(OpCodes.Ldloc_S, baseSpeedValue);
411+
labelledInstruction.labels.Add(noLiveData);
412+
362413
//insert-->
363-
//ldloc.s 18
414+
//ldsfld ConfigEntry<bool> AssemblerSpeedUIMod.configShowLiveSpeed
415+
//callvirt int32 get_Value //or something like this. just run the getter of the Value Property
416+
//brfalse noLiveData //if Value is false, branch to the labelledInstruction
417+
//ldloc.s 18 //load calculated base speed incl. power
418+
//stloc.s baseSpeedValue //use that as calculation base
419+
420+
//ldloc.s baseSpeedValue, label noLiveData
364421
//ldloca.s 0 //AssemblerComponent local var
365422
//ldfld int32[] AssemblerComponent::productCounts
366423
//ldloca.s 0 //AssemblerComponent local var
367424
//ldfld int32[] AssemblerComponent::requireCounts
368425
//call update
369426
//<-- endInsert
370-
DebugLog($"UiTextTranspiler Matcher Codes Count: {matcher.Instructions().Count}, Matcher Pos: {matcher.Pos}!");
371427
matcher.InsertAndAdvance(
372-
new CodeInstruction(OpCodes.Ldloc_S, (byte)18), //Load base speed on stack
428+
new CodeInstruction(OpCodes.Ldsfld, typeof(AssemblerSpeedUIMod).GetField("configShowLiveSpeed")), //Load config option
429+
new CodeInstruction(OpCodes.Callvirt, typeof(ConfigEntry<bool>).GetProperty("Value").GetGetMethod()), //load value of config option
430+
new CodeInstruction(OpCodes.Brfalse, noLiveData), //branch the speed loading (labelledInstruction) if setting is false
431+
new CodeInstruction(OpCodes.Ldloc_S, (byte)18),
432+
new CodeInstruction(OpCodes.Stloc_S, baseSpeedValue),
433+
434+
labelledInstruction, //Load base speed on stack
373435
new CodeInstruction(OpCodes.Ldloca_S, (byte)0),
374436
new CodeInstruction(OpCodes.Ldfld, typeof(AssemblerComponent).GetField("productCounts")), //load product counts array on stack
375437
new CodeInstruction(OpCodes.Ldloca_S, (byte)0),

DSP_AssemblerUI/Properties/AssemblyInfo.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Reflection;
1+
using DSP_AssemblerUI.AssemblerSpeedUI;
2+
using System.Reflection;
23
using System.Runtime.CompilerServices;
34
using System.Runtime.InteropServices;
45

@@ -32,5 +33,5 @@
3233
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
3334
// indem Sie "*" wie unten gezeigt eingeben:
3435
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.1.0.0")]
36-
[assembly: AssemblyFileVersion("1.1.0.0")]
36+
[assembly: AssemblyVersion(ModInfo.VersionString)]
37+
[assembly: AssemblyFileVersion(ModInfo.VersionString)]

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77

88
The speed info for both input and output can be disabled, should you prefer not showing one of them.
99
Or both of them - even though I don't understand why you would install this mod in the first place then...
10+
11+
You can also decide whether you want to display the speed with which the device currently creates or consumes resources,
12+
or if you want to display the recipe speed for the device without impact of power and full or empty slots.
1013

1114

1215
## Version History
1316
- v1.0.0 First Version. Shows Production Speeds below Items.
1417
- v1.1.0 Updated to also show input consumption speeds. Added configuration to enable/disable input and output speeds separately.
18+
- v1.2.0 Added a config option to configure whether to always show the full speed of the selected recipe or whether to show the current live speed (affected by power for example)

0 commit comments

Comments
 (0)