diff --git a/Piston.sln b/Piston.sln
index c2561cf..6831dd3 100644
--- a/Piston.sln
+++ b/Piston.sln
@@ -5,16 +5,52 @@ VisualStudioVersion = 15.0.25618.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Piston", "Piston\Piston.csproj", "{7E01635C-3B67-472E-BCD6-C5539564F214}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PistonAPI", "PistonAPI\PistonAPI.csproj", "{FBA5D932-6254-4A1E-BAF4-E229FA94E3C2}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PistonClient", "PistonClient\PistonClient.csproj", "{E36DF745-260B-4956-A2E8-09F08B2E7161}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PistonServer", "PistonServer\PistonServer.csproj", "{CA50886B-7B22-4CD8-93A0-C06F38D4F77D}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
+ Debug|x64 = Debug|x64
Release|Any CPU = Release|Any CPU
+ Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7E01635C-3B67-472E-BCD6-C5539564F214}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7E01635C-3B67-472E-BCD6-C5539564F214}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {7E01635C-3B67-472E-BCD6-C5539564F214}.Debug|x64.ActiveCfg = Debug|x64
+ {7E01635C-3B67-472E-BCD6-C5539564F214}.Debug|x64.Build.0 = Debug|x64
{7E01635C-3B67-472E-BCD6-C5539564F214}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7E01635C-3B67-472E-BCD6-C5539564F214}.Release|Any CPU.Build.0 = Release|Any CPU
+ {7E01635C-3B67-472E-BCD6-C5539564F214}.Release|x64.ActiveCfg = Release|x64
+ {7E01635C-3B67-472E-BCD6-C5539564F214}.Release|x64.Build.0 = Release|x64
+ {FBA5D932-6254-4A1E-BAF4-E229FA94E3C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {FBA5D932-6254-4A1E-BAF4-E229FA94E3C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {FBA5D932-6254-4A1E-BAF4-E229FA94E3C2}.Debug|x64.ActiveCfg = Debug|x64
+ {FBA5D932-6254-4A1E-BAF4-E229FA94E3C2}.Debug|x64.Build.0 = Debug|x64
+ {FBA5D932-6254-4A1E-BAF4-E229FA94E3C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {FBA5D932-6254-4A1E-BAF4-E229FA94E3C2}.Release|Any CPU.Build.0 = Release|Any CPU
+ {FBA5D932-6254-4A1E-BAF4-E229FA94E3C2}.Release|x64.ActiveCfg = Release|x64
+ {FBA5D932-6254-4A1E-BAF4-E229FA94E3C2}.Release|x64.Build.0 = Release|x64
+ {E36DF745-260B-4956-A2E8-09F08B2E7161}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {E36DF745-260B-4956-A2E8-09F08B2E7161}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {E36DF745-260B-4956-A2E8-09F08B2E7161}.Debug|x64.ActiveCfg = Debug|x64
+ {E36DF745-260B-4956-A2E8-09F08B2E7161}.Debug|x64.Build.0 = Debug|x64
+ {E36DF745-260B-4956-A2E8-09F08B2E7161}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {E36DF745-260B-4956-A2E8-09F08B2E7161}.Release|Any CPU.Build.0 = Release|Any CPU
+ {E36DF745-260B-4956-A2E8-09F08B2E7161}.Release|x64.ActiveCfg = Release|x64
+ {E36DF745-260B-4956-A2E8-09F08B2E7161}.Release|x64.Build.0 = Release|x64
+ {CA50886B-7B22-4CD8-93A0-C06F38D4F77D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {CA50886B-7B22-4CD8-93A0-C06F38D4F77D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {CA50886B-7B22-4CD8-93A0-C06F38D4F77D}.Debug|x64.ActiveCfg = Debug|x64
+ {CA50886B-7B22-4CD8-93A0-C06F38D4F77D}.Debug|x64.Build.0 = Debug|x64
+ {CA50886B-7B22-4CD8-93A0-C06F38D4F77D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {CA50886B-7B22-4CD8-93A0-C06F38D4F77D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {CA50886B-7B22-4CD8-93A0-C06F38D4F77D}.Release|x64.ActiveCfg = Release|x64
+ {CA50886B-7B22-4CD8-93A0-C06F38D4F77D}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/Piston/Logger.cs b/Piston/Logger.cs
new file mode 100644
index 0000000..0f7ceef
--- /dev/null
+++ b/Piston/Logger.cs
@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Sandbox;
+using VRage.Utils;
+
+namespace Piston
+{
+ public static class Logger
+ {
+ public const string Prefix = "[PISTON]";
+
+ public static void Write(string message)
+ {
+ var msg = $"{Prefix}: {message}";
+ MySandboxGame.Log.WriteLineAndConsole(msg);
+ if (!MySandboxGame.Log.LogEnabled)
+ {
+ try
+ {
+ MySandboxGame.Log.AppendToClosedLog(msg);
+ }
+ catch (Exception) { }
+ }
+ }
+ }
+}
diff --git a/Piston/MyPlayerCollectionExtensions.cs b/Piston/MyPlayerCollectionExtensions.cs
new file mode 100644
index 0000000..a1c77c1
--- /dev/null
+++ b/Piston/MyPlayerCollectionExtensions.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Sandbox.Game.Multiplayer;
+using Sandbox.Game.World;
+
+namespace Piston
+{
+ public static class MyPlayerCollectionExtensions
+ {
+ public static MyPlayer TryGetPlayerBySteamId(this MyPlayerCollection collection, ulong steamId)
+ {
+ var id = collection.GetAllPlayers().FirstOrDefault(x => x.SteamId == steamId);
+ return id == default(MyPlayer.PlayerId) ? null : collection.GetPlayerById(id);
+ }
+ }
+}
diff --git a/Piston/Piston.csproj b/Piston/Piston.csproj
index 946d6b2..1ec8ac5 100644
--- a/Piston/Piston.csproj
+++ b/Piston/Piston.csproj
@@ -1,16 +1,17 @@
-
+
Debug
AnyCPU
- 7e01635c-3b67-472e-bcd6-c5539564f214
+ {7E01635C-3B67-472E-BCD6-C5539564F214}
Library
Properties
Piston
Piston
- v4.5.2
+ v4.6.1
512
+
true
@@ -29,26 +30,99 @@
prompt
4
+
+ true
+ bin\x64\Debug\
+ DEBUG;TRACE
+ full
+ x64
+ prompt
+ MinimumRecommendedRules.ruleset
+
+
+ bin\x64\Release\
+ TRACE
+ true
+ pdbonly
+ x64
+ prompt
+ MinimumRecommendedRules.ruleset
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+ C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\Sandbox.Common.dll
+
+
+ C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\Sandbox.Game.dll
+
+
+ C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\Sandbox.Graphics.dll
+
+
+ C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\SpaceEngineers.Game.dll
+
+
+ C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\SpaceEngineers.ObjectBuilders.dll
+
+
+ C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\SpaceEngineers.ObjectBuilders.XmlSerializers.dll
+
+
+
+
+
+
+
+
+
+
+ C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.dll
+
+
+ C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Audio.dll
+
+
+ C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Game.dll
+
+
+ C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Game.XmlSerializers.dll
+
+
+ C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Input.dll
+
+
+ C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Library.dll
+
+
+ C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Math.dll
+
+
+ C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Native.dll
+
+
+ C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.OpenVRWrapper.dll
+
+
+ C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Render.dll
+
+
+ C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Render11.dll
+
+
+ C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Scripting.dll
+
-
+
+
+
+
+ {fba5d932-6254-4a1e-baf4-e229fa94e3c2}
+ PistonAPI
+
+
-
-
+
\ No newline at end of file
diff --git a/Piston/PluginManager.cs b/Piston/PluginManager.cs
new file mode 100644
index 0000000..76a3e9d
--- /dev/null
+++ b/Piston/PluginManager.cs
@@ -0,0 +1,135 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using PistonAPI;
+using Sandbox;
+using VRage.Plugins;
+using VRage.Collections;
+using VRage.Library.Collections;
+
+namespace Piston
+{
+ public class PluginManager
+ {
+ //TODO: Disable reloading if the plugin has static elements because they prevent a full reload.
+
+ public static PluginManager Static { get; } = new PluginManager();
+ public ListReader Plugins => MyPlugins.Plugins;
+
+ private List _plugins;
+ public const string PluginDir = "Plugins";
+
+ private PluginManager()
+ {
+ if (!Directory.Exists(PluginDir))
+ Directory.CreateDirectory(PluginDir);
+
+ GetPluginList();
+ }
+
+ private void GetPluginList()
+ {
+ _plugins = typeof(MyPlugins).GetField("m_plugins", BindingFlags.Static | BindingFlags.NonPublic)?.GetValue(null) as List;
+ if (_plugins == null)
+ {
+ typeof(MyPlugins).TypeInitializer.Invoke(null, null);
+ GetPluginList();
+ }
+ }
+
+ ///
+ /// Load a plugin into the game.
+ ///
+ ///
+ public void LoadPlugin(IPlugin plugin)
+ {
+ plugin.Init(MySandboxGame.Static);
+ _plugins.Add(plugin);
+ }
+
+ ///
+ /// Get the names of all the subfolders in the Plugins directory.
+ ///
+ ///
+ public string[] GetPluginFolders()
+ {
+ var dirs = Directory.GetDirectories(PluginDir);
+ for (var i = 0; i < dirs.Length; i++)
+ {
+ dirs[i] = dirs[i].Substring(PluginDir.Length + 1);
+ }
+
+ return dirs;
+ }
+
+ ///
+ /// Load all plugins in the specified folder.
+ ///
+ /// Folder in the directory
+ public void LoadPluginFolder(string folderName)
+ {
+ var relativeDir = Path.Combine(PluginDir, folderName);
+ if (!Directory.Exists(relativeDir))
+ throw new FileNotFoundException($"Plugin {folderName} does not exist in the Plugins folder.");
+
+ var fileNames = Directory.GetFiles(relativeDir, "*.dll");
+
+ foreach (var fileName in fileNames)
+ {
+ var fullPath = Path.Combine(Directory.GetCurrentDirectory(), fileName);
+ var asm = Assembly.LoadFrom(fullPath);
+
+ foreach (var type in asm.GetTypes())
+ {
+ if (type.GetInterfaces().Contains(typeof(IPlugin)))
+ {
+ var inst = Activator.CreateInstance(type);
+ LoadPlugin((IPlugin)inst);
+ }
+ }
+ }
+ }
+
+ ///
+ /// Unload a plugin from the game.
+ ///
+ ///
+ public void UnloadPlugin(IPlugin plugin)
+ {
+ _plugins.Remove(plugin);
+ plugin.Dispose();
+ }
+
+ ///
+ /// Reload a plugin.
+ ///
+ ///
+ /// Reload a non-Piston plugin
+ public void ReloadPlugin(IPlugin plugin, bool forceNonPiston = false)
+ {
+ var p = plugin as IPistonPlugin;
+ if (p == null && forceNonPiston)
+ {
+ plugin.Dispose();
+ plugin.Init(MySandboxGame.Static);
+ }
+ else
+ {
+ p?.Reload();
+ }
+ }
+
+ public void ReloadAll()
+ {
+ foreach (var plugin in _plugins)
+ {
+ var p = plugin as IPistonPlugin;
+ p?.Reload();
+ }
+ }
+ }
+}
diff --git a/PistonAPI/IPistonPlugin.cs b/PistonAPI/IPistonPlugin.cs
new file mode 100644
index 0000000..97f547c
--- /dev/null
+++ b/PistonAPI/IPistonPlugin.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Security.Cryptography.X509Certificates;
+using System.Text;
+using System.Threading.Tasks;
+using VRage.Plugins;
+
+namespace PistonAPI
+{
+ public interface IPistonPlugin : IPlugin
+ {
+ string Name { get; }
+ void Reload();
+ }
+}
diff --git a/Piston/Class1.cs b/PistonAPI/PistonAPI.cs
similarity index 71%
rename from Piston/Class1.cs
rename to PistonAPI/PistonAPI.cs
index 9f6dbdd..d25bed9 100644
--- a/Piston/Class1.cs
+++ b/PistonAPI/PistonAPI.cs
@@ -4,9 +4,10 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
-namespace Piston
+namespace PistonAPI
{
- public class Class1
+ public static class PistonAPI
{
+
}
}
diff --git a/PistonAPI/PistonAPI.csproj b/PistonAPI/PistonAPI.csproj
new file mode 100644
index 0000000..3b74a12
--- /dev/null
+++ b/PistonAPI/PistonAPI.csproj
@@ -0,0 +1,77 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {FBA5D932-6254-4A1E-BAF4-E229FA94E3C2}
+ Library
+ Properties
+ PistonAPI
+ PistonAPI
+ v4.6.1
+ 512
+
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+ true
+ bin\x64\Debug\
+ DEBUG;TRACE
+ full
+ x64
+ prompt
+ MinimumRecommendedRules.ruleset
+
+
+ bin\x64\Release\
+ TRACE
+ true
+ pdbonly
+ x64
+ prompt
+ MinimumRecommendedRules.ruleset
+
+
+
+
+
+
+
+
+
+
+
+ C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.dll
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/PistonAPI/Properties/AssemblyInfo.cs b/PistonAPI/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..c198d75
--- /dev/null
+++ b/PistonAPI/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("PistonAPI")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("PistonAPI")]
+[assembly: AssemblyCopyright("Copyright © 2016")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("fba5d932-6254-4a1e-baf4-e229fa94e3c2")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/PistonClient/App.config b/PistonClient/App.config
new file mode 100644
index 0000000..bae5d6d
--- /dev/null
+++ b/PistonClient/App.config
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/PistonClient/App.xaml b/PistonClient/App.xaml
new file mode 100644
index 0000000..ffc6794
--- /dev/null
+++ b/PistonClient/App.xaml
@@ -0,0 +1,9 @@
+
+
+
+
+
diff --git a/PistonClient/App.xaml.cs b/PistonClient/App.xaml.cs
new file mode 100644
index 0000000..efb1a1a
--- /dev/null
+++ b/PistonClient/App.xaml.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Configuration;
+using System.Data;
+using System.Linq;
+using System.Threading.Tasks;
+using System.Windows;
+
+namespace PistonClient
+{
+ ///
+ /// Interaction logic for App.xaml
+ ///
+ public partial class App : Application
+ {
+ }
+}
diff --git a/PistonClient/MainWindow.xaml b/PistonClient/MainWindow.xaml
new file mode 100644
index 0000000..0af9433
--- /dev/null
+++ b/PistonClient/MainWindow.xaml
@@ -0,0 +1,12 @@
+
+
+
+
+
diff --git a/PistonClient/MainWindow.xaml.cs b/PistonClient/MainWindow.xaml.cs
new file mode 100644
index 0000000..3229824
--- /dev/null
+++ b/PistonClient/MainWindow.xaml.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace PistonClient
+{
+ ///
+ /// Interaction logic for MainWindow.xaml
+ ///
+ public partial class MainWindow : Window
+ {
+ public MainWindow()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/PistonClient/PistonClient.csproj b/PistonClient/PistonClient.csproj
new file mode 100644
index 0000000..912e140
--- /dev/null
+++ b/PistonClient/PistonClient.csproj
@@ -0,0 +1,127 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {E36DF745-260B-4956-A2E8-09F08B2E7161}
+ WinExe
+ Properties
+ PistonClient
+ PistonClient
+ v4.6.1
+ 512
+ {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
+ 4
+ true
+
+
+
+ AnyCPU
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ AnyCPU
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+ true
+ bin\x64\Debug\
+ DEBUG;TRACE
+ full
+ x64
+ prompt
+ MinimumRecommendedRules.ruleset
+ true
+
+
+ bin\x64\Release\
+ TRACE
+ true
+ pdbonly
+ x64
+ prompt
+ MinimumRecommendedRules.ruleset
+ true
+
+
+
+
+
+
+
+
+
+
+
+ 4.0
+
+
+
+
+
+
+
+ MSBuild:Compile
+ Designer
+
+
+ MSBuild:Compile
+ Designer
+
+
+ App.xaml
+ Code
+
+
+ MainWindow.xaml
+ Code
+
+
+
+
+ Code
+
+
+ True
+ True
+ Resources.resx
+
+
+ True
+ Settings.settings
+ True
+
+
+ ResXFileCodeGenerator
+ Resources.Designer.cs
+
+
+ SettingsSingleFileGenerator
+ Settings.Designer.cs
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/PistonClient/Properties/AssemblyInfo.cs b/PistonClient/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..7b43e53
--- /dev/null
+++ b/PistonClient/Properties/AssemblyInfo.cs
@@ -0,0 +1,55 @@
+using System.Reflection;
+using System.Resources;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Windows;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("PistonClient")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("PistonClient")]
+[assembly: AssemblyCopyright("Copyright © 2016")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+//In order to begin building localizable applications, set
+//CultureYouAreCodingWith in your .csproj file
+//inside a . For example, if you are using US english
+//in your source files, set the to en-US. Then uncomment
+//the NeutralResourceLanguage attribute below. Update the "en-US" in
+//the line below to match the UICulture setting in the project file.
+
+//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
+
+
+[assembly: ThemeInfo(
+ ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
+ //(used if a resource is not found in the page,
+ // or application resource dictionaries)
+ ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
+ //(used if a resource is not found in the page,
+ // app, or any theme specific resource dictionaries)
+)]
+
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/PistonClient/Properties/Resources.Designer.cs b/PistonClient/Properties/Resources.Designer.cs
new file mode 100644
index 0000000..7ff0a64
--- /dev/null
+++ b/PistonClient/Properties/Resources.Designer.cs
@@ -0,0 +1,63 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.42000
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+namespace PistonClient.Properties {
+ using System;
+
+
+ ///
+ /// A strongly-typed resource class, for looking up localized strings, etc.
+ ///
+ // This class was auto-generated by the StronglyTypedResourceBuilder
+ // 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.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ internal class Resources {
+
+ private static global::System.Resources.ResourceManager resourceMan;
+
+ private static global::System.Globalization.CultureInfo resourceCulture;
+
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+ internal Resources() {
+ }
+
+ ///
+ /// Returns the cached ResourceManager instance used by this class.
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if (object.ReferenceEquals(resourceMan, null)) {
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("PistonClient.Properties.Resources", typeof(Resources).Assembly);
+ resourceMan = temp;
+ }
+ return resourceMan;
+ }
+ }
+
+ ///
+ /// Overrides the current thread's CurrentUICulture property for all
+ /// resource lookups using this strongly typed resource class.
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
+ return resourceCulture;
+ }
+ set {
+ resourceCulture = value;
+ }
+ }
+ }
+}
diff --git a/PistonClient/Properties/Resources.resx b/PistonClient/Properties/Resources.resx
new file mode 100644
index 0000000..af7dbeb
--- /dev/null
+++ b/PistonClient/Properties/Resources.resx
@@ -0,0 +1,117 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/PistonClient/Properties/Settings.Designer.cs b/PistonClient/Properties/Settings.Designer.cs
new file mode 100644
index 0000000..2a893da
--- /dev/null
+++ b/PistonClient/Properties/Settings.Designer.cs
@@ -0,0 +1,26 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.42000
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+namespace PistonClient.Properties {
+
+
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.0.0.0")]
+ internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
+
+ private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
+
+ public static Settings Default {
+ get {
+ return defaultInstance;
+ }
+ }
+ }
+}
diff --git a/PistonClient/Properties/Settings.settings b/PistonClient/Properties/Settings.settings
new file mode 100644
index 0000000..033d7a5
--- /dev/null
+++ b/PistonClient/Properties/Settings.settings
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/PistonServer/ChatControl.xaml b/PistonServer/ChatControl.xaml
new file mode 100644
index 0000000..7f8727a
--- /dev/null
+++ b/PistonServer/ChatControl.xaml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
diff --git a/PistonServer/ChatControl.xaml.cs b/PistonServer/ChatControl.xaml.cs
new file mode 100644
index 0000000..2942407
--- /dev/null
+++ b/PistonServer/ChatControl.xaml.cs
@@ -0,0 +1,70 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+using System.Windows.Threading;
+using Piston;
+using Sandbox;
+using Sandbox.Engine.Multiplayer;
+using Sandbox.Game.World;
+
+namespace PistonServer
+{
+ ///
+ /// Interaction logic for ChatControl.xaml
+ ///
+ public partial class ChatControl : UserControl
+ {
+ public event Action MessageEntered;
+ public ChatControl()
+ {
+ InitializeComponent();
+ }
+
+ public void MessageReceived(ulong steamId, string message, SteamSDK.ChatEntryTypeEnum chatType)
+ {
+ //Messages sent from server loop back around.
+ if (steamId == MyMultiplayer.Static.ServerId)
+ return;
+
+ var name = MySession.Static.Players.TryGetPlayerBySteamId(steamId)?.DisplayName ?? "";
+ Dispatcher.Invoke(() => AddMessage(name, message), DispatcherPriority.Normal);
+ }
+
+ public void AddMessage(string sender, string message)
+ {
+ Chat.Text += $"{DateTime.Now.ToLongTimeString()} | {sender}: {message}\n";
+ }
+
+ private void SendButton_Click(object sender, RoutedEventArgs e)
+ {
+ OnMessageEntered();
+
+ }
+
+ private void OnMessageEntered()
+ {
+ var text = Message.Text;
+ AddMessage("Server", text);
+ MySandboxGame.Static.Invoke(() => MyMultiplayer.Static.SendChatMessage(text));
+ MessageEntered?.Invoke(Message.Text);
+ Message.Text = "";
+ }
+
+ private void Message_OnKeyDown(object sender, KeyEventArgs e)
+ {
+ if (e.Key == Key.Enter)
+ OnMessageEntered();
+ }
+ }
+}
diff --git a/PistonServer/MainWindow.xaml b/PistonServer/MainWindow.xaml
new file mode 100644
index 0000000..b5b0f73
--- /dev/null
+++ b/PistonServer/MainWindow.xaml
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/PistonServer/MainWindow.xaml.cs b/PistonServer/MainWindow.xaml.cs
new file mode 100644
index 0000000..4e521b6
--- /dev/null
+++ b/PistonServer/MainWindow.xaml.cs
@@ -0,0 +1,77 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Timers;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace PistonServer
+{
+ ///
+ /// Interaction logic for MainWindow.xaml
+ ///
+ public partial class MainWindow : Window
+ {
+ private DateTime startTime;
+ private Timer uiUpdate = new Timer
+ {
+ Interval = 1000,
+ AutoReset = true,
+ };
+
+ public MainWindow()
+ {
+ InitializeComponent();
+ startTime = DateTime.Now;
+ uiUpdate.Elapsed += UiUpdate_Elapsed;
+
+ TabControl.Items.Add(new TabItem());
+ }
+
+ private void UiUpdate_Elapsed(object sender, ElapsedEventArgs e)
+ {
+ UpdateUptime();
+ }
+
+ private void UpdateUptime()
+ {
+ var currentTime = DateTime.Now;
+ var uptime = currentTime - startTime;
+
+ Dispatcher.Invoke(() => LabelUptime.Content = $"Uptime: {uptime.Days}d {uptime.Hours}h {uptime.Minutes}m");
+ }
+
+ private void BtnStart_Click(object sender, RoutedEventArgs e)
+ {
+ startTime = DateTime.Now;
+ Chat.IsEnabled = true;
+ Players.IsEnabled = true;
+ ((Button) sender).IsEnabled = false;
+ BtnStop.IsEnabled = true;
+ uiUpdate.Start();
+ ServerManager.Static.StartServerThread();
+ }
+
+ private void BtnStop_Click(object sender, RoutedEventArgs e)
+ {
+ Chat.IsEnabled = false;
+ Players.IsEnabled = false;
+ ((Button) sender).IsEnabled = false;
+ //HACK: Uncomment when restarting is possible.
+ //BtnStart.IsEnabled = true;
+ uiUpdate.Stop();
+ ServerManager.Static.StopServer();
+ }
+ }
+}
diff --git a/PistonServer/PistonServer.csproj b/PistonServer/PistonServer.csproj
new file mode 100644
index 0000000..90eba43
--- /dev/null
+++ b/PistonServer/PistonServer.csproj
@@ -0,0 +1,173 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {CA50886B-7B22-4CD8-93A0-C06F38D4F77D}
+ Exe
+ Properties
+ PistonServer
+ PistonServer
+ v4.6.1
+ 512
+ {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
+ 4
+ true
+
+
+
+ AnyCPU
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ AnyCPU
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+ true
+ bin\x64\Debug\
+ DEBUG;TRACE
+ full
+ x64
+ prompt
+ MinimumRecommendedRules.ruleset
+ true
+
+
+ bin\x64\Release\
+ TRACE
+ true
+ pdbonly
+ x64
+ prompt
+ MinimumRecommendedRules.ruleset
+ true
+
+
+
+
+
+
+ False
+ C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\DedicatedServer64\HavokWrapper.dll
+
+
+ False
+ C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\DedicatedServer64\Sandbox.Game.dll
+
+
+ C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\DedicatedServer64\SpaceEngineersDedicated.exe
+
+
+ False
+ C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\SteamSDK.dll
+
+
+
+
+
+
+
+
+
+
+ 4.0
+
+
+ False
+ C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.dll
+
+
+ False
+ C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\DedicatedServer64\VRage.Game.dll
+
+
+ False
+ C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Input.dll
+
+
+ False
+ C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Library.dll
+
+
+
+
+
+
+
+ ChatControl.xaml
+
+
+ MainWindow.xaml
+
+
+ PlayersControl.xaml
+
+
+
+
+
+
+ Code
+
+
+ True
+ True
+ Resources.resx
+
+
+ True
+ Settings.settings
+ True
+
+
+ ResXFileCodeGenerator
+ Resources.Designer.cs
+
+
+ SettingsSingleFileGenerator
+ Settings.Designer.cs
+
+
+
+
+
+ {7e01635c-3b67-472e-bcd6-c5539564f214}
+ Piston
+
+
+
+
+ MSBuild:Compile
+ Designer
+
+
+ MSBuild:Compile
+ Designer
+
+
+ MSBuild:Compile
+ Designer
+
+
+
+
+
\ No newline at end of file
diff --git a/PistonServer/PlayersControl.xaml b/PistonServer/PlayersControl.xaml
new file mode 100644
index 0000000..31843bd
--- /dev/null
+++ b/PistonServer/PlayersControl.xaml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
diff --git a/PistonServer/PlayersControl.xaml.cs b/PistonServer/PlayersControl.xaml.cs
new file mode 100644
index 0000000..f6750bd
--- /dev/null
+++ b/PistonServer/PlayersControl.xaml.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace PistonServer
+{
+ ///
+ /// Interaction logic for PlayersControl.xaml
+ ///
+ public partial class PlayersControl : UserControl
+ {
+ public PlayersControl()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/PistonServer/Program.cs b/PistonServer/Program.cs
new file mode 100644
index 0000000..b0daa39
--- /dev/null
+++ b/PistonServer/Program.cs
@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Threading;
+using Piston;
+
+namespace PistonServer
+{
+ public static class Program
+ {
+ public static MainWindow UserInterface = new MainWindow();
+ public static Dispatcher MainDispatcher { get; private set; }
+
+ [STAThread]
+ public static void Main(string[] args)
+ {
+ ServerManager.Static.RunArgs = new[] { "-console" };
+ MainDispatcher = Dispatcher.CurrentDispatcher;
+ Console.WriteLine(MainDispatcher.Thread.ManagedThreadId);
+#if DEBUG
+ Directory.SetCurrentDirectory(@"C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\DedicatedServer64");
+#endif
+
+ if (args.Contains("-nogui"))
+ ServerManager.Static.StartServer();
+ else
+ StartUI();
+
+ Dispatcher.Run();
+ }
+
+ public static void StartUI()
+ {
+ Thread.CurrentThread.Name = "UI Thread";
+ UserInterface.Show();
+ }
+ }
+}
diff --git a/PistonServer/Properties/AssemblyInfo.cs b/PistonServer/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..74bd057
--- /dev/null
+++ b/PistonServer/Properties/AssemblyInfo.cs
@@ -0,0 +1,55 @@
+using System.Reflection;
+using System.Resources;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Windows;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("PistonServer")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("PistonServer")]
+[assembly: AssemblyCopyright("Copyright © 2016")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+//In order to begin building localizable applications, set
+//CultureYouAreCodingWith in your .csproj file
+//inside a . For example, if you are using US english
+//in your source files, set the to en-US. Then uncomment
+//the NeutralResourceLanguage attribute below. Update the "en-US" in
+//the line below to match the UICulture setting in the project file.
+
+//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
+
+
+[assembly: ThemeInfo(
+ ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
+ //(used if a resource is not found in the page,
+ // or application resource dictionaries)
+ ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
+ //(used if a resource is not found in the page,
+ // app, or any theme specific resource dictionaries)
+)]
+
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/PistonServer/Properties/Resources.Designer.cs b/PistonServer/Properties/Resources.Designer.cs
new file mode 100644
index 0000000..cb90f68
--- /dev/null
+++ b/PistonServer/Properties/Resources.Designer.cs
@@ -0,0 +1,63 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.42000
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+namespace PistonServer.Properties {
+ using System;
+
+
+ ///
+ /// A strongly-typed resource class, for looking up localized strings, etc.
+ ///
+ // This class was auto-generated by the StronglyTypedResourceBuilder
+ // 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.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ internal class Resources {
+
+ private static global::System.Resources.ResourceManager resourceMan;
+
+ private static global::System.Globalization.CultureInfo resourceCulture;
+
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+ internal Resources() {
+ }
+
+ ///
+ /// Returns the cached ResourceManager instance used by this class.
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if (object.ReferenceEquals(resourceMan, null)) {
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("PistonServer.Properties.Resources", typeof(Resources).Assembly);
+ resourceMan = temp;
+ }
+ return resourceMan;
+ }
+ }
+
+ ///
+ /// Overrides the current thread's CurrentUICulture property for all
+ /// resource lookups using this strongly typed resource class.
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
+ return resourceCulture;
+ }
+ set {
+ resourceCulture = value;
+ }
+ }
+ }
+}
diff --git a/PistonServer/Properties/Resources.resx b/PistonServer/Properties/Resources.resx
new file mode 100644
index 0000000..af7dbeb
--- /dev/null
+++ b/PistonServer/Properties/Resources.resx
@@ -0,0 +1,117 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/PistonServer/Properties/Settings.Designer.cs b/PistonServer/Properties/Settings.Designer.cs
new file mode 100644
index 0000000..306c11d
--- /dev/null
+++ b/PistonServer/Properties/Settings.Designer.cs
@@ -0,0 +1,26 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.42000
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+namespace PistonServer.Properties {
+
+
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.0.0.0")]
+ internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
+
+ private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
+
+ public static Settings Default {
+ get {
+ return defaultInstance;
+ }
+ }
+ }
+}
diff --git a/PistonServer/Properties/Settings.settings b/PistonServer/Properties/Settings.settings
new file mode 100644
index 0000000..033d7a5
--- /dev/null
+++ b/PistonServer/Properties/Settings.settings
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/PistonServer/ServerManager.cs b/PistonServer/ServerManager.cs
new file mode 100644
index 0000000..005e8d8
--- /dev/null
+++ b/PistonServer/ServerManager.cs
@@ -0,0 +1,126 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Windows;
+using Piston;
+using Sandbox;
+using Sandbox.Engine.Multiplayer;
+using Sandbox.Game.World;
+using VRage.Profiler;
+
+namespace PistonServer
+{
+ public class ServerManager
+ {
+ public static ServerManager Static { get; } = new ServerManager();
+ public Thread ServerThread { get; private set; }
+ public string[] RunArgs { get; set; } = new string[0];
+
+ private readonly Assembly _dsAssembly;
+
+ private ServerManager()
+ {
+ using (var f = File.OpenRead("SpaceEngineersDedicated.exe"))
+ {
+ var bin = new byte[f.Length];
+ f.Read(bin, 0, (int)f.Length);
+ _dsAssembly = Assembly.Load(bin);
+ }
+
+ ServerThread = new Thread(StartServer);
+ MySession.OnLoading += OnSessionLoading;
+ }
+
+ private void OnSessionLoading()
+ {
+ MySession.Static.OnReady += OnSessionReady;
+ }
+
+ private void OnSessionReady()
+ {
+ MyMultiplayer.Static.ChatMessageReceived += Program.UserInterface.Chat.MessageReceived;
+ }
+
+ ///
+ /// Start server on a new thread.
+ ///
+ public void StartServerThread()
+ {
+ if (ServerThread.IsAlive)
+ {
+ throw new InvalidOperationException("The server thread is already running.");
+ }
+
+ ServerThread = new Thread(StartServer);
+ ServerThread.Start();
+ }
+
+ ///
+ /// Start server on the current thread.
+ ///
+ public void StartServer()
+ {
+ Logger.Write("Starting server.");
+
+ if (MySandboxGame.Log.LogEnabled)
+ MySandboxGame.Log.Close();
+
+ foreach (var type in _dsAssembly.GetTypes())
+ {
+ if (type.FullName.Contains("MyProgram"))
+ {
+ var method = type.GetMethod("Main", BindingFlags.Static | BindingFlags.NonPublic);
+ method.Invoke(null, new object[] {RunArgs});
+
+ break;
+ }
+ }
+ }
+
+ ///
+ /// Stop the server.
+ ///
+ ///
+ public void StopServer(bool abortThread = false)
+ {
+ if (Thread.CurrentThread != ServerThread)
+ {
+ MySandboxGame.Static?.Invoke(() => StopServer(true));
+ return;
+ }
+
+ MySandboxGame.Static.Exit();
+
+ //Unload all the static junk.
+ //TODO: Finish unloading all server data so it's in a completely clean state.
+ VRage.FileSystem.MyFileSystem.Reset();
+ VRage.Input.MyGuiGameControlsHelpers.Reset();
+ VRage.Input.MyInput.UnloadData();
+ CleanupProfilers();
+ GC.Collect(2);
+
+ Logger.Write("Server stopped.");
+ if (abortThread)
+ {
+ try { ServerThread.Abort(); }
+ catch (ThreadAbortException)
+ {
+ Logger.Write("Server thread aborted.");
+ }
+ ServerThread = null;
+ }
+ }
+
+ private void CleanupProfilers()
+ {
+ typeof(MyRenderProfiler).GetField("m_threadProfiler", BindingFlags.Static | BindingFlags.NonPublic).SetValue(null, null);
+ typeof(MyRenderProfiler).GetField("m_gpuProfiler", BindingFlags.Static | BindingFlags.NonPublic).SetValue(null, null);
+ (typeof(MyRenderProfiler).GetField("m_threadProfilers", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null) as List).Clear();
+ }
+ }
+}
diff --git a/PistonServer/SpaceEngineers.ico b/PistonServer/SpaceEngineers.ico
new file mode 100644
index 0000000..ea7041a
Binary files /dev/null and b/PistonServer/SpaceEngineers.ico differ