Skip to content

Commit

Permalink
[fix(test):] Microhid fix
Browse files Browse the repository at this point in the history
  • Loading branch information
IRacle1 committed Dec 27, 2024
1 parent 2f720e8 commit aba514f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions EXILED/Exiled.API/Features/Items/Firearm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace Exiled.API.Features.Items
using Extensions;
using InventorySystem;
using InventorySystem.Items;
using InventorySystem.Items.Autosync;
using InventorySystem.Items.Firearms;
using InventorySystem.Items.Firearms.Attachments;
using InventorySystem.Items.Firearms.Attachments.Components;
Expand Down Expand Up @@ -690,6 +691,7 @@ public override Item Clone()
/// <param name="newOwner">new <see cref="Firearm"/> owner.</param>
internal override void ChangeOwner(Player oldOwner, Player newOwner)
{
Base.InstantiationStatus = newOwner == Server.Host ? AutosyncInstantiationStatus.SimulatedInstance : AutosyncInstantiationStatus.InventoryInstance;
Base.Owner = newOwner.ReferenceHub;
Base._footprintCacheSet = false;
foreach (ModuleBase module in Base.Modules)
Expand Down
2 changes: 2 additions & 0 deletions EXILED/Exiled.API/Features/Items/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public Item(ItemBase itemBase)
ushort serial = ItemSerialGenerator.GenerateNext();
Serial = serial;
itemBase.OnAdded(null);
if (Base is ModularAutosyncItem syncItem)
syncItem.InstantiationStatus = AutosyncInstantiationStatus.SimulatedInstance;
#if DEBUG
Log.Debug($"{nameof(Item)}.ctor: Generating new serial number. Serial should now be: {serial}. // {Serial}");
#endif
Expand Down
32 changes: 32 additions & 0 deletions EXILED/Exiled.Events/Patches/Fixes/ServerHubMicroHidFix.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// -----------------------------------------------------------------------
// <copyright file="ServerHubMicroHidFix.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.Events.Patches.Fixes
{
#pragma warning disable SA1313
using API.Features.Items;
using Exiled.API.Features;

using HarmonyLib;

using InventorySystem.Items.Autosync;
using InventorySystem.Items.MicroHID.Modules;
using InventorySystem.Items.Pickups;
using InventorySystem.Items.Usables.Scp330;

/// <summary>
/// Patches <see cref="CycleSyncModule.Update()"/> to fix phantom <see cref="MicroHid"/> for <see cref="Item.Create(ItemType, API.Features.Player)"/>.
/// </summary>
[HarmonyPatch(typeof(CycleSyncModule), nameof(CycleSyncModule.Update))]
internal static class ServerHubMicroHidFix
{
private static bool Prefix(CycleSyncModule __instance)
{
return __instance.MicroHid.InstantiationStatus == AutosyncInstantiationStatus.InventoryInstance;
}
}
}

0 comments on commit aba514f

Please sign in to comment.