Skip to content

Commit

Permalink
Update for API 10
Browse files Browse the repository at this point in the history
  • Loading branch information
saltybrackets committed Jul 2, 2024
1 parent 1e60e79 commit 1e993af
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 103 deletions.
4 changes: 2 additions & 2 deletions Data/startupCommands.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"Name": "Startup Commands",
"InternalName": "StartupCommands",
"Description": "Perform various behaviors/commands right after logging into a character.",
"AssemblyVersion": "1.1.2.0",
"AssemblyVersion": "1.2.0.0",
"RepoUrl": "https://github.com/saltycog/ffxiv-startup-commands",
"IconUrl": "https://github.com/saltycog/ffxiv-startup-commands/raw/master/icon.png",
"DalamudApiLevel": 9
"DalamudApiLevel": 10
}
6 changes: 0 additions & 6 deletions StartupCommands.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ VisualStudioVersion = 16.0.29709.97
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StartupCommandsPlugin", "StartupCommandsPlugin\StartupCommandsPlugin.csproj", "{13C812E9-0D42-4B95-8646-40EEBF30636F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StartupCommandsTest", "StartupCommandsTest\StartupCommandsTest.csproj", "{4FEC9558-EB25-419F-B86E-51B8CFDA32B7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -17,10 +15,6 @@ Global
{13C812E9-0D42-4B95-8646-40EEBF30636F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{13C812E9-0D42-4B95-8646-40EEBF30636F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{13C812E9-0D42-4B95-8646-40EEBF30636F}.Release|Any CPU.Build.0 = Release|Any CPU
{4FEC9558-EB25-419F-B86E-51B8CFDA32B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4FEC9558-EB25-419F-B86E-51B8CFDA32B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4FEC9558-EB25-419F-B86E-51B8CFDA32B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4FEC9558-EB25-419F-B86E-51B8CFDA32B7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
7 changes: 2 additions & 5 deletions StartupCommandsPlugin/Config/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
public class Configuration : IPluginConfiguration
{
[NonSerialized]
private DalamudPluginInterface pluginInterface;
private IDalamudPluginInterface pluginInterface;

[NonSerialized]
private string currentCharacter;


#region Properties
public Dictionary<string, CharacterConfiguration> CharacterConfigurations { get; set; } =
new Dictionary<string, CharacterConfiguration>();

Expand Down Expand Up @@ -74,10 +72,9 @@ public bool HasCommands
}

public int Version { get; set; } = 1;
#endregion


public void Initialize(DalamudPluginInterface pluginInterface)
public void Initialize(IDalamudPluginInterface pluginInterface)
{
this.pluginInterface = pluginInterface;
}
Expand Down
21 changes: 7 additions & 14 deletions StartupCommandsPlugin/GameClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace FfxivStartupCommands
{
using System;
using System.Runtime.InteropServices;
using FFXIVClientStructs.FFXIV.Client.UI;
using FFXIVClientStructs.FFXIV.Component.GUI;


Expand All @@ -17,16 +18,11 @@ public class GameClient

public GameClient()
{
if (Plugin.PluginInterface == null)
if (Services.PluginInterface == null)
return;

// Get UI module.
IntPtr getUiModulePointer = Plugin.TargetModuleScanner.ScanText("E8 ?? ?? ?? ?? 48 83 7F ?? 00 48 8B F0");
this.uiModulePointer = Plugin.TargetModuleScanner.GetStaticAddressFromSig("48 8B 0D ?? ?? ?? ?? 48 8D 54 24 ?? 48 83 C1 10 E8 ?? ?? ?? ??");
this.getUI = Marshal.GetDelegateForFunctionPointer<GetUiModuleDelegate>(getUiModulePointer);

// Get chat box module.
IntPtr chatBoxModulePointer = Plugin.TargetModuleScanner.ScanText("48 89 5C 24 ?? 57 48 83 EC 20 48 8B FA 48 8B D9 45 84 C9");
IntPtr chatBoxModulePointer = Services.TargetModuleScanner.ScanText("48 89 5C 24 ?? 57 48 83 EC 20 48 8B FA 48 8B D9 45 84 C9");
this.getChatBox = Marshal.GetDelegateForFunctionPointer<GetChatBoxModuleDelegate>(chatBoxModulePointer);
}

Expand All @@ -36,9 +32,9 @@ public GameClient()
/// </summary>
public unsafe bool GetChatVisible()
{
if (Plugin.ClientState.LocalPlayer != null)
if (Services.ClientState.LocalPlayer != null)
{
AtkUnitBase* chatLog = (AtkUnitBase*)Plugin.GameGui.GetAddonByName("ChatLog", 1);
AtkUnitBase* chatLog = (AtkUnitBase*)Services.GameGui.GetAddonByName("ChatLog", 1);

if (chatLog != null)
return chatLog->IsVisible;
Expand All @@ -65,17 +61,14 @@ public void ChangeChatChannel()
/// Can be used to enter chat commands.
/// </summary>
/// <param name="text">Text to submit.</param>
public void SubmitToChat(string text)
public unsafe void SubmitToChat(string text)
{
IntPtr uiModule = this.getUI(Marshal.ReadIntPtr(this.uiModulePointer));

nint uiModule = (nint)UIModule.Instance();
using (ChatPayload payload = new ChatPayload(text))
{
IntPtr mem1 = Marshal.AllocHGlobal(400);
Marshal.StructureToPtr(payload, mem1, false);

this.getChatBox(uiModule, mem1, IntPtr.Zero, 0);

Marshal.FreeHGlobal(mem1);
}
}
Expand Down
113 changes: 39 additions & 74 deletions StartupCommandsPlugin/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
namespace FfxivStartupCommands
{
using Dalamud.Game;
using Dalamud.Game.ClientState;
using Dalamud.Game.Command;
using Dalamud.Game.Gui;
using Dalamud.IoC;
using Dalamud.Plugin;
using Dalamud.Plugin.Services;


/// <summary>
Expand All @@ -19,34 +14,11 @@ public class Plugin : IDalamudPlugin

private static Plugin _instance;

[PluginService]
public static DalamudPluginInterface PluginInterface { get; private set; }

[PluginService]
public static ICommandManager CommandManager { get; private set; }

[PluginService]
public static IClientState ClientState { get; private set; }

[PluginService]
public static IFramework Framework { get; private set; }

[PluginService]
public static IChatGui ChatGui { get; private set; }

[PluginService]
public static IGameGui GameGui { get; private set; }

[PluginService]
public static ISigScanner TargetModuleScanner { get; private set; }

private Configuration configuration = new Configuration();
private GameClient gameClient;
private StartupHandlers startupHandlers;
private PluginUI ui;


#region Properties
/// <summary>
/// Plugin configuration.
/// </summary>
Expand All @@ -55,8 +27,6 @@ public static Configuration Configuration
get { return Instance.configuration; }
}



/// <summary>
/// Game client utility functions.
/// </summary>
Expand Down Expand Up @@ -96,14 +66,34 @@ private static Plugin Instance
{
get
{
if (_instance == null)
{
_instance = new Plugin();
}
return _instance;
}
}
#endregion


public Plugin(IDalamudPluginInterface dalamudPluginInterface)
{
_instance = this;

Services.Initialize(dalamudPluginInterface);

if (Services.PluginInterface != null)
this.configuration = Services.PluginInterface.GetPluginConfig() as Configuration ?? new Configuration();
else
this.configuration = new Configuration();

this.configuration.Initialize(Services.PluginInterface);

this.ui = new PluginUI();

this.startupHandlers = new StartupHandlers();
this.gameClient = new GameClient();

RegisterHooks();

if (Services.ClientState.LocalPlayer != null)
Configuration.SetCurrentCharacter(Services.ClientState.LocalPlayer.Name.ToString());
}


/// <summary>
Expand All @@ -112,49 +102,24 @@ private static Plugin Instance
/// <param name="text">Text to display in chat box.</param>
public static void LogToChat(string text)
{
ChatGui.Print(text);
Services.ChatGui.Print(text);
}


public void Dispose()
{
CommandManager.RemoveHandler(mainCommandName);
PluginInterface.UiBuilder.Draw -= this.ui.Draw;
ClientState.Login -= this.startupHandlers.OnLogin;
ClientState.Logout -= this.startupHandlers.OnLogout;
Services.CommandManager.RemoveHandler(mainCommandName);
Services.PluginInterface.UiBuilder.Draw -= this.ui.Draw;

Services.ClientState.Login -= this.startupHandlers.OnLogin;
Services.ClientState.Logout -= this.startupHandlers.OnLogout;

this.ui.Dispose();
this.startupHandlers.Dispose();
//PluginInterface.Dispose();
}


public Plugin()
{
_instance = this;



if (PluginInterface != null)
this.configuration = PluginInterface.GetPluginConfig() as Configuration ?? new Configuration();
else
this.configuration = new Configuration();

this.configuration.Initialize(PluginInterface);

this.ui = new PluginUI();

this.startupHandlers = new StartupHandlers();
this.gameClient = new GameClient();

RegisterHooks();

if (ClientState.LocalPlayer != null)
Plugin.Configuration.SetCurrentCharacter(Plugin.ClientState.LocalPlayer.Name.ToString());
}


/// <summary>
/// Handler for when plugin slash command is entered in chat.
/// </summary>
Expand All @@ -170,7 +135,7 @@ private void OnCommand(string command, string args)
/// </summary>
private void RegisterCommandHooks()
{
CommandManager.AddHandler(
Services.CommandManager.AddHandler(
mainCommandName,
new CommandInfo(OnCommand)
{
Expand All @@ -181,7 +146,7 @@ private void RegisterCommandHooks()

private void RegisterHooks()
{
if (PluginInterface == null)
if (Services.PluginInterface == null)
return;

RegisterCommandHooks();
Expand All @@ -192,23 +157,23 @@ private void RegisterHooks()

private void RegisterStartupHooks()
{
ClientState.Login += this.startupHandlers.OnLogin;
ClientState.Logout += this.startupHandlers.OnLogout;
Services.ClientState.Login += this.startupHandlers.OnLogin;
Services.ClientState.Logout += this.startupHandlers.OnLogout;
}


private void RegisterUIHooks()
{
PluginInterface.UiBuilder.Draw += this.ui.Draw;
PluginInterface.UiBuilder.OpenConfigUi +=
Services.PluginInterface.UiBuilder.Draw += this.ui.Draw;
Services.PluginInterface.UiBuilder.OpenConfigUi +=
() =>
{
if (ClientState.LocalPlayer == null)
if (Services.ClientState.LocalPlayer == null)
return;

if (Configuration.CurrentCharacter == null)
{
Configuration.SetCurrentCharacter(ClientState.LocalPlayer.Name.ToString());
Configuration.SetCurrentCharacter(Services.ClientState.LocalPlayer.Name.ToString());
}

this.ui.ConfigWindow.Show();
Expand Down
34 changes: 34 additions & 0 deletions StartupCommandsPlugin/Services.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace FfxivStartupCommands;

using Dalamud.Game;
using Dalamud.IoC;
using Dalamud.Plugin;
using Dalamud.Plugin.Services;


public class Services
{
[PluginService]
public static IDalamudPluginInterface PluginInterface { get; private set; }

[PluginService]
public static ICommandManager CommandManager { get; private set; }

[PluginService]
public static IClientState ClientState { get; private set; }

[PluginService]
public static IChatGui ChatGui { get; private set; }

[PluginService]
public static IGameGui GameGui { get; private set; }

[PluginService]
public static ISigScanner TargetModuleScanner { get; private set; }


public static void Initialize(IDalamudPluginInterface dalamudPluginInterface)
{
dalamudPluginInterface.Create<Services>();
}
}
2 changes: 1 addition & 1 deletion StartupCommandsPlugin/StartupCommandsPlugin.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>1.1.1</Version>
<TargetFramework>net7.0-windows</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
<AssemblyName>StartupCommands</AssemblyName>
Expand Down
2 changes: 1 addition & 1 deletion StartupCommandsPlugin/StartupHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private static void RunCustomCommands()

private void OnChatReady()
{
Plugin.Configuration.SetCurrentCharacter(Plugin.ClientState.LocalPlayer.Name.ToString());
Plugin.Configuration.SetCurrentCharacter(Services.ClientState.LocalPlayer.Name.ToString());
RunStartupBehaviors();
}
}
Expand Down

0 comments on commit 1e993af

Please sign in to comment.