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
19 changes: 0 additions & 19 deletions Daybreak.API/Converters/PointerValueConverter.cs

This file was deleted.

15 changes: 8 additions & 7 deletions Daybreak.API/Extensions/AttributeContextExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
using Daybreak.API.Interop.GuildWars;
using Daybreak.Shared.Models.Api;
using ZLinq;

namespace Daybreak.API.Extensions;

public static class AttributeContextExtensions
{
public static List<AttributeEntry> GetAttributeEntryList(this AttributeContext[] attributes)
public static IEnumerable<AttributeEntry> GetAttributeEntryList(this AttributeStructArray54 attributes)
{
return attributes
.AsValueEnumerable()
.Take(45) // There are only 45 maximum attributes in game
.Where(a => a.LevelBase > 0 && a.Level >= a.LevelBase) // Select only attributes with points in them
.Select(a => new AttributeEntry(a.Id, a.LevelBase, a.Level)).ToList();
foreach (var attribute in attributes)
{
if (attribute.LevelBase > 0 && attribute.Level >= attribute.LevelBase)
{
yield return new AttributeEntry((uint)attribute.Id, attribute.LevelBase, attribute.Level);
}
}
}
}
36 changes: 36 additions & 0 deletions Daybreak.API/Extensions/CharacterInformationExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Daybreak.API.Interop.GuildWars;

namespace Daybreak.API.Extensions;

public static class CharacterInformationExtensions
{
public unsafe static Profession GetPrimaryProfession(this CharacterInformation characterInformation)
{
return (Profession)((characterInformation.Props[2] >> 20) & 0xF);
}

public unsafe static Profession GetSecondaryProfession(this CharacterInformation characterInformation)
{
return (Profession)((characterInformation.Props[7] >> 10) & 0xF);
}

public unsafe static uint GetLevel(this CharacterInformation characterInformation)
{
return (characterInformation.Props[7] >> 4) & 0x3F;
}

public unsafe static Campaign GetCampaign(this CharacterInformation characterInformation)
{
return (Campaign)(characterInformation.Props[7] & 0xF);
}

public unsafe static MapID GetMapId(this CharacterInformation characterInformation)
{
return (MapID)((characterInformation.Props[0] >> 16) & 0xFFFF);
}

public unsafe static bool IsPvP(this CharacterInformation characterInformation)
{
return ((characterInformation.Props[7] >> 9) & 0x1) == 0x1;
}
}
44 changes: 23 additions & 21 deletions Daybreak.API/Extensions/GameContextExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Daybreak.API.Interop.GuildWars;
using Daybreak.API.Interop;
using Daybreak.API.Interop.GuildWars;
using System.Diagnostics.CodeAnalysis;

namespace Daybreak.API.Extensions;
Expand All @@ -11,37 +12,37 @@ public static bool TryGetPlayerId(
{
playerId = 0;
if (gameContext.IsNull ||
gameContext.Pointer->WorldContext is null ||
gameContext.Pointer->WorldContext->PlayerControlledChar is null)
gameContext.Pointer->World is null ||
gameContext.Pointer->World->PlayerControlledChar is null)
{
return false;
}

playerId = gameContext.Pointer->WorldContext->PlayerControlledChar->AgentId;
playerId = gameContext.Pointer->World->PlayerControlledChar->AgentId;
return true;
}

public static bool TryGetBuildContext(
this WrappedPointer<GameContext> gameContext,
[NotNullWhen(true)] out GuildWarsArray<SkillbarContext>? skillbars,
[NotNullWhen(true)] out GuildWarsArray<SkillbarData>? skillbars,
[NotNullWhen(true)] out GuildWarsArray<PartyAttribute>? attributes,
[NotNullWhen(true)] out GuildWarsArray<ProfessionsContext>? professions,
[NotNullWhen(true)] out GuildWarsArray<ProfessionState>? professions,
[NotNullWhen(true)] out GuildWarsArray<uint>? unlockedSkills)
{
skillbars = default;
attributes = default;
professions = default;
unlockedSkills = default;
if (gameContext.IsNull ||
gameContext.Pointer->WorldContext is null)
gameContext.Pointer->World is null)
{
return false;
}

skillbars = gameContext.Pointer->WorldContext->Skillbars;
attributes = gameContext.Pointer->WorldContext->Attributes;
professions = gameContext.Pointer->WorldContext->Professions;
unlockedSkills = gameContext.Pointer->WorldContext->UnlockedCharacterSkills;
skillbars = gameContext.Pointer->World->Skillbar.Value;
attributes = gameContext.Pointer->World->Attributes.Value;
professions = gameContext.Pointer->World->PartyProfessionStates;
unlockedSkills = gameContext.Pointer->World->UnlockedCharacterSkills;
return true;
}

Expand All @@ -57,15 +58,16 @@ public static bool TryGetPlayerParty(
heroes = default;
henchmen = default;
if (gameContext.IsNull ||
gameContext.Pointer->PartyContext is null)
gameContext.Pointer->Party is 0)
{
return false;
}

partyId = gameContext.Pointer->PartyContext->PlayerParty->PartyId;
players = gameContext.Pointer->PartyContext->PlayerParty->Players;
heroes = gameContext.Pointer->PartyContext->PlayerParty->Heroes;
henchmen = gameContext.Pointer->PartyContext->PlayerParty->Henchmen;
var partyInfo = GWCA.GW.PartyMgr.GetPartyInfo(0);
partyId = partyInfo->PartyId;
players = partyInfo->Players;
heroes = partyInfo->Heroes;
henchmen = partyInfo->Henchmen;
return true;
}

Expand All @@ -75,27 +77,27 @@ public static bool TryGetHeroFlags(
{
heroFlags = default;
if (gameContext.IsNull ||
gameContext.Pointer->WorldContext is null)
gameContext.Pointer->World is null)
{
return false;
}

heroFlags = gameContext.Pointer->WorldContext->HeroFlags;
heroFlags = gameContext.Pointer->World->HeroFlags.Value;
return true;
}

public static bool TryGetAccountContext(
this WrappedPointer<GameContext> gameContext,
out WrappedPointer<AccountGameContext> accountContext)
out WrappedPointer<AccountContext> accountContext)
{
accountContext = default;
if (gameContext.IsNull ||
gameContext.Pointer->AccountContext is null)
gameContext.Pointer->Account is null)
{
return false;
}

accountContext = gameContext.Pointer->AccountContext;
accountContext = gameContext.Pointer->Account;
return true;
}
}
16 changes: 16 additions & 0 deletions Daybreak.API/Extensions/TitleExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Daybreak.API.Interop.GuildWars;

namespace Daybreak.API.Extensions;

public static class TitleExtensions
{
public static bool IsPercentageBased(this Title title)
{
return (title.Props & 1) != 0;
}

public static bool HasTiers(this Title title)
{
return (title.Props & 3) == 2;
}
}
34 changes: 34 additions & 0 deletions Daybreak.API/Interop/Frame.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Runtime.InteropServices;

namespace Daybreak.API.Interop;

[StructLayout(LayoutKind.Explicit, Pack = 1, Size = 0x1AC)]
[GWCAEquivalent("Frame")]
public readonly struct Frame
{
[FieldOffset(0x0008)]
public readonly uint FrameLayout;

[FieldOffset(0x0018)]
public readonly uint VisibilityFlags;

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

[FieldOffset(0x0024)]
public readonly uint TemplateType;

[FieldOffset(0x00b8)]
public readonly uint ChildOffsetId;

[FieldOffset(0x00bc)]
public readonly uint FrameId;

[FieldOffset(0x018C)]
public readonly uint FrameState;

public bool IsCreated => (this.FrameState & 0x4) != 0;
public bool IsHidden => (this.FrameState & 0x200) != 0;
public bool IsVisible => !this.IsHidden;
public bool IsDIsabled => (this.FrameState & 0x10) != 0;
}
26 changes: 0 additions & 26 deletions Daybreak.API/Interop/GWAddressCache.cs

This file was deleted.

Loading
Loading