Patch steam timeout to 5 seconds to work around callback issues
This commit is contained in:
44
Torch.Server/Patches/ServerResponsePatch.cs
Normal file
44
Torch.Server/Patches/ServerResponsePatch.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -252,6 +252,7 @@
|
|||||||
<Compile Include="NativeMethods.cs" />
|
<Compile Include="NativeMethods.cs" />
|
||||||
<Compile Include="Initializer.cs" />
|
<Compile Include="Initializer.cs" />
|
||||||
<Compile Include="Patches\PromotePatch.cs" />
|
<Compile Include="Patches\PromotePatch.cs" />
|
||||||
|
<Compile Include="Patches\ServerResponsePatch.cs" />
|
||||||
<Compile Include="Patches\WorldLoadExceptionPatch.cs" />
|
<Compile Include="Patches\WorldLoadExceptionPatch.cs" />
|
||||||
<Compile Include="Properties\Annotations.cs" />
|
<Compile Include="Properties\Annotations.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
@@ -18,6 +18,7 @@ using Torch.API;
|
|||||||
using Torch.API.Managers;
|
using Torch.API.Managers;
|
||||||
using Torch.API.Session;
|
using Torch.API.Session;
|
||||||
using Torch.Commands;
|
using Torch.Commands;
|
||||||
|
using Torch.Managers.PatchManager;
|
||||||
using Torch.Mod;
|
using Torch.Mod;
|
||||||
using Torch.Mod.Messages;
|
using Torch.Mod.Messages;
|
||||||
using Torch.Server.Commands;
|
using Torch.Server.Commands;
|
||||||
@@ -164,6 +165,7 @@ namespace Torch.Server
|
|||||||
IsRunning = true;
|
IsRunning = true;
|
||||||
HasRun = true;
|
HasRun = true;
|
||||||
CanRun = false;
|
CanRun = false;
|
||||||
|
PatchManager.CommitInternal();
|
||||||
Log.Info("Starting server.");
|
Log.Info("Starting server.");
|
||||||
MySandboxGame.ConfigDedicated = DedicatedInstance.DedicatedConfig.Model;
|
MySandboxGame.ConfigDedicated = DedicatedInstance.DedicatedConfig.Model;
|
||||||
|
|
||||||
|
@@ -169,7 +169,7 @@ namespace Torch.Managers.PatchManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="Commit"/>
|
/// <inheritdoc cref="Commit"/>
|
||||||
internal static void CommitInternal()
|
public static void CommitInternal()
|
||||||
{
|
{
|
||||||
lock (_rewritePatterns)
|
lock (_rewritePatterns)
|
||||||
{
|
{
|
||||||
|
@@ -22,6 +22,7 @@ using Sandbox.Game.World;
|
|||||||
using Sandbox.Graphics.GUI;
|
using Sandbox.Graphics.GUI;
|
||||||
using SpaceEngineers.Game;
|
using SpaceEngineers.Game;
|
||||||
using SpaceEngineers.Game.GUI;
|
using SpaceEngineers.Game.GUI;
|
||||||
|
using Steamworks;
|
||||||
using Torch.Utils;
|
using Torch.Utils;
|
||||||
using VRage;
|
using VRage;
|
||||||
using VRage.Audio;
|
using VRage.Audio;
|
||||||
@@ -138,18 +139,6 @@ namespace Torch
|
|||||||
{
|
{
|
||||||
bool dedicated = true;
|
bool dedicated = true;
|
||||||
Environment.SetEnvironmentVariable("SteamAppId", _appSteamId.ToString());
|
Environment.SetEnvironmentVariable("SteamAppId", _appSteamId.ToString());
|
||||||
var service = MySteamGameService.Create(true, _appSteamId);
|
|
||||||
MyServiceManager.Instance.AddService<IMyGameService>(service);
|
|
||||||
var serviceInstance = MySteamUgcService.Create(_appSteamId, service);
|
|
||||||
MyServiceManager.Instance.AddService<IMyUGCService>(serviceInstance);
|
|
||||||
MyServiceManager.Instance.AddService(new MyNullMicrophone());
|
|
||||||
MySteamGameService.InitNetworking(dedicated, service);
|
|
||||||
if (!MyGameService.HasGameServer)
|
|
||||||
{
|
|
||||||
_log.Warn("Steam service is not running! Please reinstall dedicated server.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SpaceEngineersGame.SetupBasicGameInfo();
|
SpaceEngineersGame.SetupBasicGameInfo();
|
||||||
SpaceEngineersGame.SetupPerGameSettings();
|
SpaceEngineersGame.SetupPerGameSettings();
|
||||||
MyFinalBuildConstants.APP_VERSION = MyPerGameSettings.BasicGameInfo.GameVersion;
|
MyFinalBuildConstants.APP_VERSION = MyPerGameSettings.BasicGameInfo.GameVersion;
|
||||||
@@ -164,6 +153,22 @@ namespace Torch
|
|||||||
|
|
||||||
MyFileSystem.Reset();
|
MyFileSystem.Reset();
|
||||||
MyInitializer.InvokeBeforeRun(_appSteamId, _appName, _userDataPath);
|
MyInitializer.InvokeBeforeRun(_appSteamId, _appName, _userDataPath);
|
||||||
|
|
||||||
|
_log.Info("Initializing services");
|
||||||
|
var service = MySteamGameService.Create(true, _appSteamId);
|
||||||
|
//Type.GetType("VRage.Steam.MySteamService, VRage.Steam").GetProperty("IsActive").GetSetMethod(true).Invoke(service, new object[] {SteamAPI.Init()});
|
||||||
|
MyServiceManager.Instance.AddService<IMyGameService>(service);
|
||||||
|
var serviceInstance = MySteamUgcService.Create(_appSteamId, service);
|
||||||
|
MyServiceManager.Instance.AddService<IMyUGCService>(serviceInstance);
|
||||||
|
MyServiceManager.Instance.AddService(new MyNullMicrophone());
|
||||||
|
MySteamGameService.InitNetworking(dedicated, service);
|
||||||
|
if (!MyGameService.HasGameServer)
|
||||||
|
{
|
||||||
|
_log.Warn("Steam service is not running! Please reinstall dedicated server.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_log.Info("Services initialized");
|
||||||
MySandboxGame.InitMultithreading();
|
MySandboxGame.InitMultithreading();
|
||||||
// MyInitializer.InitCheckSum();
|
// MyInitializer.InitCheckSum();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user