Skip to content

Commit

Permalink
TargetFurniture 1.0.1.8 [PUSH]
Browse files Browse the repository at this point in the history
6.5 fix
  • Loading branch information
InitialDet committed Oct 3, 2023
1 parent be720ab commit d8c526c
Show file tree
Hide file tree
Showing 8 changed files with 219 additions and 192 deletions.
12 changes: 5 additions & 7 deletions TargetFurniture/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,27 @@
using Dalamud.Configuration;

namespace TargetFurniture;

[Serializable]
public class Configuration : IPluginConfiguration
{
public bool MoveToCursor = true;

public bool UseAltTarget = false;
public int Version { get; set; } = 1;

public void Save()
{
Service.PluginInterface.SavePluginConfig(this);
}

public bool UseAltTarget = false;

public bool MoveToCursor = true;

public static Configuration Load()
{
if (Service.PluginInterface.GetPluginConfig() is Configuration config)
{
return config;
}

config = new Configuration();
config.Save();
return config;
}
}
}
35 changes: 20 additions & 15 deletions TargetFurniture/ContextMenuHousing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,44 @@
using Dalamud.Game.Text.SeStringHandling.Payloads;

namespace TargetFurniture;

public unsafe class ContextMenuHousing : IDisposable
{
private DalamudContextMenu _contextMenu = null!;

private GameObjectContextMenuItem? _contextMenuItem;

public void Toggle()
{
_contextMenu = new DalamudContextMenu(Service.PluginInterface);
_contextMenuItem = new GameObjectContextMenuItem(new SeString(new TextPayload("Target Item")), SetFurnitureActive);
_contextMenu.OnOpenGameObjectContextMenu += OnOpenContextMenu;
}

public void Dispose()
{
_contextMenu.OnOpenGameObjectContextMenu -= OnOpenContextMenu;
_contextMenu.Dispose();
}

private void OnOpenContextMenu(GameObjectContextMenuOpenArgs args)
public void Toggle()
{
_contextMenu = new DalamudContextMenu(Service.PluginInterface);
_contextMenuItem =
new GameObjectContextMenuItem(new SeString(new TextPayload("Target Item")), SetFurnitureActive);
_contextMenu.OnOpenGameObjectContextMenu += OnOpenContextMenu;
}

if (args.ParentAddonName is "HousingGoods" && _contextMenuItem != null) // To make sure it doesnt appear in the Stored tab
private void OnOpenContextMenu(GameObjectContextMenuOpenArgs args)
{
if (args.ParentAddonName is "HousingGoods" &&
_contextMenuItem != null) // To make sure it doesnt appear in the Stored tab
args.AddCustomItem(_contextMenuItem);
}

private void SetFurnitureActive(GameObjectContextMenuItemSelectedArgs args)
{
if (Service.Memory.HousingStructure->Mode == HousingLayoutMode.Rotate && Service.Memory.HousingStructure->State == ItemState.SoftSelect)
if (Service.Memory.HousingStructure->Mode == HousingLayoutMode.Rotate &&
Service.Memory.HousingStructure->State == ItemState.SoftSelect)
{
Service.Memory.SelectItem((IntPtr)Service.Memory.HousingStructure, (IntPtr)Service.Memory.HousingStructure->ActiveItem);
Service.Memory.SelectItem((IntPtr)Service.Memory.HousingStructure,
(IntPtr)Service.Memory.HousingStructure->ActiveItem);
}
else if (Service.Memory.HousingStructure->Mode == HousingLayoutMode.Move && Service.Memory.HousingStructure->State == ItemState.SoftSelect)
else if (Service.Memory.HousingStructure->Mode == HousingLayoutMode.Move &&
Service.Memory.HousingStructure->State == ItemState.SoftSelect)
{
if (Service.Configuration.UseAltTarget)
{
Expand All @@ -57,7 +62,8 @@ private void SetFurnitureActive(GameObjectContextMenuItemSelectedArgs args)

public static void TargetItem()
{
Service.Memory.SelectItem((IntPtr)Service.Memory.HousingStructure, (IntPtr)Service.Memory.HousingStructure->ActiveItem);
Service.Memory.SelectItem((IntPtr)Service.Memory.HousingStructure,
(IntPtr)Service.Memory.HousingStructure->ActiveItem);
}
}

Expand All @@ -68,5 +74,4 @@ public static async void WaitingRetarget()
await Task.Delay(60);
ContextMenuHousing.TargetItem();
}
}

}
22 changes: 13 additions & 9 deletions TargetFurniture/PluginMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,39 @@ namespace TargetFurniture;

public class PluginMemory
{
// Layout and housing module pointers.
private readonly IntPtr _layoutWorldPtr;
private unsafe LayoutWorld* Layout => (LayoutWorld*)_layoutWorldPtr;
public unsafe HousingStructure* HousingStructure => Layout->HousingStruct;

// Function for selecting an item, usually used when clicking on one in game.
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void SelectItemDelegate(IntPtr housingStruct, IntPtr item);

// Layout and housing module pointers.
private readonly IntPtr _layoutWorldPtr;
public readonly SelectItemDelegate SelectItem = null!;

public PluginMemory()
{
try
{
// Pointers for housing structures.
_layoutWorldPtr = Service.SigScanner.GetStaticAddressFromSig("48 8B 0D ?? ?? ?? ?? 48 85 C9 74 ?? 48 8B 49 40 E9 ?? ?? ?? ??");
_layoutWorldPtr =
Service.SigScanner.GetStaticAddressFromSig(
"48 8B 0D ?? ?? ?? ?? 48 85 C9 74 ?? 48 8B 49 40 E9 ?? ?? ?? ??");

// Read the pointers.
_layoutWorldPtr = Marshal.ReadIntPtr(_layoutWorldPtr);

// Select housing item.
IntPtr selectItemAddress = Service.SigScanner.ScanText("E8 ?? ?? ?? ?? 48 8B CE E8 ?? ?? ?? ?? 48 8B 6C 24 40 48 8B CE");
var selectItemAddress =
Service.SigScanner.ScanText("E8 ?? ?? ?? ?? 48 8B CE E8 ?? ?? ?? ?? 48 8B 6C 24 40 48 8B CE");
SelectItem = Marshal.GetDelegateForFunctionPointer<SelectItemDelegate>(selectItemAddress);

}
catch (Exception)
{
//PluginLog.LogError(ex, "Error while calling PluginMemory.ctor()");
}
}

private unsafe LayoutWorld* Layout => (LayoutWorld*)_layoutWorldPtr;
public unsafe HousingStructure* HousingStructure => Layout->HousingStruct;
}

public enum HousingLayoutMode
Expand Down Expand Up @@ -85,6 +88,7 @@ public unsafe struct HousingStructure
public struct HousingItem
{
[FieldOffset(0x50)] public Vector3 Position;

[FieldOffset(0x60)] public Quaternion Rotation;
// [FieldOffset(0x90)] public HousingItemUnknown1* unknown;
}
}
17 changes: 9 additions & 8 deletions TargetFurniture/PluginUI.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using Dalamud.Interface.Windowing;
using ImGuiNET;
using System;
using System;
using System.Diagnostics;
using Dalamud.Interface.Windowing;
using ImGuiNET;

namespace TargetFurniture;

public class PluginUi : Window, IDisposable
{
public PluginUi() : base($"{Service.PluginName} Settings")
Expand All @@ -28,13 +29,15 @@ public override void Draw()

ShowKofi();

Utils.Draw.Checkbox("Move Furniture to Cursor", ref Service.Configuration.MoveToCursor, "- If Enabled, the item will follow the point of your cursor.\n- If Disabled, the item will stay in place and move relative to your cursor position." +
Utils.Draw.Checkbox("Move Furniture to Cursor", ref Service.Configuration.MoveToCursor,
"- If Enabled, the item will follow the point of your cursor.\n- If Disabled, the item will stay in place and move relative to your cursor position." +
"\n\nIts recommended to have this enabled\n\nDoesn't affect the behavior of alternative mode.");

ImGui.Spacing();

ImGui.Text("(Experimental) ");
Utils.Draw.Checkbox("Enable Alternative Targeting Mode", ref Service.Configuration.UseAltTarget, "(Only for Layout Mode - Move)\nIf the default targeting mode doesn't work for you, this option might work.\n\nThis is a experimental feature and might also not work for everybody\n\nPS: After moving an item, you may see an Error Message at the top, you can ignore it.");
Utils.Draw.Checkbox("Enable Alternative Targeting Mode", ref Service.Configuration.UseAltTarget,
"(Only for Layout Mode - Move)\nIf the default targeting mode doesn't work for you, this option might work.\n\nThis is a experimental feature and might also not work for everybody\n\nPS: After moving an item, you may see an Error Message at the top, you can ignore it.");

ImGui.End();
}
Expand All @@ -47,9 +50,7 @@ private static void ShowKofi()
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, 0xAA000000 | 0x005E5BFF);

if (ImGui.Button(buttonText))
{
Process.Start(new ProcessStartInfo { FileName = "https://ko-fi.com/initialdet", UseShellExecute = true });
}

ImGui.PopStyleColor(3);
}
Expand All @@ -58,4 +59,4 @@ public override void OnClose()
{
Service.Configuration.Save();
}
}
}
16 changes: 9 additions & 7 deletions TargetFurniture/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@

namespace TargetFurniture;

public class Service
public class Service
{
public static void Initialize(DalamudPluginInterface pluginInterface) => pluginInterface.Create<Service>();

public const string PluginName = "Target Furniture";

[PluginService] public static DalamudPluginInterface PluginInterface { get; private set; } = null!;
[PluginService] public static ISigScanner SigScanner { get; private set; } = null!;
[PluginService] public static ICommandManager Commands { get; private set; } = null!;
[PluginService] public static DalamudPluginInterface PluginInterface { get; private set; } = null!;
[PluginService] public static ISigScanner SigScanner { get; private set; } = null!;
[PluginService] public static ICommandManager Commands { get; private set; } = null!;

public static PluginMemory Memory { get; set; } = null!;
public static Configuration Configuration { get; set; } = null!;
public static WindowSystem WindowSystem { get; } = new(PluginName);
}

public static void Initialize(DalamudPluginInterface pluginInterface)
{
pluginInterface.Create<Service>();
}
}
25 changes: 14 additions & 11 deletions TargetFurniture/TargetFurniture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
using Dalamud.Plugin;

namespace TargetFurniture;

public class TargetFurniture : IDalamudPlugin
{
//public static string Name => "Target Furniture";

private const string CmdConfig = "/targetfurniture";
private const string CmdConfigShort = "/tfcfg";

private readonly ContextMenuHousing _pluginContextMenu;

private static PluginUi _pluginUi = null!;

private readonly ContextMenuHousing _pluginContextMenu;

public TargetFurniture(DalamudPluginInterface pluginInterface)
{
Service.Initialize(pluginInterface);
Expand All @@ -38,14 +39,6 @@ public TargetFurniture(DalamudPluginInterface pluginInterface)
});
}

private static void OnCommand(string command, string args)
{
OnOpenConfigUi();
}

private static void OnOpenConfigUi()
=> _pluginUi.Toggle();

public void Dispose()
{
Service.Configuration.Save();
Expand All @@ -58,4 +51,14 @@ public void Dispose()
Service.PluginInterface.UiBuilder.Draw -= Service.WindowSystem.Draw;
Service.PluginInterface.UiBuilder.OpenConfigUi -= OnOpenConfigUi;
}
}

private static void OnCommand(string command, string args)
{
OnOpenConfigUi();
}

private static void OnOpenConfigUi()
{
_pluginUi.Toggle();
}
}
Loading

0 comments on commit d8c526c

Please sign in to comment.