From 75ed54117ccaf52ca0effb2644dd584620cdf716 Mon Sep 17 00:00:00 2001 From: goat Date: Sun, 3 Nov 2019 21:17:47 +0900 Subject: [PATCH] Some changes to Actor Table handling --- Dalamud/Dalamud.cs | 2 ++ Dalamud/Dalamud.csproj | 9 ++++---- Dalamud/Game/Chat/XivChatType.cs | 5 +++++ Dalamud/Game/ClientState/Actors/ActorTable.cs | 13 +++++++++--- Dalamud/Game/ClientState/ClientState.cs | 9 +++++++- Dalamud/Game/Internal/Gui/IconReplacer.cs | 21 +++++++------------ Dalamud/Game/Network/NetworkHandlers.cs | 14 ++++++------- Dalamud/XivApi.cs | 3 +++ 8 files changed, 46 insertions(+), 30 deletions(-) diff --git a/Dalamud/Dalamud.cs b/Dalamud/Dalamud.cs index 52ec31e1c..3f756922a 100644 --- a/Dalamud/Dalamud.cs +++ b/Dalamud/Dalamud.cs @@ -346,6 +346,7 @@ namespace Dalamud { var argumentsParts = arguments.Split(); switch (argumentsParts[0]) { + /* Sorry! case "setall": { foreach (var value in Enum.GetValues(typeof(CustomComboPreset)).Cast()) { if (value == CustomComboPreset.None) @@ -393,6 +394,7 @@ namespace Dalamud { } } break; + */ case "list": { foreach (var value in Enum.GetValues(typeof(CustomComboPreset)).Cast()) { if (this.Configuration.ComboPresets.HasFlag(value)) diff --git a/Dalamud/Dalamud.csproj b/Dalamud/Dalamud.csproj index d96583d65..9a99ab4ff 100644 --- a/Dalamud/Dalamud.csproj +++ b/Dalamud/Dalamud.csproj @@ -7,15 +7,16 @@ Library - $(SolutionDir)/bin + D:\Sapphire\recorder\FFXIV.Recorder\/bin false true Portable true - 2.1.0.0 - 2.1.0 + 2.2.0.0 + 2.2.0 + 2.2.0.0 @@ -27,7 +28,7 @@ E:\Sapphire\recorder\FFXIV.Recorder\/bin\Dalamud.xml - E:\Sapphire\recorder\FFXIV.Recorder\/bin\Dalamud.xml + D:\Sapphire\recorder\FFXIV.Recorder\/bin\Dalamud.xml E:\Sapphire\recorder\FFXIV.Recorder\/bin\Dalamud.xml diff --git a/Dalamud/Game/Chat/XivChatType.cs b/Dalamud/Game/Chat/XivChatType.cs index d909947cb..a52584153 100644 --- a/Dalamud/Game/Chat/XivChatType.cs +++ b/Dalamud/Game/Chat/XivChatType.cs @@ -61,6 +61,11 @@ namespace Dalamud.Game.Chat { [XivChatTypeInfo("Novice Network", "nn", 0xFF8B4513)] NoviceNetwork = 27, + [XivChatTypeInfo("Custom Emotes", "nn", 0xFF8B4513)] + CustomEmote = 28, + [XivChatTypeInfo("Standard Emotes", null, 0xFF8B4513)] + StandardEmote = 29, + [XivChatTypeInfo("Yell", "y", 0xFFFFFF00)] Yell = 30, diff --git a/Dalamud/Game/ClientState/Actors/ActorTable.cs b/Dalamud/Game/ClientState/Actors/ActorTable.cs index d1dd88a92..2dd497bc4 100644 --- a/Dalamud/Game/ClientState/Actors/ActorTable.cs +++ b/Dalamud/Game/ClientState/Actors/ActorTable.cs @@ -9,7 +9,7 @@ namespace Dalamud.Game.ClientState.Actors { /// /// This collection represents the currently spawned FFXIV actors. /// - public unsafe class ActorTable : ICollection { + public class ActorTable : ICollection { private ClientStateAddressResolver Address { get; } /// @@ -29,8 +29,15 @@ namespace Dalamud.Game.ClientState.Actors { /// at the specified spawn index. public Actor this[int index] { get { + if (index > Length) + return null; + + Log.Information("Trying to get actor at {0}", index); var tblIndex = Address.ActorTable + 8 + index * 8; - var offset = *(IntPtr*) tblIndex; + + var offset = Marshal.ReadIntPtr(tblIndex); + + Log.Information("Actor at {0}", offset.ToString()); if (offset == IntPtr.Zero) throw new Exception($"Actor slot at index {index} is invalid"); @@ -76,7 +83,7 @@ namespace Dalamud.Game.ClientState.Actors { /// /// The amount of currently spawned actors. /// - public int Length => *(int*) Address.ActorTable; + public int Length => Marshal.ReadInt32(Address.ActorTable); int ICollection.Count => Length; diff --git a/Dalamud/Game/ClientState/ClientState.cs b/Dalamud/Game/ClientState/ClientState.cs index 98e1c2e29..e0e038382 100644 --- a/Dalamud/Game/ClientState/ClientState.cs +++ b/Dalamud/Game/ClientState/ClientState.cs @@ -32,7 +32,7 @@ namespace Dalamud.Game.ClientState /// /// The local player character, if one is present. /// - public PlayerCharacter LocalPlayer => (PlayerCharacter) this.Actors[0]; + public PlayerCharacter LocalPlayer { get; private set; } /// /// The content ID of the local character. @@ -62,6 +62,13 @@ namespace Dalamud.Game.ClientState this.Actors = new ActorTable(Address); this.JobGauges = new JobGauges(Address); + + dalamud.Framework.OnUpdateEvent += FrameworkOnOnUpdateEvent; + } + + private void FrameworkOnOnUpdateEvent(Framework framework) { + LocalPlayer = (PlayerCharacter) this.Actors[0]; + Log.Verbose("FRAMEWORK UPDATE"); } } } diff --git a/Dalamud/Game/Internal/Gui/IconReplacer.cs b/Dalamud/Game/Internal/Gui/IconReplacer.cs index 069af81a8..40630cab0 100644 --- a/Dalamud/Game/Internal/Gui/IconReplacer.cs +++ b/Dalamud/Game/Internal/Gui/IconReplacer.cs @@ -24,7 +24,6 @@ namespace Dalamud.Game.Internal.Gui { private IntPtr jobInfo; private IntPtr byteBase; private Dalamud dalamud; - private PlayerCharacter localCharacter = null; public unsafe IconReplacer(Dalamud dalamud, SigScanner scanner) { this.dalamud = dalamud; @@ -68,12 +67,13 @@ namespace Dalamud.Game.Internal.Gui { /// For example, Souleater combo on DRK happens by dragging Souleater /// onto your bar and mashing it. /// - private unsafe ulong GetIconDetour(byte self, uint actionID) { + private ulong GetIconDetour(byte self, uint actionID) { // TODO: More jobs, level checking for everything. // Check if player is loaded in by trying to get their buffs. // If not, skip everything until we are (game will crash cause I'm lazy). + /* if (activeBuffArray == IntPtr.Zero) { try { activeBuffArray = FindBuffAddress(); @@ -84,24 +84,16 @@ namespace Dalamud.Game.Internal.Gui { return this.iconHook.Original(self, actionID); } } + */ // TODO: this is currently broken // As it stands, don't rely on localCharacter.level for anything. - if (localCharacter == null) { - try { - localCharacter = dalamud.ClientState.LocalPlayer; - } - catch(Exception e) { - localCharacter = null; - return this.iconHook.Original(self, actionID); - } - } + var localPlayer = this.dalamud.ClientState.LocalPlayer; // Don't clutter the spaghetti any worse than it already is. var lastMove = Marshal.ReadInt32(this.lastComboMove); var comboTime = Marshal.ReadInt32(this.comboTimer); - this.localCharacter = this.dalamud.ClientState.LocalPlayer; - var level = this.localCharacter.Level; + var level = 80; // DRAGOON // TODO: Jump/High Jump into Mirage Dive @@ -838,10 +830,11 @@ namespace Dalamud.Game.Internal.Gui { return this.iconHook.Original(self, actionID); } - private bool SearchBuffArray(short needle) { + private bool SearchBuffArray(short needle) {/* for (int i = 0; i < 60; i++) { if (Marshal.ReadInt16(activeBuffArray + 4 * i) == needle) return true; } + */ return false; } diff --git a/Dalamud/Game/Network/NetworkHandlers.cs b/Dalamud/Game/Network/NetworkHandlers.cs index eea77eb4c..ba3a636ac 100644 --- a/Dalamud/Game/Network/NetworkHandlers.cs +++ b/Dalamud/Game/Network/NetworkHandlers.cs @@ -64,18 +64,16 @@ namespace Dalamud.Game.Network { Marshal.Copy(dataPtr, data, 0, 64); var notifyType = data[16]; - var contentFinderConditionId = BitConverter.ToInt16(data, 38); + var contentFinderConditionId = BitConverter.ToInt16(data, 28); Task.Run(async () => { - if (notifyType != 4) + if (notifyType != 2 || contentFinderConditionId == 0) return; var contentFinderCondition = await XivApi.GetContentFinderCondition(contentFinderConditionId); - this.dalamud.Framework.Gui.Chat.Print("Duty Finder pop: " + contentFinderCondition["Name"]); - if (this.dalamud.BotManager.IsConnected) await this.dalamud.BotManager.ProcessCfPop(contentFinderCondition); }); @@ -179,13 +177,13 @@ namespace Dalamud.Game.Network { } private enum ZoneOpCode { - CfNotify = 0x78, + CfNotify = 0x8F, RetainerSaleItemId = 0x13F, // TODO these are probably not accurate RetainerSaleFinish = 0x138, FateSpawn = 0x226, - MarketBoardItemRequestStart = 0x13B, - MarketBoardOfferings = 0x13C, - MarketBoardHistory = 0x140 + MarketBoardItemRequestStart = 0x39D, + MarketBoardOfferings = 0x36A, + MarketBoardHistory = 0x194 } } } diff --git a/Dalamud/XivApi.cs b/Dalamud/XivApi.cs index 6515541a5..dc5e5fa8b 100644 --- a/Dalamud/XivApi.cs +++ b/Dalamud/XivApi.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Microsoft.CSharp.RuntimeBinder; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using Serilog; namespace Dalamud { @@ -68,6 +69,8 @@ namespace Dalamud public static async Task Get(string endpoint, bool noCache = false) { + Log.Verbose("XIVAPI FETCH: {0}", endpoint); + if (cachedResponses.ContainsKey(endpoint) && !noCache) return cachedResponses[endpoint];