Compare commits
26 Commits
v1.0.15-ma
...
v1.0.38-ma
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f42b9c6674 | ||
![]() |
227557f421 | ||
![]() |
0632f68aaf | ||
![]() |
0a9f299527 | ||
![]() |
67f25ab20b | ||
![]() |
ad19a7dc9e | ||
![]() |
dd854a159a | ||
![]() |
879a373e6a | ||
![]() |
ec1b017946 | ||
![]() |
cf75210304 | ||
![]() |
3696f18714 | ||
![]() |
1f7e4e869d | ||
![]() |
ba5b611994 | ||
![]() |
2bcf79efdd | ||
![]() |
d5c101bf19 | ||
![]() |
e9841b4de1 | ||
![]() |
aea0011683 | ||
![]() |
d10528f9fe | ||
![]() |
66ea4d7307 | ||
![]() |
f6ce40a854 | ||
![]() |
bd62d31298 | ||
![]() |
b1cf5fb638 | ||
![]() |
1d6a2a9a60 | ||
![]() |
455be2393e | ||
![]() |
6131a9003b | ||
![]() |
2a17c4bc09 |
17
Dockerfile
17
Dockerfile
@@ -1,17 +0,0 @@
|
|||||||
FROM mcr.microsoft.com/windows/servercore:ltsc2022
|
|
||||||
|
|
||||||
USER ContainerAdministrator
|
|
||||||
ADD https://aka.ms/highdpimfc2013x64enu vc_redist2013.exe
|
|
||||||
ADD https://aka.ms/vs/16/release/vc_redist.x64.exe vc_redist.exe
|
|
||||||
|
|
||||||
RUN vc_redist2013.exe /passive /norestart
|
|
||||||
RUN vc_redist.exe /passive /norestart
|
|
||||||
RUN del vc_redist2013.exe && del vc_redist.exe
|
|
||||||
|
|
||||||
USER ContainerUser
|
|
||||||
COPY . .
|
|
||||||
ENV TORCH_GAME_PATH="c:\dedi"
|
|
||||||
ENV TORCH_INSTANCE="c:\instance"
|
|
||||||
ENV TORCH_SERVICE="true"
|
|
||||||
ENTRYPOINT ["Torch.Server.exe"]
|
|
||||||
CMD ["-noupdate"]
|
|
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Reflection.Emit;
|
using System.Reflection.Emit;
|
||||||
@@ -8,6 +9,7 @@ using NLog;
|
|||||||
using Sandbox;
|
using Sandbox;
|
||||||
using Torch.Managers.PatchManager;
|
using Torch.Managers.PatchManager;
|
||||||
using Torch.Managers.PatchManager.MSIL;
|
using Torch.Managers.PatchManager.MSIL;
|
||||||
|
using Torch.Utils;
|
||||||
|
|
||||||
namespace Torch.Patches
|
namespace Torch.Patches
|
||||||
{
|
{
|
||||||
@@ -17,12 +19,14 @@ namespace Torch.Patches
|
|||||||
[PatchShim]
|
[PatchShim]
|
||||||
public static class WorldLoadExceptionPatch
|
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)
|
public static void Patch(PatchContext ctx)
|
||||||
{
|
{
|
||||||
ctx.GetPattern(typeof(MySandboxGame).GetMethod("InitQuickLaunch", BindingFlags.Instance | BindingFlags.NonPublic))
|
ctx.GetPattern(_quickLaunchMethod).AddTranspiler(nameof(Transpile));
|
||||||
.Transpilers.Add(typeof(WorldLoadExceptionPatch).GetMethod(nameof(Transpile), BindingFlags.Static | BindingFlags.NonPublic));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IEnumerable<MsilInstruction> Transpile(IEnumerable<MsilInstruction> method)
|
private static IEnumerable<MsilInstruction> Transpile(IEnumerable<MsilInstruction> method)
|
||||||
@@ -30,19 +34,19 @@ namespace Torch.Patches
|
|||||||
var msil = method.ToList();
|
var msil = method.ToList();
|
||||||
for (var i = 0; i < msil.Count; i++)
|
for (var i = 0; i < msil.Count; i++)
|
||||||
{
|
{
|
||||||
if (msil[i].TryCatchOperations.All(x => x.Type != MsilTryCatchOperationType.BeginClauseBlock))
|
var instruction = msil[i];
|
||||||
continue;
|
if (instruction.IsLocalStore() && instruction.Operand is MsilOperandInline.MsilOperandLocal {Value.Index: 19} operand)
|
||||||
|
|
||||||
for (; i < msil.Count; i++)
|
|
||||||
{
|
{
|
||||||
if (msil[i].OpCode != OpCodes.Leave)
|
msil.InsertRange(i + 1, new []
|
||||||
continue;
|
{
|
||||||
|
operand.Instruction.CopyWith(OpCodes.Ldloc_S),
|
||||||
msil[i] = new MsilInstruction(OpCodes.Rethrow);
|
new MsilInstruction(OpCodes.Call).InlineValue(new Action<Exception>(LogFatal).Method)
|
||||||
break;
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return msil;
|
return msil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void LogFatal(Exception e) => Log.Fatal(e.ToStringDemystified());
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,5 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using NLog;
|
||||||
|
using NLog.Config;
|
||||||
using NLog.Targets;
|
using NLog.Targets;
|
||||||
using Torch.Utils;
|
using Torch.Utils;
|
||||||
|
|
||||||
@@ -7,11 +9,11 @@ namespace Torch.Server
|
|||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
|
[STAThread]
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
var isService = Environment.GetEnvironmentVariable("TORCH_SERVICE")
|
var isService = Environment.GetEnvironmentVariable("TORCH_SERVICE")
|
||||||
?.Equals(bool.TrueString, StringComparison.OrdinalIgnoreCase) ?? false;
|
?.Equals(bool.TrueString, StringComparison.OrdinalIgnoreCase) ?? false;
|
||||||
Target.Register<LogViewerTarget>(nameof(LogViewerTarget));
|
|
||||||
//Ensures that all the files are downloaded in the Torch directory.
|
//Ensures that all the files are downloaded in the Torch directory.
|
||||||
var workingDir = AppContext.BaseDirectory;
|
var workingDir = AppContext.BaseDirectory;
|
||||||
var binDir = Path.Combine(Environment.GetEnvironmentVariable("TORCH_GAME_PATH") ?? workingDir, "DedicatedServer64");
|
var binDir = Path.Combine(Environment.GetEnvironmentVariable("TORCH_GAME_PATH") ?? workingDir, "DedicatedServer64");
|
||||||
@@ -23,8 +25,6 @@ namespace Torch.Server
|
|||||||
File.Delete(file);
|
File.Delete(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
TorchLauncher.Launch(workingDir, binDir);
|
|
||||||
|
|
||||||
// Breaks on Windows Server 2019
|
// Breaks on Windows Server 2019
|
||||||
#if TORCH_SERVICE
|
#if TORCH_SERVICE
|
||||||
if (!new ComputerInfo().OSFullName.Contains("Server 2019") && !Environment.UserInteractive)
|
if (!new ComputerInfo().OSFullName.Contains("Server 2019") && !Environment.UserInteractive)
|
||||||
@@ -45,9 +45,17 @@ namespace Torch.Server
|
|||||||
}
|
}
|
||||||
else
|
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 oldTorchCfg = Path.Combine(workingDir, "Torch.cfg");
|
||||||
var torchCfg = Path.Combine(instancePath, "Torch.cfg");
|
var torchCfg = Path.Combine(instancePath, "Torch.cfg");
|
||||||
|
|
||||||
@@ -66,18 +74,38 @@ namespace Torch.Server
|
|||||||
var handler = new UnhandledExceptionHandler(config.Data, isService);
|
var handler = new UnhandledExceptionHandler(config.Data, isService);
|
||||||
AppDomain.CurrentDomain.UnhandledException += handler.OnUnhandledException;
|
AppDomain.CurrentDomain.UnhandledException += handler.OnUnhandledException;
|
||||||
|
|
||||||
|
Target.Register<LogViewerTarget>(nameof(LogViewerTarget));
|
||||||
|
TorchLogManager.RegisterTargets(Environment.GetEnvironmentVariable("TORCH_LOG_EXTENSIONS_PATH") ??
|
||||||
|
Path.Combine(instancePath, "LoggingExtensions"));
|
||||||
|
|
||||||
|
TorchLogManager.SetConfiguration(new XmlLoggingConfiguration(newNlog));
|
||||||
|
|
||||||
var initializer = new Initializer(workingDir, config);
|
var initializer = new Initializer(workingDir, config);
|
||||||
if (!initializer.Initialize(args))
|
if (!initializer.Initialize(args))
|
||||||
Environment.Exit(1);
|
Environment.Exit(1);
|
||||||
|
|
||||||
|
TorchLauncher.Launch(workingDir, binDir);
|
||||||
|
|
||||||
CopyNative(binDir);
|
CopyNative(binDir);
|
||||||
|
|
||||||
initializer.Run(isService, instanceName, instancePath);
|
initializer.Run(isService, instanceName, instancePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void CopyNative(string binPath)
|
private static void CopyNative(string binPath)
|
||||||
|
{
|
||||||
|
var log = LogManager.GetLogger("TorchLauncher");
|
||||||
|
|
||||||
|
var workingDir = new DirectoryInfo(Directory.GetCurrentDirectory());
|
||||||
|
if (workingDir.Attributes.HasFlag(FileAttributes.ReadOnly))
|
||||||
|
{
|
||||||
|
log.Warn("Game directory is readonly. You should copy steam_api64.dll, Havok.dll from bin manually");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
var apiSource = Path.Combine(binPath, "steam_api64.dll");
|
var apiSource = Path.Combine(binPath, "steam_api64.dll");
|
||||||
var apiTarget = Path.Combine(AppContext.BaseDirectory, "steam_api64.dll");
|
var apiTarget = Path.Combine(workingDir.FullName, "steam_api64.dll");
|
||||||
if (!File.Exists(apiTarget))
|
if (!File.Exists(apiTarget))
|
||||||
{
|
{
|
||||||
File.Copy(apiSource, apiTarget);
|
File.Copy(apiSource, apiTarget);
|
||||||
@@ -89,7 +117,7 @@ namespace Torch.Server
|
|||||||
}
|
}
|
||||||
|
|
||||||
var havokSource = Path.Combine(binPath, "Havok.dll");
|
var havokSource = Path.Combine(binPath, "Havok.dll");
|
||||||
var havokTarget = Path.Combine(AppContext.BaseDirectory, "Havok.dll");
|
var havokTarget = Path.Combine(workingDir.FullName, "Havok.dll");
|
||||||
|
|
||||||
if (!File.Exists(havokTarget))
|
if (!File.Exists(havokTarget))
|
||||||
{
|
{
|
||||||
@@ -101,5 +129,14 @@ namespace Torch.Server
|
|||||||
File.Copy(havokSource, havokTarget);
|
File.Copy(havokSource, havokTarget);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (UnauthorizedAccessException)
|
||||||
|
{
|
||||||
|
// file is being used by another process, probably previous torch has not been closed yet
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
log.Error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -160,7 +160,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Page Remove="Views\WorldSelectControl.xaml" />
|
<Page Remove="Views\WorldSelectControl.xaml" />
|
||||||
<None Include="..\NLog.config" Visible="false" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="Always" />
|
<EmbeddedResource Include="..\NLog.config" Visible="false" />
|
||||||
<None Include="..\Dockerfile" Visible="false" CopyToPublishDirectory="Always" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@@ -197,7 +197,7 @@ namespace Torch.Managers.PatchManager
|
|||||||
lock (_log)
|
lock (_log)
|
||||||
{
|
{
|
||||||
var instructions = context.Body.Instructions
|
var instructions = context.Body.Instructions
|
||||||
.Select(b => new MsilInstruction(b)).ToList();
|
.Select(b => b.ToMsilInstruction()).ToList();
|
||||||
LogTarget(PrintModeEnum.Patched, false, "========== Patched method ==========");
|
LogTarget(PrintModeEnum.Patched, false, "========== Patched method ==========");
|
||||||
MethodTranspiler.IntegrityAnalysis((a, b) => LogTarget(PrintModeEnum.Patched, a, b), instructions, true);
|
MethodTranspiler.IntegrityAnalysis((a, b) => LogTarget(PrintModeEnum.Patched, a, b), instructions, true);
|
||||||
LogTarget(PrintModeEnum.Patched, false, gap);
|
LogTarget(PrintModeEnum.Patched, false, gap);
|
||||||
|
136
Torch/Managers/PatchManager/MSIL/InstructionExtensions.cs
Normal file
136
Torch/Managers/PatchManager/MSIL/InstructionExtensions.cs
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using Mono.Cecil;
|
||||||
|
using Mono.Cecil.Cil;
|
||||||
|
using MonoMod.Utils;
|
||||||
|
using Torch.Managers.PatchManager.Transpile;
|
||||||
|
using OperandType = System.Reflection.Emit.OperandType;
|
||||||
|
|
||||||
|
namespace Torch.Managers.PatchManager.MSIL;
|
||||||
|
|
||||||
|
internal static class InstructionExtensions
|
||||||
|
{
|
||||||
|
public static MsilInstruction ToMsilInstruction(this Instruction instruction)
|
||||||
|
{
|
||||||
|
static System.Reflection.Emit.Label CreateLabel(int pos)
|
||||||
|
{
|
||||||
|
var instance = Activator.CreateInstance(typeof(System.Reflection.Emit.Label),
|
||||||
|
BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.NonPublic, null,
|
||||||
|
new object[] {pos}, null);
|
||||||
|
if (instance == null)
|
||||||
|
return default;
|
||||||
|
return (System.Reflection.Emit.Label) instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
var systemOpCode = MethodContext.OpCodeLookup[instruction.OpCode.Value];
|
||||||
|
var msil = new MsilInstruction(systemOpCode);
|
||||||
|
if (instruction.Operand is null || instruction.OpCode.OperandType == Mono.Cecil.Cil.OperandType.InlineNone)
|
||||||
|
return msil;
|
||||||
|
|
||||||
|
var opType = systemOpCode.OperandType;
|
||||||
|
|
||||||
|
switch (instruction.Operand)
|
||||||
|
{
|
||||||
|
case Instruction targetInstruction when opType is OperandType.InlineBrTarget or OperandType.ShortInlineBrTarget:
|
||||||
|
msil.Operand = new MsilOperandBrTarget(msil)
|
||||||
|
{
|
||||||
|
Target = new MsilLabel(CreateLabel(targetInstruction.Offset))
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case FieldReference reference when opType == OperandType.InlineField:
|
||||||
|
msil.Operand = new MsilOperandInline.MsilOperandReflected<FieldInfo>(msil)
|
||||||
|
{
|
||||||
|
Value = reference.ResolveReflection()
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case int int32 when opType is OperandType.InlineI or OperandType.ShortInlineI:
|
||||||
|
msil.Operand = new MsilOperandInline.MsilOperandInt32(msil)
|
||||||
|
{
|
||||||
|
Value = int32
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case long int64 when opType is OperandType.InlineI8:
|
||||||
|
msil.Operand = new MsilOperandInline.MsilOperandInt64(msil)
|
||||||
|
{
|
||||||
|
Value = int64
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case MethodReference methodReference when opType is OperandType.InlineMethod:
|
||||||
|
msil.Operand = new MsilOperandInline.MsilOperandReflected<MethodBase>(msil)
|
||||||
|
{
|
||||||
|
Value = methodReference.ResolveReflection()
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case double @double when opType is OperandType.InlineR:
|
||||||
|
msil.Operand = new MsilOperandInline.MsilOperandDouble(msil)
|
||||||
|
{
|
||||||
|
Value = @double
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case null when opType is OperandType.InlineSig:
|
||||||
|
throw new NotSupportedException("InlineSignature is not supported by instruction converter");
|
||||||
|
case string @string when opType == OperandType.InlineString:
|
||||||
|
msil.Operand = new MsilOperandInline.MsilOperandString(msil)
|
||||||
|
{
|
||||||
|
Value = @string
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case Instruction[] targetInstructions when opType is OperandType.InlineSwitch:
|
||||||
|
msil.Operand = new MsilOperandSwitch(msil)
|
||||||
|
{
|
||||||
|
Labels = targetInstructions.Select(b => new MsilLabel(CreateLabel(b.Offset))).ToArray()
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case MemberReference memberReference when opType is OperandType.InlineTok:
|
||||||
|
msil.Operand = new MsilOperandInline.MsilOperandReflected<MemberInfo>(msil)
|
||||||
|
{
|
||||||
|
Value = memberReference.ResolveReflection()
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case TypeReference typeReference when opType is OperandType.InlineType:
|
||||||
|
msil.Operand = new MsilOperandInline.MsilOperandReflected<Type>(msil)
|
||||||
|
{
|
||||||
|
Value = typeReference.ResolveReflection()
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case VariableDefinition variableDefinition when opType is OperandType.InlineVar or OperandType.ShortInlineVar:
|
||||||
|
if (systemOpCode.IsLocalStore() || systemOpCode.IsLocalLoad() || systemOpCode.IsLocalLoadByRef())
|
||||||
|
msil.Operand = new MsilOperandInline.MsilOperandLocal(msil)
|
||||||
|
{
|
||||||
|
Value = new MsilLocal(variableDefinition.Index)
|
||||||
|
};
|
||||||
|
else
|
||||||
|
msil.Operand = new MsilOperandInline.MsilOperandArgument(msil)
|
||||||
|
{
|
||||||
|
Value = new MsilArgument(variableDefinition.Index)
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case ParameterDefinition parameterDefinition when opType is OperandType.InlineVar or OperandType.ShortInlineVar:
|
||||||
|
if (systemOpCode.IsLocalStore() || systemOpCode.IsLocalLoad() || systemOpCode.IsLocalLoadByRef())
|
||||||
|
msil.Operand = new MsilOperandInline.MsilOperandLocal(msil)
|
||||||
|
{
|
||||||
|
Value = new MsilLocal(parameterDefinition.Index)
|
||||||
|
};
|
||||||
|
else
|
||||||
|
msil.Operand = new MsilOperandInline.MsilOperandArgument(msil)
|
||||||
|
{
|
||||||
|
Value = new MsilArgument(parameterDefinition.Index)
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case float @float when opType == OperandType.ShortInlineR:
|
||||||
|
msil.Operand = new MsilOperandInline.MsilOperandSingle(msil)
|
||||||
|
{
|
||||||
|
Value = @float
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
#pragma warning disable 618
|
||||||
|
case null when opType == OperandType.InlinePhi:
|
||||||
|
#pragma warning restore 618
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(instruction.Operand), instruction.Operand, "Invalid operand type");
|
||||||
|
}
|
||||||
|
|
||||||
|
return msil;
|
||||||
|
}
|
||||||
|
}
|
@@ -12,6 +12,7 @@ using Mono.Cecil.Cil;
|
|||||||
using MonoMod.Utils;
|
using MonoMod.Utils;
|
||||||
using Torch.Managers.PatchManager.Transpile;
|
using Torch.Managers.PatchManager.Transpile;
|
||||||
using Torch.Utils;
|
using Torch.Utils;
|
||||||
|
using VRage.Game.VisualScripting;
|
||||||
using OpCode = System.Reflection.Emit.OpCode;
|
using OpCode = System.Reflection.Emit.OpCode;
|
||||||
using OpCodes = System.Reflection.Emit.OpCodes;
|
using OpCodes = System.Reflection.Emit.OpCodes;
|
||||||
using OperandType = System.Reflection.Emit.OperandType;
|
using OperandType = System.Reflection.Emit.OperandType;
|
||||||
@@ -88,132 +89,6 @@ namespace Torch.Managers.PatchManager.MSIL
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public MsilInstruction(Instruction instruction)
|
|
||||||
{
|
|
||||||
Label CreateLabel(int pos)
|
|
||||||
{
|
|
||||||
var instance = Activator.CreateInstance(typeof(Label),
|
|
||||||
BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.NonPublic, null,
|
|
||||||
new object[] {pos}, null);
|
|
||||||
if (instance == null)
|
|
||||||
return default;
|
|
||||||
return (Label) instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!MethodContext.OpCodeLookup.TryGetValue(instruction.OpCode.Value, out var opCode))
|
|
||||||
return;
|
|
||||||
OpCode = opCode;
|
|
||||||
|
|
||||||
var opType = opCode.OperandType;
|
|
||||||
if (opType == OperandType.InlineNone)
|
|
||||||
{
|
|
||||||
Operand = null;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
switch (instruction.Operand)
|
|
||||||
{
|
|
||||||
case OperandType.InlineNone:
|
|
||||||
break;
|
|
||||||
case Instruction targetInstruction when opType == OperandType.InlineBrTarget || opType == OperandType.ShortInlineBrTarget:
|
|
||||||
Operand = new MsilOperandBrTarget(this)
|
|
||||||
{
|
|
||||||
Target = new MsilLabel(CreateLabel(targetInstruction.Offset))
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
case FieldReference reference when opType == OperandType.InlineField:
|
|
||||||
Operand = new MsilOperandInline.MsilOperandReflected<FieldInfo>(this)
|
|
||||||
{
|
|
||||||
Value = reference.ResolveReflection()
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
case int int32 when opType == OperandType.InlineI || opType == OperandType.ShortInlineI:
|
|
||||||
Operand = new MsilOperandInline.MsilOperandInt32(this)
|
|
||||||
{
|
|
||||||
Value = int32
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
case long int64 when opType == OperandType.InlineI8:
|
|
||||||
Operand = new MsilOperandInline.MsilOperandInt64(this)
|
|
||||||
{
|
|
||||||
Value = int64
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
case MethodReference methodReference when opType == OperandType.InlineMethod:
|
|
||||||
Operand = new MsilOperandInline.MsilOperandReflected<MethodBase>(this)
|
|
||||||
{
|
|
||||||
Value = methodReference.ResolveReflection()
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
case double @double when opType == OperandType.InlineR:
|
|
||||||
Operand = new MsilOperandInline.MsilOperandDouble(this)
|
|
||||||
{
|
|
||||||
Value = @double
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
case null when opType == OperandType.InlineSig:
|
|
||||||
throw new NotSupportedException("InlineSignature is not supported by instruction converter");
|
|
||||||
case string @string when opType == OperandType.InlineString:
|
|
||||||
Operand = new MsilOperandInline.MsilOperandString(this)
|
|
||||||
{
|
|
||||||
Value = @string
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
case Instruction[] targetInstructions when opType == OperandType.InlineSwitch:
|
|
||||||
Operand = new MsilOperandSwitch(this)
|
|
||||||
{
|
|
||||||
Labels = targetInstructions.Select(b => new MsilLabel(CreateLabel(b.Offset))).ToArray()
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
case MemberReference memberReference when opType == OperandType.InlineTok:
|
|
||||||
Operand = new MsilOperandInline.MsilOperandReflected<MemberInfo>(this)
|
|
||||||
{
|
|
||||||
Value = memberReference.ResolveReflection()
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
case TypeReference typeReference when opType == OperandType.InlineType:
|
|
||||||
Operand = new MsilOperandInline.MsilOperandReflected<Type>(this)
|
|
||||||
{
|
|
||||||
Value = typeReference.ResolveReflection()
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
case VariableDefinition variableDefinition when opType == OperandType.InlineVar || opType == OperandType.ShortInlineVar:
|
|
||||||
if (OpCode.IsLocalStore() || OpCode.IsLocalLoad() || OpCode.IsLocalLoadByRef())
|
|
||||||
Operand = new MsilOperandInline.MsilOperandLocal(this)
|
|
||||||
{
|
|
||||||
Value = new MsilLocal(variableDefinition.Index)
|
|
||||||
};
|
|
||||||
else
|
|
||||||
Operand = new MsilOperandInline.MsilOperandArgument(this)
|
|
||||||
{
|
|
||||||
Value = new MsilArgument(variableDefinition.Index)
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
case ParameterDefinition parameterDefinition when opType == OperandType.InlineVar || opType == OperandType.ShortInlineVar:
|
|
||||||
if (OpCode.IsLocalStore() || OpCode.IsLocalLoad() || OpCode.IsLocalLoadByRef())
|
|
||||||
Operand = new MsilOperandInline.MsilOperandLocal(this)
|
|
||||||
{
|
|
||||||
Value = new MsilLocal(parameterDefinition.Index)
|
|
||||||
};
|
|
||||||
else
|
|
||||||
Operand = new MsilOperandInline.MsilOperandArgument(this)
|
|
||||||
{
|
|
||||||
Value = new MsilArgument(parameterDefinition.Index)
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
case float @float when opType == OperandType.ShortInlineR:
|
|
||||||
Operand = new MsilOperandInline.MsilOperandSingle(this)
|
|
||||||
{
|
|
||||||
Value = @float
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
#pragma warning disable 618
|
|
||||||
case null when opType == OperandType.InlinePhi:
|
|
||||||
#pragma warning restore 618
|
|
||||||
default:
|
|
||||||
throw new ArgumentOutOfRangeException(nameof(instruction.Operand), instruction.Operand, "Invalid operand type");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Opcode of this instruction
|
/// Opcode of this instruction
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -227,7 +102,7 @@ namespace Torch.Managers.PatchManager.MSIL
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The operand for this instruction, or null.
|
/// The operand for this instruction, or null.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public MsilOperand Operand { get; }
|
public MsilOperand Operand { get; internal set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Labels pointing to this instruction.
|
/// Labels pointing to this instruction.
|
||||||
@@ -284,7 +159,11 @@ namespace Torch.Managers.PatchManager.MSIL
|
|||||||
type = type.BaseType;
|
type = type.BaseType;
|
||||||
}
|
}
|
||||||
|
|
||||||
((MsilOperandInline<T>) Operand).Value = o;
|
if (Operand is not MsilOperandInline<T> operandInline)
|
||||||
|
throw new InvalidOperationException(
|
||||||
|
$"Type {typeof(T).FullName} is not valid operand for {Operand?.GetType().Signature()}");
|
||||||
|
|
||||||
|
operandInline.Value = o;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -5,6 +5,7 @@ using System.Runtime.CompilerServices;
|
|||||||
using NLog;
|
using NLog;
|
||||||
using NLog.Config;
|
using NLog.Config;
|
||||||
using Torch.Managers.PatchManager;
|
using Torch.Managers.PatchManager;
|
||||||
|
using Torch.Utils;
|
||||||
|
|
||||||
namespace Torch.Patches
|
namespace Torch.Patches
|
||||||
{
|
{
|
||||||
@@ -36,16 +37,13 @@ namespace Torch.Patches
|
|||||||
_log.Warn("GALogger constructor is unknown. Logging may not function.");
|
_log.Warn("GALogger constructor is unknown. Logging may not function.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ctx.GetPattern(ctor).Prefixes.Add(typeof(GameAnalyticsPatch).GetMethod(nameof(PatchLogger),
|
ctx.GetPattern(ctor).AddPrefix(nameof(PatchLogger));
|
||||||
BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void FixLogging()
|
private static void FixLogging()
|
||||||
{
|
{
|
||||||
|
TorchLogManager.RestoreGlobalConfiguration();
|
||||||
_setLogger(null, LogManager.GetLogger("GameAnalytics"));
|
_setLogger(null, LogManager.GetLogger("GameAnalytics"));
|
||||||
if (!(LogManager.Configuration is XmlLoggingConfiguration))
|
|
||||||
LogManager.Configuration = new XmlLoggingConfiguration(Path.Combine(
|
|
||||||
Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) ?? Environment.CurrentDirectory, "NLog.config"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool PatchLogger()
|
private static bool PatchLogger()
|
||||||
|
@@ -17,6 +17,7 @@ internal static class GcCollectPatch
|
|||||||
{
|
{
|
||||||
// FUCK YO KEEN
|
// FUCK YO KEEN
|
||||||
// every call results in freeze for seconds
|
// every call results in freeze for seconds
|
||||||
|
|
||||||
private static readonly MethodBase[] _targets =
|
private static readonly MethodBase[] _targets =
|
||||||
{
|
{
|
||||||
Info.OfMethod<MyPlanetTextureMapProvider>(nameof(MyPlanetTextureMapProvider.GetHeightmap)),
|
Info.OfMethod<MyPlanetTextureMapProvider>(nameof(MyPlanetTextureMapProvider.GetHeightmap)),
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -43,11 +45,14 @@ namespace Torch.Patches
|
|||||||
private static void WhitelistCtorPrefix(MyScriptCompiler scriptCompiler)
|
private static void WhitelistCtorPrefix(MyScriptCompiler scriptCompiler)
|
||||||
{
|
{
|
||||||
scriptCompiler.AddReferencedAssemblies(
|
scriptCompiler.AddReferencedAssemblies(
|
||||||
|
typeof(ValueType).Assembly.Location,
|
||||||
|
typeof(LinkedList<>).Assembly.Location,
|
||||||
typeof(Regex).Assembly.Location,
|
typeof(Regex).Assembly.Location,
|
||||||
typeof(Enumerable).Assembly.Location,
|
typeof(Enumerable).Assembly.Location,
|
||||||
typeof(ConcurrentBag<>).Assembly.Location,
|
typeof(ConcurrentBag<>).Assembly.Location,
|
||||||
typeof(ImmutableArray).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(System.Diagnostics.TraceSource).Assembly.Location,
|
||||||
typeof(ProtoBuf.Meta.RuntimeTypeModel).Assembly.Location,
|
typeof(ProtoBuf.Meta.RuntimeTypeModel).Assembly.Location,
|
||||||
Path.Combine(MyFileSystem.ExePath, "Sandbox.Game.dll"),
|
Path.Combine(MyFileSystem.ExePath, "Sandbox.Game.dll"),
|
||||||
|
41
Torch/Utils/TorchLogManager.cs
Normal file
41
Torch/Utils/TorchLogManager.cs
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.Loader;
|
||||||
|
using NLog;
|
||||||
|
using NLog.Config;
|
||||||
|
using NLog.Targets;
|
||||||
|
|
||||||
|
namespace Torch.Utils;
|
||||||
|
|
||||||
|
public static class TorchLogManager
|
||||||
|
{
|
||||||
|
private static AssemblyLoadContext LoadContext = new("TorchLog");
|
||||||
|
|
||||||
|
public static LoggingConfiguration Configuration { get; private set; }
|
||||||
|
|
||||||
|
public static void SetConfiguration(LoggingConfiguration configuration)
|
||||||
|
{
|
||||||
|
Configuration = configuration;
|
||||||
|
LogManager.Configuration = configuration;
|
||||||
|
LogManager.ReconfigExistingLoggers();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RegisterTargets(string dir)
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(dir)) return;
|
||||||
|
|
||||||
|
foreach (var type in Directory.EnumerateFiles(dir, "*.dll").Select(LoadContext.LoadFromAssemblyPath)
|
||||||
|
.SelectMany(b => b.ExportedTypes)
|
||||||
|
.Where(b => b.GetCustomAttribute<TargetAttribute>() is { }))
|
||||||
|
{
|
||||||
|
Target.Register(type.GetCustomAttribute<TargetAttribute>()!.Name, type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RestoreGlobalConfiguration()
|
||||||
|
{
|
||||||
|
SetConfiguration(Configuration);
|
||||||
|
}
|
||||||
|
}
|
19
appveyor.yml
19
appveyor.yml
@@ -11,7 +11,7 @@ platform: x64
|
|||||||
shallow_clone: true
|
shallow_clone: true
|
||||||
assembly_info:
|
assembly_info:
|
||||||
patch: true
|
patch: true
|
||||||
file: '**\AssemblyInfo.*'
|
file: '**\AssemblyVersion.*'
|
||||||
assembly_version: '{version}'
|
assembly_version: '{version}'
|
||||||
assembly_file_version: '{version}'
|
assembly_file_version: '{version}'
|
||||||
assembly_informational_version: v{version}
|
assembly_informational_version: v{version}
|
||||||
@@ -37,22 +37,21 @@ install:
|
|||||||
|
|
||||||
& "$steamCMDPath/steamcmd.exe" "+login anonymous" "+force_install_dir $steamData" "+app_update 298740" "+quit"
|
& "$steamCMDPath/steamcmd.exe" "+login anonymous" "+force_install_dir $steamData" "+app_update 298740" "+quit"
|
||||||
|
|
||||||
$dataPath = $steamData.Replace("/", "\")
|
$dataPath = $steamData.Replace("/", "\");
|
||||||
|
$contentPath = "$dataPath\Content";
|
||||||
|
if (Test-Path $contentPath) {
|
||||||
|
Remove-Item -LiteralPath $contentPath -Force -Recurse
|
||||||
|
}
|
||||||
|
|
||||||
cmd /S /C mklink /J .\GameBinaries $dataPath\DedicatedServer64
|
cmd /S /C mklink /J .\GameBinaries $dataPath\DedicatedServer64
|
||||||
cache:
|
cache:
|
||||||
- c:\steam\dedi\
|
- c:\steam\dedi\
|
||||||
- c:\steam\cmd\
|
- c:\steam\cmd\
|
||||||
before_build:
|
build_script:
|
||||||
- pwsh: dotnet restore .\Torch.Server\Torch.Server.csproj
|
|
||||||
build:
|
|
||||||
project: Torch.Server/Torch.Server.csproj
|
|
||||||
verbosity: minimal
|
|
||||||
after_build:
|
|
||||||
- pwsh: >-
|
- pwsh: >-
|
||||||
dotnet publish .\Torch.Server\Torch.Server.csproj --self-contained -c Release -o .\publish\ --no-build
|
dotnet publish .\Torch.Server\Torch.Server.csproj --self-contained -f net6-windows -r win-x64 -c Release -o .\publish\
|
||||||
|
|
||||||
Compress-Archive -Path .\publish\ -DestinationPath torch-server.zip
|
Compress-Archive -Path .\publish\* -DestinationPath .\torch-server.zip
|
||||||
artifacts:
|
artifacts:
|
||||||
- path: torch-server.zip
|
- path: torch-server.zip
|
||||||
deploy:
|
deploy:
|
||||||
|
Reference in New Issue
Block a user