diff --git a/Source/MDK/MDKPackage.GeneratedInfo.cs b/Source/MDK/MDKPackage.GeneratedInfo.cs index fb80e32..abb4ad5 100644 --- a/Source/MDK/MDKPackage.GeneratedInfo.cs +++ b/Source/MDK/MDKPackage.GeneratedInfo.cs @@ -8,7 +8,7 @@ public partial class MDKPackage /// /// The current package version /// - public static readonly Version Version = new Version("1.1.29"); + public static readonly Version Version = new Version("1.1.30"); /// /// The required IDE version diff --git a/Source/MDK/source.extension.vsixmanifest b/Source/MDK/source.extension.vsixmanifest index d7e906e..c02e998 100644 --- a/Source/MDK/source.extension.vsixmanifest +++ b/Source/MDK/source.extension.vsixmanifest @@ -1,7 +1,7 @@  - + MDK/SE A toolkit to help with ingame script (programmable block) development for Keen Software House's space sandbox Space Engineers. diff --git a/Source/MDKAnalyzer/whitelist.cache b/Source/MDKAnalyzer/whitelist.cache index e03d85f..d482de3 100644 --- a/Source/MDKAnalyzer/whitelist.cache +++ b/Source/MDKAnalyzer/whitelist.cache @@ -1,13 +1,109 @@ System.Collections.*, mscorlib -System.Collections.Generic.*, mscorlib System.Collections.Generic.*, System.Core System.Collections.Generic.*, System -System.Collections.Concurrent.*, mscorlib -System.Collections.Concurrent.*, System -System.Linq.*, System.Core +System.Collections.Generic.*, mscorlib System.Text.*, mscorlib System.Text.RegularExpressions.*, System System.Globalization.*, mscorlib +System.Linq.IQueryable+*, System.Core +System.Linq.IQueryable+*, System.Core +System.Linq.IQueryProvider+*, System.Core +System.Linq.IOrderedQueryable+*, System.Core +System.Linq.IOrderedQueryable+*, System.Core +System.Linq.Queryable+*, System.Core +System.Linq.Enumerable+*, System.Core +System.Linq.EmptyEnumerable+*, System.Core +System.Linq.IdentityFunction+*, System.Core +System.Linq.IOrderedEnumerable+*, System.Core +System.Linq.IGrouping+*, System.Core +System.Linq.ILookup+*, System.Core +System.Linq.Lookup+*, System.Core +System.Linq.Set+*, System.Core +System.Linq.GroupedEnumerable+*, System.Core +System.Linq.GroupedEnumerable+*, System.Core +System.Linq.OrderedEnumerable+*, System.Core +System.Linq.OrderedEnumerable+*, System.Core +System.Linq.EnumerableSorter+*, System.Core +System.Linq.EnumerableSorter+*, System.Core +System.Linq.Buffer+*, System.Core +System.Linq.SystemCore_EnumerableDebugView+*, System.Core +System.Linq.SystemCore_EnumerableDebugViewEmptyException+*, System.Core +System.Linq.SystemCore_EnumerableDebugView+*, System.Core +System.Linq.IIListProvider+*, System.Core +System.Linq.SingleLinkedNode+*, System.Core +System.Linq.EnumerableQuery+*, System.Core +System.Linq.EnumerableQuery+*, System.Core +System.Linq.EnumerableExecutor+*, System.Core +System.Linq.EnumerableExecutor+*, System.Core +System.Linq.EnumerableRewriter+*, System.Core +System.Linq.TypeHelper+*, System.Core +System.Linq.Strings+*, System.Core +System.Linq.Error+*, System.Core +System.Linq.AggregationMinMaxHelpers+*, System.Core +System.Linq.SRDescriptionAttribute+*, System.Core +System.Linq.SRCategoryAttribute+*, System.Core +System.Linq.SR+*, System.Core +System.Linq.Enumerable.Iterator+*, System.Core +System.Linq.Enumerable.WhereEnumerableIterator+*, System.Core +System.Linq.Enumerable.WhereArrayIterator+*, System.Core +System.Linq.Enumerable.WhereListIterator+*, System.Core +System.Linq.Enumerable.SelectEnumerableIterator+*, System.Core +System.Linq.Enumerable.WhereSelectEnumerableIterator+*, System.Core +System.Linq.Enumerable.WhereSelectArrayIterator+*, System.Core +System.Linq.Enumerable.WhereSelectListIterator+*, System.Core +System.Linq.Enumerable.AppendPrependIterator+*, System.Core +System.Linq.Enumerable.AppendPrepend1Iterator+*, System.Core +System.Linq.Enumerable.AppendPrependN+*, System.Core +System.Linq.Enumerable.d__2+*, System.Core +System.Linq.Enumerable.d__5+*, System.Core +System.Linq.Enumerable.<>c__DisplayClass6_0+*, System.Core +System.Linq.Enumerable.<>c__DisplayClass7_0+*, System.Core +System.Linq.Enumerable.d__17+*, System.Core +System.Linq.Enumerable.d__19+*, System.Core +System.Linq.Enumerable.d__21+*, System.Core +System.Linq.Enumerable.d__23+*, System.Core +System.Linq.Enumerable.d__25+*, System.Core +System.Linq.Enumerable.d__27+*, System.Core +System.Linq.Enumerable.d__29+*, System.Core +System.Linq.Enumerable.d__31+*, System.Core +System.Linq.Enumerable.d__33+*, System.Core +System.Linq.Enumerable.d__35+*, System.Core +System.Linq.Enumerable.d__38+*, System.Core +System.Linq.Enumerable.d__41+*, System.Core +System.Linq.Enumerable.d__59+*, System.Core +System.Linq.Enumerable.d__61+*, System.Core +System.Linq.Enumerable.d__64+*, System.Core +System.Linq.Enumerable.d__67+*, System.Core +System.Linq.Enumerable.d__70+*, System.Core +System.Linq.Enumerable.d__73+*, System.Core +System.Linq.Enumerable.d__75+*, System.Core +System.Linq.Enumerable.d__93+*, System.Core +System.Linq.Enumerable.d__95+*, System.Core +System.Linq.Enumerable.d__97+*, System.Core +System.Linq.Enumerable.d__113+*, System.Core +System.Linq.Enumerable.d__115+*, System.Core +System.Linq.IdentityFunction.<>c+*, System.Core +System.Linq.Lookup.Grouping+*, System.Core +System.Linq.Lookup.d__12+*, System.Core +System.Linq.Lookup.d__13+*, System.Core +System.Linq.Set.Slot+*, System.Core +System.Linq.OrderedEnumerable.d__1+*, System.Core +System.Linq.EnumerableRewriter.<>c__DisplayClass9_0+*, System.Core +System.Linq.EnumerableRewriter.<>c+*, System.Core +System.Linq.EnumerableRewriter.<>c__DisplayClass10_0+*, System.Core +System.Linq.ParallelEnumerable.<>c__10+*, System.Core +System.Linq.ParallelEnumerable.<>c__DisplayClass47_0+*, System.Core +System.Linq.ParallelEnumerable.<>c__DisplayClass48_0+*, System.Core +System.Linq.ParallelEnumerable.<>c__DisplayClass49_0+*, System.Core +System.Linq.ParallelEnumerable.<>c__DisplayClass50_0+*, System.Core +System.Linq.ParallelEnumerable.<>c__51+*, System.Core +System.Linq.ParallelEnumerable.<>c__149+*, System.Core +System.Linq.AggregationMinMaxHelpers.<>c__DisplayClass3_0+*, System.Core +System.Linq.AggregationMinMaxHelpers.<>c__DisplayClass4_0+*, System.Core +System.Linq.AggregationMinMaxHelpers.<>c+*, System.Core +System.Linq.ParallelQuery.<>c__1+*, System.Core +System.Linq.ParallelQuery.<>c__2+*, System.Core +System.Linq.Lookup.Grouping.d__7+*, System.Core object+*, mscorlib System.IDisposable+*, mscorlib string+*, mscorlib @@ -51,9 +147,6 @@ System.Xml.Serialization.XmlRootAttribute+*, System.Xml System.Xml.Serialization.XmlTextAttribute+*, System.Xml System.Xml.Serialization.XmlTypeAttribute+*, System.Xml System.Runtime.CompilerServices.RuntimeHelpers+*, mscorlib -System.IO.Stream+*, mscorlib -System.IO.TextWriter+*, mscorlib -System.IO.TextReader+*, mscorlib System.IO.BinaryReader+*, mscorlib System.IO.BinaryWriter+*, mscorlib System.NullReferenceException+*, mscorlib @@ -163,6 +256,7 @@ Sandbox.ModAPI.Interfaces.ITerminalProperty+*, Sandbox.Common Sandbox.ModAPI.Interfaces.ITerminalProperty+*, Sandbox.Common Sandbox.ModAPI.Interfaces.TerminalPropertyExtensions+*, Sandbox.Common Sandbox.Game.Localization.MySpaceTexts+*, Sandbox.Game +System.Text.StringBuilderExtensions_Format+*, VRage.Library VRage.MyFixedPoint+*, VRage.Library VRage.MyTuple+*, VRage.Library VRage.MyTuple+*, VRage.Library @@ -179,6 +273,7 @@ VRage.MyTexts.GetString(VRage.Utils.MyStringId), VRage VRage.MyTexts.Exists(VRage.Utils.MyStringId), VRage VRage.MyTexts.Get(VRage.Utils.MyStringId), VRage VRage.MyTexts.AppendFormat(System.Text.StringBuilder, VRage.Utils.MyStringId, object), VRage +VRage.MyTexts.AppendFormat(System.Text.StringBuilder, VRage.Utils.MyStringId, VRage.Utils.MyStringId), VRage VRage.MyTexts.Languages, VRage VRage.MyTexts.LanguageDescription+*, VRage VRage.MyLanguagesEnum+*, VRage @@ -193,9 +288,11 @@ VRage.Game.MyRelationsBetweenPlayerAndBlock+*, VRage.Game VRage.Game.MyRelationsBetweenPlayerAndBlockExtensions+*, VRage.Game VRage.Game.Components.MyResourceSourceComponentBase+*, VRage.Game VRage.Game.ObjectBuilders.Definitions.MyObjectBuilder_GasProperties+*, VRage.Game -VRage.Game.Components.MyComponentBase+*, VRage.Game VRage.ObjectBuilders.SerializableDefinitionId+*, VRage.Game VRage.Game.MyCubeSize+*, VRage.Game +VRage.Game.Components.MyComponentBase, VRage.Game +VRage.Game.Components.MyComponentBase.GetAs(), VRage.Game +VRage.Game.Components.MyComponentBase.ContainerBase, VRage.Game VRage.ObjectBuilders.MyObjectBuilder_Base, VRage.Game VRage.ObjectBuilders.MyObjectBuilder_Base.TypeId, VRage.Game VRage.ObjectBuilders.MyObjectBuilder_Base.SubtypeId, VRage.Game @@ -206,6 +303,7 @@ Sandbox.Game.EntityComponents.MyResourceSourceComponent.DefinedOutput, Sandbox.G Sandbox.Game.EntityComponents.MyResourceSourceComponent.ProductionEnabled, Sandbox.Game Sandbox.Game.EntityComponents.MyResourceSourceComponent.RemainingCapacity, Sandbox.Game Sandbox.Game.EntityComponents.MyResourceSourceComponent.HasCapacityRemaining, Sandbox.Game +Sandbox.Game.EntityComponents.MyResourceSourceComponent.ResourceTypes, Sandbox.Game Sandbox.Game.EntityComponents.MyResourceSinkComponent, Sandbox.Game Sandbox.Game.EntityComponents.MyResourceSinkComponent.AcceptedResources, Sandbox.Game Sandbox.Game.EntityComponents.MyResourceSinkComponent.RequiredInput, Sandbox.Game @@ -221,4 +319,6 @@ VRage.Game.Components.MyResourceSinkComponentBase.MaxRequiredInputByType(VRage.G VRage.Game.Components.MyResourceSinkComponentBase.RequiredInputByType(VRage.Game.MyDefinitionId), VRage.Game VRage.Game.Components.MyResourceSinkComponentBase.SuppliedRatioByType(VRage.Game.MyDefinitionId), VRage.Game System.ArrayExtensions, VRage.Library -System.ArrayExtensions.Contains(T[], T), VRage.Library \ No newline at end of file +System.ArrayExtensions.Contains(T[], T), VRage.Library +VRage.Game.ModAPI.Ingame.MyPhysicalInventoryItemExtensions_ModAPI+*, Sandbox.Game +System.Collections.Immutable.*, System.Collections.Immutable \ No newline at end of file diff --git a/Source/MDKListenerPlugin/Base/SpaceEngineersPlugin.cs b/Source/MDKListenerPlugin/Base/SpaceEngineersPlugin.cs new file mode 100644 index 0000000..04f9ecf --- /dev/null +++ b/Source/MDKListenerPlugin/Base/SpaceEngineersPlugin.cs @@ -0,0 +1,94 @@ +using System; +using System.Diagnostics; +using Sandbox.Game.World; +using SpaceEngineers.Game; + +namespace MDKListenerPlugin.Base +{ + public abstract class SpaceEngineersPlugin + { + bool _isInitialized; + bool _isConnectedToSession; + + public SpaceEngineersGame Game { get; private set; } + + ~SpaceEngineersPlugin() + { + Dispose(false); + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + if (MySession.Static != null) + MySession.Static.OnReady -= OnSessionReady; + MySession.OnLoading -= OnSessionLoading; + MySession.AfterLoading -= OnSessionAfterLoading; + MySession.OnUnloading -= OnSessionUnloading; + MySession.OnUnloaded -= OnSessionUnloaded; + } + } + + public void Init(object gameInstance) + { + Debugger.Launch(); + Game = (SpaceEngineersGame)gameInstance; + OnStarting(); + } + + protected virtual void OnStarting() + { } + + protected virtual void OnSessionUnloaded() + { } + + protected virtual void OnSessionUnloading() + { } + + protected virtual void OnSessionAfterLoading() + { } + + protected virtual void OnSessionLoading() + { + if (!_isConnectedToSession) + { + _isConnectedToSession = true; + MySession.Static.OnReady += OnSessionReady; + } + } + + protected virtual void OnSessionReady() + { } + + public void Update() + { + if (!_isInitialized) + { + _isInitialized = true; + OnInitialize(); + } + + if (MySession.Static == null) + return; + OnUpdate(); + } + + protected virtual void OnInitialize() + { + MySession.OnLoading += OnSessionLoading; + MySession.AfterLoading += OnSessionAfterLoading; + MySession.OnUnloading += OnSessionUnloading; + MySession.OnUnloaded += OnSessionUnloaded; + } + + protected virtual void OnUpdate() + { } + } +} \ No newline at end of file diff --git a/Source/MDKListenerPlugin/Base/SpaceEngineersSynchronizationContext.cs b/Source/MDKListenerPlugin/Base/SpaceEngineersSynchronizationContext.cs new file mode 100644 index 0000000..94678ea --- /dev/null +++ b/Source/MDKListenerPlugin/Base/SpaceEngineersSynchronizationContext.cs @@ -0,0 +1,44 @@ +using System; +using System.Threading; +using System.Threading.Tasks; +using Sandbox; + +namespace MDKListenerPlugin.Base +{ + public class SpaceEngineersSynchronizationContext : SynchronizationContext + { + readonly string _invocationId; + + public SpaceEngineersSynchronizationContext(string invocationId) + { + _invocationId = invocationId; + } + + public override void Post(SendOrPostCallback d, object state) + { + void invoke() => d(state); + MySandboxGame.Static.Invoke(invoke, _invocationId); + } + + public override void Send(SendOrPostCallback d, object state) + { + var tcs = new TaskCompletionSource(); + + void invoke() + { + try + { + d(state); + tcs.SetResult(null); + } + catch (Exception e) + { + tcs.SetException(e); + } + } + + MySandboxGame.Static.Invoke(invoke, _invocationId); + tcs.Task.Wait(); + } + } +} \ No newline at end of file diff --git a/Source/MDKListenerPlugin/MDKListenerPlugin.csproj b/Source/MDKListenerPlugin/MDKListenerPlugin.csproj new file mode 100644 index 0000000..b475d99 --- /dev/null +++ b/Source/MDKListenerPlugin/MDKListenerPlugin.csproj @@ -0,0 +1,112 @@ + + + + + Debug + AnyCPU + {47A65F5A-BF97-4601-8660-68024B8EACDB} + Library + Properties + MDKListenerPlugin + MDKListenerPlugin + v4.6.2 + 512 + true + + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + + + + ..\..\..\..\..\..\Steam\SteamApps\common\SpaceEngineers\Bin64\Sandbox.Common.dll + False + + + ..\..\..\..\..\..\Steam\SteamApps\common\SpaceEngineers\Bin64\Sandbox.Game.dll + False + + + ..\..\..\..\..\..\Steam\SteamApps\common\SpaceEngineers\Bin64\Sandbox.Graphics.dll + False + + + ..\..\..\..\..\..\Steam\SteamApps\common\SpaceEngineers\Bin64\SpaceEngineers.Game.dll + False + + + ..\..\..\..\..\..\Steam\SteamApps\common\SpaceEngineers\Bin64\SpaceEngineers.ObjectBuilders.dll + False + + + + + + + + + + + ..\..\..\..\..\..\Steam\SteamApps\common\SpaceEngineers\Bin64\VRage.dll + False + + + ..\..\..\..\..\..\Steam\SteamApps\common\SpaceEngineers\Bin64\VRage.Audio.dll + False + + + ..\..\..\..\..\..\Steam\SteamApps\common\SpaceEngineers\Bin64\VRage.Game.dll + False + + + ..\..\..\..\..\..\Steam\SteamApps\common\SpaceEngineers\Bin64\VRage.Input.dll + False + + + ..\..\..\..\..\..\Steam\SteamApps\common\SpaceEngineers\Bin64\VRage.Library.dll + False + + + ..\..\..\..\..\..\Steam\SteamApps\common\SpaceEngineers\Bin64\VRage.Math.dll + False + + + ..\..\..\..\..\..\Steam\SteamApps\common\SpaceEngineers\Bin64\VRage.Render.dll + False + + + ..\..\..\..\..\..\Steam\SteamApps\common\SpaceEngineers\Bin64\VRage.Render11.dll + False + + + ..\..\..\..\..\..\Steam\SteamApps\common\SpaceEngineers\Bin64\VRage.Scripting.dll + False + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/MDKListenerPlugin/MDKListenerPlugin.sln b/Source/MDKListenerPlugin/MDKListenerPlugin.sln new file mode 100644 index 0000000..958c758 --- /dev/null +++ b/Source/MDKListenerPlugin/MDKListenerPlugin.sln @@ -0,0 +1,45 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28010.2041 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MDKListenerPlugin", "MDKListenerPlugin.csproj", "{47A65F5A-BF97-4601-8660-68024B8EACDB}" +EndProject +Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Pipes", "..\Pipes\Pipes.shproj", "{E29ECB62-6CA9-4448-A9DB-FDC98DF6A8E0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApp", "TestApp\TestApp.csproj", "{1D7A9923-D327-4A47-9728-816C58B7BE75}" +EndProject +Global + GlobalSection(SharedMSBuildProjectFiles) = preSolution + ..\Pipes\Pipes.projitems*{47a65f5a-bf97-4601-8660-68024b8eacdb}*SharedItemsImports = 4 + ..\Pipes\Pipes.projitems*{e29ecb62-6ca9-4448-a9db-fdc98df6a8e0}*SharedItemsImports = 13 + EndGlobalSection + 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 + {47A65F5A-BF97-4601-8660-68024B8EACDB}.Debug|Any CPU.ActiveCfg = Debug|x64 + {47A65F5A-BF97-4601-8660-68024B8EACDB}.Debug|x64.ActiveCfg = Debug|x64 + {47A65F5A-BF97-4601-8660-68024B8EACDB}.Debug|x64.Build.0 = Debug|x64 + {47A65F5A-BF97-4601-8660-68024B8EACDB}.Release|Any CPU.ActiveCfg = Release|x64 + {47A65F5A-BF97-4601-8660-68024B8EACDB}.Release|x64.ActiveCfg = Release|x64 + {47A65F5A-BF97-4601-8660-68024B8EACDB}.Release|x64.Build.0 = Release|x64 + {1D7A9923-D327-4A47-9728-816C58B7BE75}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1D7A9923-D327-4A47-9728-816C58B7BE75}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1D7A9923-D327-4A47-9728-816C58B7BE75}.Debug|x64.ActiveCfg = Debug|Any CPU + {1D7A9923-D327-4A47-9728-816C58B7BE75}.Debug|x64.Build.0 = Debug|Any CPU + {1D7A9923-D327-4A47-9728-816C58B7BE75}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1D7A9923-D327-4A47-9728-816C58B7BE75}.Release|Any CPU.Build.0 = Release|Any CPU + {1D7A9923-D327-4A47-9728-816C58B7BE75}.Release|x64.ActiveCfg = Release|Any CPU + {1D7A9923-D327-4A47-9728-816C58B7BE75}.Release|x64.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {C11CBC96-FE6B-4FF3-820C-990A8CE3B0B9} + EndGlobalSection +EndGlobal diff --git a/Source/MDKListenerPlugin/Plugin.cs b/Source/MDKListenerPlugin/Plugin.cs new file mode 100644 index 0000000..afdbfe5 --- /dev/null +++ b/Source/MDKListenerPlugin/Plugin.cs @@ -0,0 +1,97 @@ +using System; +using System.Diagnostics; +using MDKListenerPlugin.Base; +using Pipes; +using Sandbox.Game.Entities.Cube; +using Sandbox.Game.Gui; +using VRage.Game.ModAPI; +using VRage.Plugins; + +namespace MDKListenerPlugin +{ + public class Plugin : SpaceEngineersPlugin, IPlugin + { + static void Dispose(ref T disposable) where T : class, IDisposable + { + disposable?.Dispose(); + disposable = null; + } + + static object GetItemInControlPanel() + { + if (MyGuiScreenTerminal.GetCurrentScreen() == MyTerminalPageEnum.ControlPanel) + { + return MyGuiScreenTerminal.InteractedEntity; + } + + return null; + } + + Server _server; + bool _available; + MyTerminalPageEnum _currentScreen; + + protected override void OnSessionReady() + { + base.OnSessionReady(); + _available = true; + } + + protected override void OnSessionUnloading() + { + _available = false; + base.OnSessionUnloading(); + } + + protected override void OnUpdate() + { + if (_available) + { + var screen = MyGuiScreenTerminal.GetCurrentScreen(); + if (screen != _currentScreen) + { + _currentScreen = screen; + OnScreenChanged(screen); + } + } + + base.OnUpdate(); + } + + void OnScreenChanged(MyTerminalPageEnum screen) + { + if (GetItemInControlPanel() is MyTerminalBlock entity) + Debug.WriteLine(entity.CustomName); + //switch (screen) + //{ + // case MyTerminalPageEnum.None: + // break; + // case MyTerminalPageEnum.Properties: + // break; + // case MyTerminalPageEnum.Inventory: + // break; + // case MyTerminalPageEnum.ControlPanel: + // break; + // case MyTerminalPageEnum.Production: + // break; + // case MyTerminalPageEnum.Info: + // break; + // case MyTerminalPageEnum.Factions: + // break; + // case MyTerminalPageEnum.Comms: + // break; + // case MyTerminalPageEnum.Gps: + // break; + // default: + // throw new ArgumentOutOfRangeException(); + //} + } + + protected override void Dispose(bool disposing) + { + if (disposing) + Dispose(ref _server); + base.Dispose(disposing); + } + } +} \ No newline at end of file diff --git a/Source/MDKListenerPlugin/ProgrammableBLockController.cs b/Source/MDKListenerPlugin/ProgrammableBLockController.cs new file mode 100644 index 0000000..503f093 --- /dev/null +++ b/Source/MDKListenerPlugin/ProgrammableBLockController.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MDKListenerPlugin +{ + public class ProgrammableBlockController + { + + } +} diff --git a/Source/MDKListenerPlugin/Properties/AssemblyInfo.cs b/Source/MDKListenerPlugin/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..3da3676 --- /dev/null +++ b/Source/MDKListenerPlugin/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("MDKListenerPlugin")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("MDKListenerPlugin")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[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("47a65f5a-bf97-4601-8660-68024b8eacdb")] + +// 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/Source/MDKListenerPlugin/TestApp/App.config b/Source/MDKListenerPlugin/TestApp/App.config new file mode 100644 index 0000000..b50c74f --- /dev/null +++ b/Source/MDKListenerPlugin/TestApp/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Source/MDKListenerPlugin/TestApp/Program.cs b/Source/MDKListenerPlugin/TestApp/Program.cs new file mode 100644 index 0000000..9256f23 --- /dev/null +++ b/Source/MDKListenerPlugin/TestApp/Program.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TestApp +{ + class Program + { + static void Main(string[] args) + { + } + } +} diff --git a/Source/MDKListenerPlugin/TestApp/Properties/AssemblyInfo.cs b/Source/MDKListenerPlugin/TestApp/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..b7fca16 --- /dev/null +++ b/Source/MDKListenerPlugin/TestApp/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("TestApp")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("TestApp")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[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("1d7a9923-d327-4a47-9728-816c58b7be75")] + +// 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/Source/MDKListenerPlugin/TestApp/TestApp.csproj b/Source/MDKListenerPlugin/TestApp/TestApp.csproj new file mode 100644 index 0000000..070eff3 --- /dev/null +++ b/Source/MDKListenerPlugin/TestApp/TestApp.csproj @@ -0,0 +1,53 @@ + + + + + Debug + AnyCPU + {1D7A9923-D327-4A47-9728-816C58B7BE75} + Exe + TestApp + TestApp + v4.6.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/MDKServices/ProjectScriptInfo.GeneratedInfo.cs b/Source/MDKServices/ProjectScriptInfo.GeneratedInfo.cs index 800fc67..248b8ad 100644 --- a/Source/MDKServices/ProjectScriptInfo.GeneratedInfo.cs +++ b/Source/MDKServices/ProjectScriptInfo.GeneratedInfo.cs @@ -7,6 +7,6 @@ partial class ProjectScriptInfo /// /// The current package version this utility assembly targets /// - public static readonly Version TargetPackageVersion = new Version("1.1.29"); + public static readonly Version TargetPackageVersion = new Version("1.1.30"); } } diff --git a/Source/Pipes/Client.cs b/Source/Pipes/Client.cs new file mode 100644 index 0000000..880f801 --- /dev/null +++ b/Source/Pipes/Client.cs @@ -0,0 +1,58 @@ +using System; +using System.IO; +using System.IO.Pipes; +using System.Security.Principal; +using System.Threading; +using System.Threading.Tasks; +using VRage.Game.ModAPI.Ingame.Utilities; + +namespace Pipes +{ + public class Client : IDisposable + { + readonly string _pipeName; + readonly string _expectedIdentity; + readonly SynchronizationContext _synchronizationContext; + + public Client(string pipeName, string expectedIdentity, SynchronizationContext synchronizationContext = null) + { + _pipeName = pipeName; + _expectedIdentity = expectedIdentity; + _synchronizationContext = synchronizationContext; + } + + //private Client() + //{ + // NamedPipeClientStream pipeClient = + // new NamedPipeClientStream(".", "testpipe", + // PipeDirection.InOut, PipeOptions.None, + // TokenImpersonationLevel.Impersonation); + //} + + public async Task Request(string transmitMessage) + { + using (var stream = new NamedPipeClientStream(".", _expectedIdentity, PipeDirection.InOut, PipeOptions.Asynchronous, TokenImpersonationLevel.Anonymous)) + { + var message = new MyCommandLine(); + stream.ReadTimeout = 500; + stream.WriteTimeout = 500; + await stream.ConnectAsync(500); + var writer = new StreamWriter(stream); + var reader = new StreamReader(stream); + var response = await reader.ReadLineAsync(); + if (string.IsNullOrWhiteSpace(response) || response != $"ID {_expectedIdentity}") + throw new ClientException("Bad response"); + writer.WriteLine($"REQUEST {transmitMessage}"); + response = await reader.ReadLineAsync(); + if (string.IsNullOrWhiteSpace(response)) + throw new ClientException("Bad response"); + var code = response.Substring(0, Math.Max(response.Length, response.IndexOf(' '))); + + } + throw new NotImplementedException(); + } + + public void Dispose() + { } + } +} \ No newline at end of file diff --git a/Source/Pipes/ClientException.cs b/Source/Pipes/ClientException.cs new file mode 100644 index 0000000..9de074f --- /dev/null +++ b/Source/Pipes/ClientException.cs @@ -0,0 +1,30 @@ +using System; +using System.Runtime.Serialization; + +namespace Pipes +{ + [Serializable] + public class ClientException : Exception + { + // + // For guidelines regarding the creation of new exception types, see + // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconerrorraisinghandlingguidelines.asp + // and + // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp07192001.asp + // + + public ClientException() + { } + + public ClientException(string message) : base(message) + { } + + public ClientException(string message, Exception inner) : base(message, inner) + { } + + protected ClientException( + SerializationInfo info, + StreamingContext context) : base(info, context) + { } + } +} \ No newline at end of file diff --git a/Source/Pipes/Pipes.projitems b/Source/Pipes/Pipes.projitems new file mode 100644 index 0000000..71ba3ff --- /dev/null +++ b/Source/Pipes/Pipes.projitems @@ -0,0 +1,17 @@ + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + true + e29ecb62-6ca9-4448-a9db-fdc98df6a8e0 + + + Pipes + + + + + + + + \ No newline at end of file diff --git a/Source/Pipes/Pipes.shproj b/Source/Pipes/Pipes.shproj new file mode 100644 index 0000000..c7d891e --- /dev/null +++ b/Source/Pipes/Pipes.shproj @@ -0,0 +1,13 @@ + + + + e29ecb62-6ca9-4448-a9db-fdc98df6a8e0 + 14.0 + + + + + + + + diff --git a/Source/Pipes/RequestAttribute.cs b/Source/Pipes/RequestAttribute.cs new file mode 100644 index 0000000..c8b76e7 --- /dev/null +++ b/Source/Pipes/RequestAttribute.cs @@ -0,0 +1,8 @@ +using System; + +namespace Pipes +{ + [AttributeUsage(AttributeTargets.Method)] + public class RequestAttribute: Attribute + { } +} \ No newline at end of file diff --git a/Source/Pipes/Server.cs b/Source/Pipes/Server.cs new file mode 100644 index 0000000..3ff37ae --- /dev/null +++ b/Source/Pipes/Server.cs @@ -0,0 +1,178 @@ +using System; +using System.IO; +using System.IO.Pipes; +using System.Threading; +using System.Threading.Tasks; +using VRage.Game.ModAPI.Ingame.Utilities; +using VRage.Utils; + +namespace Pipes +{ + public class Server : IDisposable + { + public static Server Start(string pipeName, string identity, SynchronizationContext synchronizationContext = null, int instanceCount = 4) + { + var messager = new Server(pipeName, identity, synchronizationContext ?? SynchronizationContext.Current); + messager.Start(); + return messager; + } + + readonly CancellationTokenSource _cancellation; + readonly string _pipeName; + readonly string _identity; + readonly SynchronizationContext _synchronizationContext; + Task[] _tasks; + + Server(string pipeName, string identity, SynchronizationContext synchronizationContext) + { + _cancellation = new CancellationTokenSource(); + _pipeName = pipeName; + _identity = identity; + _synchronizationContext = synchronizationContext; + } + + public event Func RequestReceived; + + void Start() + { + _tasks = new[] + { + new Task(ServerFunction, TaskCreationOptions.LongRunning), + new Task(ServerFunction, TaskCreationOptions.LongRunning), + new Task(ServerFunction, TaskCreationOptions.LongRunning), + new Task(ServerFunction, TaskCreationOptions.LongRunning) + }; + } + + public void Dispose() + { } + + async void ServerFunction() + { + while (true) + { + using (var stream = new NamedPipeServerStream(_pipeName, PipeDirection.InOut, 4, PipeTransmissionMode.Byte, PipeOptions.Asynchronous)) + { + stream.ReadTimeout = 500; + stream.WriteTimeout = 500; + var message = new MyCommandLine(); + await stream.WaitForConnectionAsync(_cancellation.Token); + if (_cancellation.IsCancellationRequested) + return; + + var writer = new StreamWriter(stream); + var reader = new StreamReader(stream); + + writer.WriteLine($"ID \"{_identity}\""); + var messageSrc = reader.ReadLine(); + if (string.IsNullOrWhiteSpace(messageSrc) || !message.TryParse(messageSrc)) + { + writer.WriteLine("400"); + continue; + } + + var completion = new TaskCompletionSource(); + _synchronizationContext.Post(OnRequest, new Request(message, completion)); + try + { + var response = completion.Task.Result; + if (response == null) + writer.WriteLine("400"); + else + writer.WriteLine($"200 {response}"); + } + catch (Exception exception) + { + void logError(object state) + { + MyLog.Default.WriteLine("MDKListenerPlugin Error"); + MyLog.Default.WriteLine((Exception)state); + } + + _synchronizationContext.Post(logError, exception); + writer.WriteLine("500"); + } + } + } + } + + void OnRequest(object state) => OnRequest((Request)state); + + protected virtual void OnRequest(Request state) + { + try + { + state.RespondWith(RequestReceived?.Invoke(this, state.Message)); + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + } + + public class Request + { + readonly TaskCompletionSource _respond; + + public Request(MyCommandLine message, TaskCompletionSource respond) + { + _respond = respond; + Message = message; + } + + public MyCommandLine Message { get; } + + public void RespondWith(string message) + { + _respond.SetResult(message); + } + + public void Fail(Exception exception) + { + _respond.SetException(exception); + } + } + + //void Server() + //{ + + // int threadId = Thread.CurrentThread.ManagedThreadId; + + // // Wait for a client to connect + // pipeServer.WaitForConnection(); + // pipeServer.WaitForConnectionAsync() + + + // Console.WriteLine("Client connected on thread[{0}].", threadId); + // try + // { + // // Read the request from the client. Once the client has + // // written to the pipe its security token will be available. + + // StreamString ss = new StreamString(pipeServer); + + // // Verify our identity to the connected client using a + // // string that the client anticipates. + + // ss.WriteString("I am the one true server!"); + // string filename = ss.ReadString(); + + // // Read in the contents of the file while impersonating the client. + // ReadFileToStream fileReader = new ReadFileToStream(ss, filename); + + // // Display the name of the user we are impersonating. + // Console.WriteLine("Reading file: {0} on thread[{1}] as user: {2}.", + // filename, threadId, pipeServer.GetImpersonationUserName()); + // pipeServer.RunAsClient(fileReader.Start); + // } + // // Catch the IOException that is raised if the pipe is broken + // // or disconnected. + // catch (IOException e) + // { + // Console.WriteLine("ERROR: {0}", e.Message); + // } + // pipeServer.Close(); + //} + } +} \ No newline at end of file