From b857506fd6b007742622941e055d2d28c53187e3 Mon Sep 17 00:00:00 2001 From: goat Date: Sat, 16 Nov 2019 21:05:44 +0900 Subject: [PATCH] 5.1 fixed, minimal chat mode --- Dalamud.Injector/Dalamud.Injector.csproj | 6 +- Dalamud/Dalamud.csproj | 6 +- Dalamud/DiscordBot/DiscordBotManager.cs | 114 +++++++++++------- .../DiscordBot/DiscordFeatureConfiguration.cs | 5 +- .../ClientState/ClientStateAddressResolver.cs | 2 +- .../Internal/Gui/ChatGuiAddressResolver.cs | 4 +- Dalamud/Game/Internal/Network/GameNetwork.cs | 2 +- Dalamud/Game/Network/NetworkHandlers.cs | 12 +- 8 files changed, 90 insertions(+), 61 deletions(-) diff --git a/Dalamud.Injector/Dalamud.Injector.csproj b/Dalamud.Injector/Dalamud.Injector.csproj index 7ccda5c39..c78eb8453 100644 --- a/Dalamud.Injector/Dalamud.Injector.csproj +++ b/Dalamud.Injector/Dalamud.Injector.csproj @@ -14,10 +14,10 @@ true - 2.9.0.0 - 2.9.0.0 + 3.1.0.0 + 3.1.0.0 XIVLauncher addon injection - 2.9.0 + 3.1.0 diff --git a/Dalamud/Dalamud.csproj b/Dalamud/Dalamud.csproj index ec8fdbac5..d99acb87b 100644 --- a/Dalamud/Dalamud.csproj +++ b/Dalamud/Dalamud.csproj @@ -14,9 +14,9 @@ true - 2.7.0.0 - 2.7.0 - 2.7.0.0 + 2.9.0.0 + 2.9.0 + 2.9.0.0 diff --git a/Dalamud/DiscordBot/DiscordBotManager.cs b/Dalamud/DiscordBot/DiscordBotManager.cs index e9195feb0..b2d6d11db 100644 --- a/Dalamud/DiscordBot/DiscordBotManager.cs +++ b/Dalamud/DiscordBot/DiscordBotManager.cs @@ -260,62 +260,88 @@ namespace Dalamud.DiscordBot { var avatarUrl = ""; var lodestoneId = 0; - try { - dynamic charCandidates = await XivApi.GetCharacterSearch(sender, world); + if (!this.config.DisableEmbeds) { + try + { + dynamic charCandidates = await XivApi.GetCharacterSearch(sender, world); - if (charCandidates.Results.Count > 0) { - avatarUrl = charCandidates.Results[0].Avatar; - lodestoneId = charCandidates.Results[0].ID; + if (charCandidates.Results.Count > 0) + { + avatarUrl = charCandidates.Results[0].Avatar; + lodestoneId = charCandidates.Results[0].ID; + } + } + catch (Exception ex) + { + Log.Error(ex, "Could not get XIVAPI character search result."); } - } catch (Exception ex) { - Log.Error(ex, "Could not get XIVAPI character search result."); } Thread.Sleep(this.config.ChatDelayMs); + var name = wasOutgoingTell + ? "You" + : sender + (string.IsNullOrEmpty(world) || string.IsNullOrEmpty(sender) + ? "" + : $" on {world}"); + for (var chatTypeIndex = 0; chatTypeIndex < chatTypeConfigs.Count(); chatTypeIndex++) { - var embedBuilder = new EmbedBuilder - { - Author = new EmbedAuthorBuilder + if (!this.config.DisableEmbeds) { + var embedBuilder = new EmbedBuilder { - IconUrl = avatarUrl, - Name = wasOutgoingTell - ? "You" - : sender + (string.IsNullOrEmpty(world) || string.IsNullOrEmpty(sender) - ? "" - : $" on {world}"), - Url = lodestoneId != 0 ? "https://eu.finalfantasyxiv.com/lodestone/character/" + lodestoneId : null - }, - Description = message, - Timestamp = DateTimeOffset.Now, - Footer = new EmbedFooterBuilder { Text = type.GetDetails().FancyName }, - Color = new Color((uint)(chatTypeConfigs.ElementAt(chatTypeIndex).Color & 0xFFFFFF)) - }; + Author = new EmbedAuthorBuilder + { + IconUrl = avatarUrl, + Name = name, + Url = lodestoneId != 0 ? "https://eu.finalfantasyxiv.com/lodestone/character/" + lodestoneId : null + }, + Description = message, + Timestamp = DateTimeOffset.Now, + Footer = new EmbedFooterBuilder { Text = type.GetDetails().FancyName }, + Color = new Color((uint)(chatTypeConfigs.ElementAt(chatTypeIndex).Color & 0xFFFFFF)) + }; - if (this.config.CheckForDuplicateMessages) - { - var recentMsg = this.recentMessages.FirstOrDefault( - msg => msg.Embeds.FirstOrDefault( - embed => embed.Description == embedBuilder.Description && - embed.Author.HasValue && - embed.Author.Value.Name == embedBuilder.Author.Name && - embed.Timestamp.HasValue && - Math.Abs( - (embed.Timestamp.Value.ToUniversalTime().Date - - embedBuilder - .Timestamp.Value.ToUniversalTime().Date) - .Milliseconds) < 15000) - != null); - - if (recentMsg != null) + if (this.config.CheckForDuplicateMessages) { - Log.Verbose("Duplicate message: [{0}] {1}", embedBuilder.Author.Name, embedBuilder.Description); - this.recentMessages.Remove(recentMsg); - return; + var recentMsg = this.recentMessages.FirstOrDefault( + msg => msg.Embeds.FirstOrDefault( + embed => embed.Description == embedBuilder.Description && + embed.Author.HasValue && + embed.Author.Value.Name == embedBuilder.Author.Name && + embed.Timestamp.HasValue && + Math.Abs( + (embed.Timestamp.Value.ToUniversalTime().Date - + embedBuilder + .Timestamp.Value.ToUniversalTime().Date) + .Milliseconds) < 15000) + != null); + + if (recentMsg != null) + { + Log.Verbose("Duplicate message: [{0}] {1}", embedBuilder.Author.Name, embedBuilder.Description); + this.recentMessages.Remove(recentMsg); + return; + } } - } - await channels.ElementAt(chatTypeIndex).SendMessageAsync(embed: embedBuilder.Build()); + await channels.ElementAt(chatTypeIndex).SendMessageAsync(embed: embedBuilder.Build()); + } else { + var simpleMessage = $"{name}: {message}"; + + if (this.config.CheckForDuplicateMessages) { + var recentMsg = this.recentMessages.FirstOrDefault( + msg => msg.Content == simpleMessage); + + if (recentMsg != null) + { + Log.Verbose("Duplicate message: {0}", simpleMessage); + this.recentMessages.Remove(recentMsg); + return; + } + } + + await channels.ElementAt(chatTypeIndex).SendMessageAsync($"{name}: {message}"); + } } } diff --git a/Dalamud/DiscordBot/DiscordFeatureConfiguration.cs b/Dalamud/DiscordBot/DiscordFeatureConfiguration.cs index 02c7f1228..2bd717863 100644 --- a/Dalamud/DiscordBot/DiscordFeatureConfiguration.cs +++ b/Dalamud/DiscordBot/DiscordFeatureConfiguration.cs @@ -32,11 +32,14 @@ namespace Dalamud.DiscordBot public class DiscordFeatureConfiguration { public string Token { get; set; } - public ulong OwnerUserId { get; set; } public bool CheckForDuplicateMessages { get; set; } public int ChatDelayMs { get; set; } + public bool DisableEmbeds { get; set; } + + public ulong OwnerUserId { get; set; } + public List ChatTypeConfigurations { get; set; } public ChannelConfiguration CfNotificationChannel { get; set; } diff --git a/Dalamud/Game/ClientState/ClientStateAddressResolver.cs b/Dalamud/Game/ClientState/ClientStateAddressResolver.cs index 885f0b31e..ba5c4c3d1 100644 --- a/Dalamud/Game/ClientState/ClientStateAddressResolver.cs +++ b/Dalamud/Game/ClientState/ClientStateAddressResolver.cs @@ -13,7 +13,7 @@ namespace Dalamud.Game.ClientState public IntPtr JobGaugeData { get; set; } protected override void Setup64Bit(SigScanner sig) { - ActorTable = sig.Module.BaseAddress + 0x1C01D90; + ActorTable = sig.Module.BaseAddress + 0x1BFBA38; LocalContentId = sig.Module.BaseAddress + 0x1C2E000; JobGaugeData = sig.Module.BaseAddress + 0x1BFD110; } diff --git a/Dalamud/Game/Internal/Gui/ChatGuiAddressResolver.cs b/Dalamud/Game/Internal/Gui/ChatGuiAddressResolver.cs index 0516fce54..974310e18 100644 --- a/Dalamud/Game/Internal/Gui/ChatGuiAddressResolver.cs +++ b/Dalamud/Game/Internal/Gui/ChatGuiAddressResolver.cs @@ -86,8 +86,8 @@ namespace Dalamud.Game.Internal.Gui { //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"); 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"); + //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 ?? ?? ?? FF 8B C8 EB 1D 0F B6 42 14 8B 4A"); } } } diff --git a/Dalamud/Game/Internal/Network/GameNetwork.cs b/Dalamud/Game/Internal/Network/GameNetwork.cs index f1928436c..a2093e1cd 100644 --- a/Dalamud/Game/Internal/Network/GameNetwork.cs +++ b/Dalamud/Game/Internal/Network/GameNetwork.cs @@ -74,7 +74,7 @@ namespace Dalamud.Game.Internal.Network { private void InjectActorControl(short cat, int param1) { var packetData = new byte[] { - 0x14, 0x00, 0x64, 0x01, 0x00, 0x00, 0x0E, 0x00, 0x17, 0x7C, 0xC5, 0x5D, 0x00, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x8D, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x17, 0x7C, 0xC5, 0x5D, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x48, 0xB2, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x43, 0x7F, 0x00, 0x00 }; diff --git a/Dalamud/Game/Network/NetworkHandlers.cs b/Dalamud/Game/Network/NetworkHandlers.cs index 9a2a92444..5f9ad6a9a 100644 --- a/Dalamud/Game/Network/NetworkHandlers.cs +++ b/Dalamud/Game/Network/NetworkHandlers.cs @@ -61,7 +61,7 @@ namespace Dalamud.Game.Network { } */ - if (opCode == ZoneOpCode.CfNotifyRoulette) { + if (opCode == ZoneOpCode.CfNotifyPop) { var data = new byte[64]; Marshal.Copy(dataPtr, data, 0, 64); @@ -197,15 +197,15 @@ namespace Dalamud.Game.Network { } private enum ZoneOpCode { - CfNotifyRoulette = 0xB3, + CfNotifyPop = 0x32D, CfNotify = 0x8F, RetainerSaleItemId = 0x13F, // TODO these are probably not accurate RetainerSaleFinish = 0x138, FateSpawn = 0x226, - MarketTaxRates = 0x76, - MarketBoardItemRequestStart = 0x39D, - MarketBoardOfferings = 0x36A, - MarketBoardHistory = 0x194 + MarketTaxRates = 0x39F, + MarketBoardItemRequestStart = 0xF2, + MarketBoardOfferings = 0x1E2, + MarketBoardHistory = 0x123 } } }