From 1fffc18da9c6959eb1264fb247fc952a00c92514 Mon Sep 17 00:00:00 2001
From: goat <16760685+goaaats@users.noreply.github.com>
Date: Sat, 25 Jul 2020 21:21:51 +0200
Subject: [PATCH] fix: DI in payloads
---
Dalamud.Injector/Program.cs | 4 ++--
.../Payloads/AutoTranslatePayload.cs | 6 ++++--
.../SeStringHandling/Payloads/ItemPayload.cs | 6 ++++--
.../SeStringHandling/Payloads/MapLinkPayload.cs | 10 +++++++---
.../SeStringHandling/Payloads/PlayerPayload.cs | 6 ++++--
.../SeStringHandling/Payloads/StatusPayload.cs | 6 ++++--
.../Payloads/UIForegroundPayload.cs | 9 ++++++---
.../SeStringHandling/Payloads/UIGlowPayload.cs | 9 ++++++---
.../Chat/SeStringHandling/SeStringManager.cs | 16 ++++++++--------
9 files changed, 45 insertions(+), 27 deletions(-)
diff --git a/Dalamud.Injector/Program.cs b/Dalamud.Injector/Program.cs
index 4c9d791ca..19b22cac1 100644
--- a/Dalamud.Injector/Program.cs
+++ b/Dalamud.Injector/Program.cs
@@ -75,9 +75,9 @@ namespace Dalamud.Injector {
Thread.Sleep(1000);
-#if NO
+#if DEBUG
// Inject exception handler
- NativeInject(process);
+ //NativeInject(process);
#endif
}
diff --git a/Dalamud/Game/Chat/SeStringHandling/Payloads/AutoTranslatePayload.cs b/Dalamud/Game/Chat/SeStringHandling/Payloads/AutoTranslatePayload.cs
index c31c4c026..c01ed0ee2 100644
--- a/Dalamud/Game/Chat/SeStringHandling/Payloads/AutoTranslatePayload.cs
+++ b/Dalamud/Game/Chat/SeStringHandling/Payloads/AutoTranslatePayload.cs
@@ -4,6 +4,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
+using Dalamud.Data;
using Dalamud.Data.TransientSheet;
namespace Dalamud.Game.Chat.SeStringHandling.Payloads
@@ -41,14 +42,15 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
///
/// Creates a new auto-translate payload.
///
+ /// DataManager instance needed to resolve game data.
/// The group id for this message.
/// The key/row id for this message. Which table this is in depends on the group id and details the Completion table.
///
/// This table is somewhat complicated in structure, and so using this constructor may not be very nice.
/// There is probably little use to create one of these, however.
///
- public AutoTranslatePayload(uint group, uint key)
- {
+ public AutoTranslatePayload(DataManager data, uint group, uint key) {
+ this.DataResolver = data;
this.group = group;
this.key = key;
}
diff --git a/Dalamud/Game/Chat/SeStringHandling/Payloads/ItemPayload.cs b/Dalamud/Game/Chat/SeStringHandling/Payloads/ItemPayload.cs
index e0ca4b481..265b8d088 100644
--- a/Dalamud/Game/Chat/SeStringHandling/Payloads/ItemPayload.cs
+++ b/Dalamud/Game/Chat/SeStringHandling/Payloads/ItemPayload.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
+using Dalamud.Data;
using Lumina.Excel.GeneratedSheets;
namespace Dalamud.Game.Chat.SeStringHandling.Payloads
@@ -65,13 +66,14 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
///
/// Creates a payload representing an interactable item link for the specified item.
///
+ /// DataManager instance needed to resolve game data.
/// The id of the item.
/// Whether or not the link should be for the high-quality variant of the item.
/// An optional name to include in the item link. Typically this should
/// be left as null, or set to the normal item name. Actual overrides are better done with the subsequent
/// TextPayload that is a part of a full item link in chat.
- public ItemPayload(uint itemId, bool isHQ, string displayNameOverride = null)
- {
+ public ItemPayload(DataManager data, uint itemId, bool isHQ, string displayNameOverride = null) {
+ this.DataResolver = data;
this.itemId = itemId;
this.IsHQ = isHQ;
this.displayName = displayNameOverride;
diff --git a/Dalamud/Game/Chat/SeStringHandling/Payloads/MapLinkPayload.cs b/Dalamud/Game/Chat/SeStringHandling/Payloads/MapLinkPayload.cs
index 41bf4565b..768d95716 100644
--- a/Dalamud/Game/Chat/SeStringHandling/Payloads/MapLinkPayload.cs
+++ b/Dalamud/Game/Chat/SeStringHandling/Payloads/MapLinkPayload.cs
@@ -2,6 +2,7 @@ using Lumina.Excel.GeneratedSheets;
using System;
using System.Collections.Generic;
using System.IO;
+using Dalamud.Data;
namespace Dalamud.Game.Chat.SeStringHandling.Payloads
{
@@ -137,13 +138,14 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
///
/// Creates an interactable MapLinkPayload from a human-readable position.
///
+ /// DataManager instance needed to resolve game data.
/// The id of the TerritoryType entry for this link.
/// The id of the Map entry for this link.
/// The human-readable x-coordinate for this link.
/// The human-readable y-coordinate for this link.
/// An optional offset to account for rounding and truncation errors; it is best to leave this untouched in most cases.
- public MapLinkPayload(uint territoryTypeId, uint mapId, float niceXCoord, float niceYCoord, float fudgeFactor = 0.05f)
- {
+ public MapLinkPayload(DataManager data, uint territoryTypeId, uint mapId, float niceXCoord, float niceYCoord, float fudgeFactor = 0.05f) {
+ this.DataResolver = data;
this.territoryTypeId = territoryTypeId;
this.mapId = mapId;
// this fudge is necessary basically to ensure we don't shift down a full tenth
@@ -156,12 +158,14 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
///
/// Creates an interactable MapLinkPayload from a raw position.
///
+ /// DataManager instance needed to resolve game data.
/// The id of the TerritoryType entry for this link.
/// The id of the Map entry for this link.
/// The internal raw x-coordinate for this link.
/// The internal raw y-coordinate for this link.
- public MapLinkPayload(uint territoryTypeId, uint mapId, int rawX, int rawY)
+ public MapLinkPayload(DataManager data, uint territoryTypeId, uint mapId, int rawX, int rawY)
{
+ this.DataResolver = data;
this.territoryTypeId = territoryTypeId;
this.mapId = mapId;
RawX = rawX;
diff --git a/Dalamud/Game/Chat/SeStringHandling/Payloads/PlayerPayload.cs b/Dalamud/Game/Chat/SeStringHandling/Payloads/PlayerPayload.cs
index ce32d1000..64ddcb374 100644
--- a/Dalamud/Game/Chat/SeStringHandling/Payloads/PlayerPayload.cs
+++ b/Dalamud/Game/Chat/SeStringHandling/Payloads/PlayerPayload.cs
@@ -3,6 +3,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
+using Dalamud.Data;
namespace Dalamud.Game.Chat.SeStringHandling.Payloads
{
@@ -56,10 +57,11 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
///
/// Create a PlayerPayload link for the specified player.
///
+ /// DataManager instance needed to resolve game data.
/// The player's displayed name.
/// The player's home server id.
- public PlayerPayload(string playerName, uint serverId)
- {
+ public PlayerPayload(DataManager data, string playerName, uint serverId) {
+ this.DataResolver = data;
this.playerName = playerName;
this.serverId = serverId;
}
diff --git a/Dalamud/Game/Chat/SeStringHandling/Payloads/StatusPayload.cs b/Dalamud/Game/Chat/SeStringHandling/Payloads/StatusPayload.cs
index b02a02cd3..a82438fc0 100644
--- a/Dalamud/Game/Chat/SeStringHandling/Payloads/StatusPayload.cs
+++ b/Dalamud/Game/Chat/SeStringHandling/Payloads/StatusPayload.cs
@@ -2,6 +2,7 @@ using Lumina.Excel.GeneratedSheets;
using System;
using System.Collections.Generic;
using System.IO;
+using Dalamud.Data;
namespace Dalamud.Game.Chat.SeStringHandling.Payloads
{
@@ -35,9 +36,10 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
///
/// Creates a new StatusPayload for the given status id.
///
+ /// DataManager instance needed to resolve game data.
/// The id of the Status for this link.
- public StatusPayload(uint statusId)
- {
+ public StatusPayload(DataManager data, uint statusId) {
+ this.DataResolver = data;
this.statusId = statusId;
}
diff --git a/Dalamud/Game/Chat/SeStringHandling/Payloads/UIForegroundPayload.cs b/Dalamud/Game/Chat/SeStringHandling/Payloads/UIForegroundPayload.cs
index 2772564e6..2fede7f94 100644
--- a/Dalamud/Game/Chat/SeStringHandling/Payloads/UIForegroundPayload.cs
+++ b/Dalamud/Game/Chat/SeStringHandling/Payloads/UIForegroundPayload.cs
@@ -2,6 +2,7 @@ using Lumina.Excel.GeneratedSheets;
using System;
using System.Collections.Generic;
using System.IO;
+using Dalamud.Data;
namespace Dalamud.Game.Chat.SeStringHandling.Payloads
{
@@ -13,7 +14,8 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
///
/// Payload representing disabling foreground color on following text.
///
- public static UIForegroundPayload UIForegroundOff => new UIForegroundPayload(0);
+ // TODO Make this work with DI
+ public static UIForegroundPayload UIForegroundOff => new UIForegroundPayload(null, 0);
public override PayloadType Type => PayloadType.UIForeground;
@@ -70,9 +72,10 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
///
/// Creates a new UIForegroundPayload for the given UIColor key.
///
+ /// DataManager instance needed to resolve game data.
///
- public UIForegroundPayload(ushort colorKey)
- {
+ public UIForegroundPayload(DataManager data, ushort colorKey) {
+ this.DataResolver = data;
this.colorKey = colorKey;
}
diff --git a/Dalamud/Game/Chat/SeStringHandling/Payloads/UIGlowPayload.cs b/Dalamud/Game/Chat/SeStringHandling/Payloads/UIGlowPayload.cs
index 60a431640..d82d249f3 100644
--- a/Dalamud/Game/Chat/SeStringHandling/Payloads/UIGlowPayload.cs
+++ b/Dalamud/Game/Chat/SeStringHandling/Payloads/UIGlowPayload.cs
@@ -2,6 +2,7 @@ using Lumina.Excel.GeneratedSheets;
using System;
using System.Collections.Generic;
using System.IO;
+using Dalamud.Data;
namespace Dalamud.Game.Chat.SeStringHandling.Payloads
{
@@ -13,7 +14,8 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
///
/// Payload representing disabling glow color on following text.
///
- public static UIGlowPayload UIGlowOff => new UIGlowPayload(0);
+ // TODO Make this work with DI
+ public static UIGlowPayload UIGlowOff => new UIGlowPayload(null, 0);
public override PayloadType Type => PayloadType.UIGlow;
@@ -70,9 +72,10 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
///
/// Creates a new UIForegroundPayload for the given UIColor key.
///
+ /// DataManager instance needed to resolve game data.
///
- public UIGlowPayload(ushort colorKey)
- {
+ public UIGlowPayload(DataManager data, ushort colorKey) {
+ this.DataResolver = data;
this.colorKey = colorKey;
}
diff --git a/Dalamud/Game/Chat/SeStringHandling/SeStringManager.cs b/Dalamud/Game/Chat/SeStringHandling/SeStringManager.cs
index ec0aae6bc..78667d574 100644
--- a/Dalamud/Game/Chat/SeStringHandling/SeStringManager.cs
+++ b/Dalamud/Game/Chat/SeStringHandling/SeStringManager.cs
@@ -60,9 +60,9 @@ namespace Dalamud.Game.Chat.SeStringHandling
// TODO: probably a cleaner way to build these than doing the bulk+insert
var payloads = new List(new Payload[]
{
- new UIForegroundPayload(0x0225),
- new UIGlowPayload(0x0226),
- new ItemPayload(itemId, isHQ),
+ new UIForegroundPayload(this.data, 0x0225),
+ new UIGlowPayload(this.data, 0x0226),
+ new ItemPayload(this.data, itemId, isHQ),
// arrow goes here
new TextPayload(displayName),
RawPayload.LinkTerminator
@@ -88,7 +88,7 @@ namespace Dalamud.Game.Chat.SeStringHandling
public SeString CreateMapLink(uint territoryId, uint mapId, int rawX, int rawY)
{
- var mapPayload = new MapLinkPayload(territoryId, mapId, rawX, rawY);
+ var mapPayload = new MapLinkPayload(this.data, territoryId, mapId, rawX, rawY);
var nameString = $"{mapPayload.PlaceName} {mapPayload.CoordinateString}";
var payloads = new List(new Payload[]
@@ -114,7 +114,7 @@ namespace Dalamud.Game.Chat.SeStringHandling
/// An SeString containing all of the payloads necessary to display a map link in the chat log.
public SeString CreateMapLink(uint territoryId, uint mapId, float xCoord, float yCoord, float fudgeFactor = 0.05f)
{
- var mapPayload = new MapLinkPayload(territoryId, mapId, xCoord, yCoord, fudgeFactor);
+ var mapPayload = new MapLinkPayload(this.data, territoryId, mapId, xCoord, yCoord, fudgeFactor);
var nameString = $"{mapPayload.PlaceName} {mapPayload.CoordinateString}";
var payloads = new List(new Payload[]
@@ -163,12 +163,12 @@ namespace Dalamud.Game.Chat.SeStringHandling
/// with the appropriate glow and coloring.
///
/// A list of all the payloads required to insert the link marker.
- public static List TextArrowPayloads()
+ public List TextArrowPayloads()
{
return new List(new Payload[]
{
- new UIForegroundPayload(0x01F4),
- new UIGlowPayload(0x01F5),
+ new UIForegroundPayload(this.data, 0x01F4),
+ new UIGlowPayload(this.data, 0x01F5),
new TextPayload($"{(char)SeIconChar.LinkMarker}"),
UIGlowPayload.UIGlowOff,
UIForegroundPayload.UIForegroundOff