diff --git a/Dalamud.Injector/Program.cs b/Dalamud.Injector/Program.cs index dfa91a07f..75c0a8a75 100644 --- a/Dalamud.Injector/Program.cs +++ b/Dalamud.Injector/Program.cs @@ -19,7 +19,7 @@ namespace Dalamud.Injector { Process.GetCurrentProcess().Kill(); }; - int pid = int.Parse(args[0]); + var pid = int.Parse(args[0]); Process process = null; diff --git a/Dalamud/Dalamud.cs b/Dalamud/Dalamud.cs index 589b5093e..3f756922a 100644 --- a/Dalamud/Dalamud.cs +++ b/Dalamud/Dalamud.cs @@ -158,8 +158,8 @@ namespace Dalamud { HelpMessage = "Unmute a word or sentence. Usage: /fatewatchremove " }); - CommandManager.AddHandler("/xldactortable", new CommandInfo(OnDebugActorTable) { - HelpMessage = "Actor table operations", + CommandManager.AddHandler("/xldstate", new CommandInfo(OnDebugPrintGameState) { + HelpMessage = "Print parsed game state", ShowInHelp = false }); @@ -318,11 +318,13 @@ namespace Dalamud { Process.Start(ChatHandlers.LastLink); } - private void OnDebugActorTable(string command, string arguments) { + private void OnDebugPrintGameState(string command, string arguments) { Framework.Gui.Chat.Print(this.ClientState.Actors.Length + " entries"); Framework.Gui.Chat.Print(this.ClientState.LocalPlayer.Name); Framework.Gui.Chat.Print(this.ClientState.LocalPlayer.CurrentWorld.Name); + Framework.Gui.Chat.Print(this.ClientState.LocalPlayer.HomeWorld.Name); Framework.Gui.Chat.Print(this.ClientState.LocalContentId.ToString("X")); + Framework.Gui.Chat.Print(Framework.Gui.Chat.LastLinkedItemId.ToString()); for (var i = 0; i < this.ClientState.Actors.Length; i++) { var actor = this.ClientState.Actors[i]; @@ -344,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) @@ -369,7 +372,6 @@ namespace Dalamud { continue; this.Configuration.ComboPresets |= value; - Framework.Gui.Chat.Print(argumentsParts[1] + " SET"); } } break; @@ -379,7 +381,6 @@ namespace Dalamud { continue; this.Configuration.ComboPresets ^= value; - Framework.Gui.Chat.Print(argumentsParts[1] + " TOGGLE"); } } break; @@ -390,10 +391,10 @@ namespace Dalamud { continue; this.Configuration.ComboPresets &= ~value; - Framework.Gui.Chat.Print(argumentsParts[1] + " UNSET"); } } 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 b14a0da76..9a99ab4ff 100644 --- a/Dalamud/Dalamud.csproj +++ b/Dalamud/Dalamud.csproj @@ -7,27 +7,28 @@ 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 - E:\Sapphire\recorder\FFXIV.Recorder\/bin\Dalamud.xml + 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/ChatHandlers.cs b/Dalamud/Game/ChatHandlers.cs index 158527216..4005107a4 100644 --- a/Dalamud/Game/ChatHandlers.cs +++ b/Dalamud/Game/ChatHandlers.cs @@ -92,8 +92,8 @@ namespace Dalamud.Game { .GetResult()); - if (this.HandledChatTypeColors.ContainsKey(type) || type == XivChatType.Say || type == XivChatType.Shout || - type == XivChatType.Alliance || type == XivChatType.TellOutgoing || type == XivChatType.Yell) { + if ((this.HandledChatTypeColors.ContainsKey(type) || type == XivChatType.Say || type == XivChatType.Shout || + type == XivChatType.Alliance || type == XivChatType.TellOutgoing || type == XivChatType.Yell) && !message.Contains((char)0x02)) { var italicsStart = message.IndexOf("*"); var italicsEnd = message.IndexOf("*", italicsStart + 1); 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/ClientState/ClientStateAddressResolver.cs b/Dalamud/Game/ClientState/ClientStateAddressResolver.cs index afe8ef25d..885f0b31e 100644 --- a/Dalamud/Game/ClientState/ClientStateAddressResolver.cs +++ b/Dalamud/Game/ClientState/ClientStateAddressResolver.cs @@ -13,8 +13,8 @@ namespace Dalamud.Game.ClientState public IntPtr JobGaugeData { get; set; } protected override void Setup64Bit(SigScanner sig) { - ActorTable = sig.Module.BaseAddress + 0x1B29B40; - LocalContentId = sig.Module.BaseAddress + 0x1B58B60; + ActorTable = sig.Module.BaseAddress + 0x1C01D90; + LocalContentId = sig.Module.BaseAddress + 0x1C2E000; JobGaugeData = sig.Module.BaseAddress + 0x1BFD110; } } diff --git a/Dalamud/Game/ClientState/Structs/Actor.cs b/Dalamud/Game/ClientState/Structs/Actor.cs index 3e1d9ac7c..4dff763c7 100644 --- a/Dalamud/Game/ClientState/Structs/Actor.cs +++ b/Dalamud/Game/ClientState/Structs/Actor.cs @@ -20,13 +20,13 @@ namespace Dalamud.Game.ClientState.Structs [FieldOffset(140)] public ObjectKind ObjectKind; [FieldOffset(141)] public byte SubKind; [FieldOffset(160)] public Position3 Position; - [FieldOffset(6296)] public byte CurrentWorld; - [FieldOffset(6298)] public byte HomeWorld; - [FieldOffset(6308)] public int CurrentHp; - [FieldOffset(6312)] public int MaxHp; - [FieldOffset(6316)] public int CurrentMp; - [FieldOffset(6320)] public int MaxMp; - [FieldOffset(6364)] public byte ClassJob; - [FieldOffset(6366)] public byte Level; + [FieldOffset(6308)] public byte CurrentWorld; + [FieldOffset(6310)] public byte HomeWorld; + [FieldOffset(6328)] public int CurrentHp; + [FieldOffset(6332)] public int MaxHp; + [FieldOffset(6336)] public int CurrentMp; + [FieldOffset(6340)] public int MaxMp; + [FieldOffset(6388)] public byte ClassJob; + [FieldOffset(6390)] public byte Level; } } diff --git a/Dalamud/Game/Internal/Gui/ChatGuiAddressResolver.cs b/Dalamud/Game/Internal/Gui/ChatGuiAddressResolver.cs index 67478e423..0516fce54 100644 --- a/Dalamud/Game/Internal/Gui/ChatGuiAddressResolver.cs +++ b/Dalamud/Game/Internal/Gui/ChatGuiAddressResolver.cs @@ -76,13 +76,18 @@ namespace Dalamud.Game.Internal.Gui { */ protected override void Setup64Bit(SigScanner sig) { - PrintMessage = sig.ScanText("4055 57 41 ?? 41 ?? 488DAC24D8FEFFFF 4881EC28020000 488B05???????? 4833C4 488985F0000000 4532D2 48894C2448"); + //PrintMessage = sig.ScanText("4055 57 41 ?? 41 ?? 488DAC24D8FEFFFF 4881EC28020000 488B05???????? 4833C4 488985F0000000 4532D2 48894C2448"); LAST PART FOR 5.1??? + PrintMessage = + sig.ScanText( + "4055 57 41 ?? 41 ?? 4157488DAC24E0FE FFFF4881EC2002 0000488B05???? ????48 33C4488985F000 000045 32D248894C2448"); //PrintMessage = sig.ScanText("4055 57 41 ?? 41 ?? 488DAC24E8FEFFFF 4881EC18020000 488B05???????? 4833C4 488985E0000000 4532D2 48894C2438"); old - + //PrintMessage = sig.ScanText("40 55 57 41 56 41 57 48 8D AC 24 D8 FE FF FF 48 81 EC 28 02 00 00 48 8B 05 63 47 4A 01 48 33 C4 48 89 85 F0 00 00 00 45 32 D2 48 89 4C 24 48 33"); //PopulateItemLinkObject = sig.ScanText("48 89 5C 24 08 57 48 83 EC 20 80 7A 06 00 48 8B DA 48 8B F9 74 14 48 8B CA E8 32 03 00 00 48 8B C8 E8 FA F2 B0 FF 8B C8 EB 1D 0F B6 42 14 8B 4A"); - PopulateItemLinkObject = sig.ScanText("48 89 5C 24 08 57 48 83 EC 20 80 7A 06 00 48 8B DA 48 8B F9 74 14 48 8B CA E8 32 03 00 00 48 8B C8 E8 ?? ?? B0 FF 8B C8 EB 1D 0F B6 42 14 8B 4A"); + + //PopulateItemLinkObject = sig.ScanText("48 89 5C 24 08 57 48 83 EC 20 80 7A 06 00 48 8B DA 48 8B F9 74 14 48 8B CA E8 32 03 00 00 48 8B C8 E8 ?? ?? B0 FF 8B C8 EB 1D 0F B6 42 14 8B 4A"); 5.0 + PopulateItemLinkObject = sig.ScanText("48 89 5C 24 08 57 48 83 EC 20 80 7A 06 00 48 8B DA 48 8B F9 74 14 48 8B CA E8 32 03 00 00 48 8B C8 E8 7A 12 AF FF 8B C8 EB 1D 0F B6 42 14 8B 4A"); } } } diff --git a/Dalamud/Game/Internal/Gui/IconReplacer.cs b/Dalamud/Game/Internal/Gui/IconReplacer.cs index 7f89b401c..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,27 +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. - int lastMove = Marshal.ReadInt32(lastComboMove); - float comboTime = (float)Marshal.ReadInt32(comboTimer); - //localCharacter = dalamud.ClientState.LocalPlayer; - //byte level = localCharacter.Level; - byte level = 80; + var lastMove = Marshal.ReadInt32(this.lastComboMove); + var comboTime = Marshal.ReadInt32(this.comboTimer); + var level = 80; // DRAGOON // TODO: Jump/High Jump into Mirage Dive @@ -841,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/Internal/Gui/TargetManager.cs b/Dalamud/Game/Internal/Gui/TargetManager.cs new file mode 100644 index 000000000..a6a1c45ee --- /dev/null +++ b/Dalamud/Game/Internal/Gui/TargetManager.cs @@ -0,0 +1,55 @@ +using Dalamud.Game.ClientState; +using Dalamud.Game.ClientState.Actors.Types; +using Dalamud.Game.ClientState.Structs.JobGauge; +using Dalamud.Hooking; +using Serilog; +using System; +using System.Diagnostics; +using System.Runtime.InteropServices; +using XIVLauncher.Dalamud; + +namespace Dalamud.Game.Internal.Gui { + public class TargetManager { + public delegate IntPtr GetTargetDelegate(IntPtr manager); + + private Hook getTargetHook; + + private TargetManagerAddressResolver Address; + + public unsafe TargetManager(Dalamud dalamud, SigScanner scanner) { + this.Address = new TargetManagerAddressResolver(); + this.Address.Setup(scanner); + + Log.Verbose("===== T A R G E T M A N A G E R ====="); + Log.Verbose("GetTarget address {GetTarget}", Address.GetTarget); + + this.getTargetHook = new Hook(this.Address.GetTarget, new GetTargetDelegate(GetTargetDetour), this); + } + + public void Enable() { + this.getTargetHook.Enable(); + } + + public void Dispose() { + this.getTargetHook.Dispose(); + } + + private IntPtr GetTargetDetour(IntPtr manager) + { + try { + var res = this.getTargetHook.Original(manager); + + var test = Marshal.ReadInt32(res); + + Log.Debug($"GetTargetDetour {manager.ToInt64():X} -> RET: {res:X}"); + + return res; + } + catch (Exception ex) + { + Log.Error(ex, "Exception GetTargetDetour hook."); + return this.getTargetHook.Original(manager); + } + } + } +} diff --git a/Dalamud/Game/Internal/Gui/TargetManagerAddressResolver.cs b/Dalamud/Game/Internal/Gui/TargetManagerAddressResolver.cs new file mode 100644 index 000000000..137742bc0 --- /dev/null +++ b/Dalamud/Game/Internal/Gui/TargetManagerAddressResolver.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Dalamud.Game.Internal.Gui { + class TargetManagerAddressResolver : BaseAddressResolver { + public IntPtr GetTarget { get; private set; } + + protected override void Setup64Bit(SigScanner sig) { + this.GetTarget = sig.ScanText("40 57 48 83 EC 40 48 8B F9 48 8B 49 08 48 8B 01 FF 50 40 66 83 B8 CA 81 00 00 00 74 33 48 8B 4F 08 48 8B 01 FF 50 40 66 83 B8 CA 81 00 00 04 74"); + } + } +} diff --git a/Dalamud/Game/Internal/Network/GameNetworkAddressResolver.cs b/Dalamud/Game/Internal/Network/GameNetworkAddressResolver.cs index 08868c3a4..02f76e865 100644 --- a/Dalamud/Game/Internal/Network/GameNetworkAddressResolver.cs +++ b/Dalamud/Game/Internal/Network/GameNetworkAddressResolver.cs @@ -5,7 +5,8 @@ namespace Dalamud.Game.Internal.Network { public IntPtr ProcessZonePacket { get; private set; } protected override void Setup64Bit(SigScanner sig) { - ProcessZonePacket = sig.ScanText("48 89 74 24 18 57 48 83 EC 50 8B F2 49 8B F8 41 0F B7 50 02 8B CE E8 ?? ?? 7A FF 0F B7 57 02 8D 42 89 3D 5F 02 00 00 0F 87 60 01 00 00 4C 8D 05"); + //ProcessZonePacket = sig.ScanText("48 89 74 24 18 57 48 83 EC 50 8B F2 49 8B F8 41 0F B7 50 02 8B CE E8 ?? ?? 7A FF 0F B7 57 02 8D 42 89 3D 5F 02 00 00 0F 87 60 01 00 00 4C 8D 05"); + ProcessZonePacket = sig.ScanText("48 89 74 24 18 57 48 83 EC 50 8B F2 49 8B F8 41 0F B7 50 02 8B CE E8 ?? ?? 73 FF 0F B7 57 02 8D 42 ?? 3D ?? ?? 00 00 0F 87 60 01 00 00 4C 8D 05"); } } } 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];