diff --git a/1.3/Assemblies/VanillaPowerExpanded.dll b/1.3/Assemblies/VanillaPowerExpanded.dll index 244cf3b..4a91368 100644 Binary files a/1.3/Assemblies/VanillaPowerExpanded.dll and b/1.3/Assemblies/VanillaPowerExpanded.dll differ diff --git a/1.3/Source/VanillaPowerExpanded/VanillaPowerExpanded/GasNet/Comps/CompGasTrader_Buffer.cs b/1.3/Source/VanillaPowerExpanded/VanillaPowerExpanded/GasNet/Comps/CompGasTrader_Buffer.cs index 637e4df..0de2921 100644 --- a/1.3/Source/VanillaPowerExpanded/VanillaPowerExpanded/GasNet/Comps/CompGasTrader_Buffer.cs +++ b/1.3/Source/VanillaPowerExpanded/VanillaPowerExpanded/GasNet/Comps/CompGasTrader_Buffer.cs @@ -16,33 +16,27 @@ namespace GasNetwork public class CompGasTrader_Buffer : CompGasTrader { private static readonly StringBuilder sb = new StringBuilder(); - private bool bufferOff; - private float desired; - private float stored; + private bool bufferOff; + private float desired; + private float stored; public new CompProperties_GasTrader_Buffer Props => props as CompProperties_GasTrader_Buffer; - public bool HasFuel => stored > 0; - public float Fuel => stored; + public bool HasFuel => stored > 0; + public float Fuel => stored; public virtual Vector2 BarSize => new Vector2(1f, .16f); public override void PostSpawnSetup(bool respawningAfterLoad) { base.PostSpawnSetup(respawningAfterLoad); - if (!respawningAfterLoad) - { - desired = Props.maxBuffer; - } + if (!respawningAfterLoad) desired = Props.maxBuffer; } public void ConsumeFuel(float amount) { stored -= amount; - if (stored < 0) - { - stored = 0; - } + if (stored < 0) stored = 0; } public override void CompTick() @@ -52,22 +46,15 @@ public override void CompTick() if (GasOn) { stored += GasConsumptionPerTick; - if (stored > Props.maxBuffer) - { - stored = Props.maxBuffer; - } + if (stored > Props.maxBuffer) stored = Props.maxBuffer; } if (parent.IsHashIntervalTick(GenTicks.TicksPerRealSecond)) { if (bufferOff || stored >= desired) - { GasConsumption = 0; - } else - { GasConsumption = Props.gasConsumption; - } } } @@ -77,23 +64,16 @@ public override string CompInspectStringExtra() sb.AppendLine(base.CompInspectStringExtra()); sb.AppendLine(I18n.Stored(stored, Mathf.RoundToInt(Props.maxBuffer))); if (bufferOff) - { sb.AppendLine(I18n.BufferOff); - } else if (Math.Abs(desired - Props.maxBuffer) > Mathf.Epsilon) - { sb.AppendLine(I18n.DesiredBuffer(desired, Props.maxBuffer)); - } return sb.ToString().Trim(); } public override IEnumerable CompGetGizmosExtra() { - foreach (var gizmo in base.CompGetGizmosExtra()) - { - yield return gizmo; - } + foreach (var gizmo in base.CompGetGizmosExtra()) yield return gizmo; // TODO: Add buffer toggle gizmo. // TODO: Add buffer size gizmo. @@ -113,13 +93,13 @@ public override void PostDraw() base.PostDraw(); var barRequest = new GenDraw.FillableBarRequest { - center = parent.DrawPos + Vector3.up * .2f + Vector3.forward * .25f, - size = BarSize, + center = parent.DrawPos + Vector3.up * .2f + Vector3.forward * .25f, + size = BarSize, fillPercent = stored / Props.maxBuffer, - filledMat = Resources.GasBarFilledMaterial, + filledMat = Resources.GasBarFilledMaterial, unfilledMat = Resources.GasBarUnfilledMaterial, - margin = .1f, - rotation = parent.Rotation.Rotated(RotationDirection.Clockwise) + margin = .1f, + rotation = parent.Rotation.Rotated(RotationDirection.Clockwise) }; GenDraw.DrawFillableBar(barRequest); } @@ -131,9 +111,9 @@ public class Command_Buffer : Command public class CompProperties_GasTrader_Buffer : CompProperties_GasTrader { - public float maxBuffer = 125; - public bool showBufferSlider = true; - public bool showBufferToggle = true; + public float maxBuffer = 125; + public bool showBufferSlider = true; + public bool showBufferToggle = true; } [HarmonyPatch(typeof(CompLaunchable), nameof(CompLaunchable.FuelingPortSourceHasAnyFuel), MethodType.Getter)] @@ -151,15 +131,9 @@ public static bool Prefix(ref bool __result, CompLaunchable __instance) var fuelingPort = __instance.FuelingPortSource; if (fuelingPort != null) { - if (fuelingPort.TryGetComp(out var refuelable)) - { - __result = refuelable.HasFuel; - } - - if (fuelingPort.TryGetComp(out var buffer)) - { - __result |= buffer.HasFuel; - } + if (fuelingPort.TryGetComp(out var refuelable)) __result = refuelable.HasFuel; + + if (fuelingPort.TryGetComp(out var buffer)) __result |= buffer.HasFuel; } } @@ -178,13 +152,8 @@ public static bool Prefix(ref float __result, CompLaunchable __instance) { var fuelingPort = __instance.FuelingPortSource; if (fuelingPort.TryGetComp(out var refuelable)) - { __result = refuelable.Fuel; - } - else if (fuelingPort.TryGetComp(out var buffer)) - { - __result = buffer.Fuel; - } + else if (fuelingPort.TryGetComp(out var buffer)) __result = buffer.Fuel; } // the vanilla method assumes that CompRefuelable exists. @@ -196,7 +165,7 @@ public static bool Prefix(ref float __result, CompLaunchable __instance) public static class CompLaunchable_TryLaunch { public static IEnumerable Transpiler(IEnumerable _instructions, - ILGenerator generator) + ILGenerator generator) { var tryGetComp_MI = AccessTools.Method(typeof(ThingCompUtility), nameof(ThingCompUtility.TryGetComp)); var tryGetComp_CompRefuelable_MI = tryGetComp_MI.MakeGenericMethod(typeof(CompRefuelable)); @@ -217,24 +186,29 @@ public static IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable _instructions, - ILGenerator generator) + ILGenerator generator) { var instructions = _instructions.ToList(); for (var i = 0; i < instructions.Count; i++) @@ -71,16 +62,19 @@ public static IEnumerable Transpiler(IEnumerable 4 - && instructions[i - 4].LoadsField(Helpers.PowerConduit_FI) - && instructions[i - 3].Branches(out _) - && instructions[i - 2].LoadsConstant(1L) - && instructions[i - 1].opcode == OpCodes.Ret - && instructions[i - 0].opcode == OpCodes.Ldarg_0) + && instructions[i - 4].LoadsField(Helpers.PowerConduit_FI) + && instructions[i - 3].Branches(out _) + && instructions[i - 2].LoadsConstant(1L) + && instructions[i - 1].opcode == OpCodes.Ret + && instructions[i - 0].opcode == OpCodes.Ldarg_0) { - yield return new CodeInstruction(OpCodes.Ldloc_3); + yield return new CodeInstruction(OpCodes.Ldloc_2); + yield return new CodeInstruction(OpCodes.Ldfld, + AccessTools.Field(AccessTools.Inner(typeof(GenConstruct), "<>c__DisplayClass16_0"), + "oldDefBuilt")); yield return new CodeInstruction(OpCodes.Call, AccessTools.Method( - typeof(Helpers), - nameof(Helpers.GasCheck))); + typeof(Helpers), + nameof(Helpers.GasCheck))); var label = generator.DefineLabel(); yield return new CodeInstruction(OpCodes.Brfalse, label); @@ -126,7 +120,7 @@ public class GenConstruct_BlocksConstruction AccessTools.Field(typeof(Thing), nameof(Thing.def)); public static IEnumerable Transpiler(IEnumerable _instructions, - ILGenerator generator) + ILGenerator generator) { var instructions = _instructions.ToList(); for (var i = 0; i < instructions.Count; i++) @@ -134,21 +128,21 @@ public static IEnumerable Transpiler(IEnumerable 5 - && instructions[i - 5].LoadsField(Helpers.PowerConduit_FI) - && instructions[i - 4].Branches(out var _dump) - && instructions[i - 3].LoadsConstant(0L) - && instructions[i - 2].opcode == OpCodes.Ret - && instructions[i - 1].opcode == OpCodes.Ldarg_1 - && instructions[i - 0].LoadsField(def_FI)) + && instructions[i - 5].LoadsField(Helpers.PowerConduit_FI) + && instructions[i - 4].Branches(out var _dump) + && instructions[i - 3].LoadsConstant(0L) + && instructions[i - 2].opcode == OpCodes.Ret + && instructions[i - 1].opcode == OpCodes.Ldarg_1 + && instructions[i - 0].LoadsField(def_FI)) { // push constructible.def yield return new CodeInstruction(OpCodes.Ldloc_1); // pop target.def & constructible.def, push bool yield return new CodeInstruction(OpCodes.Call, - AccessTools.Method( - typeof(Helpers), - nameof(Helpers.GasCheck2))); + AccessTools.Method( + typeof(Helpers), + nameof(Helpers.GasCheck2))); // on false, skip to next check. // on true control passes to returning false.