Skip to content

Commit 50194ee

Browse files
committed
fix: gun info not applying (too early)
1 parent 4287f5f commit 50194ee

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

KeepInventory/Helper/InventoryHelper.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public static class InventoryHelper
1414
{
1515
public static Dictionary<string, string> Aliases { get; } = new() { { "HeadSlotContainer", "Head" } };
1616

17+
internal static Dictionary<InventorySlotReceiver, Il2CppSystem.Action> Callback = [];
18+
1719
public static List<InventorySlotReceiver> GetAllSlots(this RigManager rigManager)
1820
{
1921
return rigManager?.GetComponentsInChildren<InventorySlotReceiver>().ToList();
@@ -64,7 +66,11 @@ public static void SpawnInSlot(this InventorySlotReceiver receiver, Barcode barc
6466
if (callback != null)
6567
{
6668
var awaiter = task.GetAwaiter();
67-
awaiter.OnCompleted((Il2CppSystem.Action)(() => callback?.Invoke(receiver?._slottedWeapon?.GetComponentInParent<Poolee>()?.gameObject)));
69+
Il2CppSystem.Action action = (Il2CppSystem.Action)(() => callback?.Invoke(receiver?._slottedWeapon?.GetComponentInParent<Poolee>()?.gameObject));
70+
if (!Utilities.Fusion.IsConnected)
71+
awaiter.OnCompleted(action);
72+
else
73+
Callback.Add(receiver, action);
6874
}
6975
}
7076
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
using BoneLib;
8+
9+
using HarmonyLib;
10+
11+
using Il2CppSLZ.Marrow;
12+
13+
using KeepInventory.Helper;
14+
15+
namespace KeepInventory.Patches
16+
{
17+
[HarmonyPatch(typeof(InventorySlotReceiver))]
18+
public static class ReceiverPatches
19+
{
20+
[HarmonyPostfix]
21+
[HarmonyPatch(nameof(InventorySlotReceiver.OnHandDrop))]
22+
public static void Postfix(InventorySlotReceiver __instance)
23+
{
24+
if (!Core.HasFusion || !Utilities.Fusion.IsConnected)
25+
return;
26+
27+
if (__instance.GetComponentInParent<RigManager>() != Player.RigManager)
28+
return;
29+
30+
if (!InventoryHelper.Callback.TryGetValue(__instance, out var action))
31+
return;
32+
33+
action?.Invoke();
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)