first
This commit is contained in:
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
bin/
|
||||||
|
obj/
|
||||||
|
/packages/
|
||||||
|
riderModule.iml
|
||||||
|
/_ReSharper.Caches/
|
16
CringeLauncher.sln
Normal file
16
CringeLauncher.sln
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CringeLauncher", "CringeLauncher\CringeLauncher.csproj", "{219C897E-452D-49B5-80C4-F3008718C16A}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{219C897E-452D-49B5-80C4-F3008718C16A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{219C897E-452D-49B5-80C4-F3008718C16A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{219C897E-452D-49B5-80C4-F3008718C16A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{219C897E-452D-49B5-80C4-F3008718C16A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
25
CringeLauncher/CringeLauncher.csproj
Normal file
25
CringeLauncher/CringeLauncher.csproj
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net6.0-windows</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Lib.Harmony" Version="2.2.2" />
|
||||||
|
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.9.0" IncludeAssets="compile" PrivateAssets="all" />
|
||||||
|
<PackageReference Include="NLog" Version="5.0.5" />
|
||||||
|
<PackageReference Include="SpaceEngineersDedicated.ReferenceAssemblies" Version="1.201.13" IncludeAssets="compile" PrivateAssets="all" />
|
||||||
|
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="6.0.1" />
|
||||||
|
<PackageReference Include="System.Management" Version="6.0.0" />
|
||||||
|
<PackageReference Include="System.Private.ServiceModel" Version="4.10.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<Target Name="Unfuckit" AfterTargets="Build">
|
||||||
|
<Delete Files="$(OutputPath)$(AssemblyName).deps.json" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
</Project>
|
131
CringeLauncher/Launcher.cs
Normal file
131
CringeLauncher/Launcher.cs
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
using HarmonyLib;
|
||||||
|
using Sandbox;
|
||||||
|
using Sandbox.Engine.Multiplayer;
|
||||||
|
using Sandbox.Engine.Networking;
|
||||||
|
using Sandbox.Engine.Platform.VideoMode;
|
||||||
|
using Sandbox.Engine.Utils;
|
||||||
|
using Sandbox.Game;
|
||||||
|
using Sandbox.Game.Localization;
|
||||||
|
using SpaceEngineers.Game;
|
||||||
|
using SpaceEngineers.Game.Achievements;
|
||||||
|
using SpaceEngineers.Game.GUI;
|
||||||
|
using VRage;
|
||||||
|
using VRage.EOS;
|
||||||
|
using VRage.FileSystem;
|
||||||
|
using VRage.Game;
|
||||||
|
using VRage.GameServices;
|
||||||
|
using VRage.Mod.Io;
|
||||||
|
using VRage.Platform.Windows;
|
||||||
|
using VRage.Steam;
|
||||||
|
using VRage.UserInterface;
|
||||||
|
using VRageRender;
|
||||||
|
|
||||||
|
namespace CringeLauncher;
|
||||||
|
|
||||||
|
public class Launcher : IDisposable
|
||||||
|
{
|
||||||
|
private const uint AppId = 244850U;
|
||||||
|
private SpaceEngineersGame? _game;
|
||||||
|
private readonly Harmony _harmony = new("CringeLauncher");
|
||||||
|
|
||||||
|
public void Initialize(string[] args)
|
||||||
|
{
|
||||||
|
_harmony.PatchAll(typeof(Launcher).Assembly);
|
||||||
|
InitTexts();
|
||||||
|
SpaceEngineersGame.SetupBasicGameInfo();
|
||||||
|
MyFinalBuildConstants.APP_VERSION = MyPerGameSettings.BasicGameInfo.GameVersion.GetValueOrDefault();
|
||||||
|
MyVRageWindows.Init(MyPerGameSettings.BasicGameInfo.ApplicationName, MySandboxGame.Log,
|
||||||
|
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||||
|
MyPerGameSettings.BasicGameInfo.ApplicationName),
|
||||||
|
false, false);
|
||||||
|
MyInitializer.InvokeBeforeRun(AppId, MyPerGameSettings.BasicGameInfo.ApplicationName,
|
||||||
|
MyVRage.Platform.System.GetAppDataPath(), true, 3, () =>
|
||||||
|
{
|
||||||
|
MyFakes.VOICE_CHAT_MIC_SENSITIVITY = MySandboxGame.Config.MicSensitivity;
|
||||||
|
MyPlatformGameSettings.VOICE_CHAT_AUTOMATIC_ACTIVATION = MySandboxGame.Config.AutomaticVoiceChatActivation;
|
||||||
|
});
|
||||||
|
MyVRage.Platform.Init();
|
||||||
|
InitUgc();
|
||||||
|
SpaceEngineersGame.SetupPerGameSettings();
|
||||||
|
MySandboxGame.InitMultithreading();
|
||||||
|
MyVRage.Platform.System.OnThreadpoolInitialized();
|
||||||
|
InitRender();
|
||||||
|
MyFileSystem.InitUserSpecific(MyGameService.UserId.ToString());
|
||||||
|
_game = new(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Run() => _game?.Run();
|
||||||
|
|
||||||
|
#region Keen shit
|
||||||
|
|
||||||
|
private static void InitTexts()
|
||||||
|
{
|
||||||
|
MyLanguage.ObtainCurrentOSCulture();
|
||||||
|
var textsPath = Path.Combine(MyFileSystem.RootPath, "Content\\Data\\Localization\\CoreTexts");
|
||||||
|
var hashSet = new HashSet<MyLanguagesEnum>();
|
||||||
|
MyTexts.LoadSupportedLanguages(textsPath, hashSet);
|
||||||
|
|
||||||
|
if (!MyTexts.Languages.TryGetValue(MyLanguage.GetOsLanguageCurrentOfficial(), out var description) &&
|
||||||
|
!MyTexts.Languages.TryGetValue(MyLanguagesEnum.English, out description))
|
||||||
|
return;
|
||||||
|
|
||||||
|
MyTexts.LoadTexts(textsPath, description.CultureName, description.SubcultureName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void InitUgc()
|
||||||
|
{
|
||||||
|
var steamGameService = MySteamGameService.Create(false, AppId);
|
||||||
|
MyServiceManager.Instance.AddService(steamGameService);
|
||||||
|
|
||||||
|
var aggregator = new MyServerDiscoveryAggregator();
|
||||||
|
MySteamGameService.InitNetworking(false, steamGameService, MyPerGameSettings.GameName, aggregator);
|
||||||
|
MyEOSService.InitNetworking(false, MyPerGameSettings.GameName, steamGameService, "xyza7891964JhtVD93nm3nZp8t1MbnhC",
|
||||||
|
"AKGM16qoFtct0IIIA8RCqEIYG4d4gXPPDNpzGuvlhLA", "24b1cd652a18461fa9b3d533ac8d6b5b",
|
||||||
|
"1958fe26c66d4151a327ec162e4d49c8", "07c169b3b641401496d352cad1c905d6",
|
||||||
|
"https://retail.epicgames.com/", MyEOSService.CreatePlatform(),
|
||||||
|
MyPlatformGameSettings.VERBOSE_NETWORK_LOGGING, ArraySegment<string>.Empty, aggregator,
|
||||||
|
MyMultiplayer.Channels);
|
||||||
|
|
||||||
|
MyServiceManager.Instance.AddService<IMyServerDiscovery>(aggregator);
|
||||||
|
|
||||||
|
MyServiceManager.Instance.AddService(MySteamGameService.CreateMicrophone());
|
||||||
|
|
||||||
|
MyGameService.WorkshopService.AddAggregate(MySteamUgcService.Create(AppId, steamGameService));
|
||||||
|
|
||||||
|
var modUgc = MyModIoService.Create(MyServiceManager.Instance.GetService<IMyGameService>(), "spaceengineers", "264",
|
||||||
|
"1fb4489996a5e8ffc6ec1135f9985b5b", "331", "f2b64abe55452252b030c48adc0c1f0e",
|
||||||
|
MyPlatformGameSettings.UGC_TEST_ENVIRONMENT, false);
|
||||||
|
modUgc.IsConsentGiven = MySandboxGame.Config.ModIoConsent;
|
||||||
|
MyGameService.WorkshopService.AddAggregate(modUgc);
|
||||||
|
|
||||||
|
MySpaceEngineersAchievements.Initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void InitRender()
|
||||||
|
{
|
||||||
|
var renderQualityHint = MyVRage.Platform.Render.GetRenderQualityHint();
|
||||||
|
var preset = MyGuiScreenOptionsGraphics.GetPreset(renderQualityHint);
|
||||||
|
|
||||||
|
MyRenderProxy.Settings.User = MyVideoSettingsManager
|
||||||
|
.GetGraphicsSettingsFromConfig(ref preset, renderQualityHint > MyRenderPresetEnum.CUSTOM)
|
||||||
|
.PerformanceSettings.RenderSettings;
|
||||||
|
MyRenderProxy.Settings.EnableAnsel = MyPlatformGameSettings.ENABLE_ANSEL;
|
||||||
|
MyRenderProxy.Settings.EnableAnselWithSprites = MyPlatformGameSettings.ENABLE_ANSEL_WITH_SPRITES;
|
||||||
|
|
||||||
|
var graphicsRenderer = MySandboxGame.Config.GraphicsRenderer;
|
||||||
|
MySandboxGame.Config.GraphicsRenderer = graphicsRenderer;
|
||||||
|
|
||||||
|
_ = new MyEngine();
|
||||||
|
MyRenderProxy.Initialize(new MyDX11Render(MyRenderProxy.Settings));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_game?.Dispose();
|
||||||
|
MyGameService.ShutDown();
|
||||||
|
MyInitializer.InvokeAfterRun();
|
||||||
|
MyVRage.Done();
|
||||||
|
}
|
||||||
|
}
|
30
CringeLauncher/Patches/ScriptCompilerInitializationPatch.cs
Normal file
30
CringeLauncher/Patches/ScriptCompilerInitializationPatch.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
using System.Collections.Concurrent;
|
||||||
|
using System.Collections.Immutable;
|
||||||
|
using System.Reflection;
|
||||||
|
using HarmonyLib;
|
||||||
|
using VRage.Scripting;
|
||||||
|
|
||||||
|
namespace CringeLauncher.Patches;
|
||||||
|
|
||||||
|
[HarmonyPatch]
|
||||||
|
public static class ScriptCompilerInitializationPatch
|
||||||
|
{
|
||||||
|
private static MethodInfo TargetMethod()
|
||||||
|
{
|
||||||
|
return AccessTools.Method(Type.GetType("VRage.Scripting.MyVRageScriptingInternal, VRage.Scripting", true),
|
||||||
|
"Initialize");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool Prefix(Thread updateThread, Type[] referencedTypes, string[] symbols)
|
||||||
|
{
|
||||||
|
MyModWatchdog.Init(updateThread);
|
||||||
|
MyScriptCompiler.Static.AddImplicitIngameNamespacesFromTypes(referencedTypes);
|
||||||
|
MyScriptCompiler.Static.AddConditionalCompilationSymbols(symbols);
|
||||||
|
|
||||||
|
using var batch = MyScriptCompiler.Static.Whitelist.OpenBatch();
|
||||||
|
batch.AllowTypes(MyWhitelistTarget.ModApi, typeof(ConcurrentQueue<>));
|
||||||
|
batch.AllowNamespaceOfTypes(MyWhitelistTarget.Both, typeof(ImmutableArray));
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
20
CringeLauncher/Patches/WhitelistAllowPatch.cs
Normal file
20
CringeLauncher/Patches/WhitelistAllowPatch.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using HarmonyLib;
|
||||||
|
using VRage.Scripting;
|
||||||
|
|
||||||
|
namespace CringeLauncher.Patches;
|
||||||
|
|
||||||
|
[HarmonyPatch]
|
||||||
|
public static class WhitelistAllowPatch
|
||||||
|
{
|
||||||
|
private static MethodInfo TargetMethod()
|
||||||
|
{
|
||||||
|
return AccessTools.Method(AccessTools.Inner(typeof(MyScriptWhitelist), "MyWhitelistBatch"), "AllowMembers");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Prefix(ref MemberInfo[] members)
|
||||||
|
{
|
||||||
|
if (members.Any(b => b is null))
|
||||||
|
members = members.Where(b => b is { }).ToArray();
|
||||||
|
}
|
||||||
|
}
|
45
CringeLauncher/Patches/WhitelistPatch.cs
Normal file
45
CringeLauncher/Patches/WhitelistPatch.cs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
using System.Collections.Concurrent;
|
||||||
|
using System.Collections.Immutable;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using HarmonyLib;
|
||||||
|
using VRage.FileSystem;
|
||||||
|
using VRage.Scripting;
|
||||||
|
|
||||||
|
namespace CringeLauncher.Patches;
|
||||||
|
|
||||||
|
[HarmonyPatch(typeof(MyScriptWhitelist), MethodType.Constructor, typeof(MyScriptCompiler))]
|
||||||
|
public static class WhitelistPatch
|
||||||
|
{
|
||||||
|
private static void Prefix(MyScriptCompiler scriptCompiler)
|
||||||
|
{
|
||||||
|
var baseDir = new FileInfo(typeof(Type).Assembly.Location).DirectoryName!;
|
||||||
|
|
||||||
|
scriptCompiler.AddReferencedAssemblies(
|
||||||
|
typeof(Type).Assembly.Location,
|
||||||
|
typeof(LinkedList<>).Assembly.Location,
|
||||||
|
typeof(Regex).Assembly.Location,
|
||||||
|
typeof(Enumerable).Assembly.Location,
|
||||||
|
typeof(ConcurrentBag<>).Assembly.Location,
|
||||||
|
typeof(ImmutableArray).Assembly.Location,
|
||||||
|
typeof(PropertyChangedEventArgs).Assembly.Location,
|
||||||
|
typeof(TypeConverter).Assembly.Location,
|
||||||
|
typeof(System.Diagnostics.TraceSource).Assembly.Location,
|
||||||
|
typeof(System.Security.Policy.Evidence).Assembly.Location,
|
||||||
|
Path.Combine(MyFileSystem.ExePath, "ProtoBuf.Net.dll"),
|
||||||
|
Path.Combine(MyFileSystem.ExePath, "ProtoBuf.Net.Core.dll"),
|
||||||
|
Path.Combine(baseDir, "netstandard.dll"),
|
||||||
|
Path.Combine(baseDir, "System.Runtime.dll"),
|
||||||
|
Path.Combine(MyFileSystem.ExePath, "Sandbox.Game.dll"),
|
||||||
|
Path.Combine(MyFileSystem.ExePath, "Sandbox.Common.dll"),
|
||||||
|
Path.Combine(MyFileSystem.ExePath, "Sandbox.Graphics.dll"),
|
||||||
|
Path.Combine(MyFileSystem.ExePath, "VRage.dll"),
|
||||||
|
Path.Combine(MyFileSystem.ExePath, "VRage.Library.dll"),
|
||||||
|
Path.Combine(MyFileSystem.ExePath, "VRage.Math.dll"),
|
||||||
|
Path.Combine(MyFileSystem.ExePath, "VRage.Game.dll"),
|
||||||
|
Path.Combine(MyFileSystem.ExePath, "VRage.Render.dll"),
|
||||||
|
Path.Combine(MyFileSystem.ExePath, "VRage.Input.dll"),
|
||||||
|
Path.Combine(MyFileSystem.ExePath, "SpaceEngineers.ObjectBuilders.dll"),
|
||||||
|
Path.Combine(MyFileSystem.ExePath, "SpaceEngineers.Game.dll"));
|
||||||
|
}
|
||||||
|
}
|
37
CringeLauncher/Patches/WhitelistRegistrationPatch.cs
Normal file
37
CringeLauncher/Patches/WhitelistRegistrationPatch.cs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Reflection.Emit;
|
||||||
|
using HarmonyLib;
|
||||||
|
using Microsoft.CodeAnalysis;
|
||||||
|
using VRage.Scripting;
|
||||||
|
|
||||||
|
namespace CringeLauncher.Patches;
|
||||||
|
|
||||||
|
[HarmonyPatch]
|
||||||
|
public static class WhitelistRegistrationPatch
|
||||||
|
{
|
||||||
|
private static IEnumerable<MethodInfo> TargetMethods()
|
||||||
|
{
|
||||||
|
yield return AccessTools.Method(typeof(MyScriptWhitelist), "Register",
|
||||||
|
new[] { typeof(MyWhitelistTarget), typeof(INamespaceSymbol), typeof(Type) });
|
||||||
|
yield return AccessTools.Method(typeof(MyScriptWhitelist), "Register",
|
||||||
|
new[] { typeof(MyWhitelistTarget), typeof(ITypeSymbol), typeof(Type) });
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
|
||||||
|
{
|
||||||
|
var ins = instructions.ToList();
|
||||||
|
var throwIns = ins.FindAll(b => b.opcode == OpCodes.Throw).Select(b => ins.IndexOf(b));
|
||||||
|
foreach (var index in throwIns)
|
||||||
|
{
|
||||||
|
var i = index;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
ins[i] = new(OpCodes.Nop);
|
||||||
|
} while (ins[--i].opcode.OperandType != OperandType.ShortInlineBrTarget);
|
||||||
|
|
||||||
|
ins[index] = new(OpCodes.Ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ins;
|
||||||
|
}
|
||||||
|
}
|
12
CringeLauncher/Program.cs
Normal file
12
CringeLauncher/Program.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
using CringeLauncher;
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
while (!Debugger.IsAttached)
|
||||||
|
Thread.Sleep(100);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
using var launcher = new Launcher();
|
||||||
|
|
||||||
|
launcher.Initialize(args);
|
||||||
|
launcher.Run();
|
Reference in New Issue
Block a user