Debian packaging patches are maintained in Git.
--- openbve-1.4.0.9.orig/openBVE/Texture.BmpGifJpegPngTiff/Texture.BmpGifJpegPngTiff.csproj
+++ openbve-1.4.0.9/openBVE/Texture.BmpGifJpegPngTiff/Texture.BmpGifJpegPngTiff.csproj
@@ -7,7 +7,7 @@
     <OutputType>Library</OutputType>
     <RootNamespace>Plugin</RootNamespace>
     <AssemblyName>Texture.BmpGifJpegPngTiff</AssemblyName>
-    <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <SourceAnalysisOverrideSettingsFile>C:\Documents and Settings\Administrator\Application Data\ICSharpCode/SharpDevelop3.0\Settings.SourceAnalysis</SourceAnalysisOverrideSettingsFile>
     <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
--- openbve-1.4.0.9.orig/openBVE/Texture.Ace/Texture.Ace.csproj
+++ openbve-1.4.0.9/openBVE/Texture.Ace/Texture.Ace.csproj
@@ -7,7 +7,7 @@
     <OutputType>Library</OutputType>
     <RootNamespace>Texture.Ace</RootNamespace>
     <AssemblyName>Texture.Ace</AssemblyName>
-    <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <SourceAnalysisOverrideSettingsFile>C:\Documents and Settings\Administrator\Application Data\ICSharpCode/SharpDevelop3.0\Settings.SourceAnalysis</SourceAnalysisOverrideSettingsFile>
     <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
--- openbve-1.4.0.9.orig/openBVE/OpenBve/OpenBve.csproj
+++ openbve-1.4.0.9/openBVE/OpenBve/OpenBve.csproj
@@ -1,4 +1,4 @@
-﻿<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
   <PropertyGroup>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -21,7 +21,7 @@
     <RunCodeAnalysis>False</RunCodeAnalysis>
     <RunSourceAnalysis>False</RunSourceAnalysis>
     <ApplicationIcon>..\icon.ico</ApplicationIcon>
-    <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <DebugSymbols>true</DebugSymbols>
@@ -34,7 +34,8 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
-    <DebugType>None</DebugType>
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>PdbOnly</DebugType>
     <Optimize>true</Optimize>
     <PlatformTarget>x86</PlatformTarget>
     <OutputPath>bin\Release\</OutputPath>
@@ -216,4 +217,4 @@
   <Target Name="AfterBuild">
   </Target>
   -->
-</Project>
\ No newline at end of file
+</Project>
--- openbve-1.4.0.9.orig/openBVE/OpenBve/System/Plugins.cs
+++ openbve-1.4.0.9/openBVE/OpenBve/System/Plugins.cs
@@ -72,6 +72,13 @@ namespace OpenBve {
 		internal static void LoadPlugins() {
 			UnloadPlugins();
 			string folder = Program.FileSystem.GetDataFolder("Plugins");
+			// Executable data (== .dlls) may need to live somewhere else, so such an
+			// option probably may need adding to 'filesystem.cfg' in the future. -sladen
+			if(!System.IO.Directory.Exists(folder))
+				folder = OpenBveApi.Path.CombineDirectory(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Plugins");
+			// And if that doesn't work, just hard code it. -sladen
+			//if(!System.IO.Directory.Exists(folder))
+			//  folder = "/usr/lib/openbve/Plugins";
 			string[] files = Directory.GetFiles(folder);
 			List<Plugin> list = new List<Plugin>();
 			foreach (string file in files) {
--- openbve-1.4.0.9.orig/openBVE/OpenBve/OldCode/Renderer.cs
+++ openbve-1.4.0.9/openBVE/OpenBve/OldCode/Renderer.cs
@@ -277,7 +277,7 @@ namespace OpenBve {
 			Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);
 			Gl.glDisable(Gl.GL_BLEND); BlendEnabled = false;
 			Gl.glEnable(Gl.GL_DEPTH_TEST);
-			Gl.glDepthMask(Gl.GL_TRUE);
+			Gl.glDepthMask(true);
 			Gl.glMaterialfv(Gl.GL_FRONT_AND_BACK, Gl.GL_EMISSION, new float[] { 0.0f, 0.0f, 0.0f, 1.0f }); EmissiveEnabled = false;
 			SetAlphaFunc(Gl.GL_GREATER, 0.9f);
 		}
@@ -435,7 +435,7 @@ namespace OpenBve {
 			SortPolygons(DynamicAlpha);
 			if (Interface.CurrentOptions.TransparencyMode == TransparencyMode.Performance) {
 				Gl.glEnable(Gl.GL_BLEND); BlendEnabled = true;
-				Gl.glDepthMask(Gl.GL_FALSE);
+				Gl.glDepthMask(false);
 				SetAlphaFunc(Gl.GL_GREATER, 0.0f);
 				for (int i = 0; i < DynamicAlpha.FaceCount; i++) {
 					RenderFace(ref DynamicAlpha.Faces[i], cx, cy, cz);
@@ -443,7 +443,7 @@ namespace OpenBve {
 			} else {
 				Gl.glDisable(Gl.GL_BLEND); BlendEnabled = false;
 				SetAlphaFunc(Gl.GL_EQUAL, 1.0f);
-				Gl.glDepthMask(Gl.GL_TRUE);
+				Gl.glDepthMask(true);
 				for (int i = 0; i < DynamicAlpha.FaceCount; i++) {
 					int r = (int)ObjectManager.Objects[DynamicAlpha.Faces[i].ObjectIndex].Mesh.Faces[DynamicAlpha.Faces[i].FaceIndex].Material;
 					if (ObjectManager.Objects[DynamicAlpha.Faces[i].ObjectIndex].Mesh.Materials[r].BlendMode == World.MeshMaterialBlendMode.Normal & ObjectManager.Objects[DynamicAlpha.Faces[i].ObjectIndex].Mesh.Materials[r].GlowAttenuationData == 0) {
@@ -454,7 +454,7 @@ namespace OpenBve {
 				}
 				Gl.glEnable(Gl.GL_BLEND); BlendEnabled = true;
 				SetAlphaFunc(Gl.GL_LESS, 1.0f);
-				Gl.glDepthMask(Gl.GL_FALSE);
+				Gl.glDepthMask(false);
 				bool additive = false;
 				for (int i = 0; i < DynamicAlpha.FaceCount; i++) {
 					int r = (int)ObjectManager.Objects[DynamicAlpha.Faces[i].ObjectIndex].Mesh.Faces[DynamicAlpha.Faces[i].FaceIndex].Material;
@@ -475,7 +475,7 @@ namespace OpenBve {
 			}
 			// motion blur
 			Gl.glDisable(Gl.GL_DEPTH_TEST);
-			Gl.glDepthMask(Gl.GL_FALSE);
+			Gl.glDepthMask(false);
 			SetAlphaFunc(Gl.GL_GREATER, 0.0f);
 			if (Interface.CurrentOptions.MotionBlur != Interface.MotionBlurMode.None) {
 				if (LightingEnabled) {
@@ -493,7 +493,7 @@ namespace OpenBve {
 			Glu.gluLookAt(0.0, 0.0, 0.0, dx, dy, dz, ux, uy, uz);
 			if (World.CameraRestriction == World.CameraRestrictionMode.NotAvailable) {
 				// 3d cab
-				Gl.glDepthMask(Gl.GL_TRUE);
+				Gl.glDepthMask(true);
 				Gl.glEnable(Gl.GL_DEPTH_TEST);
 				Gl.glClear(Gl.GL_DEPTH_BUFFER_BIT);
 				if (!LightingEnabled) {
@@ -511,7 +511,7 @@ namespace OpenBve {
 				SortPolygons(OverlayAlpha);
 				if (Interface.CurrentOptions.TransparencyMode == TransparencyMode.Performance) {
 					Gl.glEnable(Gl.GL_BLEND); BlendEnabled = true;
-					Gl.glDepthMask(Gl.GL_FALSE);
+					Gl.glDepthMask(false);
 					SetAlphaFunc(Gl.GL_GREATER, 0.0f);
 					for (int i = 0; i < OverlayAlpha.FaceCount; i++) {
 						RenderFace(ref OverlayAlpha.Faces[i], cx, cy, cz);
@@ -519,7 +519,7 @@ namespace OpenBve {
 				} else {
 					Gl.glDisable(Gl.GL_BLEND); BlendEnabled = false;
 					SetAlphaFunc(Gl.GL_EQUAL, 1.0f);
-					Gl.glDepthMask(Gl.GL_TRUE);
+					Gl.glDepthMask(true);
 					for (int i = 0; i < OverlayAlpha.FaceCount; i++) {
 						int r = (int)ObjectManager.Objects[OverlayAlpha.Faces[i].ObjectIndex].Mesh.Faces[OverlayAlpha.Faces[i].FaceIndex].Material;
 						if (ObjectManager.Objects[OverlayAlpha.Faces[i].ObjectIndex].Mesh.Materials[r].BlendMode == World.MeshMaterialBlendMode.Normal & ObjectManager.Objects[OverlayAlpha.Faces[i].ObjectIndex].Mesh.Materials[r].GlowAttenuationData == 0) {
@@ -530,7 +530,7 @@ namespace OpenBve {
 					}
 					Gl.glEnable(Gl.GL_BLEND); BlendEnabled = true;
 					SetAlphaFunc(Gl.GL_LESS, 1.0f);
-					Gl.glDepthMask(Gl.GL_FALSE);
+					Gl.glDepthMask(false);
 					bool additive = false;
 					for (int i = 0; i < OverlayAlpha.FaceCount; i++) {
 						int r = (int)ObjectManager.Objects[OverlayAlpha.Faces[i].ObjectIndex].Mesh.Faces[OverlayAlpha.Faces[i].FaceIndex].Material;
@@ -558,7 +558,7 @@ namespace OpenBve {
 				if (!BlendEnabled) {
 					Gl.glEnable(Gl.GL_BLEND); BlendEnabled = true;
 				}
-				Gl.glDepthMask(Gl.GL_FALSE);
+				Gl.glDepthMask(false);
 				Gl.glDisable(Gl.GL_DEPTH_TEST);
 				UnsetAlphaFunc();
 				SortPolygons(OverlayAlpha);
--- openbve-1.4.0.9.orig/openBVE/OpenBve/OldCode/Program.cs
+++ openbve-1.4.0.9/openBVE/OpenBve/OldCode/Program.cs
@@ -6,6 +6,8 @@ using System.Reflection;
 using System.Windows.Forms;
 using Tao.OpenGl;
 using Tao.Sdl;
+using System.Threading;
+using System.Windows.Forms;
 
 namespace OpenBve {
 	public static partial class Program {
@@ -21,6 +23,15 @@ namespace OpenBve {
 		private static bool SdlWindowCreated = false;
 		internal static Host CurrentHost = new Host();
 
+		internal static void WatchdogExit()
+		{
+			int delay = 5000; // milliseconds
+			Console.Error.WriteLine("WatchdogExit: starting timer");
+			System.Threading.Thread.Sleep(delay);
+			Console.Error.WriteLine("WatchdogExit: Something did not shutdown quickly enough, forcing exit");
+			Environment.FailFast("WatchdogExit: Something did not shutdown quickly enough, forcing exit");
+		}
+
 		// main
 		[STAThread]
 		private static void Main(string[] args) {
@@ -74,6 +85,13 @@ namespace OpenBve {
 			if(SdlWindowCreated & Interface.CurrentOptions.FullscreenMode) {
 				Sdl.SDL_SetVideoMode(Interface.CurrentOptions.WindowWidth, Interface.CurrentOptions.WindowHeight, 32, Sdl.SDL_OPENGL | Sdl.SDL_DOUBLEBUF);
 			}
+
+			// Start a watchdog timer, so that even if SDL/OpenAL hang freeing buffers,
+			// the program will still successfully force a quit.
+			Thread Watchdog = new Thread(new ThreadStart(WatchdogExit));
+			Watchdog.IsBackground = true;
+			Watchdog.Start();
+
 			Renderer.Deinitialize();
 			Textures.Deinitialize();
 			Plugins.UnloadPlugins();
@@ -103,6 +121,7 @@ namespace OpenBve {
 					MessageBox.Show(ex.Message + "\n\nProcess = " + FileSystem.RestartProcess + "\nArguments = " + arguments, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
 				}
 			}
+			Environment.Exit(0);
 		}
 
 		// get exception text
--- openbve-1.4.0.9.orig/openBVE/OpenBve/OldCode/PluginManager.cs
+++ openbve-1.4.0.9/openBVE/OpenBve/OldCode/PluginManager.cs
@@ -455,6 +455,14 @@ namespace OpenBve {
 		/// <returns>Whether the plugin was loaded successfully.</returns>
 		internal static bool LoadDefaultPlugin(TrainManager.Train train, string trainFolder) {
 			string file = OpenBveApi.Path.CombineFile(Program.FileSystem.GetDataFolder("Plugins"), "OpenBveAts.dll");
+			// Executable data (== .dlls) may need to live somewhere else, so such an
+			// option probably may need adding to 'filesystem.cfg' in the future. -sladen
+			// Note that should path determination logic may want to be shared with
+			// the similiar statement in System/Plugins.cs
+			if(!System.IO.File.Exists(file))
+				file = OpenBveApi.Path.CombineFile(OpenBveApi.Path.CombineDirectory(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Plugins"), "OpenBveAts.dll");
+			// Or ... just hard code it as a massive kludge -sladen
+			//file = "/usr/lib/openbve/Plugins/OpenBveAts.dll";
 			bool success = LoadPlugin(train, file, trainFolder);
 			if (success) {
 				train.Plugin.IsDefault = true;
--- openbve-1.4.0.9.orig/openBVE/OpenBveApi/OpenBveApi.csproj
+++ openbve-1.4.0.9/openBVE/OpenBveApi/OpenBveApi.csproj
@@ -7,7 +7,7 @@
     <OutputType>Library</OutputType>
     <RootNamespace>OpenBveApi</RootNamespace>
     <AssemblyName>OpenBveApi</AssemblyName>
-    <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <SourceAnalysisOverrideSettingsFile>C:\Documents and Settings\Administrator\Application Data\ICSharpCode/SharpDevelop3.0\Settings.SourceAnalysis</SourceAnalysisOverrideSettingsFile>
     <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
@@ -35,8 +35,8 @@
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
     <OutputPath>bin\Release\</OutputPath>
-    <DebugSymbols>false</DebugSymbols>
-    <DebugType>None</DebugType>
+    <DebugSymbols>True</DebugSymbols>
+    <DebugType>PdbOnly</DebugType>
     <Optimize>True</Optimize>
     <CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
     <DefineConstants>TRACE</DefineConstants>
@@ -76,4 +76,4 @@
       <DependentUpon>Math.cs</DependentUpon>
     </Compile>
   </ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
--- openbve-1.4.0.9.orig/openBVE/Sound.Flac/Sound.Flac.csproj
+++ openbve-1.4.0.9/openBVE/Sound.Flac/Sound.Flac.csproj
@@ -7,7 +7,7 @@
     <OutputType>Library</OutputType>
     <RootNamespace>Sound.Flac</RootNamespace>
     <AssemblyName>Sound.Flac</AssemblyName>
-    <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <SourceAnalysisOverrideSettingsFile>C:\Documents and Settings\Administrator\Application Data\ICSharpCode/SharpDevelop3.0\Settings.SourceAnalysis</SourceAnalysisOverrideSettingsFile>
     <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
--- openbve-1.4.0.9.orig/openBVE/Sound.RiffWave/Sound.RiffWave.csproj
+++ openbve-1.4.0.9/openBVE/Sound.RiffWave/Sound.RiffWave.csproj
@@ -7,7 +7,7 @@
     <OutputType>Library</OutputType>
     <RootNamespace>Plugin</RootNamespace>
     <AssemblyName>Sound.RiffWave</AssemblyName>
-    <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <SourceAnalysisOverrideSettingsFile>C:\Documents and Settings\Administrator\Application Data\ICSharpCode/SharpDevelop3.0\Settings.SourceAnalysis</SourceAnalysisOverrideSettingsFile>
     <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
--- openbve-1.4.0.9.orig/openBVE/OpenBveAts/OpenBveAts.csproj
+++ openbve-1.4.0.9/openBVE/OpenBveAts/OpenBveAts.csproj
@@ -7,7 +7,7 @@
     <OutputType>Library</OutputType>
     <RootNamespace>OpenBveAts</RootNamespace>
     <AssemblyName>OpenBveAts</AssemblyName>
-    <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <SourceAnalysisOverrideSettingsFile>C:\Documents and Settings\Administrator\Application Data\ICSharpCode/SharpDevelop3.0\Settings.SourceAnalysis</SourceAnalysisOverrideSettingsFile>
     <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
