private static int OnAddItem(void *pItemRepository, void **ppItem, byte x, byte y, byte z, int bAllowEncumbrance, int bMergeItem) { CItemRepository itemRepository = CItemRepository.FromPointer(pItemRepository); NwGameObject? parent = itemRepository.m_oidParent.ToNwObject <NwGameObject>(); // Early out if parent isn't an item or placeable or Bad Things(tm) happen if (parent is null || parent is not NwItem && parent is not NwPlaceable) { return(Hook.CallOriginal(pItemRepository, ppItem, x, y, z, bAllowEncumbrance, bMergeItem)); } if (ppItem == null) { return(Hook.CallOriginal(pItemRepository, ppItem, x, y, z, bAllowEncumbrance, bMergeItem)); } OnInventoryItemAdd eventData = new OnInventoryItemAdd { AcquiredBy = parent, Item = CNWSItem.FromPointer(*ppItem).ToNwObject <NwItem>() !, }; eventData.Result = new Lazy <bool>(() => !eventData.PreventItemAdd && Hook.CallOriginal(pItemRepository, ppItem, x, y, z, bAllowEncumbrance, bMergeItem).ToBool()); ProcessEvent(eventData); return(eventData.Result.Value.ToInt()); } }
private static int OnRemoveItem(void *pItemRepository, void *pItem) { CItemRepository itemRepository = CItemRepository.FromPointer(pItemRepository); NwGameObject? parent = itemRepository.m_oidParent.ToNwObject <NwGameObject>(); // Early out if parent isn't an item or placeable or Bad Things(tm) happen if (parent is null || parent is not NwItem && parent is not NwPlaceable) { return(Hook.CallOriginal(pItemRepository, pItem)); } ProcessEvent(new OnInventoryItemRemove { RemovedFrom = parent, Item = CNWSItem.FromPointer(pItem).ToNwObject <NwItem>() !, });