Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Daybreak.API/Controllers/Rest/InventoryController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Daybreak.API.Services;
using Daybreak.Shared.Models.Api;
using Microsoft.AspNetCore.Mvc;
using Net.Sdk.Web;

namespace Daybreak.API.Controllers.Rest;

[GenerateController("api/v1/rest/inventory")]
[Tags("Inventory")]
public sealed class InventoryController(
InventoryService inventoryService)
{
private readonly InventoryService inventoryService = inventoryService;

[GenerateGet]
[EndpointName("GetInventory")]
[EndpointSummary("Get Inventory information")]
[EndpointDescription("Get the inventory of the current player. Returns a serialized InventoryInformation object")]
[ProducesResponseType<InventoryInformation>(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status503ServiceUnavailable)]
public async Task<IResult> GetInventory(CancellationToken cancellationToken)
{
var inventoryInformation = await this.inventoryService.GetInventoryInformation(cancellationToken);
return inventoryInformation is null ?
Results.StatusCode(StatusCodes.Status503ServiceUnavailable) :
Results.Ok(inventoryInformation);
}
}
30 changes: 30 additions & 0 deletions Daybreak.API/Interop/GuildWars/Bag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Runtime.InteropServices;

namespace Daybreak.API.Interop.GuildWars;

public enum BagType
{
None,
Inventory,
Equipped,
NotCollected,
Storage,
MaterialsStorage
}

[StructLayout(LayoutKind.Explicit, Pack = 1)]
public readonly unsafe struct Bag
{
[FieldOffset(0x0000)]
public readonly BagType Type;
[FieldOffset(0x0004)]
public readonly uint Index;
[FieldOffset(0x000C)]
public readonly uint ContainerItem;
[FieldOffset(0x0010)]
public readonly uint ItemsCount;
[FieldOffset(0x0014)]
public readonly Bag* Bags;
[FieldOffset(0x0018)]
public readonly GuildWarsArray<WrappedPointer<Item>> Items;
}
6 changes: 6 additions & 0 deletions Daybreak.API/Interop/GuildWars/GameContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public readonly unsafe struct GameContext
[FieldOffset(0x0014)]
public readonly MapContext* MapContext;

[FieldOffset(0x0018)]
public readonly TextParserContext* TextParserContext;

[FieldOffset(0x0028)]
public readonly AccountGameContext* AccountContext;

Expand All @@ -20,6 +23,9 @@ public readonly unsafe struct GameContext
[FieldOffset(0x003C)]
public readonly GuildContext* GuildContext;

[FieldOffset(0x0040)]
public readonly ItemContext* ItemContext;

[FieldOffset(0x0044)]
public readonly CharContext* CharContext;

Expand Down
58 changes: 58 additions & 0 deletions Daybreak.API/Interop/GuildWars/Inventory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System.Runtime.InteropServices;

namespace Daybreak.API.Interop.GuildWars;

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public readonly unsafe struct Inventory
{
public readonly Bag* UnusedBag;
public readonly Bag* Backpack;
public readonly Bag* BeltPouch;
public readonly Bag* Bag1;
public readonly Bag* Bag2;
public readonly Bag* EquipmentPack;
public readonly Bag* MaterialStorage;
public readonly Bag* UnclaimedItems;
public readonly Bag* Storage1;
public readonly Bag* Storage2;
public readonly Bag* Storage3;
public readonly Bag* Storage4;
public readonly Bag* Storage5;
public readonly Bag* Storage6;
public readonly Bag* Storage7;
public readonly Bag* Storage8;
public readonly Bag* Storage9;
public readonly Bag* Storage10;
public readonly Bag* Storage11;
public readonly Bag* Storage12;
public readonly Bag* Storage13;
public readonly Bag* Storage14;
public readonly Bag* EquippedItems;
public readonly Item* Bundle;
public readonly uint StoragePanesUnlocked;

public readonly Bag*[] Bags => [
this.Backpack,
this.BeltPouch,
this.Bag1,
this.Bag2,
this.EquipmentPack,
this.MaterialStorage,
this.UnclaimedItems,
this.Storage1,
this.Storage2,
this.Storage3,
this.Storage4,
this.Storage5,
this.Storage6,
this.Storage7,
this.Storage8,
this.Storage9,
this.Storage10,
this.Storage11,
this.Storage12,
this.Storage13,
this.Storage14,
this.EquippedItems
];
}
127 changes: 127 additions & 0 deletions Daybreak.API/Interop/GuildWars/Item.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
using System.Runtime.InteropServices;

namespace Daybreak.API.Interop.GuildWars;

public enum ItemType : byte
{
Salvage,
Axe = 2,
Bag,
Boots,
Bow,
Bundle,
Chestpiece,
Rune_Mod,
Usable,
Dye,
Materials_Zcoins,
Offhand,
Gloves,
Hammer = 15,
Headpiece,
CC_Shards,
Key,
Leggings,
Gold_Coin,
Quest_Item,
Wand,
Shield = 24,
Staff = 26,
Sword,
Kit = 29,
Trophy,
Scroll,
Daggers,
Present,
Minipet,
Scythe,
Spear,
Storybook = 43,
Costume,
Costume_Headpiece,
Unknown = 0xff
};

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public readonly struct ItemModifier(uint mod)
{
public static readonly ItemModifier Zero = new();

public readonly uint Mod = mod;

public uint Identifier => this.Mod >> 16;
public uint Arg1 => (this.Mod & 0x0000FF00) >> 8;
public uint Arg2 => this.Mod & 0x000000FF;
public uint Arg => this.Mod & 0x0000FFFF;
}

[StructLayout(LayoutKind.Explicit, Pack = 1)]
public readonly unsafe struct Item
{
[FieldOffset(0x0000)]
public readonly uint ItemId;

[FieldOffset(0x0004)]
public readonly uint AgentId;

[FieldOffset(0x0008)]
public readonly Bag* BagEquipped;

[FieldOffset(0x000C)]
public readonly Bag* Bag;

[FieldOffset(0x0010)]
public readonly ItemModifier* Modifiers;

[FieldOffset(0x0014)]
public readonly uint ModifiersCount;

[FieldOffset(0x001C)]
public readonly uint ModelFileId;

[FieldOffset(0x0020)]
public readonly ItemType Type;

[FieldOffset(0x0024)]
public readonly ushort Value;

[FieldOffset(0x0028)]
public readonly uint Interaction;

[FieldOffset(0x002C)]
public readonly uint ModelId;

[FieldOffset(0x0030)]
public readonly char* InfoString;

[FieldOffset(0x0034)]
public readonly char* NameEncoded;

[FieldOffset(0x0038)]
public readonly char* CompleteNameEncoded;

[FieldOffset(0x003C)]
public readonly char* SingleItemName;

[FieldOffset(0x0048)]
public readonly ushort ItemFormula;

[FieldOffset(0x004A)]
public readonly byte IsMaterialSalvageable;

[FieldOffset(0x004C)]
public readonly ushort Quantity;

[FieldOffset(0x004E)]
public readonly byte Equipped;

[FieldOffset(0x004F)]
public readonly byte Profession;

[FieldOffset(0x0050)]
public readonly uint Slot;

public readonly bool Stackable => (this.Interaction & 0x80000) != 0;

public readonly bool Inscribable => (this.Interaction & 0x08000000) != 0;
}
16 changes: 16 additions & 0 deletions Daybreak.API/Interop/GuildWars/ItemContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Runtime.InteropServices;

namespace Daybreak.API.Interop.GuildWars;

[StructLayout(LayoutKind.Explicit, Pack = 1)]
public readonly struct ItemContext
{
[FieldOffset(0x0024)]
public readonly GuildWarsArray<WrappedPointer<Bag>> Bags;

[FieldOffset(0x00B8)]
public readonly GuildWarsArray<WrappedPointer<Item>> Items;

[FieldOffset(0x00F8)]
public readonly WrappedPointer<Inventory> Inventory;
}
10 changes: 10 additions & 0 deletions Daybreak.API/Interop/GuildWars/TextParserContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Runtime.InteropServices;

namespace Daybreak.API.Interop.GuildWars;

[StructLayout(LayoutKind.Explicit, Pack = 1)]
public struct TextParserContext
{
[FieldOffset(0x01D0)]
public Language Language;
}
9 changes: 9 additions & 0 deletions Daybreak.API/Models/DecodeStringContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Daybreak.API.Interop.GuildWars;

namespace Daybreak.API.Models;

public struct DecodeStringContext(WrappedPointer<char> encodedString, TaskCompletionSource<string?> taskCompletionSource)
{
public WrappedPointer<char> EncodedString = encodedString;
public TaskCompletionSource<string?> TaskCompletionSource = taskCompletionSource;
}
1 change: 1 addition & 0 deletions Daybreak.API/Serialization/ApiJsonSerializerContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace Daybreak.API.Serialization;
[JsonSerializable(typeof(TitleInfo))]
[JsonSerializable(typeof(LoginInfo))]
[JsonSerializable(typeof(MainPlayerBuildContext))]
[JsonSerializable(typeof(InventoryInformation))]
public partial class ApiJsonSerializerContext : JsonSerializerContext
{
}
Loading
Loading