Skip to content

Commit

Permalink
6.5 Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
InitialDet committed Oct 3, 2023
1 parent ad4ac9a commit be720ab
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 92 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.vs/
obj/
bin/
*.user
*.user
.idea/
9 changes: 4 additions & 5 deletions TargetFurniture/Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
using Dalamud.Configuration;
using Dalamud.Plugin;
using System;
using System;
using Dalamud.Configuration;

namespace MoveFurniture;
namespace TargetFurniture;
[Serializable]
public class Configuration : IPluginConfiguration
{
public int Version { get; set; } = 1;

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

public bool UseAltTarget = false;
Expand Down
34 changes: 16 additions & 18 deletions TargetFurniture/ContextMenuHousing.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
using System;
using Dalamud.Logging;
using System.Threading.Tasks;
using Dalamud.ContextMenu;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Game.Text.SeStringHandling.Payloads;

namespace MoveFurniture;
namespace TargetFurniture;
public unsafe class ContextMenuHousing : IDisposable
{
DalamudContextMenu ContextMenu = null!;
private DalamudContextMenu _contextMenu = null!;

GameObjectContextMenuItem? contextMenuItem;
AwaitingTarget waiting = new();
private GameObjectContextMenuItem? _contextMenuItem;

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

public void Dispose()
{
if (ContextMenu != null)
ContextMenu.OnOpenGameObjectContextMenu -= OnOpenContextMenu;
_contextMenu.OnOpenGameObjectContextMenu -= OnOpenContextMenu;
_contextMenu.Dispose();
}

private void OnOpenContextMenu(GameObjectContextMenuOpenArgs args)
{

if (args.ParentAddonName is "HousingGoods" && contextMenuItem != null) // To make sure it doenst appear in the Stored tab
args.AddCustomItem(contextMenuItem);
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)
Expand All @@ -51,24 +49,24 @@ private void SetFurnitureActive(GameObjectContextMenuItemSelectedArgs args)
// To make the item follow the cursor you need to retarget it, for reasons idk you need a small delay before the second target for it to work
TargetItem();
if (Service.Configuration.MoveToCursor)
waiting.waitingRetarget(this);
PluginLog.Debug($"Finished");
AwaitingTarget.WaitingRetarget();
//PluginLog.Debug($"Finished");
}
}
}

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

public class AwaitingTarget
public static class AwaitingTarget
{
public async void waitingRetarget(ContextMenuHousing contextMenuHousing)
public static async void WaitingRetarget()
{
await Task.Delay(60);
contextMenuHousing.TargetItem();
ContextMenuHousing.TargetItem();
}
}

21 changes: 10 additions & 11 deletions TargetFurniture/PluginMemory.cs
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
using Dalamud.Logging;
using System;
using System;
using System.Numerics;
using System.Runtime.InteropServices;

namespace MoveFurniture;
namespace TargetFurniture;

public class PluginMemory
{
// Layout and housing module pointers.
private readonly IntPtr layoutWorldPtr;
public unsafe LayoutWorld* Layout => (LayoutWorld*)layoutWorldPtr;
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);
public SelectItemDelegate SelectItem = null!;
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);
_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");
SelectItem = Marshal.GetDelegateForFunctionPointer<SelectItemDelegate>(selectItemAddress);

}
catch (Exception ex)
catch (Exception)
{
PluginLog.LogError(ex, "Error while calling PluginMemory.ctor()");
//PluginLog.LogError(ex, "Error while calling PluginMemory.ctor()");
}
}
}
Expand Down Expand Up @@ -83,7 +82,7 @@ public unsafe struct HousingStructure
}

[StructLayout(LayoutKind.Explicit)]
public unsafe struct HousingItem
public struct HousingItem
{
[FieldOffset(0x50)] public Vector3 Position;
[FieldOffset(0x60)] public Quaternion Rotation;
Expand Down
15 changes: 5 additions & 10 deletions TargetFurniture/PluginUI.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
using Dalamud.Interface;
using Dalamud.Interface.Windowing;
using Dalamud.Interface.Windowing;
using ImGuiNET;
using System;
using Dalamud.Interface.Colors;
using System.Numerics;
using MoveFurniture;
using System.Diagnostics;

namespace TargetFurniture;
public class PluginUI : Window, IDisposable
public class PluginUi : Window, IDisposable
{

public PluginUI() : base($"{Service.PluginName} Settings")
public PluginUi() : base($"{Service.PluginName} Settings")
{
Service.WindowSystem.AddWindow(this);

Expand Down Expand Up @@ -44,9 +39,9 @@ public override void Draw()
ImGui.End();
}

public static void ShowKofi()
private static void ShowKofi()
{
string buttonText = "Support on Ko-fi";
const string buttonText = "Support on Ko-fi";
ImGui.PushStyleColor(ImGuiCol.Button, 0xFF000000 | 0x005E5BFF);
ImGui.PushStyleColor(ImGuiCol.ButtonActive, 0xDD000000 | 0x005E5BFF);
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, 0xAA000000 | 0x005E5BFF);
Expand Down
17 changes: 8 additions & 9 deletions TargetFurniture/Service.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
using Dalamud.Game;
using Dalamud.Game.Command;
using Dalamud.Interface.Windowing;
using Dalamud.IoC;
using Dalamud.Plugin;
using Dalamud.Plugin.Services;

namespace MoveFurniture;
namespace TargetFurniture;

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

public const string PluginName = "Target Furniture";

[PluginService] public static DalamudPluginInterface PluginInterface { get; set; } = null!;
[PluginService] public static SigScanner SigScanner { get; set; } = null!;
[PluginService] public static CommandManager 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 WindowSystem(PluginName);
public static WindowSystem WindowSystem { get; } = new(PluginName);
}

46 changes: 22 additions & 24 deletions TargetFurniture/TargetFurniture.cs
Original file line number Diff line number Diff line change
@@ -1,63 +1,61 @@
using Dalamud.Game.Command;
using Dalamud.Plugin;
using TargetFurniture;

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

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

public ContextMenuHousing PluginContextMenu;
private readonly ContextMenuHousing _pluginContextMenu;

private static PluginUI PluginUI = null!;
private static PluginUi _pluginUi = null!;

public TargetFurniture(DalamudPluginInterface pluginInterface)
{

Service.Initialize(pluginInterface);
Service.Configuration = Configuration.Load();
Service.PluginInterface!.UiBuilder.Draw += Service.WindowSystem.Draw;
Service.PluginInterface!.UiBuilder.OpenConfigUi += OnOpenConfigUi;
Service.PluginInterface.UiBuilder.Draw += Service.WindowSystem.Draw;
Service.PluginInterface.UiBuilder.OpenConfigUi += OnOpenConfigUi;

Service.Memory = new();
Service.Memory = new PluginMemory();

PluginUI = new PluginUI();
_pluginUi = new PluginUi();

PluginContextMenu = new();
PluginContextMenu.Toggle();
_pluginContextMenu = new ContextMenuHousing();
_pluginContextMenu.Toggle();

Service.Commands.AddHandler(cmdConfig, new CommandInfo(OnCommand)
Service.Commands.AddHandler(CmdConfig, new CommandInfo(OnCommand)
{
HelpMessage = "Open Config Window"
});

Service.Commands.AddHandler(cmdConfigShort, new CommandInfo(OnCommand)
Service.Commands.AddHandler(CmdConfigShort, new CommandInfo(OnCommand)
{
HelpMessage = "Short Command for the Config Window "
});
}

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

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

public void Dispose()
{
Service.Configuration.Save();

PluginContextMenu.Dispose();
PluginUI.Dispose();
_pluginContextMenu.Dispose();
_pluginUi.Dispose();

Service.Commands.RemoveHandler(cmdConfig);
Service.Commands.RemoveHandler(cmdConfigShort);
Service.PluginInterface!.UiBuilder.Draw -= Service.WindowSystem.Draw;
Service.Commands.RemoveHandler(CmdConfig);
Service.Commands.RemoveHandler(CmdConfigShort);
Service.PluginInterface.UiBuilder.Draw -= Service.WindowSystem.Draw;
Service.PluginInterface.UiBuilder.OpenConfigUi -= OnOpenConfigUi;
}
}
6 changes: 3 additions & 3 deletions TargetFurniture/TargetFurniture.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Authors>Det</Authors>
<Version>1.0.1.7</Version>
<Version>1.0.1.8</Version>
<Description>You can now select furnitures from the Housing Menu</Description>
<PackageProjectUrl>https://github.com/InitialDet/TargetForniture</PackageProjectUrl>
</PropertyGroup>
Expand Down Expand Up @@ -41,8 +41,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Dalamud.ContextMenu" Version="1.2.1" />
<PackageReference Include="DalamudPackager" Version="2.1.10" />
<PackageReference Include="Dalamud.ContextMenu" Version="1.3.1" />
<PackageReference Include="DalamudPackager" Version="2.1.12" />
<Reference Include="FFXIVClientStructs">
<HintPath>$(DalamudLibPath)FFXIVClientStructs.dll</HintPath>
<Private>false</Private>
Expand Down
3 changes: 1 addition & 2 deletions TargetFurniture/TargetFurniture.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
],
"InternalName": "TargetFurniture",
"ApplicableVersion": "any",
"DalamudApiLevel": 8,
"LoadPriority": 0,
"Changelog": "6.3 update"
"Changelog": "6.5 update"
}
5 changes: 2 additions & 3 deletions TargetFurniture/Utils/Draw.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Numerics;
using Dalamud.Interface;
using System.Numerics;
using Dalamud.Interface.Components;
using Dalamud.Interface.Utility;
using ImGuiNET;

namespace TargetFurniture.Utils {
Expand Down
12 changes: 6 additions & 6 deletions TargetFurniture/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"net7.0-windows7.0": {
"Dalamud.ContextMenu": {
"type": "Direct",
"requested": "[1.2.1, )",
"resolved": "1.2.1",
"contentHash": "RiBkn1OYRTnVbfUGYolLBE8MOeXjok+JiZaryb27oGa7YARCTu0XgUzkRiCglujknsHOn5kAaXsT3TUJmqMigg=="
"requested": "[1.3.1, )",
"resolved": "1.3.1",
"contentHash": "ptAxut5PiLnzZ4G/KQdHJVcyklC/BF3otHJ7zYVUPiKBjsOCoF0n/6h2jK7e+8ev2Y1yAY3Wtx2GuXLFQgt9Uw=="
},
"DalamudPackager": {
"type": "Direct",
"requested": "[2.1.10, )",
"resolved": "2.1.10",
"contentHash": "S6NrvvOnLgT4GDdgwuKVJjbFo+8ZEj+JsEYk9ojjOR/MMfv1dIFpT8aRJQfI24rtDcw1uF+GnSSMN4WW1yt7fw=="
"requested": "[2.1.12, )",
"resolved": "2.1.12",
"contentHash": "Sc0PVxvgg4NQjcI8n10/VfUQBAS4O+Fw2pZrAqBdRMbthYGeogzu5+xmIGCGmsEZ/ukMOBuAqiNiB5qA3MRalg=="
}
}
}
Expand Down

0 comments on commit be720ab

Please sign in to comment.