From 318fef283e57221349eb6412db63d63399f4fb86 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 3 Feb 2017 19:44:01 -0500 Subject: [PATCH] Fix crash handler --- ModLauncher/App.config | 6 + ModLauncher/ModLauncher.csproj | 102 +++++++++++++++ ModLauncher/Program.cs | 33 +++++ ModLauncher/Properties/AssemblyInfo.cs | 36 ++++++ ModLauncher/Properties/Resources.Designer.cs | 71 +++++++++++ ModLauncher/Properties/Resources.resx | 117 ++++++++++++++++++ ModLauncher/Properties/Settings.Designer.cs | 30 +++++ ModLauncher/Properties/Settings.settings | 7 ++ ModLauncher/README.txt | 9 ++ .../My Project/AssemblyInfo.vb | 10 +- .../My Project/Resources.Designer.vb | 25 ++-- .../My Project/Settings.Designer.vb | 62 +++++----- ...ftOS.Modding.VB.LegacySkinConverter.vbproj | 7 +- ShiftOS_TheReturn.sln | 6 + ShiftOS_TheReturn/AudioManager.cs | 8 +- ShiftOS_TheReturn/CrashHandler.cs | 18 +-- ShiftOS_TheReturn/SaveSystem.cs | 5 + 17 files changed, 488 insertions(+), 64 deletions(-) create mode 100644 ModLauncher/App.config create mode 100644 ModLauncher/ModLauncher.csproj create mode 100644 ModLauncher/Program.cs create mode 100644 ModLauncher/Properties/AssemblyInfo.cs create mode 100644 ModLauncher/Properties/Resources.Designer.cs create mode 100644 ModLauncher/Properties/Resources.resx create mode 100644 ModLauncher/Properties/Settings.Designer.cs create mode 100644 ModLauncher/Properties/Settings.settings create mode 100644 ModLauncher/README.txt diff --git a/ModLauncher/App.config b/ModLauncher/App.config new file mode 100644 index 0000000..88fa402 --- /dev/null +++ b/ModLauncher/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ModLauncher/ModLauncher.csproj b/ModLauncher/ModLauncher.csproj new file mode 100644 index 0000000..7021bfe --- /dev/null +++ b/ModLauncher/ModLauncher.csproj @@ -0,0 +1,102 @@ + + + + + Debug + AnyCPU + {AEACB7B5-E8FC-4569-BBD3-5053A694D6EC} + WinExe + Properties + ModLauncher + ModLauncher + v4.5.2 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + {a8cba038-c147-4a8d-b170-de6d9ece8364} + ShiftOS.Modding.VB.LegacySkinConverter + + + {ff0b1831-ac9f-4093-9747-ddae4467516a} + ShiftOS.Modding.VirtualMachine + + + {2295d2e2-3a00-4e02-b66f-b961ac329fe6} + ShiftOS.WinForms + + + {7C979B07-0585-4033-A110-E5555B9D6651} + ShiftOS.Engine + + + + + + + + \ No newline at end of file diff --git a/ModLauncher/Program.cs b/ModLauncher/Program.cs new file mode 100644 index 0000000..66e9726 --- /dev/null +++ b/ModLauncher/Program.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Forms; +using ShiftOS.Engine; + +namespace ModLauncher +{ + [Namespace("modlauncher")] + public static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + ShiftOS.WinForms.Program.Main(); + } + + [Command("throwcrash")] + public static bool ThrowCrash() + { + new Thread(() => + { + throw new Exception("User triggered crash using modlauncher.throwcrash command."); + }).Start(); + return true; + } + } +} diff --git a/ModLauncher/Properties/AssemblyInfo.cs b/ModLauncher/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c81934b --- /dev/null +++ b/ModLauncher/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("ModLauncher")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ModLauncher")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[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("aeacb7b5-e8fc-4569-bbd3-5053a694d6ec")] + +// 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/ModLauncher/Properties/Resources.Designer.cs b/ModLauncher/Properties/Resources.Designer.cs new file mode 100644 index 0000000..f9213a0 --- /dev/null +++ b/ModLauncher/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// 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 ModLauncher.Properties +{ + + + /// + /// 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 ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ModLauncher.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/ModLauncher/Properties/Resources.resx b/ModLauncher/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/ModLauncher/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/ModLauncher/Properties/Settings.Designer.cs b/ModLauncher/Properties/Settings.Designer.cs new file mode 100644 index 0000000..fcf42de --- /dev/null +++ b/ModLauncher/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// 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 ModLauncher.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.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/ModLauncher/Properties/Settings.settings b/ModLauncher/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/ModLauncher/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/ModLauncher/README.txt b/ModLauncher/README.txt new file mode 100644 index 0000000..f9499eb --- /dev/null +++ b/ModLauncher/README.txt @@ -0,0 +1,9 @@ +What the hell is ModLauncher doing...? + +Well - it's a mod launcher. Simple as that. When debugging +ShiftOS, if you want to write a mod for the game, set this +project as startup - then add a reference to the mod's project. +Then when you hit F5, ShiftOS will launch with the mod you added +loaded up. This is useful because without it, you would have to +make your mod an EXE file and bootstrap the ShiftOS launch sequence +yourself. This takes care of that for you. \ No newline at end of file diff --git a/ShiftOS.Modding.VB.LegacySkinConverter/My Project/AssemblyInfo.vb b/ShiftOS.Modding.VB.LegacySkinConverter/My Project/AssemblyInfo.vb index 9326cc7..42f5b7b 100644 --- a/ShiftOS.Modding.VB.LegacySkinConverter/My Project/AssemblyInfo.vb +++ b/ShiftOS.Modding.VB.LegacySkinConverter/My Project/AssemblyInfo.vb @@ -8,11 +8,11 @@ Imports System.Runtime.InteropServices ' Review the values of the assembly attributes - - - + + + - + @@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices ' by using the '*' as shown below: ' - + diff --git a/ShiftOS.Modding.VB.LegacySkinConverter/My Project/Resources.Designer.vb b/ShiftOS.Modding.VB.LegacySkinConverter/My Project/Resources.Designer.vb index 5fc46e0..68c522a 100644 --- a/ShiftOS.Modding.VB.LegacySkinConverter/My Project/Resources.Designer.vb +++ b/ShiftOS.Modding.VB.LegacySkinConverter/My Project/Resources.Designer.vb @@ -11,9 +11,10 @@ Option Strict On Option Explicit On +Imports System Namespace My.Resources - + '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 @@ -21,20 +22,20 @@ Namespace My.Resources ''' ''' A strongly-typed resource class, for looking up localized strings, etc. ''' - _ + _ Friend Module Resources - + Private resourceMan As Global.System.Resources.ResourceManager - + Private resourceCulture As Global.System.Globalization.CultureInfo - + ''' ''' Returns the cached ResourceManager instance used by this class. ''' - _ + _ Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager Get If Object.ReferenceEquals(resourceMan, Nothing) Then @@ -44,17 +45,17 @@ Namespace My.Resources Return resourceMan End Get End Property - + ''' ''' Overrides the current thread's CurrentUICulture property for all ''' resource lookups using this strongly typed resource class. ''' - _ + _ Friend Property Culture() As Global.System.Globalization.CultureInfo Get Return resourceCulture End Get - Set(ByVal value As Global.System.Globalization.CultureInfo) + Set resourceCulture = value End Set End Property diff --git a/ShiftOS.Modding.VB.LegacySkinConverter/My Project/Settings.Designer.vb b/ShiftOS.Modding.VB.LegacySkinConverter/My Project/Settings.Designer.vb index b219bbc..2ef0172 100644 --- a/ShiftOS.Modding.VB.LegacySkinConverter/My Project/Settings.Designer.vb +++ b/ShiftOS.Modding.VB.LegacySkinConverter/My Project/Settings.Designer.vb @@ -13,42 +13,42 @@ Option Explicit On Namespace My - - _ + + _ Partial Friend NotInheritable Class MySettings Inherits Global.System.Configuration.ApplicationSettingsBase - - Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings), MySettings) - + + Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings) + #Region "My.Settings Auto-Save Functionality" #If _MyType = "WindowsForms" Then - Private Shared addedHandler As Boolean + Private Shared addedHandler As Boolean - Private Shared addedHandlerLockObject As New Object + Private Shared addedHandlerLockObject As New Object - _ - Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs) - If My.Application.SaveMySettingsOnExit Then - My.Settings.Save() - End If - End Sub + _ + Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs) + If My.Application.SaveMySettingsOnExit Then + My.Settings.Save() + End If + End Sub #End If #End Region - + Public Shared ReadOnly Property [Default]() As MySettings Get - + #If _MyType = "WindowsForms" Then - If Not addedHandler Then - SyncLock addedHandlerLockObject - If Not addedHandler Then - AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings - addedHandler = True - End If - End SyncLock - End If + If Not addedHandler Then + SyncLock addedHandlerLockObject + If Not addedHandler Then + AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings + addedHandler = True + End If + End SyncLock + End If #End If Return defaultInstance End Get @@ -57,13 +57,13 @@ Namespace My End Namespace Namespace My - - _ + + _ Friend Module MySettingsProperty - - _ + + _ Friend ReadOnly Property Settings() As Global.ShiftOS.Modding.VB.LegacySkinConverter.My.MySettings Get Return Global.ShiftOS.Modding.VB.LegacySkinConverter.My.MySettings.Default diff --git a/ShiftOS.Modding.VB.LegacySkinConverter/ShiftOS.Modding.VB.LegacySkinConverter.vbproj b/ShiftOS.Modding.VB.LegacySkinConverter/ShiftOS.Modding.VB.LegacySkinConverter.vbproj index f0e5cc2..3a53cc8 100644 --- a/ShiftOS.Modding.VB.LegacySkinConverter/ShiftOS.Modding.VB.LegacySkinConverter.vbproj +++ b/ShiftOS.Modding.VB.LegacySkinConverter/ShiftOS.Modding.VB.LegacySkinConverter.vbproj @@ -5,12 +5,13 @@ Debug AnyCPU {A8CBA038-C147-4A8D-B170-DE6D9ECE8364} - Exe - ShiftOS.Modding.VB.LegacySkinConverter.Module1 + Library + + ShiftOS.Modding.VB.LegacySkinConverter ShiftOS.Modding.VB.LegacySkinConverter 512 - Console + Windows v4.5.2 true diff --git a/ShiftOS_TheReturn.sln b/ShiftOS_TheReturn.sln index 65165ab..98857fa 100644 --- a/ShiftOS_TheReturn.sln +++ b/ShiftOS_TheReturn.sln @@ -17,6 +17,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShiftOS.Modding.VirtualMach EndProject Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "ShiftOS.Modding.VB.LegacySkinConverter", "ShiftOS.Modding.VB.LegacySkinConverter\ShiftOS.Modding.VB.LegacySkinConverter.vbproj", "{A8CBA038-C147-4A8D-B170-DE6D9ECE8364}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModLauncher", "ModLauncher\ModLauncher.csproj", "{AEACB7B5-E8FC-4569-BBD3-5053A694D6EC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -51,6 +53,10 @@ Global {A8CBA038-C147-4A8D-B170-DE6D9ECE8364}.Debug|Any CPU.Build.0 = Debug|Any CPU {A8CBA038-C147-4A8D-B170-DE6D9ECE8364}.Release|Any CPU.ActiveCfg = Release|Any CPU {A8CBA038-C147-4A8D-B170-DE6D9ECE8364}.Release|Any CPU.Build.0 = Release|Any CPU + {AEACB7B5-E8FC-4569-BBD3-5053A694D6EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AEACB7B5-E8FC-4569-BBD3-5053A694D6EC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AEACB7B5-E8FC-4569-BBD3-5053A694D6EC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AEACB7B5-E8FC-4569-BBD3-5053A694D6EC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ShiftOS_TheReturn/AudioManager.cs b/ShiftOS_TheReturn/AudioManager.cs index 5923aa1..1ea4575 100644 --- a/ShiftOS_TheReturn/AudioManager.cs +++ b/ShiftOS_TheReturn/AudioManager.cs @@ -67,7 +67,13 @@ namespace ShiftOS.Engine _out.Volume = volume; } - + internal static void Kill() + { + _running = false; + _out.Stop(); + _out.Dispose(); + _reader.Dispose(); + } } public interface IAudioProvider diff --git a/ShiftOS_TheReturn/CrashHandler.cs b/ShiftOS_TheReturn/CrashHandler.cs index 331a55a..a723136 100644 --- a/ShiftOS_TheReturn/CrashHandler.cs +++ b/ShiftOS_TheReturn/CrashHandler.cs @@ -95,20 +95,14 @@ namespace ShiftOS.Engine public static void Start(Exception e) { - if (SaveSystem.CurrentSave != null) - { - TerminalBackend.InvokeCommand("sos.save"); //save ShiftOS to disk before killing the session - } - - //Close ALL FORMS in the current session. - while (Application.OpenForms.Count != 0) - { - Application.OpenForms[0].Dispose(); - } - - //Disconnect us from the ShiftOS multi-user domain. + if(SaveSystem.CurrentSave != null) + TerminalBackend.InvokeCommand("sos.save"); + AudioManager.Kill(); ServerManager.Disconnect(); + while (Application.OpenForms.Count > 0) + Application.OpenForms[0].Close(); + //Set our global exception variable, and show the exception dialog. HandledException = e; System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); diff --git a/ShiftOS_TheReturn/SaveSystem.cs b/ShiftOS_TheReturn/SaveSystem.cs index 4934221..d2cc521 100644 --- a/ShiftOS_TheReturn/SaveSystem.cs +++ b/ShiftOS_TheReturn/SaveSystem.cs @@ -58,6 +58,11 @@ namespace ShiftOS.Engine /// Whether ShiftOS should initiate it's Windows Forms front-end. public static void Begin(bool useDefaultUI = true) { + AppDomain.CurrentDomain.UnhandledException += (o, a) => + { + CrashHandler.Start((Exception)a.ExceptionObject); + }; + if (!System.IO.File.Exists(Paths.SaveFile)) { var root = new ShiftOS.Objects.ShiftFS.Directory();