reflection part 2

This commit is contained in:
Tyfon
2024-07-11 21:58:20 -07:00
parent 8ad0b8c5f7
commit 3d8c9cc232
10 changed files with 178 additions and 84 deletions

View File

@@ -13,14 +13,14 @@ namespace UIFixes
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(GClass1855), nameof(GClass1855.method_9));
return AccessTools.Method(R.ItemReceiver.Type, "method_9"); // GClass1855
}
// The patched method can't handle new items that aren't in stash root.
// Find items that are in subcontainers and handle them first - the patched method will ignore items that have a CurrentAddress
// This is a subset of the original method - doesn't handle slots, equipment containers, etc.
[PatchPrefix]
public static void Prefix(ref GClass1198[] newItems, Profile ___profile_0, ItemFactory ___itemFactory, GClass2780 ___gclass2780_0)
public static void Prefix(object __instance, ref JsonItem[] newItems, Profile ___profile_0, ItemFactory ___itemFactory)
{
Inventory inventory = ___profile_0.Inventory;
StashClass stash = inventory.Stash;
@@ -40,10 +40,12 @@ namespace UIFixes
List<Item> stashItems = stash.GetNotMergedItems().ToList();
ItemFactory.GStruct135 tree = ___itemFactory.FlatItemsToTree(unhandledItems.ToArray(), true, null);
InventoryControllerClass inventoryController = new R.ItemReceiver(__instance).InventoryController;
var tree = ___itemFactory.FlatItemsToTree(unhandledItems.ToArray(), true, null);
foreach (Item item in tree.Items.Values.Where(i => i.CurrentAddress == null))
{
GClass1198 newItem = unhandledItems.First(i => i._id == item.Id);
var newItem = unhandledItems.First(i => i._id == item.Id);
if (newItem.parentId != null || newItem.slotId != null)
{
// Assuming here that unhandled items are trying to go into containers in the stash - find that container
@@ -52,14 +54,14 @@ namespace UIFixes
{
if (containerCollection.GetContainer(newItem.slotId) is StashGridClass grid)
{
LocationInGrid location = GClass1496.CreateItemLocation<LocationInGrid>(newItem.location);
LocationInGrid location = LocationJsonParser.CreateItemLocation<LocationInGrid>(newItem.location);
ItemAddress itemAddress = new GridItemAddress(grid, location);
GStruct414<GClass2798> operation = InteractionsHandlerClass.Add(item, itemAddress, ___gclass2780_0, false);
var operation = InteractionsHandlerClass.Add(item, itemAddress, inventoryController, false);
if (operation.Succeeded)
{
operation.Value.RaiseEvents(___gclass2780_0, CommandStatus.Begin);
operation.Value.RaiseEvents(___gclass2780_0, CommandStatus.Succeed);
operation.Value.RaiseEvents(inventoryController, CommandStatus.Begin);
operation.Value.RaiseEvents(inventoryController, CommandStatus.Succeed);
}
}
}