-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Windows] Add FreeSO style dynamic linking of Monogame
DirectX by default in Windows. Use `-dx` and `-gl` to manually switch. Should make azure build usable.
- Loading branch information
1 parent
6057764
commit 42e8a77
Showing
6 changed files
with
279 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using FSO.Client; | ||
using FSO.LotView; | ||
using FSO.UI; | ||
using Simitone.Client; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
|
||
namespace Simitone.Windows | ||
{ | ||
public class GameStartProxy | ||
{ | ||
public void Start(bool useDX) | ||
{ | ||
GameFacade.DirectX = useDX; | ||
World.DirectX = useDX; | ||
SimitoneGame game = new SimitoneGame(); | ||
var form = (Form)Form.FromHandle(game.Window.Handle); | ||
if (form != null) form.FormClosing += Form_FormClosing; | ||
game.Run(); | ||
game.Dispose(); | ||
} | ||
|
||
private static void Form_FormClosing(object sender, FormClosingEventArgs e) | ||
{ | ||
e.Cancel = !(GameFacade.Screens.CurrentUIScreen?.CloseAttempt() ?? true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
Client/Simitone/Simitone.Windows/Utils/MonogameLinker.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Simitone.Windows.Utils | ||
{ | ||
class MonogameLinker | ||
{ | ||
//detects OS and copies the correct version of monogame into the parent directory. | ||
//there is probably a better way to do this that doesn't mess with multiple clients | ||
|
||
public static string AssemblyDir = "./"; | ||
|
||
public static bool Link(bool preferDX11) | ||
{ | ||
OperatingSystem os = Environment.OSVersion; | ||
PlatformID pid = os.Platform; | ||
|
||
bool linux = false; | ||
if (pid == PlatformID.MacOSX || pid == PlatformID.Unix) linux = true; | ||
|
||
if (linux && preferDX11) | ||
{ | ||
Console.WriteLine("DirectX is usually only available on Windows. I hope you know what you're doing..."); | ||
} | ||
|
||
try | ||
{ | ||
string contentDir = "Content/OGL/"; | ||
string monogameDir = "Monogame/WindowsGL/"; | ||
if (!linux) | ||
{ | ||
if (preferDX11) | ||
{ | ||
contentDir = "Content/DX/"; | ||
monogameDir = "Monogame/Windows/"; | ||
} | ||
} | ||
//Check if MacOS by checkking user directory. Because PlatformID.MacOSX is not true on OS X. | ||
else if (Directory.Exists("/Users")) | ||
{ | ||
monogameDir = "Monogame/MacOS/"; | ||
return false; | ||
} | ||
else | ||
{ | ||
monogameDir = "Monogame/Linux/"; | ||
return false; | ||
} | ||
|
||
if (File.Exists("Monogame.Framework.dll")) File.Delete("Monogame.Framework.dll"); | ||
|
||
AssemblyDir = monogameDir; | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine("Unable to link Monogame. Continuing... (" + e.ToString() + ")"); | ||
} | ||
|
||
return preferDX11; | ||
} | ||
|
||
private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs) | ||
{ | ||
// Get the subdirectories for the specified directory. | ||
DirectoryInfo dir = new DirectoryInfo(sourceDirName); | ||
|
||
if (!dir.Exists) | ||
{ | ||
throw new DirectoryNotFoundException( | ||
"Source directory does not exist or could not be found: " | ||
+ sourceDirName); | ||
} | ||
|
||
DirectoryInfo[] dirs = dir.GetDirectories(); | ||
// If the destination directory doesn't exist, create it. | ||
if (!Directory.Exists(destDirName)) | ||
{ | ||
Directory.CreateDirectory(destDirName); | ||
} | ||
|
||
// Get the files in the directory and copy them to the new location. | ||
FileInfo[] files = dir.GetFiles(); | ||
foreach (FileInfo file in files) | ||
{ | ||
string temppath = Path.Combine(destDirName, file.Name); | ||
file.CopyTo(temppath, true); | ||
} | ||
|
||
// If copying subdirectories, copy them and their contents to new location. | ||
if (copySubDirs) | ||
{ | ||
foreach (DirectoryInfo subdir in dirs) | ||
{ | ||
string temppath = Path.Combine(destDirName, subdir.Name); | ||
DirectoryCopy(subdir.FullName, temppath, copySubDirs); | ||
} | ||
} | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.