From 3c7e5fe8c9eb659ae6a9d2fb4803b37f042331f7 Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Sat, 9 Mar 2024 00:34:40 +0100 Subject: [PATCH] Add shutdown plogon --- .gitmodules | 9 ++++ AutoRetainerAPI | 1 + AutoShutdown/.gitignore | 1 + AutoShutdown/AutoShutdown.csproj | 66 ++++++++++++++++++++++++++++ AutoShutdown/AutoShutdown.json | 6 +++ AutoShutdown/DalamudPackager.targets | 21 +++++++++ AutoShutdown/Plogon.cs | 64 +++++++++++++++++++++++++++ AutoShutdown/packages.lock.json | 25 +++++++++++ ECommons | 1 + LLib | 1 + TheWatcher.sln | 18 ++++++++ 11 files changed, 213 insertions(+) create mode 100644 .gitmodules create mode 160000 AutoRetainerAPI create mode 100644 AutoShutdown/.gitignore create mode 100644 AutoShutdown/AutoShutdown.csproj create mode 100644 AutoShutdown/AutoShutdown.json create mode 100644 AutoShutdown/DalamudPackager.targets create mode 100644 AutoShutdown/Plogon.cs create mode 100644 AutoShutdown/packages.lock.json create mode 160000 ECommons create mode 160000 LLib diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..57a80b5 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,9 @@ +[submodule "AutoRetainerAPI"] + path = AutoRetainerAPI + url = https://github.com/PunishXIV/AutoRetainerAPI.git +[submodule "ECommons"] + path = ECommons + url = https://github.com/NightmareXIV/ECommons.git +[submodule "LLib"] + path = LLib + url = https://git.carvel.li/liza/LLib.git diff --git a/AutoRetainerAPI b/AutoRetainerAPI new file mode 160000 index 0000000..75a0db1 --- /dev/null +++ b/AutoRetainerAPI @@ -0,0 +1 @@ +Subproject commit 75a0db11d7cc982b54f9cacb8a2b9c17b023b718 diff --git a/AutoShutdown/.gitignore b/AutoShutdown/.gitignore new file mode 100644 index 0000000..9b1c8b1 --- /dev/null +++ b/AutoShutdown/.gitignore @@ -0,0 +1 @@ +/dist diff --git a/AutoShutdown/AutoShutdown.csproj b/AutoShutdown/AutoShutdown.csproj new file mode 100644 index 0000000..72fadbb --- /dev/null +++ b/AutoShutdown/AutoShutdown.csproj @@ -0,0 +1,66 @@ + + + net7.0-windows + 0.1 + 11.0 + enable + true + false + false + dist + true + portable + $(SolutionDir)=X:\ + true + portable + + + + $(appdata)\XIVLauncher\addon\Hooks\dev\ + + + + $(DALAMUD_HOME)/ + + + + + + + + + $(DalamudLibPath)Dalamud.dll + false + + + $(DalamudLibPath)ImGui.NET.dll + false + + + $(DalamudLibPath)Lumina.dll + false + + + $(DalamudLibPath)Lumina.Excel.dll + false + + + $(DalamudLibPath)Newtonsoft.Json.dll + false + + + $(DalamudLibPath)FFXIVClientStructs.dll + false + + + + + + + + + + + + + diff --git a/AutoShutdown/AutoShutdown.json b/AutoShutdown/AutoShutdown.json new file mode 100644 index 0000000..6cae74a --- /dev/null +++ b/AutoShutdown/AutoShutdown.json @@ -0,0 +1,6 @@ +{ + "Name": "AutoShutdown", + "Author": "Liza Carvelli", + "Punchline": "", + "Description": "" +} diff --git a/AutoShutdown/DalamudPackager.targets b/AutoShutdown/DalamudPackager.targets new file mode 100644 index 0000000..97ade9a --- /dev/null +++ b/AutoShutdown/DalamudPackager.targets @@ -0,0 +1,21 @@ + + + + + + + + + + diff --git a/AutoShutdown/Plogon.cs b/AutoShutdown/Plogon.cs new file mode 100644 index 0000000..efdacee --- /dev/null +++ b/AutoShutdown/Plogon.cs @@ -0,0 +1,64 @@ +using System; +using System.Reflection; +using AutoRetainerAPI; +using Dalamud.Plugin; +using Dalamud.Plugin.Services; +using ECommons; +using LLib; + +namespace AutoShutdown; + +public class Plogon : IDalamudPlugin +{ + private readonly AutoRetainerApi _autoRetainerApi; + private readonly DalamudReflector _reflector; + private readonly IPluginLog _pluginLog; + private readonly IClientState _clientState; + + public Plogon(DalamudPluginInterface pluginInterface, IFramework framework, IPluginLog pluginLog, IClientState clientState) + { + ECommonsMain.Init(pluginInterface, this); + _autoRetainerApi = new AutoRetainerApi(); + _reflector = new DalamudReflector(pluginInterface, framework, pluginLog); + _pluginLog = pluginLog; + _clientState = clientState; + + _clientState.Login += SetupShutdown; + + framework.RunOnTick(SetupShutdown, TimeSpan.FromSeconds(5)); + } + + private long StartedAt { get; } = Environment.TickCount64; + private long ShutdownAt => StartedAt + TimeSpan.FromDays(2).Ticks; + + private void SetupShutdown() + { + if (_autoRetainerApi.Ready && _reflector.TryGetDalamudPlugin("AutoRetainer", out var autoRetainer, false, true)) + { + var shutdown = autoRetainer.GetType().Assembly.GetType("AutoRetainer.Modules.Shutdown")!; + + var shutdownAt = shutdown.GetField("ShutdownAt", BindingFlags.Static | BindingFlags.NonPublic)!; + var forceShutdownAt = shutdown.GetField("ForceShutdownAt", BindingFlags.Static | BindingFlags.NonPublic)!; + + var currentShutdownAt = (long?)shutdownAt.GetValue(null) ?? 0; + if (currentShutdownAt == 0) + { + _pluginLog.Information($"Setting shutdown date to {new DateTime(ShutdownAt)}"); + shutdownAt.SetValue(null, ShutdownAt); + forceShutdownAt.SetValue(null, ShutdownAt + TimeSpan.FromMinutes(10).Ticks); + } + else + { + _pluginLog.Information($"Shutdown is already set to {new DateTime(currentShutdownAt)}"); + } + } + } + + public void Dispose() + { + _clientState.Login -= SetupShutdown; + _reflector.Dispose(); + _autoRetainerApi.Dispose(); + ECommonsMain.Dispose(); + } +} diff --git a/AutoShutdown/packages.lock.json b/AutoShutdown/packages.lock.json new file mode 100644 index 0000000..84c5a5c --- /dev/null +++ b/AutoShutdown/packages.lock.json @@ -0,0 +1,25 @@ +{ + "version": 1, + "dependencies": { + "net7.0-windows7.0": { + "DalamudPackager": { + "type": "Direct", + "requested": "[2.1.12, )", + "resolved": "2.1.12", + "contentHash": "Sc0PVxvgg4NQjcI8n10/VfUQBAS4O+Fw2pZrAqBdRMbthYGeogzu5+xmIGCGmsEZ/ukMOBuAqiNiB5qA3MRalg==" + }, + "autoretainerapi": { + "type": "Project", + "dependencies": { + "ECommons": "[2.1.0, )" + } + }, + "ecommons": { + "type": "Project" + }, + "llib": { + "type": "Project" + } + } + } +} \ No newline at end of file diff --git a/ECommons b/ECommons new file mode 160000 index 0000000..f1c688a --- /dev/null +++ b/ECommons @@ -0,0 +1 @@ +Subproject commit f1c688a0599b41d70230021328a575da7351cf91 diff --git a/LLib b/LLib new file mode 160000 index 0000000..865a608 --- /dev/null +++ b/LLib @@ -0,0 +1 @@ +Subproject commit 865a6080319f8ccbcd5fd5b0004404822b6e60d4 diff --git a/TheWatcher.sln b/TheWatcher.sln index 70b3594..d83eacf 100644 --- a/TheWatcher.sln +++ b/TheWatcher.sln @@ -4,6 +4,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TheWatcher", "TheWatcher\Th EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoShutdown", "AutoShutdown\AutoShutdown.csproj", "{95EA0D93-CFA6-4B4E-9F9D-C1B99D9F3E6A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoRetainerAPI", "AutoRetainerAPI\AutoRetainerAPI\AutoRetainerAPI.csproj", "{92BCF7DE-68B8-4417-8661-2F299194E8E3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ECommons", "ECommons\ECommons\ECommons.csproj", "{71433C33-5218-42B9-B55B-DE176BFE7F8F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LLib", "LLib\LLib.csproj", "{628C0B5B-347A-4FB4-8DE8-F71D42180DA2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -18,5 +24,17 @@ Global {95EA0D93-CFA6-4B4E-9F9D-C1B99D9F3E6A}.Debug|Any CPU.Build.0 = Debug|Any CPU {95EA0D93-CFA6-4B4E-9F9D-C1B99D9F3E6A}.Release|Any CPU.ActiveCfg = Release|Any CPU {95EA0D93-CFA6-4B4E-9F9D-C1B99D9F3E6A}.Release|Any CPU.Build.0 = Release|Any CPU + {92BCF7DE-68B8-4417-8661-2F299194E8E3}.Debug|Any CPU.ActiveCfg = Debug|x64 + {92BCF7DE-68B8-4417-8661-2F299194E8E3}.Debug|Any CPU.Build.0 = Debug|x64 + {92BCF7DE-68B8-4417-8661-2F299194E8E3}.Release|Any CPU.ActiveCfg = Release|x64 + {92BCF7DE-68B8-4417-8661-2F299194E8E3}.Release|Any CPU.Build.0 = Release|x64 + {71433C33-5218-42B9-B55B-DE176BFE7F8F}.Debug|Any CPU.ActiveCfg = Debug|x64 + {71433C33-5218-42B9-B55B-DE176BFE7F8F}.Debug|Any CPU.Build.0 = Debug|x64 + {71433C33-5218-42B9-B55B-DE176BFE7F8F}.Release|Any CPU.ActiveCfg = Release|x64 + {71433C33-5218-42B9-B55B-DE176BFE7F8F}.Release|Any CPU.Build.0 = Release|x64 + {628C0B5B-347A-4FB4-8DE8-F71D42180DA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {628C0B5B-347A-4FB4-8DE8-F71D42180DA2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {628C0B5B-347A-4FB4-8DE8-F71D42180DA2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {628C0B5B-347A-4FB4-8DE8-F71D42180DA2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal