summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-04-02 21:30:55 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-04-02 21:30:55 -0400
commit3fa0433c9862d1922cd0540848d2bd8716934d1f (patch)
tree2b09a736395b9bda09e3a4c408cdff51dbd63f81
parent62c1f11109b3a16e4e1d526e8ddc891015c507b0 (diff)
downloadSMAPI-3fa0433c9862d1922cd0540848d2bd8716934d1f.tar.gz
SMAPI-3fa0433c9862d1922cd0540848d2bd8716934d1f.tar.bz2
SMAPI-3fa0433c9862d1922cd0540848d2bd8716934d1f.zip
add initial support for 64-bit Windows hack (#767)
-rw-r--r--build/common.targets12
-rw-r--r--docs/technical/smapi.md3
-rw-r--r--src/SMAPI.Mods.ConsoleCommands/SMAPI.Mods.ConsoleCommands.csproj2
-rw-r--r--src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj2
-rw-r--r--src/SMAPI/Constants.cs56
-rw-r--r--src/SMAPI/Framework/Logging/LogManager.cs3
-rw-r--r--src/SMAPI/Framework/SCore.cs2
-rw-r--r--src/SMAPI/SMAPI.csproj6
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 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-
- <Import Project="find-game-folder.targets" />
-
<!--set properties -->
<PropertyGroup>
<Version>3.9.5</Version>
@@ -9,9 +6,15 @@
<LangVersion>latest</LangVersion>
<AssemblySearchPaths>$(AssemblySearchPaths);{GAC}</AssemblySearchPaths>
- <DefineConstants Condition="$(OS) == 'Windows_NT'">$(DefineConstants);SMAPI_FOR_WINDOWS;SMAPI_FOR_XNA</DefineConstants>
+
+ <!--<DefineConstants>$(DefineConstants);SMAPI_FOR_WINDOWS_64BIT_HACK</DefineConstants>-->
+ <DefineConstants Condition="$(OS) == 'Windows_NT'">$(DefineConstants);SMAPI_FOR_WINDOWS</DefineConstants>
+ <DefineConstants Condition="$(OS) == 'Windows_NT' AND !$(DefineConstants.Contains(SMAPI_FOR_WINDOWS_64BIT_HACK))">$(DefineConstants);SMAPI_FOR_XNA</DefineConstants>
</PropertyGroup>
+ <!--find game folder-->
+ <Import Project="find-game-folder.targets" />
+
<!-- if game path is invalid, show one user-friendly error instead of a slew of reference errors -->
<Target Name="ValidateInstallPath" AfterTargets="BeforeBuild">
<Error Condition="!Exists('$(GamePath)')" Text="Failed to find the game install path automatically. You can specify where to find it; see https://smapi.io/package/custom-game-path." />
@@ -76,5 +79,4 @@
<!-- Somehow this makes Visual Studio for Mac recognise the previous section. Nobody knows why. -->
<PropertyGroup Condition="'$(RunConfiguration)' == 'Default'" />
-
</Project>
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 @@
<!-- Windows only -->
<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
- <Reference Include="Netcode" HintPath="$(GamePath)\Netcode.dll" Private="False" />
+ <Reference Include="Netcode" HintPath="$(GamePath)\Netcode.dll" Private="False" Condition="!$(DefineConstants.Contains(SMAPI_FOR_WINDOWS_64BIT_HACK))" />
</ItemGroup>
<!-- Game framework -->
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 @@
<!-- Windows only -->
<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
- <Reference Include="Netcode" HintPath="$(GamePath)\Netcode.dll" Private="False" />
+ <Reference Include="Netcode" HintPath="$(GamePath)\Netcode.dll" Private="False" Condition="!$(DefineConstants.Contains(SMAPI_FOR_WINDOWS_64BIT_HACK))" />
</ItemGroup>
<!-- Game framework -->
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
/// <summary>The target game platform.</summary>
internal static GamePlatform Platform { get; } = (GamePlatform)Enum.Parse(typeof(GamePlatform), LowLevelEnvironmentUtility.DetectPlatform());
+ /// <summary>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.</summary>
+ internal static bool IsWindows64BitHack { get; } =
+#if SMAPI_FOR_WINDOWS_64BIT_HACK
+ true;
+#else
+ false;
+#endif
+
/// <summary>The game framework running the game.</summary>
internal static GameFramework GameFramework { get; } =
#if SMAPI_FOR_XNA
@@ -47,7 +55,7 @@ namespace StardewModdingAPI
#endif
/// <summary>The game's assembly name.</summary>
- internal static string GameAssemblyName => EarlyConstants.Platform == GamePlatform.Windows ? "Stardew Valley" : "StardewValley";
+ internal static string GameAssemblyName => EarlyConstants.Platform == GamePlatform.Windows && !EarlyConstants.IsWindows64BitHack ? "Stardew Valley" : "StardewValley";
/// <summary>The <see cref="Context.ScreenId"/> value which should appear in the SMAPI log, if any.</summary>
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 ?? "<unknown>"}");
#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 @@
<Import Project="..\..\build\common.targets" />
+ <PropertyGroup Condition="$(DefineConstants.Contains(SMAPI_FOR_WINDOWS_64BIT_HACK))">
+ <PlatformTarget>x64</PlatformTarget>
+ </PropertyGroup>
+
<ItemGroup>
<PackageReference Include="LargeAddressAware" Version="1.0.5" />
<PackageReference Include="Mono.Cecil" Version="0.11.3" />
@@ -34,7 +38,7 @@
<!-- Windows only -->
<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
- <Reference Include="Netcode" HintPath="$(GamePath)\Netcode.dll" Private="False" />
+ <Reference Include="Netcode" HintPath="$(GamePath)\Netcode.dll" Private="False" Condition="!$(DefineConstants.Contains(SMAPI_FOR_WINDOWS_64BIT_HACK))" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>