diff --git a/ChatTwo/ChatTwo.csproj b/ChatTwo/ChatTwo.csproj index 58870f6..79b3afc 100755 --- a/ChatTwo/ChatTwo.csproj +++ b/ChatTwo/ChatTwo.csproj @@ -1,6 +1,6 @@ - 1.30.1 + 1.30.2 net9.0-windows enable enable diff --git a/ChatTwo/GameFunctions/GameFunctions.cs b/ChatTwo/GameFunctions/GameFunctions.cs index 99ead69..c97f3b1 100755 --- a/ChatTwo/GameFunctions/GameFunctions.cs +++ b/ChatTwo/GameFunctions/GameFunctions.cs @@ -124,8 +124,11 @@ internal unsafe class GameFunctions : IDisposable agent->Index = 0; agent->Flag1 &= 0xEF; agent->ItemId = id; - agent->Flag2 = 1; - agent->Flag3 = 0; + // agent->Flag2 = 1; + // agent->Flag3 = 0; + // TODO: Revert whenever CS is merged + *(byte*)((nint)agent + 0x21A) = 1; + *(byte*)((nint)agent + 0x21E) = 0; // This just probably needs to be set agent->AddonId = addon->Id; diff --git a/ChatTwo/PayloadHandler.cs b/ChatTwo/PayloadHandler.cs index a452e87..deb7482 100755 --- a/ChatTwo/PayloadHandler.cs +++ b/ChatTwo/PayloadHandler.cs @@ -287,6 +287,45 @@ public sealed class PayloadHandler var isLeft = chatRect.SizeX < viewportSize.X / 2; var isTop = chatRect.SizeY < viewportSize.Y / 2; + var mousePos = ImGui.GetMousePos(); + + // addon spawned left of mouse cursor + if (addonRect.X < mousePos.X) + { + if (isLeft) + addonRect.X = (short)mousePos.X + 5; + } + else + { + if (!isLeft) + addonRect.X = Math.Max(0, (short)mousePos.X - 5 - addonRect.Width); + } + + if (!chatRect.HasOverlap(addonRect)) + { + atk->SetPosition((short) addonRect.X, (short) addonRect.Y); + return; + } + + // addon spawned above mouse cursor + if (addonRect.Y < mousePos.Y) + { + if (isTop) + addonRect.Y = (short)mousePos.Y + 5; + } + else + { + if (!isTop) + addonRect.Y = Math.Max(0, (short)mousePos.Y - 5 - addonRect.Height); // prevent it going below 0 + } + + if (!chatRect.HasOverlap(addonRect)) + { + atk->SetPosition((short) addonRect.X, (short) addonRect.Y); + return; + } + + // Spawning right/bottom of mouse cursor didn't solve the overlap, so we spawn it next to the chat var x = isLeft ? chatRect.SizeX : LogWindow.LastWindowPos.X - atkSize.X; var y = Math.Clamp(chatRect.SizeY - atkSize.Y, 0, float.MaxValue); y -= isTop ? 0 : Plugin.Config.TooltipOffset; // offset to prevent cut-off on the bottom diff --git a/ChatTwo/Util/MathUtil.cs b/ChatTwo/Util/MathUtil.cs index 2195cc2..aca34d2 100644 --- a/ChatTwo/Util/MathUtil.cs +++ b/ChatTwo/Util/MathUtil.cs @@ -27,6 +27,11 @@ public static class MathUtil public Rectangle(Vector2 pos, Vector2 size) : this((int) pos.X, (int) pos.Y, (int) size.X, (int) size.Y) { } + + public override string ToString() + { + return $"X: {X} Y: {Y} Width: {Width} Height: {Height}"; + } } // From: https://stackoverflow.com/a/306379