Skip to content

Commit

Permalink
Minimap player arrow (#673)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexMacocian committed Apr 23, 2024
1 parent faa47f3 commit 641aa82
Show file tree
Hide file tree
Showing 33 changed files with 74 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Daybreak.GWCA/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ endif()
set(VERSION_MAJOR 0)
set(VERSION_MINOR 9)
set(VERSION_PATCH 9)
set(VERSION_TWEAK 33)
set(VERSION_TWEAK 36)

set(VERSION_RC "${CMAKE_CURRENT_BINARY_DIR}/version.rc")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/version.rc.in" "${VERSION_RC}" @ONLY)
Expand Down
1 change: 1 addition & 0 deletions Daybreak.GWCA/header/payloads/LivingEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace Daybreak {
uint32_t EntityAllegiance = 0;
float Health;
float Energy;
float RotationAngle;
};

void to_json(json& j, const LivingEntity& p);
Expand Down
1 change: 1 addition & 0 deletions Daybreak.GWCA/header/payloads/StatePayload.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Daybreak {
uint32_t State = 0;
float Health = 0;
float Energy = 0;
float RotationAngle = 0;
};

void to_json(json& j, const StatePayload& p);
Expand Down
2 changes: 2 additions & 0 deletions Daybreak.GWCA/source/GameModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ namespace Daybreak::Modules::GameModule {
entity.PosY = agent.pos.y;
entity.Health = agent.hp;
entity.Energy = agent.energy;
entity.RotationAngle = agent.rotation_angle;
if (agent.primary == 0) {
const auto npc = GW::Agents::GetNPCByID(agent.player_number);
if (npc) {
Expand Down Expand Up @@ -257,6 +258,7 @@ namespace Daybreak::Modules::GameModule {
player.SecondaryProfessionId = (uint32_t)agent->secondary;
player.Health = agent->hp * (agent->max_hp > 0 ? agent->max_hp : 1);
player.Energy = agent->energy * (agent->max_energy > 0 ? agent->max_energy : 1);
player.RotationAngle = agent->rotation_angle;
}
else if (professionState) {
player.PrimaryProfessionId = (uint32_t)professionState->primary;
Expand Down
1 change: 1 addition & 0 deletions Daybreak.GWCA/source/GameStateModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace Daybreak::Modules::GameStateModule {
state.State = agent.type_map;
state.Health = agent.hp * (agent.max_hp > 0 ? agent.max_hp : 1);
state.Energy = agent.energy * (agent.max_energy > 0 ? agent.max_energy : 1);
state.RotationAngle = agent.rotation_angle;
states.push_back(state);
}

Expand Down
1 change: 1 addition & 0 deletions Daybreak.GWCA/source/MainPlayerModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ namespace Daybreak::Modules::MainPlayerModule {
player.SecondaryProfessionId = (uint32_t)agent->secondary;
player.Health = agent->hp * (agent->max_hp > 0 ? agent->max_hp : 1);
player.Energy = agent->energy * (agent->max_energy > 0 ? agent->max_energy : 1);
player.RotationAngle = agent->rotation_angle;
}
else if (professionState) {
player.PrimaryProfessionId = (uint32_t)professionState->primary;
Expand Down
3 changes: 2 additions & 1 deletion Daybreak.GWCA/source/payloads/LivingEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ namespace Daybreak {
{"EntityState", p.EntityState},
{"EntityAllegiance", p.EntityAllegiance},
{"Health", p.Health},
{"Energy", p.Energy}
{"Energy", p.Energy},
{"RotationAngle", p.RotationAngle}
};
}
}
3 changes: 2 additions & 1 deletion Daybreak.GWCA/source/payloads/StatePayload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ namespace Daybreak {
{"PosY", p.PosY},
{"State", p.State},
{"Health", p.Health},
{"Energy", p.Energy}
{"Energy", p.Energy},
{"RotationAngle", p.RotationAngle}
};
}
}
4 changes: 4 additions & 0 deletions Daybreak/Controls/Minimap/GuildwarsMinimap.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,14 @@ this.GameData is null ||
this.GameData.MainPlayer!.Position = mainPlayerState?.Position ?? new Position();
this.GameData.MainPlayer!.CurrentHealth = mainPlayerState?.Health ?? 0;
this.GameData.MainPlayer!.CurrentEnergy = mainPlayerState?.Energy ?? 0;
this.GameData.MainPlayer!.RotationAngle = mainPlayerState?.RotationAngle ?? 0;
foreach (var worldPlayer in this.GameData.WorldPlayers!)
{
var worldPlayerState = this.GameState.States?.FirstOrDefault(state => state.Id == worldPlayer.Id);
worldPlayer.Position = worldPlayerState?.Position ?? new Position();
worldPlayer.CurrentHealth = worldPlayerState?.Health ?? 0;
worldPlayer.CurrentEnergy = worldPlayerState?.Energy ?? 0;
worldPlayer.RotationAngle = worldPlayerState?.RotationAngle ?? 0;
}

foreach (var partyPlayer in this.GameData.Party!)
Expand All @@ -181,6 +183,7 @@ this.GameData is null ||
partyPlayer.Position = partyPlayerState?.Position ?? new Position();
partyPlayer.CurrentHealth = partyPlayerState?.Health ?? 0;
partyPlayer.CurrentEnergy = partyPlayerState?.Energy ?? 0;
partyPlayer.RotationAngle = partyPlayerState?.RotationAngle ?? 0;
}

foreach (var entity in this.GameData.LivingEntities!)
Expand All @@ -190,6 +193,7 @@ this.GameData is null ||
entity.State = state?.State ?? LivingEntityState.Unknown;
entity.Health = state?.Health ?? 0;
entity.Energy = state?.Energy ?? 0;
entity.RotationAngle = state?.RotationAngle ?? 0;
}

this.Angle = this.CanRotate ? (this.GameState.Camera.Yaw - (Math.PI / 2)) * (180 / Math.PI) : 0;
Expand Down
2 changes: 2 additions & 0 deletions Daybreak/Daybreak.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<None Remove="Resources\Snow3.png" />
<None Remove="Resources\Snow4.png" />
<None Remove="Services\Drawing\Resources\Bag.svg" />
<None Remove="Services\Drawing\Resources\CircledArrow.svg" />
<None Remove="Services\Drawing\Resources\CircledStar.svg" />
<None Remove="Services\Drawing\Resources\Dungeon.svg" />
<None Remove="Services\Drawing\Resources\DungeonBoss.svg" />
Expand All @@ -48,6 +49,7 @@
<EmbeddedResource Include="Resources\Snow3.png" />
<EmbeddedResource Include="Resources\Snow4.png" />
<EmbeddedResource Include="Services\Drawing\Resources\Bag.svg" />
<EmbeddedResource Include="Services\Drawing\Resources\CircledArrow.svg" />
<EmbeddedResource Include="Services\Drawing\Resources\CircledStar.svg" />
<EmbeddedResource Include="Services\Drawing\Resources\Dungeon.svg" />
<EmbeddedResource Include="Services\Drawing\Resources\DungeonBoss.svg" />
Expand Down
1 change: 1 addition & 0 deletions Daybreak/Models/Guildwars/EntityGameState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ public sealed class EntityGameState
public LivingEntityState State { get; set; }
public float Health { get; set; }
public float Energy { get; set; }
public float RotationAngle { get; set; }
}
1 change: 1 addition & 0 deletions Daybreak/Models/Guildwars/IPositionalEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
public interface IPositionalEntity
{
Position? Position { get; }
float RotationAngle { get; }
}
2 changes: 2 additions & 0 deletions Daybreak/Models/Guildwars/LivingEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ public sealed class LivingEntity : IEntity
public float Health { get; set; }

public float Energy { get; set; }

public float RotationAngle { get; set; }
}
1 change: 1 addition & 0 deletions Daybreak/Models/Guildwars/MainPlayerInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public sealed class MainPlayerInformation : IEntity
public float MaxEnergy { get; init; }
public float HealthRegen { get; init; }
public float EnergyRegen { get; init; }
public float RotationAngle { get; set; }
public bool HardModeUnlocked { get; init; }
public uint Experience { get; init; }
public uint Morale { get; init; }
Expand Down
1 change: 1 addition & 0 deletions Daybreak/Models/Guildwars/MapIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ public sealed class MapIcon : IPositionalEntity
public Position? Position { get; init; }
public GuildwarsIcon? Icon { get; init; }
public Affiliation? Affiliation { get; init; }
public float RotationAngle { get; } = 0f;
}
1 change: 1 addition & 0 deletions Daybreak/Models/Guildwars/PlayerInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ public sealed class PlayerInformation : IEntity
public float MaxEnergy { get; init; }
public float HealthRegen { get; init; }
public float EnergyRegen { get; init; }
public float RotationAngle { get; set; }
}
1 change: 1 addition & 0 deletions Daybreak/Models/Guildwars/QuestMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ public sealed class QuestMetadata : IPositionalEntity
public Position? Position { get; init; }
public Map? From { get; init; }
public Map? To { get; init; }
public float RotationAngle { get; } = 0f;
}
1 change: 1 addition & 0 deletions Daybreak/Models/Guildwars/WorldPlayerInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ public sealed class WorldPlayerInformation : IEntity
public float MaxEnergy { get; init; }
public float HealthRegen { get; init; }
public float EnergyRegen { get; init; }
public float RotationAngle { get; set; }
}
7 changes: 5 additions & 2 deletions Daybreak/Services/Drawing/DrawingService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Daybreak.Models;
using Daybreak.Models.Guildwars;
using Daybreak.Services.Drawing.Modules;
using Daybreak.Services.Screenshots.Models;
using Slim;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -100,7 +101,8 @@ gameData.Party is null ||
{
if (module.CanDrawEntity(entity))
{
module.DrawEntity(finalX, finalY, this.finalEntitySize, angle, bitmap, false, this.foregroundColor);
var entityAngle = -(entity.RotationAngle - (Math.PI / 2));
module.DrawEntity(finalX, finalY, this.finalEntitySize, angle, entityAngle, bitmap, false, this.foregroundColor);
}
}
}
Expand All @@ -113,7 +115,8 @@ gameData.Party is null ||
{
if (module.CanDrawEntity(targetedEntity))
{
module.DrawEntity(finalTargetedX, finalTargetedY, this.finalEntitySize, angle, bitmap, true, this.foregroundColor);
var entityAngle = -(targetedEntity.RotationAngle - (Math.PI / 2));
module.DrawEntity(finalTargetedX, finalTargetedY, this.finalEntitySize, angle, entityAngle, bitmap, true, this.foregroundColor);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public override bool CanDrawEntity(IEntity entity)
livingEntity.State is LivingEntityState.Boss;
}

public override void DrawEntity(int finalX, int finalY, int size, double angle, WriteableBitmap bitmap, bool targeted, Color shade)
public override void DrawEntity(int finalX, int finalY, int size, double cameraAngle, double entityAngle, WriteableBitmap bitmap, bool targeted, Color shade)
{
this.DrawSvg(bitmap, finalX, finalY, size, angle, targeted ? this.OutlineColor : this.FillColor, this.FillColor, shade);
this.DrawSvg(bitmap, finalX, finalY, size, cameraAngle, targeted ? this.OutlineColor : this.FillColor, this.FillColor, shade);
}
}
6 changes: 3 additions & 3 deletions Daybreak/Services/Drawing/Modules/DrawingModuleBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ public abstract class DrawingModuleBase

public virtual bool CanDrawEngagementArea(IEntity entity) => false;

public virtual void DrawEntity(int finalX, int finalY, int size, double angle, WriteableBitmap bitmap, bool targeted, Color shade) { }
public virtual void DrawEntity(int finalX, int finalY, int size, double cameraAngle, double entityAngle, WriteableBitmap bitmap, bool targeted, Color shade) { }

public virtual void DrawMapIcon(int finalX, int finalY, int size, double angle, WriteableBitmap bitmap, Affiliation affiliation, Color shade) { }
public virtual void DrawMapIcon(int finalX, int finalY, int size, double cameraAngle, WriteableBitmap bitmap, Affiliation affiliation, Color shade) { }

public virtual void DrawPlayerPositionHistory(int finalX, int finalY, int size, WriteableBitmap bitmap, Color shade) { }

public virtual void DrawPathFinding(int finalX, int finalY, int size, WriteableBitmap bitmap, Color color, Color shade) { }

public virtual void DrawQuestObjective(int finalX, int finalY, int size, double angle, WriteableBitmap bitmap, Color color, Color shade) { }
public virtual void DrawQuestObjective(int finalX, int finalY, int size, double cameraAngle, WriteableBitmap bitmap, Color color, Color shade) { }

public virtual void DrawEngagementArea(int finalX, int finalY, int size, WriteableBitmap bitmap, Color shade) { }
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
using Daybreak.Models.Guildwars;
using Daybreak.Services.Drawing.Modules.Primitives;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace Daybreak.Services.Drawing.Modules.Entities;
public sealed class MainPlayerDrawingModule : CircleEntityDrawingModuleBase
public sealed class MainPlayerDrawingModule : EmbeddedSvgDrawingModuleBase<MainPlayerDrawingModule>
{
protected override Color FillColor { get; } = Colors.Green;
private Color OutlineColor { get; } = Colors.Chocolate;
private Color FillColor { get; } = Colors.Green;
protected override string EmbeddedSvgPath { get; } = "Daybreak.Services.Drawing.Resources.CircledArrow.svg";

public override bool CanDrawEntity(IEntity entity)
{
return entity is MainPlayerInformation;
}

public override void DrawEntity(int finalX, int finalY, int size, double cameraAngle, double entityAngle, WriteableBitmap bitmap, bool targeted, Color shade)
{
var angle = entityAngle != 0 ? entityAngle : cameraAngle;
this.DrawSvg(bitmap, finalX, finalY, size, angle, targeted ? this.OutlineColor : this.FillColor, this.FillColor, shade);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public override bool CanDrawEntity(IEntity entity)
livingEntity.NpcDefinition == Npc.Unknown);
}

public override void DrawEntity(int finalX, int finalY, int size, double angle, WriteableBitmap bitmap, bool targeted, Color shade)
public override void DrawEntity(int finalX, int finalY, int size, double cameraAngle, double entityAngle, WriteableBitmap bitmap, bool targeted, Color shade)
{
this.DrawSvg(bitmap, finalX, finalY, (int)(size / 1.3), angle, this.StrokeColor, Colors.Transparent, shade);
this.DrawSvg(bitmap, finalX, finalY, (int)(size / 1.3), cameraAngle, this.StrokeColor, Colors.Transparent, shade);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public abstract class CircleEntityDrawingModuleBase : CircleDrawingModuleBase
{
protected abstract Color FillColor { get; }

public override void DrawEntity(int finalX, int finalY, int size, double angle, WriteableBitmap bitmap, bool targeted, Color shade)
public override void DrawEntity(int finalX, int finalY, int size, double cameraAngle, double entityAngle, WriteableBitmap bitmap, bool targeted, Color shade)
{
this.DrawFilledCircle(bitmap, finalX, finalY, size, this.FillColor, shade);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ public abstract class CircleTargetedEntityDrawingModuleBase : CircleEntityDrawin
{
protected virtual Color OutlineColor { get; } = Colors.Chocolate;

public override sealed void DrawEntity(int finalX, int finalY, int size, double angle, WriteableBitmap bitmap, bool targeted, Color shade)
public override sealed void DrawEntity(int finalX, int finalY, int size, double angle, double entityAngle, WriteableBitmap bitmap, bool targeted, Color shade)
{
if (targeted)
{
var outlineSize = size + (size / 5);
this.DrawFilledCircle(bitmap, finalX, finalY, outlineSize, this.OutlineColor, shade);
}

base.DrawEntity(finalX, finalY, size, angle, bitmap, targeted, shade);
base.DrawEntity(finalX, finalY, size, angle, entityAngle, bitmap, targeted, shade);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public abstract class StarEntityDrawingModuleBase : StarDrawingModuleBase
{
protected abstract Color FillColor { get; }

public override void DrawEntity(int finalX, int finalY, int size, double angle, WriteableBitmap bitmap, bool targeted, Color shade)
public override void DrawEntity(int finalX, int finalY, int size, double cameraAngle, double entityAngle, WriteableBitmap bitmap, bool targeted, Color shade)
{
this.DrawFilledStar(bitmap, finalX, finalY, size, angle, this.FillColor, shade);
this.DrawFilledStar(bitmap, finalX, finalY, size, cameraAngle, this.FillColor, shade);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ public abstract class StarTargetedEntityDrawingModuleBase : StarEntityDrawingMod
{
protected virtual Color OutlineColor { get; } = Colors.Chocolate;

public override sealed void DrawEntity(int finalX, int finalY, int size, double angle, WriteableBitmap bitmap, bool targeted, Color shade)
public override sealed void DrawEntity(int finalX, int finalY, int size, double angle, double entityAngle, WriteableBitmap bitmap, bool targeted, Color shade)
{
base.DrawEntity(finalX, finalY, size, angle, bitmap, targeted, shade);
base.DrawEntity(finalX, finalY, size, angle, entityAngle, bitmap, targeted, shade);
if (targeted)
{
var thickness = size / 5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public abstract class TriangleEntityDrawingModuleBase : TriangleDrawingModuleBas
{
protected abstract Color FillColor { get; }

public override void DrawEntity(int finalX, int finalY, int size, double angle, WriteableBitmap bitmap, bool targeted, Color shade)
public override void DrawEntity(int finalX, int finalY, int size, double cameraAngle, double entityAngle, WriteableBitmap bitmap, bool targeted, Color shade)
{
this.DrawFilledTriangle(bitmap, finalX, finalY, size, angle, this.FillColor, shade);
this.DrawFilledTriangle(bitmap, finalX, finalY, size, cameraAngle, this.FillColor, shade);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ public abstract class TriangleTargetedEntityDrawingModuleBase : TriangleEntityDr
{
protected virtual Color OutlineColor { get; } = Colors.Chocolate;

public override sealed void DrawEntity(int finalX, int finalY, int size, double angle, WriteableBitmap bitmap, bool targeted, Color shade)
public override sealed void DrawEntity(int finalX, int finalY, int size, double angle, double entityAngle, WriteableBitmap bitmap, bool targeted, Color shade)
{
base.DrawEntity(finalX, finalY, size, angle, bitmap, targeted, shade);
base.DrawEntity(finalX, finalY, size, angle, entityAngle, bitmap, targeted, shade);
if (targeted)
{
var thickness = size / 5;
Expand Down
5 changes: 5 additions & 0 deletions Daybreak/Services/Drawing/Resources/CircledArrow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 7 additions & 2 deletions Daybreak/Services/Scanner/GWCAMemoryReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,8 @@ public async Task EnsureInitialized(uint processId, CancellationToken cancellati
_ => LivingEntityState.Unknown
},
Health = state.Health,
Energy = state.Energy
Energy = state.Energy,
RotationAngle = state.RotationAngle
};
}).ToList();

Expand Down Expand Up @@ -826,6 +827,7 @@ private static MainPlayerInformation ParsePayload(MainPlayerPayload mainPlayerPa
Timer = worldPlayer.Timer,
TitleInformation = worldPlayer.TitleInformation,
UnlockedProfession = worldPlayer.UnlockedProfession,
RotationAngle = worldPlayer.RotationAngle,
QuestLog = mainPlayerPayload.QuestLog?.Select(metadata =>
{
if (!Quest.TryParse((int)metadata.Id, out var q))
Expand Down Expand Up @@ -865,6 +867,7 @@ private static WorldPlayerInformation ParsePayload(WorldPlayerPayload worldPlaye
Name = worldPlayerPayload.Name,
Timer = partyPlayer.Timer,
UnlockedProfession = partyPlayer.UnlockedProfession,
RotationAngle = partyPlayer.RotationAngle,
TitleInformation = new TitleInformation
{
CurrentPoints = worldPlayerPayload.Title?.CurrentPoints,
Expand Down Expand Up @@ -924,6 +927,7 @@ private static PlayerInformation ParsePayload(PartyPlayerPayload partyPlayerPayl
NpcDefinition = livingEntity.NpcDefinition,
ModelType = livingEntity.ModelType ?? 0,
Timer = livingEntity.Timer,
RotationAngle = livingEntity.RotationAngle,
UnlockedProfession = partyPlayerPayload.UnlockedProfession?.Select(id =>
{
if (Profession.TryParse((int)id, out var profession))
Expand Down Expand Up @@ -959,7 +963,8 @@ private static LivingEntity ParsePayload(LivingEntityPayload livingEntityPayload
Y = livingEntityPayload.PosY,
},
Health = livingEntityPayload.Health,
Energy = livingEntityPayload.Energy
Energy = livingEntityPayload.Energy,
RotationAngle = livingEntityPayload.RotationAngle
};
}

Expand Down
Loading

0 comments on commit 641aa82

Please sign in to comment.