Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
chirpxiv committed Sep 28, 2024
0 parents commit ed0db5c
Show file tree
Hide file tree
Showing 18 changed files with 1,290 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.vs/
obj/
bin/
*.user
.idea/*
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "GLib"]
path = GLib
url = git@github.com:ktisis-tools/GLib.git
1 change: 1 addition & 0 deletions GLib
Submodule GLib added at 754f39
34 changes: 34 additions & 0 deletions GoodOmen.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29709.97
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GoodOmen", "GoodOmen\GoodOmen.csproj", "{13C812E9-0D42-4B95-8646-40EEBF30636F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GLib", "GLib\GLib\GLib.csproj", "{3D18C5CD-9DEF-4DF5-A35D-7F56A99E804F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{13C812E9-0D42-4B95-8646-40EEBF30636F}.Debug|x64.ActiveCfg = Debug|x64
{13C812E9-0D42-4B95-8646-40EEBF30636F}.Debug|x64.Build.0 = Debug|x64
{13C812E9-0D42-4B95-8646-40EEBF30636F}.Release|x64.ActiveCfg = Release|x64
{13C812E9-0D42-4B95-8646-40EEBF30636F}.Release|x64.Build.0 = Release|x64
{4FEC9558-EB25-419F-B86E-51B8CFDA32B7}.Debug|x64.ActiveCfg = Debug|x64
{4FEC9558-EB25-419F-B86E-51B8CFDA32B7}.Debug|x64.Build.0 = Debug|x64
{4FEC9558-EB25-419F-B86E-51B8CFDA32B7}.Release|x64.ActiveCfg = Release|x64
{4FEC9558-EB25-419F-B86E-51B8CFDA32B7}.Release|x64.Build.0 = Release|x64
{3D18C5CD-9DEF-4DF5-A35D-7F56A99E804F}.Debug|x64.ActiveCfg = Debug|Any CPU
{3D18C5CD-9DEF-4DF5-A35D-7F56A99E804F}.Debug|x64.Build.0 = Debug|Any CPU
{3D18C5CD-9DEF-4DF5-A35D-7F56A99E804F}.Release|x64.ActiveCfg = Release|Any CPU
{3D18C5CD-9DEF-4DF5-A35D-7F56A99E804F}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B17E85B1-5F60-4440-9F9A-3DDE877E8CDF}
EndGlobalSection
EndGlobal
22 changes: 22 additions & 0 deletions GoodOmen/Config.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Collections.Generic;
using System.Numerics;

using Dalamud.Configuration;

namespace GoodOmen;

public class Config : IPluginConfiguration {
public int Version { get; set; } = 1;

public bool Enabled = true;

public bool GlobalColor = false;
public Vector4 Color = new(1.0f);

public Dictionary<ushort, DutySetup> DutyColors = new();

public class DutySetup {
public bool Enabled = true;
public Vector4 Color = new(1.0f);
}
}
37 changes: 37 additions & 0 deletions GoodOmen/Core/CommandHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;

using Dalamud.Game.Command;
using Dalamud.Plugin.Services;

using GoodOmen.Interface;

namespace GoodOmen.Core;

public class CommandHandler : IDisposable {
private const string CommandName = "/goodomen";

private readonly ICommandManager _cmd;
private readonly GuiManager _gui;

public CommandHandler(
ICommandManager cmd,
GuiManager gui
) {
this._cmd = cmd;
this._gui = gui;
}

public void Register() {
this._cmd.AddHandler(CommandName, new CommandInfo(this.HandleCommand) {
HelpMessage = "Opens the GoodOmen configuration window."
});
}

private void HandleCommand(string _, string args) {
this._gui.ToggleConfigWindow();
}

public void Dispose() {
this._cmd.RemoveHandler(CommandName);
}
}
47 changes: 47 additions & 0 deletions GoodOmen/Core/HookManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;

using Dalamud.Hooking;
using Dalamud.Plugin.Services;
using Dalamud.Utility.Signatures;

using GoodOmen.Structs;

namespace GoodOmen.Core;

public class HookManager : IDisposable {
public bool Enabled => this.CreateOmenHook.IsEnabled;

public event VfxSpawnEvent? OnSpawn;
public unsafe delegate void VfxSpawnEvent(VfxResourceInstance* instance);

[Signature("E8 ?? ?? ?? ?? 48 89 84 FB ?? ?? ?? ?? 48 85 C0 74 53", DetourName = nameof(CreateOmenDetour))]
private Hook<CreateOmenDelegate> CreateOmenHook = null!;
private unsafe delegate VfxData* CreateOmenDelegate(uint a1, nint a2, nint a3, float a4, int a5, int a6, float a7, int a8, char isEnemy, char a10);

public HookManager(
IGameInteropProvider interop
) {
interop.InitializeFromAttributes(this);
}

public void SetEnabled(bool enable) {
if (enable)
this.CreateOmenHook.Enable();
else
this.CreateOmenHook.Disable();
}

private unsafe VfxData* CreateOmenDetour(uint a1, nint a2, nint a3, float a4, int a5, int a6, float a7, int a8, char isEnemy, char a10) {
var vfx = this.CreateOmenHook.Original(a1, a2, a3, a4, a5, a6, a7, a8, isEnemy, a10);
if (isEnemy == 1 && vfx != null) {
var instance = vfx->Instance;
if (instance != null) this.OnSpawn?.Invoke(instance);
}
return vfx;
}

public void Dispose() {
this.CreateOmenHook.Disable();
this.CreateOmenHook.Dispose();
}
}
54 changes: 54 additions & 0 deletions GoodOmen/Core/OmenManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Numerics;

using FFXIVClientStructs.FFXIV.Client.Game;

using GoodOmen.Structs;

namespace GoodOmen.Core;

public class OmenManager : IDisposable {
private readonly Config _config;
private readonly HookManager _hooks;

public bool Enabled {
get => this._hooks.Enabled;
set {
this._config.Enabled = value;
this._hooks.SetEnabled(value);
}
}

public OmenManager(
Config config,
HookManager hooks
) {
this._config = config;
this._hooks = hooks;
}

public unsafe void Initialize() {
this._hooks.SetEnabled(this._config.Enabled);
this._hooks.OnSpawn += this.OnSpawn;
}

private unsafe void OnSpawn(VfxResourceInstance* instance) {
if (instance->Color.Equals(Vector4.One) && this.TryGetColor(out var color))
instance->Color = color;
}

private unsafe bool TryGetColor(out Vector4 color) {
var id = GameMain.Instance()->CurrentContentFinderConditionId;
if (this._config.DutyColors.TryGetValue(id, out var setup) && setup.Enabled) {
color = setup.Color;
return true;
}

color = this._config.Color;
return this._config.GlobalColor;
}

public void Dispose() {
this._hooks.Dispose();
}
}
44 changes: 44 additions & 0 deletions GoodOmen/GoodOmen.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Dalamud.Plugin;
using Dalamud.Plugin.Services;

using GoodOmen.Core;
using GoodOmen.Interface;

namespace GoodOmen;

public sealed class GoodOmen : IDalamudPlugin {
private readonly IDalamudPluginInterface _dpi;

private readonly Config _config;
private readonly OmenManager _omens;
private readonly GuiManager _gui;
private readonly CommandHandler _cmd;

public GoodOmen(
IDalamudPluginInterface dpi,
IGameInteropProvider interop,
ICommandManager cmd,
IDataManager data
) {
this._dpi = dpi;
this._config = dpi.GetPluginConfig() as Config ?? new Config();

var hooks = new HookManager(interop);
this._omens = new OmenManager(this._config, hooks);
this._omens.Initialize();

var dutySelect = new DutySelect(data);
var cfgWindow = new ConfigWindow(this._dpi, this._config, this._omens, dutySelect);
this._gui = new GuiManager(cfgWindow, dpi.UiBuilder);

this._cmd = new CommandHandler(cmd, this._gui);
this._cmd.Register();
}

public void Dispose() {
this._omens.Dispose();
this._gui.Dispose();
this._cmd.Dispose();
this._dpi.SavePluginConfig(this._config);
}
}
62 changes: 62 additions & 0 deletions GoodOmen/GoodOmen.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Authors>Chirp</Authors>
<Version>0.1.1.0</Version>
</PropertyGroup>

<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<Platforms>x64</Platforms>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

<PropertyGroup>
<DalamudLibPath>$(appdata)\XIVLauncher\addon\Hooks\dev\</DalamudLibPath>
</PropertyGroup>
<PropertyGroup Condition="'$(OS)' != 'Windows_NT' OR '$(CI)' == 'true'">
<DalamudLibPath>$(DALAMUD_HOME)/</DalamudLibPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DalamudPackager" Version="2.1.13" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<Reference Include="FFXIVClientStructs">
<HintPath>$(DalamudLibPath)FFXIVClientStructs.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="Dalamud">
<HintPath>$(DalamudLibPath)Dalamud.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="ImGui.NET">
<HintPath>$(DalamudLibPath)ImGui.NET.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="ImGuiScene">
<HintPath>$(DalamudLibPath)ImGuiScene.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="Lumina">
<HintPath>$(DalamudLibPath)Lumina.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="Lumina.Excel">
<HintPath>$(DalamudLibPath)Lumina.Excel.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>$(DalamudLibPath)Newtonsoft.Json.dll</HintPath>
<Private>false</Private>
</Reference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\GLib\GLib\GLib.csproj" />
</ItemGroup>
</Project>
15 changes: 15 additions & 0 deletions GoodOmen/GoodOmen.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"Author": "Chirp",
"Name": "GoodOmen",
"PunchLine": "Accessibility plugin for modifying AoE colors.",
"Description": "Accessibility plugin for modifying AoE colors.",
"InternalName": "GoodOmen",
"AssemblyVersion": "0.2.0",
"ApplicableVersion": "any",
"DalamudApiLevel": 10,
"Tags": [
"omen",
"aoe",
"color"
]
}
Loading

0 comments on commit ed0db5c

Please sign in to comment.