add luckperms plugin

This commit is contained in:
zznty
2023-11-09 16:53:02 +07:00
parent b05113f971
commit ec5e20b922
98 changed files with 3230 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<LangVersion>12</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugSymbols>false</DebugSymbols>
<DebugType>none</DebugType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Krafs.Publicizer" Version="2.2.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="PolySharp" Version="1.13.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="torch.server.referenceassemblies" Version="1.3.1.260-master" PrivateAssets="all" IncludeAssets="compile" />
</ItemGroup>
<ItemGroup>
<Publicize Include="Torch:Torch.TorchBase.RegisterAuxAssembly" />
<Publicize Include="Torch:Torch.Managers.PluginManager._plugins" />
<Publicize Include="Torch:Torch.TorchPluginBase.Manifest" />
<Publicize Include="Torch:Torch.TorchPluginBase.StoragePath" />
</ItemGroup>
<ItemGroup>
<Content Include="manifest.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Always</CopyToPublishDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LuckPerms.Torch\LuckPerms.Torch.csproj" ReferenceOutputAssembly="false" Private="false" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.IO.Compression" />
</ItemGroup>
<Target Name="BuildArchive" BeforeTargets="PreBuildEvent">
<PropertyGroup>
<PluginDir>..\LuckPerms.Torch\bin\$(Configuration)\$(TargetFramework)\win-x64\</PluginDir>
<PluginZipPath>$(BaseIntermediateOutputPath)$(Configuration)\$(TargetFramework)\plugin.zip</PluginZipPath>
</PropertyGroup>
<ZipDirectory DestinationFile="$(PluginZipPath)" SourceDirectory="$(PluginDir)" Overwrite="true" />
<ItemGroup>
<EmbeddedResource Include="$(PluginZipPath)" LogicalName="plugin.zip" />
</ItemGroup>
</Target>
</Project>

View File

@@ -0,0 +1,72 @@
using System.IO.Compression;
using System.Reflection;
using System.Runtime.CompilerServices;
using NLog;
using Torch;
using Torch.API;
using Torch.API.Managers;
using Torch.API.Plugins;
using Torch.Managers;
namespace LuckPerms.Loader;
public class Plugin : TorchPluginBase
{
private static readonly ITorchPlugin MainPluginInstance;
private static readonly ILogger Log = LogManager.GetLogger("LuckPerms.Loader");
static Plugin()
{
#pragma warning disable CS0618 // Type or member is obsolete
var torch = (ITorchServer)TorchBase.Instance;
#pragma warning restore CS0618 // Type or member is obsolete
var dir = new DirectoryInfo(Path.Combine(torch.InstancePath, "cache", "luckperms.loader"));
if (dir.Exists)
dir.Delete(true);
Log.Info($"Extracting cache to {dir}");
using (var pluginStream = typeof(Plugin).Assembly.GetManifestResourceStream("plugin.zip")!)
using (var archive = new ZipArchive(pluginStream, ZipArchiveMode.Read))
archive.ExtractToDirectory(dir.FullName);
Log.Info("Injecting LuckPerms");
AppDomain.CurrentDomain.AssemblyResolve += (_, args) =>
{
var fileName = args.Name[..args.Name.IndexOf(',')];
var path = Path.Combine(dir.FullName, fileName + ".dll");
return File.Exists(path) ? Assembly.LoadFile(path) : null;
};
var mainAssembly = Assembly.LoadFile(Path.Combine(dir.FullName, "LuckPerms.Torch.dll"));
var pluginType = mainAssembly.GetType("LuckPerms.Torch.Plugin", true)!;
// a hacky way to configure JVM
RuntimeHelpers.RunClassConstructor(pluginType.TypeHandle);
TorchBase.RegisterAuxAssembly(mainAssembly);
MainPluginInstance = (ITorchPlugin)Activator.CreateInstance(pluginType)!;
if (MainPluginInstance is not TorchPluginBase pluginBase) return;
pluginBase.Manifest = PluginManifest.Load(Path.Combine(dir.FullName, "manifest.xml"));
pluginBase.StoragePath = torch.InstancePath;
}
public override void Init(ITorchBase torch)
{
var pluginManager = torch.Managers.GetManager<PluginManager>();
pluginManager._plugins.Remove(Manifest.Guid);
pluginManager._plugins.Add(Manifest.Guid, MainPluginInstance);
MainPluginInstance.Init(torch);
Log.Info("Injected successfully");
}
}

View File

@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<PluginManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Name>LuckPerms.Loader</Name>
<Guid>7E4B3CC8-64FA-416E-8910-AACDF2DA5E2C</Guid>
<Version>v5.4.106</Version>
</PluginManifest>

View File

@@ -0,0 +1,67 @@
{
"version": 1,
"dependencies": {
".NETFramework,Version=v4.8": {
"Krafs.Publicizer": {
"type": "Direct",
"requested": "[2.2.1, )",
"resolved": "2.2.1",
"contentHash": "QGI4nMGQbKsuFUUboixVHu4mv3lHB5RejIa7toIlzTmwLkuCYYEpUBJjmy3OpXYyj5dVSZAXVbr4oeMSloE67Q=="
},
"Microsoft.NETFramework.ReferenceAssemblies": {
"type": "Direct",
"requested": "[1.0.3, )",
"resolved": "1.0.3",
"contentHash": "vUc9Npcs14QsyOD01tnv/m8sQUnGTGOw1BCmKcv77LBJY7OxhJ+zJF7UD/sCL3lYNFuqmQEVlkfS4Quif6FyYg==",
"dependencies": {
"Microsoft.NETFramework.ReferenceAssemblies.net48": "1.0.3"
}
},
"PolySharp": {
"type": "Direct",
"requested": "[1.13.2, )",
"resolved": "1.13.2",
"contentHash": "XwNhfkr7IeUiH8AE4pzob8YioxfL6nxgAx+fHEeWCObY/NZuBMfWLh39FznXbneKvagiqeeI7quIvZ6P1eVaEA=="
},
"Torch.Server.ReferenceAssemblies": {
"type": "Direct",
"requested": "[1.3.1.260-master, )",
"resolved": "1.3.1.260-master",
"contentHash": "p9fHBwPI2BZDLO2PiSPvJxHQ7lksYf/20BZ0uUxMlSnJk/AvFUpjT6CMxJWow4UuAFG+NcPEI4VhxZ5x9jhGGA==",
"dependencies": {
"NLog": "4.4.12",
"Newtonsoft.Json": "12.0.2",
"SpaceEngineersDedicated.ReferenceAssemblies": "1.203.505"
}
},
"Microsoft.NETFramework.ReferenceAssemblies.net48": {
"type": "Transitive",
"resolved": "1.0.3",
"contentHash": "zMk4D+9zyiEWByyQ7oPImPN/Jhpj166Ky0Nlla4eXlNL8hI/BtSJsgR8Inldd4NNpIAH3oh8yym0W2DrhXdSLQ=="
},
"Newtonsoft.Json": {
"type": "Transitive",
"resolved": "12.0.2",
"contentHash": "rTK0s2EKlfHsQsH6Yx2smvcTCeyoDNgCW7FEYyV01drPlh2T243PR2DiDXqtC5N4GDm4Ma/lkxfW5a/4793vbA=="
},
"NLog": {
"type": "Transitive",
"resolved": "4.4.12",
"contentHash": "fODew3BFT2XhAuqhGo2ZYT9OJE0ciGEBfvKXOmAAvaDsP/3ROIf083p8QUnmwKKw4jCkVW06ObX6gn/eFi2Skg=="
},
"protobuf-net": {
"type": "Transitive",
"resolved": "1.0.0",
"contentHash": "kTGOK0E87473sOImOjgZOnz3kTC2aMLffoRWQLYNuBLJnwNNmjanF9IkevZ9Q7yYLeABQfcF3BpeepuMntMVNw=="
},
"SpaceEngineersDedicated.ReferenceAssemblies": {
"type": "Transitive",
"resolved": "1.203.505",
"contentHash": "Wq4GIn2ilHyFdLdVKdVhC7iGQ+1FdVsChKY6hyQluFYSSV7oe8bDc9aTZC8XgxNMKCZoQBSVyaYHxQD+74BySQ==",
"dependencies": {
"protobuf-net": "1.0.0"
}
}
}
}
}