diff --git a/Torch.Mod/TorchModCore.cs b/Torch.Mod/TorchModCore.cs
index 877ca8c..7767b2e 100644
--- a/Torch.Mod/TorchModCore.cs
+++ b/Torch.Mod/TorchModCore.cs
@@ -11,7 +11,7 @@ namespace Torch.Mod
[MySessionComponentDescriptor(MyUpdateOrder.AfterSimulation)]
public class TorchModCore : MySessionComponentBase
{
- public const ulong MOD_ID = 1406994352;
+ public const ulong MOD_ID = 2722000298;
private static bool _init;
public static bool Debug;
diff --git a/Torch.Server.Tests/Torch.Server.Tests.csproj b/Torch.Server.Tests/Torch.Server.Tests.csproj
index 60e82a6..3c02a7c 100644
--- a/Torch.Server.Tests/Torch.Server.Tests.csproj
+++ b/Torch.Server.Tests/Torch.Server.Tests.csproj
@@ -7,7 +7,7 @@
Properties
Torch.Server.Tests
Torch.Server.Tests
- v4.6.1
+ v4.8
512
@@ -104,4 +104,4 @@
-
+
\ No newline at end of file
diff --git a/Torch.Server.Tests/app.config b/Torch.Server.Tests/app.config
index a73892d..cf4f4e1 100644
--- a/Torch.Server.Tests/app.config
+++ b/Torch.Server.Tests/app.config
@@ -1,11 +1,11 @@
-
+
-
-
+
+
-
\ No newline at end of file
+
diff --git a/Torch.Server/Properties/Resources.Designer.cs b/Torch.Server/Properties/Resources.Designer.cs
index 9d38f2c..313aa89 100644
--- a/Torch.Server/Properties/Resources.Designer.cs
+++ b/Torch.Server/Properties/Resources.Designer.cs
@@ -19,7 +19,7 @@ namespace Torch.Server.Properties {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
diff --git a/Torch.Server/Properties/Settings.Designer.cs b/Torch.Server/Properties/Settings.Designer.cs
index 335c439..d0644e2 100644
--- a/Torch.Server/Properties/Settings.Designer.cs
+++ b/Torch.Server/Properties/Settings.Designer.cs
@@ -12,7 +12,7 @@ namespace Torch.Server.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.0.0.0")]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
diff --git a/Torch.Server/Torch.Server.csproj b/Torch.Server/Torch.Server.csproj
index 2f0d9eb..7bcdbdd 100644
--- a/Torch.Server/Torch.Server.csproj
+++ b/Torch.Server/Torch.Server.csproj
@@ -7,7 +7,7 @@
Properties
Torch.Server
Torch.Server
- v4.6.1
+ v4.8
512
{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
4
@@ -381,6 +381,7 @@
ResXFileCodeGenerator
Resources.Designer.cs
+
SettingsSingleFileGenerator
@@ -533,4 +534,4 @@
copy "$(SolutionDir)NLog.config" "$(TargetDir)" & copy "$(SolutionDir)NLog-user.config" "$(TargetDir)"
-
+
\ No newline at end of file
diff --git a/Torch.Server/app.config b/Torch.Server/app.config
new file mode 100644
index 0000000..3e0e37c
--- /dev/null
+++ b/Torch.Server/app.config
@@ -0,0 +1,3 @@
+
+
+
diff --git a/Torch.Server/packages.config b/Torch.Server/packages.config
index b1ff266..e04f668 100644
--- a/Torch.Server/packages.config
+++ b/Torch.Server/packages.config
@@ -1,6 +1,6 @@
-
+
diff --git a/Torch.Tests/Torch.Tests.csproj b/Torch.Tests/Torch.Tests.csproj
index 098c623..016e97b 100644
--- a/Torch.Tests/Torch.Tests.csproj
+++ b/Torch.Tests/Torch.Tests.csproj
@@ -7,7 +7,7 @@
Properties
Torch.Tests
Torch.Tests
- v4.6.1
+ v4.8
512
@@ -95,4 +95,4 @@
-
+
\ No newline at end of file
diff --git a/Torch.Tests/app.config b/Torch.Tests/app.config
index a73892d..cf4f4e1 100644
--- a/Torch.Tests/app.config
+++ b/Torch.Tests/app.config
@@ -1,11 +1,11 @@
-
+
-
-
+
+
-
\ No newline at end of file
+
diff --git a/Torch/Managers/PatchManager/AssemblyMemory.cs b/Torch/Managers/PatchManager/AssemblyMemory.cs
index 4504993..7af2479 100644
--- a/Torch/Managers/PatchManager/AssemblyMemory.cs
+++ b/Torch/Managers/PatchManager/AssemblyMemory.cs
@@ -30,6 +30,17 @@ namespace Torch.Managers.PatchManager
return handle.GetFunctionPointer().ToInt64();
}
+ internal static void UnprotectMemoryPage(long memory) {
+ if (NativeLibrary.IsWindows) {
+ var succ = NativeLibrary.VirtualProtect(
+ new IntPtr(memory), new UIntPtr(1),
+ NativeLibrary.Protection.PAGE_EXECUTE_READWRITE, out var _ignored);
+
+ if (!succ) {
+ throw new System.ComponentModel.Win32Exception();
+ }
+ }
+ }
// x64 ISA format:
diff --git a/Torch/Managers/PatchManager/DecoratedMethod.cs b/Torch/Managers/PatchManager/DecoratedMethod.cs
index a5b27a9..018b480 100644
--- a/Torch/Managers/PatchManager/DecoratedMethod.cs
+++ b/Torch/Managers/PatchManager/DecoratedMethod.cs
@@ -51,6 +51,7 @@ namespace Torch.Managers.PatchManager
_revertAddress = AssemblyMemory.GetMethodBodyStart(_method);
var newAddress = AssemblyMemory.GetMethodBodyStart(patch);
+ AssemblyMemory.UnprotectMemoryPage(_revertAddress);
_revertData = AssemblyMemory.WriteJump(_revertAddress, newAddress);
_pinnedPatch = GCHandle.Alloc(patch);
_log.Log(PrintMode != 0 ? LogLevel.Info : LogLevel.Debug,
diff --git a/Torch/Managers/PatchManager/NativeLibrary.cs b/Torch/Managers/PatchManager/NativeLibrary.cs
new file mode 100644
index 0000000..6df98d0
--- /dev/null
+++ b/Torch/Managers/PatchManager/NativeLibrary.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Torch.Managers.PatchManager {
+ internal static class NativeLibrary {
+ private static readonly HashSet WindowsPlatformIDSet = new HashSet
+ {
+ PlatformID.Win32NT, PlatformID.Win32S, PlatformID.Win32Windows, PlatformID.WinCE
+ };
+
+ public static bool IsWindows {
+ get {
+ return WindowsPlatformIDSet.Contains(Environment.OSVersion.Platform);
+ }
+ }
+
+ [Flags]
+ public enum Protection {
+ PAGE_NOACCESS = 0x01,
+ PAGE_READONLY = 0x02,
+ PAGE_READWRITE = 0x04,
+ PAGE_WRITECOPY = 0x08,
+ PAGE_EXECUTE = 0x10,
+ PAGE_EXECUTE_READ = 0x20,
+ PAGE_EXECUTE_READWRITE = 0x40,
+ PAGE_EXECUTE_WRITECOPY = 0x80,
+ PAGE_GUARD = 0x100,
+ PAGE_NOCACHE = 0x200,
+ PAGE_WRITECOMBINE = 0x400
+ }
+
+ [DllImport("kernel32.dll")]
+ public static extern bool VirtualProtect(IntPtr lpAddress, UIntPtr dwSize,
+ Protection flNewProtect, out Protection lpflOldProtect);
+ }
+}
diff --git a/Torch/Torch.csproj b/Torch/Torch.csproj
index 982c836..318535a 100644
--- a/Torch/Torch.csproj
+++ b/Torch/Torch.csproj
@@ -1,4 +1,4 @@
-
+
@@ -7,7 +7,7 @@
Properties
Torch
Torch
- v4.6.1
+ v4.8
512
@@ -234,6 +234,7 @@
+
@@ -377,4 +378,4 @@
-
+
\ No newline at end of file
diff --git a/Torch/app.config b/Torch/app.config
index a73892d..cf4f4e1 100644
--- a/Torch/app.config
+++ b/Torch/app.config
@@ -1,11 +1,11 @@
-
+
-
-
+
+
-
\ No newline at end of file
+
diff --git a/Torch/packages.config b/Torch/packages.config
index 7f9ae61..e28ce57 100644
--- a/Torch/packages.config
+++ b/Torch/packages.config
@@ -1,6 +1,6 @@
-
+