From c9674b0646a9e349ab27f0eee26a780bf00193df Mon Sep 17 00:00:00 2001 From: Infi Date: Wed, 26 Mar 2025 21:12:41 +0100 Subject: [PATCH] - API 12 - Cleanup --- .build.yml | 22 -------------- ChatTwo.Tests/ChatTwo.Tests.csproj | 2 +- ChatTwo/ChatTwo.csproj | 48 +++--------------------------- ChatTwo/Chunk.cs | 4 +-- ChatTwo/GameFunctions/Chat.cs | 11 +++---- ChatTwo/GameFunctions/ChatBox.cs | 2 +- ChatTwo/Message.cs | 2 +- ChatTwo/MessageManager.cs | 1 - ChatTwo/PayloadHandler.cs | 6 ++-- ChatTwo/Ui/Settings.cs | 9 +++--- ChatTwo/Util/ChunkUtil.cs | 4 +-- ChatTwo/Util/MathUtil.cs | 33 ++++++++++++-------- ChatTwo/packages.lock.json | 14 ++++++--- fix_resources.sh | 6 ---- global.json | 7 ----- 15 files changed, 56 insertions(+), 115 deletions(-) delete mode 100755 .build.yml delete mode 100755 fix_resources.sh delete mode 100755 global.json diff --git a/.build.yml b/.build.yml deleted file mode 100755 index 485c808..0000000 --- a/.build.yml +++ /dev/null @@ -1,22 +0,0 @@ -image: fedora/latest -packages: - - dotnet - - wget - - unzip - - zip -tasks: - - download-dalamud: | - mkdir dalamud - cd dalamud - wget https://github.com/goatcorp/dalamud-distrib/raw/main/latest.zip - unzip latest.zip - rm latest.zip - - build-plugin: | - cd ChatTwo/ChatTwo - dotnet build -c Release -p:IsCI=true - - package: | - cd ChatTwo/ChatTwo/bin/Release/net5.0-windows - zip -r release.zip ChatTwo -artifacts: - - ChatTwo/ChatTwo/bin/Release/net5.0-windows/ChatTwo/latest.zip - - ChatTwo/ChatTwo/bin/Release/net5.0-windows/release.zip diff --git a/ChatTwo.Tests/ChatTwo.Tests.csproj b/ChatTwo.Tests/ChatTwo.Tests.csproj index 07a4679..80dc8ff 100644 --- a/ChatTwo.Tests/ChatTwo.Tests.csproj +++ b/ChatTwo.Tests/ChatTwo.Tests.csproj @@ -1,7 +1,7 @@ - net8.0-windows + net9.0-windows false diff --git a/ChatTwo/ChatTwo.csproj b/ChatTwo/ChatTwo.csproj index 1cf6f70..91ae6a7 100755 --- a/ChatTwo/ChatTwo.csproj +++ b/ChatTwo/ChatTwo.csproj @@ -1,59 +1,19 @@ - + - 1.29.20 - net8.0-windows + 1.30.0 + net9.0-windows enable enable true false true true - preview + latest true full - - $(AppData)\XIVLauncher\addon\Hooks\dev - - - - $(DALAMUD_HOME) - - - - $(HOME)/dalamud - - - - $(DalamudLibPath)\Dalamud.dll - false - - - $(DalamudLibPath)\FFXIVClientStructs.dll - false - - - $(DalamudLibPath)\ImGui.NET.dll - false - - - $(DalamudLibPath)\Lumina.dll - false - - - $(DalamudLibPath)\Lumina.Excel.dll - false - - - $(DalamudLibPath)\Newtonsoft.Json.dll - false - - - - - diff --git a/ChatTwo/Chunk.cs b/ChatTwo/Chunk.cs index 81ab669..54b57a4 100755 --- a/ChatTwo/Chunk.cs +++ b/ChatTwo/Chunk.cs @@ -54,7 +54,7 @@ public enum ChunkSource Content, } -[MessagePackObject] +[MessagePackObject(AllowPrivate = true)] public class TextChunk : Chunk { [Key(2)] @@ -121,7 +121,7 @@ public class TextChunk : Chunk } } -[MessagePackObject] +[MessagePackObject(AllowPrivate = true)] public class IconChunk : Chunk { [Key(2)] diff --git a/ChatTwo/GameFunctions/Chat.cs b/ChatTwo/GameFunctions/Chat.cs index 534de83..59cf502 100755 --- a/ChatTwo/GameFunctions/Chat.cs +++ b/ChatTwo/GameFunctions/Chat.cs @@ -17,6 +17,7 @@ using FFXIVClientStructs.FFXIV.Client.UI.Info; using FFXIVClientStructs.FFXIV.Client.UI.Misc; using FFXIVClientStructs.FFXIV.Client.UI.Shell; using FFXIVClientStructs.FFXIV.Component.GUI; +using InteropGenerator.Runtime; using Lumina.Text.ReadOnly; using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.ValueType; @@ -98,7 +99,7 @@ internal sealed unsafe class Chat : IDisposable internal string? GetLinkshellName(uint idx) { var utf = InfoProxyChat.Instance()->GetLinkShellName(idx); - return utf == null ? null : MemoryHelper.ReadStringNullTerminated((nint) utf); + return utf.HasValue ? utf.ToString() : null; } internal string? GetCrossLinkshellName(uint idx) @@ -199,9 +200,9 @@ internal sealed unsafe class Chat : IDisposable string? addIfNotPresent = null; var str = value + 2; - if (str != null && ((int) str->Type & 0xF) == (int) ValueType.String && str->String != null) + if (str != null && ((int) str->Type & 0xF) == (int) ValueType.String && str->String.HasValue) { - var add = MemoryHelper.ReadStringNullTerminated((nint) str->String); + var add = str->String.ToString(); if (add.Length > 0) addIfNotPresent = add; } @@ -227,7 +228,7 @@ internal sealed unsafe class Chat : IDisposable return 1; } - private byte* ChangeChannelNameDetour(AgentChatLog* agent) + private CStringPointer ChangeChannelNameDetour(AgentChatLog* agent) { var ret = ChangeChannelNameHook.Original(agent); if (agent == null) @@ -525,7 +526,7 @@ internal sealed unsafe class Chat : IDisposable { var uC = Utf8String.FromString(c.ToString()); - uC->SanitizeString(0x27F, Utf8String.CreateEmpty()); + uC->SanitizeString((AllowedEntities) 0x27F); var wasValid = uC->ToString().Length > 0; uC->Dtor(true); diff --git a/ChatTwo/GameFunctions/ChatBox.cs b/ChatTwo/GameFunctions/ChatBox.cs index b129a07..a6f9b8c 100644 --- a/ChatTwo/GameFunctions/ChatBox.cs +++ b/ChatTwo/GameFunctions/ChatBox.cs @@ -33,7 +33,7 @@ public unsafe class ChatBox { var uText = Utf8String.FromString(text); - uText->SanitizeString(0x27F, (Utf8String*)nint.Zero); + uText->SanitizeString((AllowedEntities) 0x27F); var sanitised = uText->ToString(); uText->Dtor(true); diff --git a/ChatTwo/Message.cs b/ChatTwo/Message.cs index c246198..dfbeffa 100755 --- a/ChatTwo/Message.cs +++ b/ChatTwo/Message.cs @@ -337,7 +337,7 @@ internal partial class Message else if (split == "") { var agentMap = AgentMap.Instance(); - if (agentMap->IsFlagMarkerSet == 0) + if (!agentMap->IsFlagMarkerSet) { AddChunkWithMessage(text.NewWithStyle(chunk.Source, chunk.Link, split)); continue; diff --git a/ChatTwo/MessageManager.cs b/ChatTwo/MessageManager.cs index 9104c1c..dacd5a6 100644 --- a/ChatTwo/MessageManager.cs +++ b/ChatTwo/MessageManager.cs @@ -267,7 +267,6 @@ internal class MessageManager : IAsyncDisposable if (tab.Identifier == currentTabId) Plugin.ServerCore.SendNewMessage(message); } - } } diff --git a/ChatTwo/PayloadHandler.cs b/ChatTwo/PayloadHandler.cs index f118ea3..a452e87 100755 --- a/ChatTwo/PayloadHandler.cs +++ b/ChatTwo/PayloadHandler.cs @@ -277,10 +277,10 @@ public sealed class PayloadHandler var atkPos = new Vector2(component.ScreenX, component.ScreenY); var atkSize = new Vector2(component.GetWidth() * component.ScaleX, component.GetHeight() * component.GetScaleY()); - var chatRect = MathUtil.Rectangle.FromPosAndSize(LogWindow.LastWindowPos, LogWindow.LastWindowSize); - var addonRect = MathUtil.Rectangle.FromPosAndSize(atkPos, atkSize); + var chatRect = new MathUtil.Rectangle(LogWindow.LastWindowPos, LogWindow.LastWindowSize); + var addonRect = new MathUtil.Rectangle(atkPos, atkSize); - if (!MathUtil.CheckRectOverlap(chatRect, addonRect)) + if (!chatRect.HasOverlap(addonRect)) return; var viewportSize = ImGuiHelpers.MainViewport.Size; diff --git a/ChatTwo/Ui/Settings.cs b/ChatTwo/Ui/Settings.cs index 190e11b..b9fee83 100755 --- a/ChatTwo/Ui/Settings.cs +++ b/ChatTwo/Ui/Settings.cs @@ -80,7 +80,7 @@ public sealed class SettingsWindow : Window using (var table = ImRaii.Table("##chat2-settings-table", 2)) { - if (table) + if (table.Success) { ImGui.TableSetupColumn("tab", ImGuiTableColumnFlags.WidthFixed); ImGui.TableSetupColumn("settings", ImGuiTableColumnFlags.WidthStretch); @@ -99,10 +99,11 @@ public sealed class SettingsWindow : Window ImGui.TableNextColumn(); - var height = ImGui.GetContentRegionAvail().Y - ImGui.GetStyle().FramePadding.Y * 2 - ImGui.GetStyle().ItemSpacing.Y - - ImGui.GetStyle().ItemInnerSpacing.Y * 2 - ImGui.CalcTextSize("A").Y; + var style = ImGui.GetStyle(); + var height = ImGui.GetContentRegionAvail().Y - style.FramePadding.Y * 2 - style.ItemSpacing.Y - style.ItemInnerSpacing.Y * 2 - ImGui.CalcTextSize("A").Y; + using var child = ImRaii.Child("##chat2-settings", new Vector2(-1, height)); - if (child) + if (child.Success) Tabs[CurrentTab].Draw(changed); } } diff --git a/ChatTwo/Util/ChunkUtil.cs b/ChatTwo/Util/ChunkUtil.cs index 5db9802..e7d673a 100755 --- a/ChatTwo/Util/ChunkUtil.cs +++ b/ChatTwo/Util/ChunkUtil.cs @@ -41,14 +41,14 @@ internal static class ChunkUtil case PayloadType.UIForeground: var foregroundPayload = (UIForegroundPayload) payload; if (foregroundPayload.IsEnabled) - foreground.Push(foregroundPayload.UIColor.Value.UIForeground); + foreground.Push(foregroundPayload.UIColor.Value.Dark); else if (foreground.Count > 0) foreground.Pop(); break; case PayloadType.UIGlow: var glowPayload = (UIGlowPayload) payload; if (glowPayload.IsEnabled) - glow.Push(glowPayload.UIColor.Value.UIGlow); + glow.Push(glowPayload.UIColor.Value.Light); else if (glow.Count > 0) glow.Pop(); break; diff --git a/ChatTwo/Util/MathUtil.cs b/ChatTwo/Util/MathUtil.cs index 850e5b5..2195cc2 100644 --- a/ChatTwo/Util/MathUtil.cs +++ b/ChatTwo/Util/MathUtil.cs @@ -4,30 +4,39 @@ namespace ChatTwo.Util; public static class MathUtil { - public struct Rectangle + public record Rectangle { public int X; public int Y; public int Width; public int Height; - public static Rectangle FromPosAndSize(Vector2 pos, Vector2 size) + public int SizeX; + public int SizeY; + + public Rectangle(int x, int y, int width, int height) { - return new Rectangle - { - X = (int) pos.X, - Y = (int) pos.Y, - Width = (int) size.X, - Height = (int) size.Y - }; + X = x; + Y = y; + Width = width; + Height = height; + + SizeX = X + Width; + SizeY = Y + Height; } - public int SizeX => X + Width; - public int SizeY => Y + Height; + public Rectangle(Vector2 pos, Vector2 size) + : this((int) pos.X, (int) pos.Y, (int) size.X, (int) size.Y) { } } // From: https://stackoverflow.com/a/306379 - public static bool CheckRectOverlap(Rectangle a, Rectangle b) + /// + /// Checks if two rectangles overlap at any point. + /// + /// + /// + /// True if overlapping + public static bool HasOverlap(this Rectangle a, Rectangle b) { bool ValueInRange(int value, int min, int max) => value > min && value < max; diff --git a/ChatTwo/packages.lock.json b/ChatTwo/packages.lock.json index f7aeb6d..5907b82 100644 --- a/ChatTwo/packages.lock.json +++ b/ChatTwo/packages.lock.json @@ -1,12 +1,18 @@ { "version": 1, "dependencies": { - "net8.0-windows7.0": { + "net9.0-windows7.0": { "DalamudPackager": { "type": "Direct", - "requested": "[11.0.0, )", - "resolved": "11.0.0", - "contentHash": "bjT7XUlhIJSmsE/O76b7weUX+evvGQctbQB8aKXt94o+oPWxHpCepxAGMs7Thow3AzCyqWs7cOpp9/2wcgRRQA==" + "requested": "[12.0.0, )", + "resolved": "12.0.0", + "contentHash": "J5TJLV3f16T/E2H2P17ClWjtfEBPpq3yxvqW46eN36JCm6wR+EaoaYkqG9Rm5sHqs3/nK/vKjWWyvEs/jhKoXw==" + }, + "DotNet.ReproducibleBuilds": { + "type": "Direct", + "requested": "[1.2.25, )", + "resolved": "1.2.25", + "contentHash": "xCXiw7BCxHJ8pF6wPepRUddlh2dlQlbr81gXA72hdk4FLHkKXas7EH/n+fk5UCA/YfMqG1Z6XaPiUjDbUNBUzg==" }, "MessagePack": { "type": "Direct", diff --git a/fix_resources.sh b/fix_resources.sh deleted file mode 100755 index 407a6ca..0000000 --- a/fix_resources.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -for f in ChatTwo/Resources/Language.resx ChatTwo/Resources/Language.*.resx; do - sed -i 's/ xml:space="preserve"//g' "$f" - xmlstarlet fo -e utf-8 -s 4 "$f" | sponge "$f" -done diff --git a/global.json b/global.json deleted file mode 100755 index cbde930..0000000 --- a/global.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "sdk": { - "version": "5.0.0", - "rollForward": "latestMajor", - "allowPrerelease": true - } -} \ No newline at end of file