mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 10:17:22 +01:00
Merge pull request #1649 from Soreepeong/fix/ifontatlas-dock-windowdecoration
Temp fix insufficient ImDrawList texture handling
This commit is contained in:
commit
45d30ed9d2
4 changed files with 128 additions and 3 deletions
|
|
@ -11,6 +11,7 @@ using System.Text.Unicode;
|
||||||
using Dalamud.Game.Text;
|
using Dalamud.Game.Text;
|
||||||
using Dalamud.Hooking.WndProcHook;
|
using Dalamud.Hooking.WndProcHook;
|
||||||
using Dalamud.Interface.GameFonts;
|
using Dalamud.Interface.GameFonts;
|
||||||
|
using Dalamud.Interface.Internal.ManagedAsserts;
|
||||||
using Dalamud.Interface.ManagedFontAtlas.Internals;
|
using Dalamud.Interface.ManagedFontAtlas.Internals;
|
||||||
using Dalamud.Interface.Utility;
|
using Dalamud.Interface.Utility;
|
||||||
|
|
||||||
|
|
@ -28,7 +29,6 @@ namespace Dalamud.Interface.Internal;
|
||||||
[ServiceManager.BlockingEarlyLoadedService]
|
[ServiceManager.BlockingEarlyLoadedService]
|
||||||
internal sealed unsafe class DalamudIme : IDisposable, IServiceType
|
internal sealed unsafe class DalamudIme : IDisposable, IServiceType
|
||||||
{
|
{
|
||||||
private const int ImGuiContextTextStateOffset = 0x4588;
|
|
||||||
private const int CImGuiStbTextCreateUndoOffset = 0xB57A0;
|
private const int CImGuiStbTextCreateUndoOffset = 0xB57A0;
|
||||||
private const int CImGuiStbTextUndoOffset = 0xB59C0;
|
private const int CImGuiStbTextUndoOffset = 0xB59C0;
|
||||||
|
|
||||||
|
|
@ -178,7 +178,7 @@ internal sealed unsafe class DalamudIme : IDisposable, IServiceType
|
||||||
internal char InputModeIcon { get; private set; }
|
internal char InputModeIcon { get; private set; }
|
||||||
|
|
||||||
private static ImGuiInputTextState* TextState =>
|
private static ImGuiInputTextState* TextState =>
|
||||||
(ImGuiInputTextState*)(ImGui.GetCurrentContext() + ImGuiContextTextStateOffset);
|
(ImGuiInputTextState*)(ImGui.GetCurrentContext() + ImGuiContextOffsets.TextStateOffset);
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,6 @@ internal sealed unsafe class ImGuiClipboardFunctionProvider : IServiceType, IDis
|
||||||
private ImGuiClipboardFunctionProvider(InterfaceManager.InterfaceManagerWithScene imws)
|
private ImGuiClipboardFunctionProvider(InterfaceManager.InterfaceManagerWithScene imws)
|
||||||
{
|
{
|
||||||
// Effectively waiting for ImGui to become available.
|
// Effectively waiting for ImGui to become available.
|
||||||
_ = imws;
|
|
||||||
Debug.Assert(ImGuiHelpers.IsImGuiInitialized, "IMWS initialized but IsImGuiInitialized is false?");
|
Debug.Assert(ImGuiHelpers.IsImGuiInitialized, "IMWS initialized but IsImGuiInitialized is false?");
|
||||||
|
|
||||||
var io = ImGui.GetIO();
|
var io = ImGui.GetIO();
|
||||||
|
|
|
||||||
124
Dalamud/Interface/Internal/ImGuiDrawListFixProvider.cs
Normal file
124
Dalamud/Interface/Internal/ImGuiDrawListFixProvider.cs
Normal file
|
|
@ -0,0 +1,124 @@
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Numerics;
|
||||||
|
|
||||||
|
using Dalamud.Hooking;
|
||||||
|
|
||||||
|
using ImGuiNET;
|
||||||
|
|
||||||
|
namespace Dalamud.Interface.Internal;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fixes ImDrawList not correctly dealing with the current texture for that draw list not in tune with the global
|
||||||
|
/// state. Currently, ImDrawList::AddPolyLine and ImDrawList::AddRectFilled are affected.
|
||||||
|
///
|
||||||
|
/// * The implementation for AddRectFilled is entirely replaced with the hook below.
|
||||||
|
/// * The implementation for AddPolyLine is wrapped with Push/PopTextureID.
|
||||||
|
///
|
||||||
|
/// TODO:
|
||||||
|
/// * imgui_draw.cpp:1433 ImDrawList::AddRectFilled
|
||||||
|
/// The if block needs a PushTextureID(_Data->TexIdCommon)/PopTextureID() block,
|
||||||
|
/// if _Data->TexIdCommon != _CmdHeader.TextureId.
|
||||||
|
/// * imgui_draw.cpp:729 ImDrawList::AddPolyLine
|
||||||
|
/// The if block always needs to call PushTextureID if the abovementioned condition is not met.
|
||||||
|
/// Change push_texture_id to only have one condition.
|
||||||
|
/// </summary>
|
||||||
|
[ServiceManager.EarlyLoadedService]
|
||||||
|
internal sealed unsafe class ImGuiDrawListFixProvider : IServiceType, IDisposable
|
||||||
|
{
|
||||||
|
private const int CImGuiImDrawListAddPolyLineOffset = 0x589B0;
|
||||||
|
private const int CImGuiImDrawListAddRectFilled = 0x59FD0;
|
||||||
|
private const int CImGuiImDrawListSharedDataTexIdCommonOffset = 0;
|
||||||
|
|
||||||
|
private readonly Hook<ImDrawListAddPolyLine> hookImDrawListAddPolyline;
|
||||||
|
private readonly Hook<ImDrawListAddRectFilled> hookImDrawListAddRectFilled;
|
||||||
|
|
||||||
|
[ServiceManager.ServiceConstructor]
|
||||||
|
private ImGuiDrawListFixProvider(InterfaceManager.InterfaceManagerWithScene imws)
|
||||||
|
{
|
||||||
|
// Force cimgui.dll to be loaded.
|
||||||
|
_ = ImGui.GetCurrentContext();
|
||||||
|
var cimgui = Process.GetCurrentProcess().Modules.Cast<ProcessModule>()
|
||||||
|
.First(x => x.ModuleName == "cimgui.dll")
|
||||||
|
.BaseAddress;
|
||||||
|
|
||||||
|
this.hookImDrawListAddPolyline = Hook<ImDrawListAddPolyLine>.FromAddress(
|
||||||
|
cimgui + CImGuiImDrawListAddPolyLineOffset,
|
||||||
|
this.ImDrawListAddPolylineDetour);
|
||||||
|
this.hookImDrawListAddRectFilled = Hook<ImDrawListAddRectFilled>.FromAddress(
|
||||||
|
cimgui + CImGuiImDrawListAddRectFilled,
|
||||||
|
this.ImDrawListAddRectFilledDetour);
|
||||||
|
this.hookImDrawListAddPolyline.Enable();
|
||||||
|
this.hookImDrawListAddRectFilled.Enable();
|
||||||
|
}
|
||||||
|
|
||||||
|
private delegate void ImDrawListAddPolyLine(
|
||||||
|
ImDrawListPtr drawListPtr,
|
||||||
|
ref Vector2 points,
|
||||||
|
int pointsCount,
|
||||||
|
uint color,
|
||||||
|
ImDrawFlags flags,
|
||||||
|
float thickness);
|
||||||
|
|
||||||
|
private delegate void ImDrawListAddRectFilled(
|
||||||
|
ImDrawListPtr drawListPtr,
|
||||||
|
ref Vector2 min,
|
||||||
|
ref Vector2 max,
|
||||||
|
uint col,
|
||||||
|
float rounding,
|
||||||
|
ImDrawFlags flags);
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
this.hookImDrawListAddPolyline.Dispose();
|
||||||
|
this.hookImDrawListAddRectFilled.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ImDrawListAddRectFilledDetour(
|
||||||
|
ImDrawListPtr drawListPtr,
|
||||||
|
ref Vector2 min,
|
||||||
|
ref Vector2 max,
|
||||||
|
uint col,
|
||||||
|
float rounding,
|
||||||
|
ImDrawFlags flags)
|
||||||
|
{
|
||||||
|
if (rounding < 0 || (flags & ImDrawFlags.RoundCornersMask) == ImDrawFlags.RoundCornersMask)
|
||||||
|
{
|
||||||
|
var texIdCommon = *(nint*)(drawListPtr._Data + CImGuiImDrawListSharedDataTexIdCommonOffset);
|
||||||
|
var pushTextureId = texIdCommon != drawListPtr._CmdHeader.TextureId;
|
||||||
|
if (pushTextureId)
|
||||||
|
drawListPtr.PushTextureID(texIdCommon);
|
||||||
|
|
||||||
|
drawListPtr.PrimReserve(6, 4);
|
||||||
|
drawListPtr.PrimRect(min, max, col);
|
||||||
|
|
||||||
|
if (pushTextureId)
|
||||||
|
drawListPtr.PopTextureID();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
drawListPtr.PathRect(min, max, rounding, flags);
|
||||||
|
drawListPtr.PathFillConvex(col);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ImDrawListAddPolylineDetour(
|
||||||
|
ImDrawListPtr drawListPtr,
|
||||||
|
ref Vector2 points,
|
||||||
|
int pointsCount,
|
||||||
|
uint color,
|
||||||
|
ImDrawFlags flags,
|
||||||
|
float thickness)
|
||||||
|
{
|
||||||
|
var texIdCommon = *(nint*)(drawListPtr._Data + CImGuiImDrawListSharedDataTexIdCommonOffset);
|
||||||
|
var pushTextureId = texIdCommon != drawListPtr._CmdHeader.TextureId;
|
||||||
|
if (pushTextureId)
|
||||||
|
drawListPtr.PushTextureID(texIdCommon);
|
||||||
|
|
||||||
|
this.hookImDrawListAddPolyline.Original(drawListPtr, ref points, pointsCount, color, flags, thickness);
|
||||||
|
|
||||||
|
if (pushTextureId)
|
||||||
|
drawListPtr.PopTextureID();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -18,4 +18,6 @@ internal static class ImGuiContextOffsets
|
||||||
public const int FontStackOffset = 0x7A4;
|
public const int FontStackOffset = 0x7A4;
|
||||||
|
|
||||||
public const int BeginPopupStackOffset = 0x7B8;
|
public const int BeginPopupStackOffset = 0x7B8;
|
||||||
|
|
||||||
|
public const int TextStateOffset = 0x4588;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue