Add shutdown plogon

master
Liza 2024-03-09 00:34:40 +01:00
parent ffe86011b4
commit 3c7e5fe8c9
Signed by: liza
GPG Key ID: 7199F8D727D55F67
11 changed files with 213 additions and 0 deletions

9
.gitmodules vendored Normal file
View File

@ -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

1
AutoRetainerAPI Submodule

@ -0,0 +1 @@
Subproject commit 75a0db11d7cc982b54f9cacb8a2b9c17b023b718

1
AutoShutdown/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/dist

View File

@ -0,0 +1,66 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework>
<Version>0.1</Version>
<LangVersion>11.0</LangVersion>
<Nullable>enable</Nullable>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<OutputPath>dist</OutputPath>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DebugType>portable</DebugType>
<PathMap Condition="$(SolutionDir) != ''">$(SolutionDir)=X:\</PathMap>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<DebugType>portable</DebugType>
</PropertyGroup>
<PropertyGroup>
<DalamudLibPath>$(appdata)\XIVLauncher\addon\Hooks\dev\</DalamudLibPath>
</PropertyGroup>
<PropertyGroup Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))'">
<DalamudLibPath>$(DALAMUD_HOME)/</DalamudLibPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DalamudPackager" Version="2.1.12"/>
</ItemGroup>
<ItemGroup>
<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="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>
<Reference Include="FFXIVClientStructs">
<HintPath>$(DalamudLibPath)FFXIVClientStructs.dll</HintPath>
<Private>false</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AutoRetainerAPI\AutoRetainerAPI\AutoRetainerAPI.csproj"/>
<ProjectReference Include="..\ECommons\ECommons\ECommons.csproj"/>
<ProjectReference Include="..\LLib\LLib.csproj" />
</ItemGroup>
<Target Name="RenameLatestZip" AfterTargets="PackagePlugin" Condition="'$(Configuration)' == 'Release'">
<Exec Command="rename $(OutDir)$(AssemblyName)\latest.zip $(AssemblyName)-$(Version).zip"/>
</Target>
</Project>

View File

@ -0,0 +1,6 @@
{
"Name": "AutoShutdown",
"Author": "Liza Carvelli",
"Punchline": "",
"Description": ""
}

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<Target Name="PackagePlugin" AfterTargets="Build" Condition="'$(Configuration)' == 'Debug'">
<DalamudPackager
ProjectDir="$(ProjectDir)"
OutputPath="$(OutputPath)"
AssemblyName="$(AssemblyName)"
MakeZip="false"
VersionComponents="2"/>
</Target>
<Target Name="PackagePlugin" AfterTargets="Build" Condition="'$(Configuration)' == 'Release'">
<DalamudPackager
ProjectDir="$(ProjectDir)"
OutputPath="$(OutputPath)"
AssemblyName="$(AssemblyName)"
MakeZip="true"
VersionComponents="2"
Exclude="Gearsetter.deps.json"/>
</Target>
</Project>

64
AutoShutdown/Plogon.cs Normal file
View File

@ -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();
}
}

View File

@ -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"
}
}
}
}

1
ECommons Submodule

@ -0,0 +1 @@
Subproject commit f1c688a0599b41d70230021328a575da7351cf91

1
LLib Submodule

@ -0,0 +1 @@
Subproject commit 865a6080319f8ccbcd5fd5b0004404822b6e60d4

View File

@ -4,6 +4,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TheWatcher", "TheWatcher\Th
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoShutdown", "AutoShutdown\AutoShutdown.csproj", "{95EA0D93-CFA6-4B4E-9F9D-C1B99D9F3E6A}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoShutdown", "AutoShutdown\AutoShutdown.csproj", "{95EA0D93-CFA6-4B4E-9F9D-C1B99D9F3E6A}"
EndProject 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 Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU 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}.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.ActiveCfg = Release|Any CPU
{95EA0D93-CFA6-4B4E-9F9D-C1B99D9F3E6A}.Release|Any CPU.Build.0 = 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 EndGlobalSection
EndGlobal EndGlobal