diff --git a/EXILED/Exiled.API/Features/Items/MicroHid.cs b/EXILED/Exiled.API/Features/Items/MicroHid.cs index aaf29b6689..f83dab90d3 100644 --- a/EXILED/Exiled.API/Features/Items/MicroHid.cs +++ b/EXILED/Exiled.API/Features/Items/MicroHid.cs @@ -30,11 +30,6 @@ public MicroHid(MicroHIDItem itemBase) : base(itemBase) { Base = itemBase; - - EnergyManager = Base.EnergyManager; - BrokenModule = Base.BrokenSync; - InputModule = Base.InputSync; - CycleController = Base.CycleController; } /// @@ -48,22 +43,22 @@ internal MicroHid() /// /// Gets the of the MicroHID. /// - public EnergyManagerModule EnergyManager { get; } + public EnergyManagerModule EnergyManager => Base.EnergyManager; /// /// Gets the of the MicroHID. /// - public BrokenSyncModule BrokenModule { get; } + public BrokenSyncModule BrokenModule => Base.BrokenSync; /// /// Gets the of the MicroHID. /// - public InputSyncModule InputModule { get; } + public InputSyncModule InputModule => Base.InputSync; /// /// Gets the of the MicroHID. /// - public CycleController CycleController { get; } + public CycleController CycleController => Base.CycleController; /// /// Gets or sets the remaining energy in the MicroHID. @@ -219,16 +214,5 @@ public bool TryGetFireController(MicroHidFiringMode firingMode, out T module) /// /// A string containing MicroHid-related data. public override string ToString() => $"{Type} ({Serial}) [{Weight}] *{Scale}* |{Energy}| -{State}-"; - - /// - internal override void ReadPickupInfo(Pickup pickup) - { - base.ReadPickupInfo(pickup); - - if (pickup.Is(out Pickups.MicroHIDPickup microHidPickup)) - { - Energy = microHidPickup.Energy; - } - } } } \ No newline at end of file diff --git a/EXILED/Exiled.API/Features/Pickups/MicroHIDPickup.cs b/EXILED/Exiled.API/Features/Pickups/MicroHIDPickup.cs index 87e21bf58d..255c32b6ad 100644 --- a/EXILED/Exiled.API/Features/Pickups/MicroHIDPickup.cs +++ b/EXILED/Exiled.API/Features/Pickups/MicroHIDPickup.cs @@ -50,7 +50,11 @@ internal MicroHIDPickup() /// /// Gets or sets the MicroHID Energy Level. /// - public float Energy { get; set; } + public float Energy + { + get => EnergyManagerModule.GetEnergy(Serial); + set => EnergyManagerModule.SyncEnergy[Serial] = value; + } /// /// Gets or sets the . @@ -144,16 +148,5 @@ public bool TryGetFireController(MicroHidFiringMode firingMode, out T module) /// /// A string containing MicroHIDPickup related data. public override string ToString() => $"{Type} ({Serial}) [{Weight}] *{Scale}* |{Energy}|"; - - /// - internal override void ReadItemInfo(Item item) - { - base.ReadItemInfo(item); - - if (item.Is(out MicroHid microHid)) - { - Energy = microHid.Energy; - } - } } } diff --git a/EXILED/Exiled.Events/EventArgs/Player/UsingMicroHIDEnergyEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/UsingMicroHIDEnergyEventArgs.cs index 1d207cd801..86e76a2e75 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/UsingMicroHIDEnergyEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/UsingMicroHIDEnergyEventArgs.cs @@ -25,16 +25,16 @@ public class UsingMicroHIDEnergyEventArgs : IDeniableEvent, IItemEvent /// /// /// - /// + /// /// /// /// /// /// - public UsingMicroHIDEnergyEventArgs(MicroHIDItem microHIDitem, float drain, bool isAllowed = true) + public UsingMicroHIDEnergyEventArgs(MicroHIDItem microHIDitem, float newEnergy, bool isAllowed = true) { MicroHID = Item.Get(microHIDitem); - Drain = MicroHID.Energy - drain; + Drain = MicroHID.Energy - newEnergy; IsAllowed = isAllowed; } diff --git a/EXILED/Exiled.Events/Patches/Events/Player/ChangingMicroHIDState.cs b/EXILED/Exiled.Events/Patches/Events/Player/ChangingMicroHIDState.cs index 12f83e0c6c..c45000b676 100644 --- a/EXILED/Exiled.Events/Patches/Events/Player/ChangingMicroHIDState.cs +++ b/EXILED/Exiled.Events/Patches/Events/Player/ChangingMicroHIDState.cs @@ -68,7 +68,7 @@ private static IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable newInstructions = ListPool.Pool.Get(instructions); - int index = newInstructions.FindLastIndex(instruction => instruction.opcode == OpCodes.Ldloc_0); + int index = newInstructions.FindLastIndex(instruction => instruction.opcode == OpCodes.Ldloc_1); newInstructions.InsertRange( index, @@ -64,7 +64,7 @@ private static IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable instruction.opcode == OpCodes.Ldarg_0) + offset; + int offset = -4; + int index = newInstructions.FindLastIndex(i => i.Calls(Method(typeof(EnergyManagerModule), nameof(EnergyManagerModule.ServerSetEnergy)))) + offset; newInstructions.InsertRange(index, new CodeInstruction[] { // this.MicroHID - new(OpCodes.Ldarg_0), + new CodeInstruction(OpCodes.Ldarg_0).MoveLabelsFrom(newInstructions[index]), new(OpCodes.Callvirt, PropertyGetter(typeof(EnergyManagerModule), nameof(EnergyManagerModule.MicroHid))), - // energy + // newEnergy new(OpCodes.Ldloc_0), // true new(OpCodes.Ldc_I4_1), - // UsingMicroHIDEnergyEventArgs ev = new(this.MicroHID, energy, true); + // calculate drain by delta between old energy and new energy + // UsingMicroHIDEnergyEventArgs ev = new(this.MicroHID, newEnergy, true); new(OpCodes.Newobj, GetDeclaredConstructors(typeof(UsingMicroHIDEnergyEventArgs))[0]), new(OpCodes.Dup), new(OpCodes.Dup), @@ -66,7 +67,7 @@ private static IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable.Pool.Return(newInstructions); } } -} \ No newline at end of file +}