add support for userdev launch in ide
All checks were successful
Build / Compute Version (push) Successful in 8s
Build / Build Nuget package (CringeBootstrap.Abstractions) (push) Successful in 4m5s
Build / Build Nuget package (NuGet) (push) Successful in 4m8s
Build / Build Nuget package (SharedCringe) (push) Successful in 4m9s
Build / Build Nuget package (CringePlugins) (push) Successful in 4m30s
Build / Build Launcher (push) Successful in 5m22s

add template for user plugins
This commit is contained in:
zznty
2025-07-07 02:44:02 +07:00
parent 7c236355d4
commit f238b52f95
16 changed files with 782 additions and 35 deletions

View File

@@ -1,5 +1,6 @@
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Metadata;
using System.Runtime.Loader;
using CringeBootstrap;
using CringeBootstrap.Abstractions;
@@ -47,9 +48,20 @@ context.AddDependencyOverride("CringeLauncher");
context.AddDependencyOverride("CringePlugins");
context.AddDependencyOverride("EOSSDK");
var launcher = context.LoadFromAssemblyName(new AssemblyName("CringeLauncher"));
var entrypoint = Environment.GetEnvironmentVariable("DOTNET_BOOTSTRAP_ENTRYPOINT") ??
"CringeLauncher.Launcher, CringeLauncher";
if (!TypeName.TryParse(entrypoint, out var entrypointName) ||
entrypointName.AssemblyName is null)
{
Console.Error.WriteLine($"Invalid entrypoint name: {entrypoint}");
Console.Error.WriteLine("Bootstrap encountered a fatal error and will shutdown.");
Console.Read();
return;
}
using var corePlugin = (ICorePlugin) launcher.CreateInstance("CringeLauncher.Launcher")!;
var launcher = context.LoadFromAssemblyName(entrypointName.AssemblyName.ToAssemblyName());
using var corePlugin = (ICorePlugin) launcher.CreateInstance(entrypointName.FullName)!;
corePlugin.Initialize(args);
corePlugin.Run();

View File

@@ -0,0 +1,13 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"CringeBootstrap": {
"commandName": "Project",
"commandLineArgs": "\"C:\\Program Files (x86)\\Steam\\steamapps\\common\\SpaceEngineers\\Bin64\\SpaceEngineers.exe\"",
"environmentVariables": {
"DOTNET_BOOTSTRAP_ENTRYPOINT": "CringeLauncher.UserDev.UserDevLauncher, CringeLauncher",
"DOTNET_USERDEV_RUNDIR": "data"
}
}
}
}

View File

@@ -1,16 +1,18 @@
<Solution>
<Configurations>
<Platform Name="x64"/>
<BuildType Name="Debug"/>
<BuildType Name="Release"/>
</Configurations>
<Project Path="CringeBootstrap.Abstractions/CringeBootstrap.Abstractions.csproj"/>
<Project Path="CringeBootstrap/CringeBootstrap.csproj">
<BuildDependency Project="TestPlugin/TestPlugin.csproj"/>
</Project>
<Project Path="CringeLauncher/CringeLauncher.csproj"/>
<Project Path="CringePlugins/CringePlugins.csproj"/>
<Project Path="NuGet/NuGet.csproj"/>
<Project Path="SharedCringe/SharedCringe.csproj"/>
<Project Path="TestPlugin/TestPlugin.csproj"/>
</Solution>
<Configurations>
<BuildType Name="Debug" />
<BuildType Name="Release" />
<Platform Name="x64" />
</Configurations>
<Project Path="CringeBootstrap.Abstractions/CringeBootstrap.Abstractions.csproj" />
<Project Path="CringeBootstrap/CringeBootstrap.csproj">
<BuildDependency Project="TestPlugin/TestPlugin.csproj" />
</Project>
<Project Path="CringeLauncher/CringeLauncher.csproj" />
<Project Path="CringePlugins.MSBuild/CringePlugins.MSBuild.csproj" />
<Project Path="CringePlugins.Templates/CringePlugins.Templates.csproj" />
<Project Path="CringePlugins/CringePlugins.csproj" />
<Project Path="NuGet/NuGet.csproj" />
<Project Path="SharedCringe/SharedCringe.csproj" />
<Project Path="TestPlugin/TestPlugin.csproj" />
</Solution>

View File

@@ -45,15 +45,27 @@ namespace CringeLauncher;
public class Launcher : ICorePlugin
{
private const uint AppId = 244850U;
private readonly string? _gameDataDirectoryPathOverride;
protected const uint AppId = 244850U;
private SpaceEngineersGame? _game;
private readonly Harmony _harmony = new("CringeBootstrap");
private IPluginsLifetime? _lifetime;
private MyGameRenderComponent? _renderComponent;
private readonly DirectoryInfo _configDir = Directory.CreateDirectory(
Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "CringeLauncher", "config"));
private readonly DirectoryInfo _configDir;
private readonly DirectoryInfo _dir;
public Launcher() : this(null) { }
protected Launcher(string? gameDataDirectoryPathOverride)
{
_gameDataDirectoryPathOverride = gameDataDirectoryPathOverride;
_dir = Directory.CreateDirectory(Path.Join(
gameDataDirectoryPathOverride ?? Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"CringeLauncher"));
_configDir = _dir.CreateSubdirectory("config");
}
public void Initialize(string[] args)
{
@@ -107,7 +119,7 @@ public class Launcher : ICorePlugin
MyFinalBuildConstants.APP_VERSION = MyPerGameSettings.BasicGameInfo.GameVersion.GetValueOrDefault();
MyShaderCompiler.Init(MyShaderCompiler.TargetPlatform.PC, false);
MyVRageWindows.Init(MyPerGameSettings.BasicGameInfo.ApplicationName, MySandboxGame.Log,
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
Path.Join(_gameDataDirectoryPathOverride ?? Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
MyPerGameSettings.BasicGameInfo.ApplicationName),
false, false);
@@ -168,7 +180,8 @@ public class Launcher : ICorePlugin
var retryPolicy = HttpPolicyExtensions.HandleTransientHttpError()
.WaitAndRetryAsync(5, _ => TimeSpan.FromSeconds(1));
services.AddHttpClient<PluginsLifetime>()
services.AddHttpClient<PluginsLifetime, PluginsLifetime>((client, provider) =>
new PluginsLifetime(provider.GetRequiredService<ConfigHandler>(), client, _dir))
.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler
{
AutomaticDecompression = DecompressionMethods.All
@@ -225,7 +238,7 @@ public class Launcher : ICorePlugin
return MyVRage.Platform.Windows.Window;
}
private async Task<bool> CheckUpdatesDisabledAsync(Logger logger)
protected virtual async Task<bool> CheckUpdatesDisabledAsync(Logger logger)
{
var path = Path.Join(_configDir.FullName, "launcher.json");
@@ -319,7 +332,7 @@ public class Launcher : ICorePlugin
MyTexts.LoadTexts(textsPath, description.CultureName, description.SubcultureName);
}
public static void InitUgc()
protected virtual void InitUgc()
{
var steamGameService = MySteamGameService.Create(false, AppId);
MyServiceManager.Instance.AddService(steamGameService);

View File

@@ -0,0 +1,429 @@
using VRage.GameServices;
namespace CringeLauncher.UserDev.Networking;
public class UserDevGameService(uint appId) : IMyGameService
{
private readonly List<MyPackage> m_packageIds = [];
public uint AppId { get; } = appId;
public bool IsActive => true;
public bool IsOnline { get; }
public bool IsOverlayEnabled { get; }
public bool IsOverlayBrowserAvailable { get; }
public bool OwnsGame { get; }
public ulong UserId
{
get => 1234567891011;
set
{
}
}
public ulong OnlineUserId => UserId;
public char PlatformIcon => VRage.GameServices.PlatformIcon.PC;
public string UserName => "Dev";
public string OnlineName => UserName;
public bool CanQuickLaunch { get; }
public void QuickLaunch()
{
}
public MyGameServiceUniverse UserUniverse => MyGameServiceUniverse.Dev;
public string BranchName => "userdev";
public string BranchNameFriendly => "UserDev";
public event Action<bool>? OnOverlayActivated;
public event Action<uint>? OnDLCInstalled;
public event Action<bool>? OnUserChanged;
public event Action<bool>? OnSignInStateChanged;
public event Action<string>? OnActivityLaunch;
public event Action? OnUpdate;
public event Action<bool>? OnUpdateNetworkThread;
public event Action? OnLobbyStart;
public event Action? OnSessionUnload;
public void OpenOverlayUrl(string url, bool predetermined = true)
{
}
public void SetNotificationPosition(NotificationPosition notificationPosition)
{
}
public void ShutDown()
{
}
public bool IsAppInstalled(uint appId) => true;
public void OpenDlcInShop(uint dlcId)
{
}
public void OpenInventoryItemInShop(int itemId)
{
}
public bool IsDlcSupported(uint dlcId) => true;
public bool IsDlcInstalled(uint dlcId) => true;
public void AddDlcPackages(List<MyDlcPackage> packages)
{
m_packageIds.Clear();
foreach (var package in packages)
{
if (!string.IsNullOrEmpty(package.XboxPackageId) && !string.IsNullOrEmpty(package.XboxStoreId))
m_packageIds.Add(new MyPackage
{
DlcId = package.AppId,
PackageId = package.XboxPackageId,
StoreId = package.XboxStoreId
});
}
}
public int GetDLCCount() => m_packageIds.Count;
public bool GetDLCDataByIndex(
int index,
out uint dlcId,
out bool available,
out string name,
int nameBufferSize)
{
if (index >= m_packageIds.Count)
{
dlcId = 0U;
available = false;
name = string.Empty;
return false;
}
available = true;
dlcId = m_packageIds[index].DlcId;
name = "Dev" + index;
return true;
}
public void OpenOverlayUser(ulong id)
{
}
public bool GetAuthSessionTicket(out uint ticketHandle, byte[] buffer, out uint length)
{
ticketHandle = 0U;
length = 0U;
return false;
}
public void LoadStats()
{
}
public IMyAchievement? GetAchievement(string achievementName, string statName, float maxValue)
{
return null;
}
public IMyAchievement? GetAchievement(string achievementName) => null;
public void RegisterAchievement(string achievementName, string xblId)
{
}
public void ResetAllStats(bool achievementsToo)
{
}
public void StoreStats()
{
}
public string GetPersonaName(ulong userId) => string.Empty;
public bool HasFriend(ulong userId) => false;
public string GetClanName(ulong groupId) => string.Empty;
public void Update()
{
OnUpdate?.Invoke();
}
public void UpdateNetworkThread(bool sessionEnabled)
{
OnUpdateNetworkThread?.Invoke(sessionEnabled);
}
public bool IsUserInGroup(ulong groupId) => false;
public bool GetRemoteStorageQuota(out ulong totalBytes, out ulong availableBytes)
{
totalBytes = 0UL;
availableBytes = 0UL;
return false;
}
public int GetRemoteStorageFileCount() => 0;
public string GetRemoteStorageFileNameAndSize(int fileIndex, out int fileSizeInBytes)
{
fileSizeInBytes = 0;
return string.Empty;
}
public bool IsRemoteStorageFilePersisted(string file) => false;
public bool RemoteStorageFileForget(string file) => false;
public ulong CreatePublishedFileUpdateRequest(ulong publishedFileId) => 0;
public void UpdatePublishedFileTags(ulong updateHandle, string[] tags)
{
}
public void UpdatePublishedFileFile(ulong updateHandle, string steamItemFileName)
{
}
public void UpdatePublishedFilePreviewFile(ulong updateHandle, string steamPreviewFileName)
{
}
public void FileDelete(string steamItemFileName)
{
}
public bool FileExists(string fileName) => false;
public int GetFileSize(string fileName) => 0;
public ulong FileWriteStreamOpen(string fileName) => 0;
public void FileWriteStreamWriteChunk(ulong handle, byte[] buffer, int size)
{
}
public void FileWriteStreamClose(ulong handle)
{
}
public void CommitPublishedFileUpdate(
ulong updateHandle,
Action<bool, MyRemoteStorageUpdatePublishedFileResult> onCallResult)
{
}
public void PublishWorkshopFile(
string file,
string previewFile,
string title,
string description,
string longDescription,
MyPublishedFileVisibility visibility,
string[] tags,
Action<bool, MyRemoteStoragePublishFileResult> onCallResult)
{
}
public void SubscribePublishedFile(
ulong publishedFileId,
Action<bool, MyRemoteStorageSubscribePublishedFileResult> onCallResult)
{
}
public void FileShare(
string file,
Action<bool, MyRemoteStorageFileShareResult> onCallResult)
{
}
public string ServiceName => nameof (UserDevGameService);
public string ServiceDisplayName => "UserDev Game Service";
public bool OpenProfileForMute { get; }
public int GetFriendsCount() => 0;
public ulong GetFriendIdByIndex(int index) => 0;
public string GetFriendNameByIndex(int index) => string.Empty;
public void SaveToCloudAsync(
string storageName,
byte[] buffer,
Action<CloudResult>? completedAction)
{
completedAction?.Invoke(CloudResult.Failed);
}
public CloudResult SaveToCloud(string fileName, byte[] buffer) => CloudResult.Failed;
public CloudResult SaveToCloud(string containerName, List<MyCloudFile> fileNames)
{
return CloudResult.Failed;
}
public bool LoadFromCloudAsync(string fileName, Action<byte[]> completedAction) => false;
public List<MyCloudFileInfo>? GetCloudFiles(string directoryFilter)
{
return null;
}
public byte[]? LoadFromCloud(string fileName) => null;
public bool DeleteFromCloud(string fileName) => false;
public bool IsProductOwned(uint productId, out DateTime? purchaseTime)
{
purchaseTime = null;
return false;
}
public void RequestEncryptedAppTicket(string url, Action<bool, string> onDone)
{
}
public void RequestAuthToken(string clientId, Action<bool, string, int> onDone)
{
}
public void RequestPermissions(
Permissions permission,
bool attemptResolution,
Action<PermissionResult>? onDone)
{
onDone?.Invoke(permission == Permissions.UGC ? PermissionResult.Error : PermissionResult.Granted);
}
public void RequestPermissionsWithTargetUser(
Permissions permission,
ulong userId,
Action<PermissionResult>? onDone)
{
onDone?.Invoke(PermissionResult.Granted);
}
public void OnThreadpoolInitialized()
{
}
public bool GetInstallStatus(out int percentage)
{
percentage = 100;
return true;
}
public void Trace(bool enable)
{
}
public void SetPlayerMuted(ulong playerId, bool muted)
{
}
public ulong[]? GetBlockListRaw() => null;
HashSet<ulong>? IMyGameService.GetBlockList() => null;
public ulong[]? GetBlockList() => null;
public bool IsPlayerMuted(ulong playerId) => false;
public void UpdateMutedPlayers(Action onDone) => onDone.InvokeIfNotNull();
public MyGameServiceAccountType GetServerAccountType(ulong steamId)
{
return MyGameServiceAccountType.Invalid;
}
public void DeleteUnnecessaryFilesFromTempFolder()
{
}
public void OnSessionLoaded(string campaignName, string currentMissionName)
{
}
public void OnSessionReady(bool multiplayer, bool dedicated)
{
}
public void OnLoadingScreenCompleted()
{
}
public void OnGameSaved(bool success, string savePath)
{
}
public void OnCampaignFinishing()
{
}
public void LobbyStarts() => OnLobbyStart.InvokeIfNotNull();
public void OnMissionFinished(string missionName)
{
}
public void OnSessionUnloaded() => OnSessionUnload.InvokeIfNotNull();
public void OnSessionUnloading()
{
}
public bool ActivityInProgress { get; }
public LoadActivityResult GetActivityLoadInformation(string activityId)
{
return new LoadActivityResult();
}
public void OnPlayersChanged(int playersCount)
{
}
public ulong GetModsCacheFreeSpace() => ulong.MaxValue;
public void FormatModsCache()
{
}
public void PrintStats()
{
}
public bool IsPlayerBlocked(ulong playerId) => false;
private struct MyPackage
{
public uint DlcId;
public string PackageId;
public string StoreId;
}
}

View File

@@ -0,0 +1,23 @@
using CringeLauncher.UserDev.Networking;
using NLog;
using VRage;
using VRage.GameServices;
namespace CringeLauncher.UserDev;
public class UserDevLauncher() : Launcher(Environment.GetEnvironmentVariable("DOTNET_USERDEV_RUNDIR"))
{
protected override void InitUgc()
{
var gameService = new UserDevGameService(AppId);
MyServiceManager.Instance.AddService<IMyGameService>(gameService);
MyServiceManager.Instance.AddService<IMyNetworking>(new MyNullNetworking(gameService));
MyServiceManager.Instance.AddService<IMyLobbyDiscovery>(new MyNullLobbyDiscovery());
MyServiceManager.Instance.AddService<IMyServerDiscovery>(new MyNullServerDiscovery());
}
protected override Task<bool> CheckUpdatesDisabledAsync(Logger logger)
{
return Task.FromResult(true);
}
}

View File

@@ -0,0 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<!-- This property tells MSBuild where the root folder of the package's build assets should be. Because we are not a library package, we should not pack to 'lib'. Instead, we choose 'tasks' by convention. -->
<BuildOutputTargetFolder>tasks</BuildOutputTargetFolder>
<!-- NuGet does validation that libraries in a package are exposed as dependencies, but we _explicitly_ do not want that behavior for MSBuild tasks. They are isolated by design. Therefore we ignore this specific warning. -->
<NoWarn>NU5100</NoWarn>
<DebugType>embedded</DebugType>
<IsPackable>true</IsPackable>
<Version>1.0.0</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.0.0" PrivateAssets="all" />
<PackageReference Include="PolySharp" Version="1.15.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Content Include="build\CringePlugins.MSBuild.targets">
<PackagePath>build\</PackagePath>
</Content>
<Content Include="build\CringePlugins.MSBuild.props">
<PackagePath>build\</PackagePath>
</Content>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,86 @@
using System;
using System.IO;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Microsoft.Win32;
namespace CringePlugins.MSBuild;
public class GenerateRunConfig : Task
{
[Required] public required string RunConfigPath { get; set; }
[Required] public required string ProjectName { get; set; }
private const string RunConfigTemplate = """
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"$projectName$ Dev Client": {
"commandName": "Executable",
"executablePath": "BootstrapExecutablePathPlaceholder",
"commandLineArgs": "\"GameExecutablePathPlaceholder\"",
"environmentVariables": {
"DOTNET_BOOTSTRAP_ENTRYPOINT": "CringeLauncher.UserDev.UserDevLauncher, CringeLauncher",
"DOTNET_USERDEV_RUNDIR": "data",
"DOTNET_USERDEV_PLUGINDIR": "."
}
}
}
}
""";
public override bool Execute()
{
if (Environment.OSVersion.Platform != PlatformID.Win32NT)
{
Log.LogError("Only windows is supported");
return false;
}
// branch off so jit wont notice in case Win32 package is missing from sdk distribution on non-windows platforms
// too lazy to test if it actually is missing
return ExecuteInternal();
}
private bool ExecuteInternal()
{
string? GetInstallLocation(RegistryKey baseKey, string subKey)
{
using var key = baseKey.OpenSubKey(subKey);
return key?.GetValue("InstallLocation") as string;
}
var gamePath = GetInstallLocation(Registry.LocalMachine,
@"Software\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 244850");
var bootstrapPath = GetInstallLocation(Registry.CurrentUser,
@"Software\Microsoft\Windows\CurrentVersion\Uninstall\CringeLauncher");
if (string.IsNullOrEmpty(gamePath))
{
Log.LogError("Failed to find Space Engineers install location");
return false;
}
if (string.IsNullOrEmpty(bootstrapPath))
{
Log.LogError("Failed to find CringeLauncher install location");
return false;
}
gamePath = Path.Combine(gamePath, @"Bin64\SpaceEngineers.exe").Replace(@"\", @"\\");
bootstrapPath = Path.Combine(bootstrapPath, @"current\CringeBootstrap.exe").Replace(@"\", @"\\");
var runConfigText = RunConfigTemplate
.Replace("BootstrapExecutablePathPlaceholder", bootstrapPath)
.Replace("GameExecutablePathPlaceholder", gamePath)
.Replace("$projectName$", ProjectName);
var runConfigDir = Path.GetDirectoryName(RunConfigPath);
if (runConfigDir is not null && !Directory.Exists(runConfigDir))
Directory.CreateDirectory(runConfigDir);
File.WriteAllText(RunConfigPath, runConfigText);
return true;
}
}

View File

@@ -0,0 +1,14 @@
<Project>
<PropertyGroup>
<!--The folder where the custom task will be present. It points to inside the NuGet package. -->
<CustomTasksFolder>$(MSBuildThisFileDirectory)..\tasks\netstandard2.0</CustomTasksFolder>
<!--Reference to the assembly which contains the MSBuild Task-->
<CustomTasksAssembly>$(CustomTasksFolder)\$(MSBuildThisFileName).dll</CustomTasksAssembly>
</PropertyGroup>
<UsingTask TaskName="$(MSBuildThisFileName).GenerateRunConfig" AssemblyFile="$(CustomTasksAssembly)" />
<PropertyGroup>
<RunConfigPath Condition="'$(RunConfigPath)' == ''">$(ProjectDir)Properties\launchSettings.json</RunConfigPath>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,9 @@
<Project>
<Target Name="_GenerateRunConfig" AfterTargets="CollectPackageReferences" Condition=" '$([System.OperatingSystem]::IsWindows())' == 'True' ">
<GenerateRunConfig RunConfigPath="$(RunConfigPath)" ProjectName="$(MSBuildProjectName)" />
</Target>
<Target Name="AfterClean">
<Delete Files="$(RunConfigPath)" ContinueOnError="true" />
</Target>
</Project>

View File

@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<IncludeBuildOutput>False</IncludeBuildOutput>
<IncludeSource>False</IncludeSource>
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
<OutputPath>$(ArtifactsTmpDir)</OutputPath>
<EnableDefaultItems>False</EnableDefaultItems>
<IsPackable>true</IsPackable>
<IsShipping>true</IsShipping>
<IsShippingPackage>true</IsShippingPackage>
<NoWarn>2008;NU5105</NoWarn>
<NoPackageAnalysis>true</NoPackageAnalysis>
<PackageType>Template</PackageType>
<SuppressDependenciesWhenPacking>True</SuppressDependenciesWhenPacking>
<Version>1.0.0</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Remove="Microsoft.NETCore.App" />
<Content Include="content\**">
<PackagePath>content</PackagePath>
</Content>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<UseWindowsForms>true</UseWindowsForms>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<RestoreAdditionalProjectSources>https://ng.zznty.ru/v3/index.json</RestoreAdditionalProjectSources>
<EnableDynamicLoading>true</EnableDynamicLoading>
<PackageType>CringePlugin</PackageType>
<Authors>CringeLauncher</Authors>
<PackageId>Plugin.$projectName$</PackageId>
<AssemblyName>Plugin.$projectName$</AssemblyName>
<Title>TitlePlaceholder</Title>
<Description>DescriptionPlaceholder</Description>
<LangVersion>preview</LangVersion>
<PackageIcon>icon.png</PackageIcon>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CringePlugins" Version="*" ExcludeAssets="runtime; native" />
<PackageReference Include="CringePlugins.MSBuild" Version="*" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<None Include="icon.png" Pack="true" PackagePath="" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,29 @@
{
"$schema": "http://json.schemastore.org/template",
"author": "zznty",
"classifications": [ "CringeLauncher", "SpaceEngineers", "Plugin" ],
"identity": "CringePlugins.PluginTemplate.Plugin",
"name": "SpaceEngineers Plugin Template",
"shortName": "cringeplugin",
"tags": {
"language": "C#",
"type": "project"
},
"defaultName": "Plugin",
"sourceName": "$projectName$",
"postActions": [],
"symbols": {
"title": {
"type": "parameter",
"defaultValue": "Test Plugin",
"description": "The title of the plugin",
"replaces": "TitlePlaceholder"
},
"description": {
"type": "parameter",
"defaultValue": "This is a test plugin",
"description": "The description of the plugin",
"replaces": "DescriptionPlaceholder"
}
}
}

View File

@@ -0,0 +1,18 @@
using VRage.Plugins;
namespace $projectName$;
public class Plugin : IPlugin
{
public void Init(object gameInstance)
{
}
public void Update()
{
}
public void Dispose()
{
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 KiB

View File

@@ -15,7 +15,7 @@ using VRage.FileSystem;
namespace CringePlugins.Loader;
internal class PluginsLifetime(ConfigHandler configHandler, HttpClient client) : IPluginsLifetime
internal class PluginsLifetime(ConfigHandler configHandler, HttpClient client, DirectoryInfo dir) : IPluginsLifetime
{
public static ImmutableArray<DerivedAssemblyLoadContext> Contexts { get; private set; } = [];
private static readonly Lock ContextsLock = new();
@@ -25,8 +25,9 @@ internal class PluginsLifetime(ConfigHandler configHandler, HttpClient client) :
public string Name => "Loading Plugins";
private ImmutableArray<PluginInstance> _plugins = [];
private readonly DirectoryInfo _dir = Directory.CreateDirectory(Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "CringeLauncher"));
private readonly NuGetRuntimeFramework _runtimeFramework = new(NuGetFramework.ParseFolder("net9.0-windows10.0.19041.0"), RuntimeInformation.RuntimeIdentifier);
private readonly NuGetRuntimeFramework _runtimeFramework =
new(NuGetFramework.ParseFolder("net9.0-windows10.0.19041.0"), RuntimeInformation.RuntimeIdentifier);
private ConfigReference<PackagesConfig>? _configReference;
private ConfigReference<LauncherConfig>? _launcherConfig;
@@ -41,7 +42,7 @@ internal class PluginsLifetime(ConfigHandler configHandler, HttpClient client) :
await Task.Delay(10000);
#endif
DiscoverLocalPlugins(_dir.CreateSubdirectory("plugins"));
DiscoverLocalPlugins(dir.CreateSubdirectory("plugins"));
progress.Report("Loading config");
@@ -56,7 +57,7 @@ internal class PluginsLifetime(ConfigHandler configHandler, HttpClient client) :
// TODO take into account the target framework runtime identifier
var resolver = new PackageResolver(_runtimeFramework.Framework, packagesConfig.Packages, sourceMapping);
var cacheDir = _dir.CreateSubdirectory("cache");
var cacheDir = dir.CreateSubdirectory("cache");
var invalidPackages = new List<PackageReference>();
var packages = await resolver.ResolveAsync(cacheDir, launcherConfig.DisablePluginUpdates, invalidPackages);
@@ -78,7 +79,8 @@ internal class PluginsLifetime(ConfigHandler configHandler, HttpClient client) :
progress.Report("Downloading packages");
var builtInPackages = await BuiltInPackages.GetPackagesAsync(_runtimeFramework);
var cachedPackages = await PackageResolver.DownloadPackagesAsync(cacheDir, packages, builtInPackages.Keys.ToHashSet(), progress);
var cachedPackages =
await PackageResolver.DownloadPackagesAsync(cacheDir, packages, builtInPackages.Keys.ToHashSet(), progress);
progress.Report("Loading plugins");
@@ -87,7 +89,8 @@ internal class PluginsLifetime(ConfigHandler configHandler, HttpClient client) :
await LoadPlugins(cachedPackages, sourceMapping, packagesConfig, builtInPackages);
RenderHandler.Current.RegisterComponent(new PluginListComponent(_configReference, _launcherConfig, sourceMapping, MyFileSystem.ExePath, _plugins));
RenderHandler.Current.RegisterComponent(new PluginListComponent(_configReference, _launcherConfig,
sourceMapping, MyFileSystem.ExePath, _plugins));
}
public static async Task ReloadPlugin(PluginInstance instance)
@@ -96,7 +99,7 @@ internal class PluginsLifetime(ConfigHandler configHandler, HttpClient client) :
{
var (oldContext, newContext) = await instance.ReloadAsync();
lock(ContextsLock)
lock (ContextsLock)
{
Contexts = Contexts.Remove(oldContext).Add(newContext);
}
@@ -122,6 +125,7 @@ internal class PluginsLifetime(ConfigHandler configHandler, HttpClient client) :
Log.Error(e, "Failed to instantiate plugin {Plugin}", instance.Metadata);
}
}
Contexts = contextBuilder.ToImmutable();
}
@@ -136,7 +140,7 @@ internal class PluginsLifetime(ConfigHandler configHandler, HttpClient client) :
resolvedPackages.TryAdd(package.Package.Id, package);
}
var manifestBuilder = new DependencyManifestBuilder(_dir.CreateSubdirectory("cache"), sourceMapping,
var manifestBuilder = new DependencyManifestBuilder(dir.CreateSubdirectory("cache"), sourceMapping,
dependency =>
{
resolvedPackages.TryGetValue(dependency.Id, out var package);
@@ -187,7 +191,9 @@ internal class PluginsLifetime(ConfigHandler configHandler, HttpClient client) :
{
var plugins = ImmutableArray<PluginInstance>.Empty.ToBuilder();
foreach (var directory in dir.EnumerateDirectories())
foreach (var directory in Environment.GetEnvironmentVariable("DOTNET_USERDEV_PLUGINDIR") is { } userDevPlugin
? [new(userDevPlugin), ..dir.GetDirectories()]
: dir.EnumerateDirectories())
{
var files = directory.GetFiles("*.deps.json");
@@ -201,7 +207,8 @@ internal class PluginsLifetime(ConfigHandler configHandler, HttpClient client) :
_plugins = plugins.ToImmutable();
}
private static void LoadComponent(ImmutableArray<PluginInstance>.Builder plugins, string path, PluginMetadata? metadata = null, bool local = false)
private static void LoadComponent(ImmutableArray<PluginInstance>.Builder plugins, string path,
PluginMetadata? metadata = null, bool local = false)
{
try
{