Compare commits
3 Commits
v1.0.27-ma
...
v1.0.30-ma
Author | SHA1 | Date | |
---|---|---|---|
![]() |
3696f18714 | ||
![]() |
1f7e4e869d | ||
![]() |
ba5b611994 |
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Reflection.Emit;
|
||||
@@ -8,6 +9,7 @@ using NLog;
|
||||
using Sandbox;
|
||||
using Torch.Managers.PatchManager;
|
||||
using Torch.Managers.PatchManager.MSIL;
|
||||
using Torch.Utils;
|
||||
|
||||
namespace Torch.Patches
|
||||
{
|
||||
@@ -17,12 +19,14 @@ namespace Torch.Patches
|
||||
[PatchShim]
|
||||
public static class WorldLoadExceptionPatch
|
||||
{
|
||||
private static readonly ILogger _log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private static readonly ILogger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
[ReflectedMethodInfo(typeof(MySandboxGame), "InitQuickLaunch")]
|
||||
private static MethodInfo _quickLaunchMethod = null!;
|
||||
|
||||
public static void Patch(PatchContext ctx)
|
||||
{
|
||||
ctx.GetPattern(typeof(MySandboxGame).GetMethod("InitQuickLaunch", BindingFlags.Instance | BindingFlags.NonPublic))
|
||||
.Transpilers.Add(typeof(WorldLoadExceptionPatch).GetMethod(nameof(Transpile), BindingFlags.Static | BindingFlags.NonPublic));
|
||||
ctx.GetPattern(_quickLaunchMethod).AddTranspiler(nameof(Transpile));
|
||||
}
|
||||
|
||||
private static IEnumerable<MsilInstruction> Transpile(IEnumerable<MsilInstruction> method)
|
||||
@@ -30,19 +34,19 @@ namespace Torch.Patches
|
||||
var msil = method.ToList();
|
||||
for (var i = 0; i < msil.Count; i++)
|
||||
{
|
||||
if (msil[i].TryCatchOperations.All(x => x.Type != MsilTryCatchOperationType.BeginClauseBlock))
|
||||
continue;
|
||||
|
||||
for (; i < msil.Count; i++)
|
||||
var instruction = msil[i];
|
||||
if (instruction.IsLocalStore() && instruction.Operand is MsilOperandInline.MsilOperandLocal {Value.Index: 19} operand)
|
||||
{
|
||||
if (msil[i].OpCode != OpCodes.Leave)
|
||||
continue;
|
||||
|
||||
msil[i] = new MsilInstruction(OpCodes.Rethrow);
|
||||
break;
|
||||
msil.InsertRange(i + 1, new []
|
||||
{
|
||||
operand.Instruction.CopyWith(OpCodes.Ldloc_S),
|
||||
new MsilInstruction(OpCodes.Call).InlineValue(new Action<Exception>(LogFatal).Method)
|
||||
});
|
||||
}
|
||||
}
|
||||
return msil;
|
||||
}
|
||||
|
||||
private static void LogFatal(Exception e) => Log.Fatal(e.ToStringDemystified());
|
||||
}
|
||||
}
|
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using NLog;
|
||||
using NLog.Config;
|
||||
using NLog.Targets;
|
||||
using Torch.Utils;
|
||||
|
||||
@@ -7,11 +9,11 @@ namespace Torch.Server
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var isService = Environment.GetEnvironmentVariable("TORCH_SERVICE")
|
||||
?.Equals(bool.TrueString, StringComparison.OrdinalIgnoreCase) ?? false;
|
||||
Target.Register<LogViewerTarget>(nameof(LogViewerTarget));
|
||||
//Ensures that all the files are downloaded in the Torch directory.
|
||||
var workingDir = AppContext.BaseDirectory;
|
||||
var binDir = Path.Combine(Environment.GetEnvironmentVariable("TORCH_GAME_PATH") ?? workingDir, "DedicatedServer64");
|
||||
@@ -23,8 +25,6 @@ namespace Torch.Server
|
||||
File.Delete(file);
|
||||
}
|
||||
|
||||
TorchLauncher.Launch(workingDir, binDir);
|
||||
|
||||
// Breaks on Windows Server 2019
|
||||
#if TORCH_SERVICE
|
||||
if (!new ComputerInfo().OSFullName.Contains("Server 2019") && !Environment.UserInteractive)
|
||||
@@ -45,14 +45,26 @@ namespace Torch.Server
|
||||
}
|
||||
else
|
||||
{
|
||||
instancePath = Path.GetFullPath(instanceName);
|
||||
instancePath = Directory.CreateDirectory(instanceName).FullName;
|
||||
}
|
||||
|
||||
var oldNlog = Path.Combine(workingDir, "NLog.config");
|
||||
var newNlog = Path.Combine(instancePath, "NLog.config");
|
||||
if (File.Exists(oldNlog))
|
||||
File.Move(oldNlog, newNlog, true);
|
||||
else if (!File.Exists(newNlog))
|
||||
using (var f = File.Create(newNlog))
|
||||
typeof(Program).Assembly.GetManifestResourceStream("Torch.Server.NLog.config")!.CopyTo(f);
|
||||
|
||||
var oldTorchCfg = Path.Combine(workingDir, "Torch.cfg");
|
||||
var torchCfg = Path.Combine(instancePath, "Torch.cfg");
|
||||
|
||||
if (File.Exists(oldTorchCfg))
|
||||
File.Move(oldTorchCfg, torchCfg, true);
|
||||
|
||||
Target.Register<LogViewerTarget>(nameof(LogViewerTarget));
|
||||
LogManager.Configuration = new XmlLoggingConfiguration(newNlog);
|
||||
LogManager.ReconfigExistingLoggers();
|
||||
|
||||
var config = Persistent<TorchConfig>.Load(torchCfg);
|
||||
config.Data.InstanceName = instanceName;
|
||||
@@ -70,6 +82,8 @@ namespace Torch.Server
|
||||
if (!initializer.Initialize(args))
|
||||
Environment.Exit(1);
|
||||
|
||||
TorchLauncher.Launch(workingDir, binDir);
|
||||
|
||||
CopyNative(binDir);
|
||||
initializer.Run(isService, instanceName, instancePath);
|
||||
}
|
||||
|
@@ -160,6 +160,6 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Remove="Views\WorldSelectControl.xaml" />
|
||||
<None Include="..\NLog.config" Visible="false" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="Always" />
|
||||
<EmbeddedResource Include="..\NLog.config" Visible="false" />
|
||||
</ItemGroup>
|
||||
</Project>
|
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -43,11 +45,14 @@ namespace Torch.Patches
|
||||
private static void WhitelistCtorPrefix(MyScriptCompiler scriptCompiler)
|
||||
{
|
||||
scriptCompiler.AddReferencedAssemblies(
|
||||
typeof(ValueType).Assembly.Location,
|
||||
typeof(LinkedList<>).Assembly.Location,
|
||||
typeof(Regex).Assembly.Location,
|
||||
typeof(Enumerable).Assembly.Location,
|
||||
typeof(ConcurrentBag<>).Assembly.Location,
|
||||
typeof(ImmutableArray).Assembly.Location,
|
||||
typeof(System.ComponentModel.TypeConverter).Assembly.Location,
|
||||
typeof(PropertyChangedEventArgs).Assembly.Location,
|
||||
typeof(TypeConverter).Assembly.Location,
|
||||
typeof(System.Diagnostics.TraceSource).Assembly.Location,
|
||||
typeof(ProtoBuf.Meta.RuntimeTypeModel).Assembly.Location,
|
||||
Path.Combine(MyFileSystem.ExePath, "Sandbox.Game.dll"),
|
||||
|
Reference in New Issue
Block a user