diff --git a/TGS.Server/Instance/Byond.cs b/TGS.Server/Instance/Byond.cs
index 81bbc02352..59d1bc4606 100644
--- a/TGS.Server/Instance/Byond.cs
+++ b/TGS.Server/Instance/Byond.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Net;
+using System.Diagnostics;
using System.Text.RegularExpressions;
using System.Threading;
using TGS.Interface;
@@ -43,7 +44,11 @@ namespace TGS.Server
///
/// The instance directory to modify the BYOND cfg before installation
///
- const string ByondConfigDir = StagingDirectory + "/BYOND/cfg";
+ const string ByondConfigDir = StagingDirectoryInner + "/cfg";
+ ///
+ /// The instance that contains the BYOND directx redistributable
+ ///
+ const string ByondDXDir = StagingDirectoryInner + "/directx";
///
/// BYOND's DreamDaemon config file in the cfg modification directory
///
@@ -76,6 +81,11 @@ namespace TGS.Server
///
Thread RevisionStaging;
+ ///
+ /// Global lock for installing DirectX if necessary
+ ///
+ static object DirectXInstallLock = new object();
+
///
/// Called when the is setup. Prepares the BYOND updater
///
@@ -266,6 +276,44 @@ namespace TGS.Server
Directory.CreateDirectory(RelativePath(ByondConfigDir));
File.WriteAllText(RelativePath(ByondDDConfig), ByondNoPromptTrustedMode);
+ if (major >= 512 && minor >= 1427)
+ {
+ if (Monitor.TryEnter(DirectXInstallLock))
+ try
+ {
+ //always install it, it's pretty fast and will do better redundancy checking than us
+ using (var p = new Process())
+ {
+ p.StartInfo.Arguments = "/silent";
+ var rbdx = RelativePath(ByondDXDir);
+ p.StartInfo.FileName = rbdx + "/DXSETUP.exe";
+ p.StartInfo.UseShellExecute = false;
+ p.StartInfo.WorkingDirectory = rbdx;
+ p.Start();
+ try
+ {
+ p.WaitForExit();
+ }
+ finally
+ {
+ try
+ {
+ p.Kill();
+ p.WaitForExit();
+ }
+ catch (InvalidOperationException) { }
+ }
+
+ if(p.ExitCode != 0)
+ throw new Exception("Failed to install included DirectX! Exit code: " + p.ExitCode);
+ }
+ }
+ finally
+ {
+ Monitor.Exit(DirectXInstallLock);
+ }
+ }
+
lock (ByondLock)
File.WriteAllText(RelativePath(StagingDirectoryInner + VersionFile), String.Format("{0}.{1}", major, minor));