HUDManager/HUD Manager/GameFunctions.cs

77 lines
2.9 KiB
C#
Raw Permalink Normal View History

2021-03-08 15:03:11 +00:00
using System;
using System.Runtime.InteropServices;
2021-08-24 01:21:29 +00:00
using FFXIVClientStructs.FFXIV.Component.GUI;
2021-03-08 15:03:11 +00:00
namespace HUD_Manager {
public class GameFunctions {
// private delegate IntPtr GetBaseUiObjectDelegate();
2021-03-08 15:03:11 +00:00
private delegate void SetPositionDelegate(IntPtr windowBase, short x, short y);
private delegate void SetAlphaDelegate(IntPtr windowBase, byte alpha);
private delegate byte UpdateAddonPositionDelegate(IntPtr raptureAtkUnitManager, IntPtr addon, byte clicked);
// private readonly GetBaseUiObjectDelegate _getBaseUiObject;
private readonly SetPositionDelegate _setPosition;
private readonly SetAlphaDelegate _setAlpha;
private readonly UpdateAddonPositionDelegate _updateAddonPosition;
2021-03-08 15:03:11 +00:00
private Plugin Plugin { get; }
public GameFunctions(Plugin plugin) {
this.Plugin = plugin;
2021-08-24 01:21:29 +00:00
var setPositionPtr = this.Plugin.SigScanner.ScanText("4C 8B 89 ?? ?? ?? ?? 41 0F BF C0");
var setAlphaPtr = this.Plugin.SigScanner.ScanText("F6 81 ?? ?? ?? ?? ?? 88 91 ?? ?? ?? ??");
var updatePositionPtr = this.Plugin.SigScanner.ScanText("E8 ?? ?? ?? ?? 48 8B 8B ?? ?? ?? ?? 33 D2 48 8B 01 FF 90 ?? ?? ?? ??");
// var baseUiPtr = this.Plugin.Interface.TargetModuleScanner.ScanText("E8 ?? ?? ?? ?? 0F BF D5");
2021-03-08 15:03:11 +00:00
this._setPosition = Marshal.GetDelegateForFunctionPointer<SetPositionDelegate>(setPositionPtr);
this._setAlpha = Marshal.GetDelegateForFunctionPointer<SetAlphaDelegate>(setAlphaPtr);
this._updateAddonPosition = Marshal.GetDelegateForFunctionPointer<UpdateAddonPositionDelegate>(updatePositionPtr);
2021-03-08 15:03:11 +00:00
}
public void SetAddonPosition(string uiName, short x, short y) {
2021-08-24 01:21:29 +00:00
var addon = this.Plugin.GameGui.GetAddonByName(uiName, 1);
if (addon == IntPtr.Zero) {
return;
}
2021-03-08 15:03:11 +00:00
2021-08-24 01:21:29 +00:00
var baseUi = this.Plugin.GameGui.GetUIModule();
var manager = Marshal.ReadIntPtr(baseUi + 0x20);
2021-03-08 15:03:11 +00:00
this._updateAddonPosition(
manager,
2021-08-24 01:21:29 +00:00
addon,
1
);
2021-08-24 01:21:29 +00:00
this._setPosition(addon, x, y);
this._updateAddonPosition(
manager,
2021-08-24 01:21:29 +00:00
addon,
0
);
2021-03-08 15:03:11 +00:00
}
2021-08-24 01:21:29 +00:00
public unsafe Vector2<short>? GetAddonPosition(string uiName) {
var addon = this.Plugin.GameGui.GetAddonByName(uiName, 1);
if (addon == IntPtr.Zero) {
return null;
2021-03-08 15:03:11 +00:00
}
2021-08-24 01:21:29 +00:00
var unit = (AtkUnitBase*) addon;
return new Vector2<short>(unit->X, unit->Y);
}
2021-03-08 15:03:11 +00:00
public void SetAddonAlpha(string name, byte alpha) {
2021-08-24 01:21:29 +00:00
var addon = this.Plugin.GameGui.GetAddonByName(name, 1);
if (addon == IntPtr.Zero) {
return;
}
2021-03-08 15:03:11 +00:00
2021-08-24 01:21:29 +00:00
this._setAlpha(addon, alpha);
2021-03-08 15:03:11 +00:00
}
}
}