Patch steam timeout to 5 seconds to work around callback issues

This commit is contained in:
John Gross
2020-11-25 16:44:01 -08:00
parent aa5963b29b
commit f7a63f17cc
5 changed files with 65 additions and 13 deletions

View File

@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using NLog;
using Sandbox.Engine.Multiplayer;
using Sandbox.Game.World;
using Torch.API.Managers;
using Torch.Managers.PatchManager;
using Torch.Managers.PatchManager.MSIL;
using Torch.Server.Managers;
using VRage.Game.ModAPI;
namespace Torch.Patches
{
[PatchShim]
public static class ServerResponsePatch
{
private static Logger _log = LogManager.GetCurrentClassLogger();
public static void Patch(PatchContext ctx)
{
var transpiler = typeof(ServerResponsePatch).GetMethod(nameof(Transpile), BindingFlags.Public | BindingFlags.Static);
ctx.GetPattern(typeof(MyDedicatedServerBase).GetMethod("Initialize", BindingFlags.NonPublic | BindingFlags.Instance))
.Transpilers.Add(transpiler);
_log.Info("Patching Steam response polling");
}
public static IEnumerable<MsilInstruction> Transpile(IEnumerable<MsilInstruction> instructions)
{
// Reduce response timeout from 100 seconds to 5 seconds.
foreach (var instruction in instructions)
{
if (instruction.OpCode == OpCodes.Ldc_I4 && instruction.Operand is MsilOperandInline.MsilOperandInt32 inlineI32 && inlineI32.Value == 1000)
{
_log.Info("Patching Steam response timeout to 5 seconds");
inlineI32.Value = 50;
}
yield return instruction;
}
}
}
}

View File

@@ -252,6 +252,7 @@
<Compile Include="NativeMethods.cs" />
<Compile Include="Initializer.cs" />
<Compile Include="Patches\PromotePatch.cs" />
<Compile Include="Patches\ServerResponsePatch.cs" />
<Compile Include="Patches\WorldLoadExceptionPatch.cs" />
<Compile Include="Properties\Annotations.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

View File

@@ -18,6 +18,7 @@ using Torch.API;
using Torch.API.Managers;
using Torch.API.Session;
using Torch.Commands;
using Torch.Managers.PatchManager;
using Torch.Mod;
using Torch.Mod.Messages;
using Torch.Server.Commands;
@@ -164,6 +165,7 @@ namespace Torch.Server
IsRunning = true;
HasRun = true;
CanRun = false;
PatchManager.CommitInternal();
Log.Info("Starting server.");
MySandboxGame.ConfigDedicated = DedicatedInstance.DedicatedConfig.Model;