Compare commits

..

19 Commits

Author SHA1 Message Date
z__
879a373e6a added possibility to call SetConfiguration again if needed 2022-02-04 14:42:37 +07:00
z__
ec1b017946 added nlog custom targets assemblies loading 2022-02-04 14:33:32 +07:00
z__
cf75210304 fixed game analytics logger crash 2022-02-04 13:44:04 +07:00
z__
3696f18714 move nlog config to instance and move default to resources 2022-02-04 13:25:56 +07:00
z__
1f7e4e869d final fixes for warfare 2 2022-02-04 12:09:17 +07:00
z__
ba5b611994 add STA thread back, not being added automatically on local build 2022-02-04 10:38:47 +07:00
z__
2bcf79efdd to trigger autobuild to fix warfare 2 update 2022-02-04 09:47:22 +07:00
z__
d5c101bf19 i believe we're done 2022-02-03 19:49:16 +07:00
z__
e9841b4de1 now should work 2022-02-03 19:43:54 +07:00
z__
aea0011683 maybe 2022-02-03 19:41:13 +07:00
z__
d10528f9fe fixed RID 2022-02-03 19:39:07 +07:00
z__
66ea4d7307 build script update 2022-02-03 19:34:06 +07:00
z__
f6ce40a854 again updated ci buildfile 2022-02-03 19:04:42 +07:00
zznty
bd62d31298 trash dockerfile, it will be on separate repo 2022-02-03 18:50:15 +07:00
z__
b1cf5fb638 i wanna believe this is the last for appveyor.yml 2022-02-03 18:44:02 +07:00
z__
1d6a2a9a60 fix fucking github's new lines 2022-02-03 18:41:55 +07:00
zznty
455be2393e fix build error 2022-02-03 18:38:49 +07:00
zznty
6131a9003b corrently assign version on publish 2022-02-03 18:35:50 +07:00
zznty
2a17c4bc09 Update appveyor.yml
it cannot cache if size larger than 1gb 
so delete unnecessary files
2022-02-03 18:29:25 +07:00
9 changed files with 105 additions and 53 deletions

View File

@@ -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"]

View File

@@ -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());
} }
} }

View File

@@ -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,15 +45,26 @@ 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");
if (File.Exists(oldTorchCfg)) if (File.Exists(oldTorchCfg))
File.Move(oldTorchCfg, torchCfg, true); File.Move(oldTorchCfg, torchCfg, true);
Target.Register<LogViewerTarget>(nameof(LogViewerTarget));
TorchLogManager.SetConfiguration(new XmlLoggingConfiguration(newNlog));
var config = Persistent<TorchConfig>.Load(torchCfg); var config = Persistent<TorchConfig>.Load(torchCfg);
config.Data.InstanceName = instanceName; config.Data.InstanceName = instanceName;
config.Data.InstancePath = instancePath; config.Data.InstancePath = instancePath;
@@ -70,6 +81,11 @@ namespace Torch.Server
if (!initializer.Initialize(args)) if (!initializer.Initialize(args))
Environment.Exit(1); Environment.Exit(1);
TorchLauncher.Launch(workingDir, binDir);
TorchLogManager.SetConfiguration(TorchLogManager.Configuration,
Environment.GetEnvironmentVariable("TORCH_LOG_EXTENSIONS_PATH") ??
Path.Combine(instancePath, "LoggingExtensions"));
CopyNative(binDir); CopyNative(binDir);
initializer.Run(isService, instanceName, instancePath); initializer.Run(isService, instanceName, instancePath);
} }

View File

@@ -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>

View File

@@ -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()

View File

@@ -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)),

View File

@@ -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"),

View File

@@ -0,0 +1,47 @@
using System;
using System.IO;
using System.Runtime.Loader;
using NLog;
using NLog.Config;
namespace Torch.Utils;
public static class TorchLogManager
{
private static AssemblyLoadContext LoadContext;
public static LoggingConfiguration Configuration { get; private set; }
public static void SetConfiguration(LoggingConfiguration configuration, string extensionsDir = null)
{
Configuration = configuration;
LogManager.Setup()
.SetupExtensions(builder =>
{
if (extensionsDir is null || !Directory.Exists(extensionsDir))
return;
if (LoadContext is null)
{
LoadContext = new("TorchLog");
foreach (var file in Directory.EnumerateFiles(extensionsDir, "*.dll", SearchOption.AllDirectories))
{
builder.RegisterAssembly(LoadContext.LoadFromAssemblyPath(file));
}
return;
}
foreach (var assembly in LoadContext.Assemblies)
{
builder.RegisterAssembly(assembly);
}
})
.SetupLogFactory(builder => builder.SetThrowConfigExceptions(true))
.LoadConfiguration(configuration);
LogManager.ReconfigExistingLoggers();
}
public static void RestoreGlobalConfiguration()
{
LogManager.Configuration = Configuration;
LogManager.ReconfigExistingLoggers();
}
}

View File

@@ -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: