From 3fa0433c9862d1922cd0540848d2bd8716934d1f Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 2 Apr 2021 21:30:55 -0400 Subject: add initial support for 64-bit Windows hack (#767) --- build/common.targets | 12 +++-- docs/technical/smapi.md | 3 +- .../SMAPI.Mods.ConsoleCommands.csproj | 2 +- .../SMAPI.Mods.ErrorHandler.csproj | 2 +- src/SMAPI/Constants.cs | 56 +++++++++++----------- src/SMAPI/Framework/Logging/LogManager.cs | 3 ++ src/SMAPI/Framework/SCore.cs | 2 +- src/SMAPI/SMAPI.csproj | 6 ++- 8 files changed, 49 insertions(+), 37 deletions(-) diff --git a/build/common.targets b/build/common.targets index d680fa74..8137a6f3 100644 --- a/build/common.targets +++ b/build/common.targets @@ -1,7 +1,4 @@ - - - 3.9.5 @@ -9,9 +6,15 @@ latest $(AssemblySearchPaths);{GAC} - $(DefineConstants);SMAPI_FOR_WINDOWS;SMAPI_FOR_XNA + + + $(DefineConstants);SMAPI_FOR_WINDOWS + $(DefineConstants);SMAPI_FOR_XNA + + + @@ -76,5 +79,4 @@ - diff --git a/docs/technical/smapi.md b/docs/technical/smapi.md index e77d9d82..993bddfb 100644 --- a/docs/technical/smapi.md +++ b/docs/technical/smapi.md @@ -57,7 +57,8 @@ SMAPI uses a small number of conditional compilation constants, which you can se flag | purpose ---- | ------- `SMAPI_FOR_WINDOWS` | Whether SMAPI is being compiled for Windows; if not set, the code assumes Linux/MacOS. Set automatically in `common.targets`. -`SMAPI_FOR_XNA` | Whether SMAPI is being compiled for XNA Framework; if not set, the code assumes MonoGame. Set automatically in `common.targets` with the same value as `SMAPI_FOR_WINDOWS`. +`SMAPI_FOR_WINDOWS_64BIT_HACK` | Whether SMAPI is being [compiled for Windows with a 64-bit Linux version of the game](https://github.com/Pathoschild/SMAPI/issues/767). This is highly specialized and shouldn't be used in most cases. False by default. +`SMAPI_FOR_XNA` | Whether SMAPI is being compiled for XNA Framework; if not set, the code assumes MonoGame. Set automatically in `common.targets` with the same value as `SMAPI_FOR_WINDOWS` (unless `SMAPI_FOR_WINDOWS_64BIT_HACK` is set). `HARMONY_2` | Whether to enable experimental Harmony 2.0 support and rewrite existing Harmony 1._x_ mods for compatibility. Note that you need to replace `build/0Harmony.dll` with a Harmony 2.0 build (or switch to a package reference) to use this flag. ## For SMAPI developers diff --git a/src/SMAPI.Mods.ConsoleCommands/SMAPI.Mods.ConsoleCommands.csproj b/src/SMAPI.Mods.ConsoleCommands/SMAPI.Mods.ConsoleCommands.csproj index a187c1ff..432fdc35 100644 --- a/src/SMAPI.Mods.ConsoleCommands/SMAPI.Mods.ConsoleCommands.csproj +++ b/src/SMAPI.Mods.ConsoleCommands/SMAPI.Mods.ConsoleCommands.csproj @@ -19,7 +19,7 @@ - + diff --git a/src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj b/src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj index 788f6f16..56daa710 100644 --- a/src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj +++ b/src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj @@ -19,7 +19,7 @@ - + diff --git a/src/SMAPI/Constants.cs b/src/SMAPI/Constants.cs index 8b0c952d..af9b7aa2 100644 --- a/src/SMAPI/Constants.cs +++ b/src/SMAPI/Constants.cs @@ -38,6 +38,14 @@ namespace StardewModdingAPI /// The target game platform. internal static GamePlatform Platform { get; } = (GamePlatform)Enum.Parse(typeof(GamePlatform), LowLevelEnvironmentUtility.DetectPlatform()); + /// Whether SMAPI is being compiled for Windows with a 64-bit Linux version of the game. This is highly specialized and shouldn't be used in most cases. + internal static bool IsWindows64BitHack { get; } = +#if SMAPI_FOR_WINDOWS_64BIT_HACK + true; +#else + false; +#endif + /// The game framework running the game. internal static GameFramework GameFramework { get; } = #if SMAPI_FOR_XNA @@ -47,7 +55,7 @@ namespace StardewModdingAPI #endif /// The game's assembly name. - internal static string GameAssemblyName => EarlyConstants.Platform == GamePlatform.Windows ? "Stardew Valley" : "StardewValley"; + internal static string GameAssemblyName => EarlyConstants.Platform == GamePlatform.Windows && !EarlyConstants.IsWindows64BitHack ? "Stardew Valley" : "StardewValley"; /// The value which should appear in the SMAPI log, if any. internal static int? LogScreenId { get; set; } @@ -231,33 +239,27 @@ namespace StardewModdingAPI targetAssemblies.Add(typeof(StardewModdingAPI.IManifest).Assembly); // get changes for platform - switch (targetPlatform) + if (Constants.Platform != Platform.Windows || EarlyConstants.IsWindows64BitHack) { - case Platform.Linux: - case Platform.Mac: - removeAssemblyReferences.AddRange(new[] - { - "Netcode", - "Stardew Valley" - }); - targetAssemblies.Add( - typeof(StardewValley.Game1).Assembly // note: includes Netcode types on Linux/Mac - ); - break; - - case Platform.Windows: - removeAssemblyReferences.Add( - "StardewValley" - ); - targetAssemblies.AddRange(new[] - { - typeof(Netcode.NetBool).Assembly, - typeof(StardewValley.Game1).Assembly - }); - break; - - default: - throw new InvalidOperationException($"Unknown target platform '{targetPlatform}'."); + removeAssemblyReferences.AddRange(new[] + { + "Netcode", + "Stardew Valley" + }); + targetAssemblies.Add( + typeof(StardewValley.Game1).Assembly // note: includes Netcode types on Linux/Mac + ); + } + else + { + removeAssemblyReferences.Add( + "StardewValley" + ); + targetAssemblies.AddRange(new[] + { + typeof(Netcode.NetBool).Assembly, + typeof(StardewValley.Game1).Assembly + }); } // get changes for game framework diff --git a/src/SMAPI/Framework/Logging/LogManager.cs b/src/SMAPI/Framework/Logging/LogManager.cs index 243ca3ae..38d561e5 100644 --- a/src/SMAPI/Framework/Logging/LogManager.cs +++ b/src/SMAPI/Framework/Logging/LogManager.cs @@ -287,6 +287,9 @@ namespace StardewModdingAPI.Framework.Logging string platformLabel = EnvironmentUtility.GetFriendlyPlatformName(Constants.Platform); if ((Constants.GameFramework == GameFramework.Xna) != (Constants.Platform == Platform.Windows)) platformLabel += $" with {Constants.GameFramework}"; +#if SMAPI_FOR_WINDOWS_64BIT_HACK + platformLabel += " 64-bit hack"; +#endif // init logging this.Monitor.Log($"SMAPI {Constants.ApiVersion} with Stardew Valley {Constants.GameVersion} on {platformLabel}", LogLevel.Info); diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index ebb21555..22c58099 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -419,7 +419,7 @@ namespace StardewModdingAPI.Framework Game1.mapDisplayDevice = new SDisplayDevice(Game1.content, Game1.game1.GraphicsDevice); // log GPU info -#if SMAPI_FOR_WINDOWS +#if SMAPI_FOR_WINDOWS && !SMAPI_FOR_WINDOWS_64BIT_HACK this.Monitor.Log($"Running on GPU: {Game1.game1.GraphicsDevice?.Adapter?.Description ?? ""}"); #endif } diff --git a/src/SMAPI/SMAPI.csproj b/src/SMAPI/SMAPI.csproj index ceef33df..413d9f33 100644 --- a/src/SMAPI/SMAPI.csproj +++ b/src/SMAPI/SMAPI.csproj @@ -14,6 +14,10 @@ + + x64 + + @@ -34,7 +38,7 @@ - + -- cgit