Created
March 16, 2022 02:21
-
-
Save slotthhy/4aaa6c53d5039d079e11537b9e935b7c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Dalamud.Game.Command; | |
using Dalamud.Plugin; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Numerics; | |
using System.Runtime.InteropServices; | |
using Dalamud.Data; | |
using Dalamud.Game; | |
using Dalamud.Utility; | |
using ImGuiNET; | |
using Lumina.Excel.GeneratedSheets; | |
namespace Whoops; | |
public class RoulTest : IDalamudPlugin | |
{ | |
private delegate byte IsRouletteRewardAvailablePrototype(IntPtr unknown, byte rouletteType); | |
private readonly IsRouletteRewardAvailablePrototype _isRouletteRewardAvailable; | |
private readonly IntPtr RouletteRewardThisPtr; | |
public string Name => "RoulTest"; | |
private const string CommandName = "/roul"; | |
private readonly CommandManager _cmdMgr; | |
private readonly DalamudPluginInterface _pi; | |
private bool _uiVisible; | |
private readonly Dictionary<uint, ContentRoulette> _contentRoulette; | |
public RoulTest( | |
CommandManager cmdMgr, | |
DataManager dataMgr, | |
SigScanner sigScanner, | |
DalamudPluginInterface pluginInterface) | |
{ | |
_cmdMgr = cmdMgr; | |
_pi = pluginInterface; | |
cmdMgr.AddHandler(CommandName, new CommandInfo(OnCommand) | |
{ | |
HelpMessage = "/roul" | |
}); | |
var isRouletteRewardAvailableSig = "48 83 EC 28 84 D2 75 07 32 C0"; | |
var isRouletteRewardAvailablePtr = sigScanner.ScanText(isRouletteRewardAvailableSig); | |
_isRouletteRewardAvailable = Marshal.GetDelegateForFunctionPointer<IsRouletteRewardAvailablePrototype>(isRouletteRewardAvailablePtr); | |
var rouletteRewardThisPtrSig = "48 8D 0D ?? ?? ?? ?? E8 ?? ?? ?? ?? 84 C0 74 0C 48 8D 4C 24"; | |
RouletteRewardThisPtr = sigScanner.GetStaticAddressFromSig(rouletteRewardThisPtrSig); | |
_contentRoulette = dataMgr.GetExcelSheet<ContentRoulette>().ToDictionary(k => k.RowId, v => v); | |
_pi.UiBuilder.Draw += DrawUI; | |
_pi.UiBuilder.DisableAutomaticUiHide = true; | |
_pi.UiBuilder.DisableCutsceneUiHide = true; | |
_pi.UiBuilder.DisableGposeUiHide = true; | |
_pi.UiBuilder.DisableUserUiHide = true; | |
_pi.UiBuilder.OpenConfigUi += DrawConfigUI; | |
} | |
private byte IsRouletteRewardAvailable(byte type) | |
{ | |
return _isRouletteRewardAvailable(RouletteRewardThisPtr, type); | |
} | |
public void Dispose() | |
{ | |
_cmdMgr.RemoveHandler(CommandName); | |
} | |
private void OnCommand(string command, string args) | |
{ | |
_uiVisible = !_uiVisible; | |
} | |
private void DrawConfigUI() | |
{ | |
_uiVisible = true; | |
} | |
private void DrawUI() | |
{ | |
Draw(); | |
} | |
public void Draw() | |
{ | |
DrawMainWindow(); | |
} | |
public void DrawMainWindow() | |
{ | |
if (!_uiVisible) return; | |
if (!ImGui.Begin("Roulette", ref _uiVisible)) | |
{ | |
ImGui.End(); | |
return; | |
} | |
if (ImGui.CollapsingHeader("Roulette Reward")) | |
{ | |
ImGui.BeginChild("scrolling##roul", new Vector2(0, 0), false, ImGuiWindowFlags.HorizontalScrollbar); | |
ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(0, 0)); | |
for (uint i = 0; i < _contentRoulette.Count; i++) | |
{ | |
var roul = _contentRoulette[i]; | |
var name = roul.Name.ToDalamudString().TextValue; | |
if (name.IsNullOrEmpty()) continue; | |
var avail = IsRouletteRewardAvailable((byte)i) == 0 ? "No" : "Yes"; | |
ImGui.Text($"{name}: {avail}"); | |
} | |
ImGui.PopStyleVar(); | |
ImGui.EndChild(); | |
} | |
ImGui.End(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment