From e89de6316d8a8b2e0169790b2a14427892828be5 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 30 Oct 2021 19:53:28 -0400 Subject: add set_farm_type console command --- .../Commands/Player/SetFarmTypeCommand.cs | 91 ++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/SetFarmTypeCommand.cs (limited to 'src') diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/SetFarmTypeCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/SetFarmTypeCommand.cs new file mode 100644 index 00000000..0bebd2b7 --- /dev/null +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/SetFarmTypeCommand.cs @@ -0,0 +1,91 @@ +using System.Collections.Generic; +using System.Linq; +using StardewValley; + +namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player +{ + /// A command which changes the player's farm type. + internal class SetFarmTypeCommand : ConsoleCommand + { + /********* + ** Fields + *********/ + /// The vanilla farm type IDs. + private static readonly ISet VanillaFarmTypes = new HashSet( + Enumerable.Range(0, Farm.layout_max + 1) + ); + + + /********* + ** Public methods + *********/ + /// Construct an instance. + public SetFarmTypeCommand() + : base("set_farm_type", $"Sets the current player's farm type.\n\nUsage: set_farm_type \n- farm type: one of {string.Join(", ", SetFarmTypeCommand.VanillaFarmTypes.Select(id => $"{id} ({SetFarmTypeCommand.GetFarmLabel(id)})"))}.") { } + + /// Handle the command. + /// Writes messages to the console and log file. + /// The command name. + /// The command arguments. + public override void Handle(IMonitor monitor, string command, ArgumentParser args) + { + // validation checks + if (!Context.IsWorldReady) + { + monitor.Log("You must load a save to use this command.", LogLevel.Error); + return; + } + + // parse argument + if (!args.TryGetInt(0, "farm type", out int farmType, min: 0, max: Farm.layout_max)) + return; + + // handle + if (Game1.whichFarm == farmType) + { + monitor.Log($"Your current farm is already set to {farmType} ({SetFarmTypeCommand.GetFarmLabel(farmType)}).", LogLevel.Info); + return; + } + + this.SetFarmType(farmType); + monitor.Log($"Your current farm has been converted to {farmType} ({SetFarmTypeCommand.GetFarmLabel(farmType)}).", LogLevel.Warn); + monitor.Log("Saving and reloading is recommended to make sure everything is updated for the change.", LogLevel.Warn); + } + + + /********* + ** Private methods + *********/ + /// Change the farm type to the given value. + /// The farm type ID. + private void SetFarmType(int type) + { + Game1.whichFarm = type; + + Farm farm = Game1.getFarm(); + farm.mapPath.Value = $@"Maps\{Farm.getMapNameFromTypeInt(Game1.whichFarm)}"; + farm.reloadMap(); + } + + /// Get the display name for a vanilla farm type. + /// The farm type. + private static string GetFarmLabel(int type) + { + string translationKey = type switch + { + Farm.default_layout => "Character_FarmStandard", + Farm.riverlands_layout => "Character_FarmFishing", + Farm.forest_layout => "Character_FarmForaging", + Farm.mountains_layout => "Character_FarmMining", + Farm.combat_layout => "Character_FarmCombat", + Farm.fourCorners_layout => "Character_FarmFourCorners", + Farm.beach_layout => "Character_FarmBeach", + _ => null + }; + + return translationKey != null + ? Game1.content.LoadString(@$"Strings\UI:{translationKey}").Split('_')[0] + : type.ToString(); + } + } +} -- cgit From 96db1d931552ef8973cdf07e3f1d4a4618992276 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 31 Oct 2021 14:14:21 -0400 Subject: update Content Patcher schema for 1.24.0 --- docs/release-notes.md | 3 +++ src/SMAPI.Web/wwwroot/schemas/content-patcher.json | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/docs/release-notes.md b/docs/release-notes.md index 42519b1f..efda7267 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -5,6 +5,9 @@ * For players: * Added `set_farm_type` [console command](https://stardewvalleywiki.com/Modding:Console_commands#Console_commands) to change the current farm type. +* For the web UI: + * Updated the JSON validator/schema for Content Patcher 1.24.0. + ## 3.12.8 Released 18 October 2021 for Stardew Valley 1.5.4. diff --git a/src/SMAPI.Web/wwwroot/schemas/content-patcher.json b/src/SMAPI.Web/wwwroot/schemas/content-patcher.json index aac4ff0f..d39574ef 100644 --- a/src/SMAPI.Web/wwwroot/schemas/content-patcher.json +++ b/src/SMAPI.Web/wwwroot/schemas/content-patcher.json @@ -12,11 +12,11 @@ "properties": { "Format": { "title": "Format version", - "description": "The format version. You should always use the latest version to enable the latest features and avoid obsolete behavior.", + "description": "The format version. You should always use the latest version to enable the latest features, avoid obsolete behavior, and reduce load times.", "type": "string", - "const": "1.23.0", + "const": "1.24.0", "@errorMessages": { - "const": "Incorrect value '@value'. This should be set to the latest format version, currently '1.23.0'." + "const": "Incorrect value '@value'. You should always use the latest format version (currently 1.24.0) to enable the latest features, avoid obsolete behavior, and reduce load times." } }, "ConfigSchema": { -- cgit From 01f59000e96357ec5288c4cc86348c90ce272ba4 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 31 Oct 2021 14:37:51 -0400 Subject: ignore WebDeploy files --- .gitignore | 2 ++ src/SMAPI.Web/SMAPI.Web.csproj | 2 ++ 2 files changed, 4 insertions(+) (limited to 'src') diff --git a/.gitignore b/.gitignore index b7f0d3e6..527ac6bb 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ [Oo]bj/ # Visual Studio cache/options +.config/ .vs/ # ReSharper @@ -32,3 +33,4 @@ appsettings.Development.json # Azure generated files src/SMAPI.Web/Properties/PublishProfiles/*.pubxml +src/SMAPI.Web/Properties/ServiceDependencies/* - Web Deploy/ diff --git a/src/SMAPI.Web/SMAPI.Web.csproj b/src/SMAPI.Web/SMAPI.Web.csproj index 4c8465a6..c1ba3ddc 100644 --- a/src/SMAPI.Web/SMAPI.Web.csproj +++ b/src/SMAPI.Web/SMAPI.Web.csproj @@ -9,6 +9,8 @@ + + -- cgit From 12e0c1519663b7106c5672ce75c6e94d8ab7638f Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 27 Nov 2021 22:37:21 -0500 Subject: migrate web project to .NET 6, update web & unit test packages --- .../SMAPI.ModBuildConfig.Analyzer.Tests.csproj | 4 ++-- src/SMAPI.Web/SMAPI.Web.csproj | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/SMAPI.ModBuildConfig.Analyzer.Tests/SMAPI.ModBuildConfig.Analyzer.Tests.csproj b/src/SMAPI.ModBuildConfig.Analyzer.Tests/SMAPI.ModBuildConfig.Analyzer.Tests.csproj index 8cc61f44..dc3d8320 100644 --- a/src/SMAPI.ModBuildConfig.Analyzer.Tests/SMAPI.ModBuildConfig.Analyzer.Tests.csproj +++ b/src/SMAPI.ModBuildConfig.Analyzer.Tests/SMAPI.ModBuildConfig.Analyzer.Tests.csproj @@ -7,9 +7,9 @@ - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/SMAPI.Web/SMAPI.Web.csproj b/src/SMAPI.Web/SMAPI.Web.csproj index c1ba3ddc..f1400e62 100644 --- a/src/SMAPI.Web/SMAPI.Web.csproj +++ b/src/SMAPI.Web/SMAPI.Web.csproj @@ -2,7 +2,7 @@ SMAPI.Web StardewModdingAPI.Web - net5.0 + net6.0 latest @@ -15,16 +15,16 @@ - - + + - - - - + + + + - + -- cgit From b64cec918d1511b6b71c9d2e30f987e9b5cc24fd Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 27 Nov 2021 22:45:14 -0500 Subject: remove direct download for beta versions With this change, only the main version has a direct download. Showing beta info here caused a few issues: * The vast majority of players don't use the game beta, so they were often confused about which version to download. * Beta versions typically have much longer release info (e.g. detailed summary, release notes, caveats and warnings, etc), and the extra download button made the player guide button under it less prominent and visible. Those both contributed to information overload and the above confusion. * Unlike main versions, beta versions aren't permanently archived on GitHub (since the beta branch is routinely rebased onto the latest stable update). That makes it messy to manage beta releases through GitHub. Instead there's now a message under the download button which clearly links to where the beta version can be downloaded. --- src/SMAPI.Web/Controllers/IndexController.cs | 52 +++++--------------- src/SMAPI.Web/Framework/ConfigModels/SiteConfig.cs | 7 +-- src/SMAPI.Web/ViewModels/IndexModel.cs | 15 ++---- src/SMAPI.Web/Views/Index/Index.cshtml | 57 +++++----------------- src/SMAPI.Web/appsettings.json | 3 +- src/SMAPI.Web/wwwroot/Content/css/index.css | 4 ++ 6 files changed, 35 insertions(+), 103 deletions(-) (limited to 'src') diff --git a/src/SMAPI.Web/Controllers/IndexController.cs b/src/SMAPI.Web/Controllers/IndexController.cs index 080285ab..f2f4c342 100644 --- a/src/SMAPI.Web/Controllers/IndexController.cs +++ b/src/SMAPI.Web/Controllers/IndexController.cs @@ -57,21 +57,16 @@ namespace StardewModdingAPI.Web.Controllers { // choose versions ReleaseVersion[] versions = await this.GetReleaseVersionsAsync(); - ReleaseVersion stableVersion = versions.LastOrDefault(version => !version.IsBeta && !version.IsForDevs); - ReleaseVersion stableVersionForDevs = versions.LastOrDefault(version => !version.IsBeta && version.IsForDevs); - ReleaseVersion betaVersion = versions.LastOrDefault(version => version.IsBeta && !version.IsForDevs); - ReleaseVersion betaVersionForDevs = versions.LastOrDefault(version => version.IsBeta && version.IsForDevs); + ReleaseVersion stableVersion = versions.LastOrDefault(version => !version.IsForDevs); + ReleaseVersion stableVersionForDevs = versions.LastOrDefault(version => version.IsForDevs); // render view IndexVersionModel stableVersionModel = stableVersion != null ? new IndexVersionModel(stableVersion.Version.ToString(), stableVersion.Release.Body, stableVersion.Asset.DownloadUrl, stableVersionForDevs?.Asset.DownloadUrl) - : new IndexVersionModel("unknown", "", "https://github.com/Pathoschild/SMAPI/releases", null); // just in case something goes wrong) - IndexVersionModel betaVersionModel = betaVersion != null && this.SiteConfig.BetaEnabled - ? new IndexVersionModel(betaVersion.Version.ToString(), betaVersion.Release.Body, betaVersion.Asset.DownloadUrl, betaVersionForDevs?.Asset.DownloadUrl) - : null; + : new IndexVersionModel("unknown", "", "https://github.com/Pathoschild/SMAPI/releases", null); // just in case something goes wrong // render view - var model = new IndexModel(stableVersionModel, betaVersionModel, this.SiteConfig.BetaBlurb, this.SiteConfig.SupporterList); + var model = new IndexModel(stableVersionModel, this.SiteConfig.OtherBlurb, this.SiteConfig.SupporterList); return this.View(model); } @@ -93,27 +88,12 @@ namespace StardewModdingAPI.Web.Controllers { entry.AbsoluteExpiration = DateTimeOffset.UtcNow.Add(this.CacheTime); - // get latest release (whether preview or stable) - GitRelease stableRelease = await this.GitHub.GetLatestReleaseAsync(this.RepositoryName, includePrerelease: true); + // get latest stable release + GitRelease release = await this.GitHub.GetLatestReleaseAsync(this.RepositoryName, includePrerelease: false); - // split stable/prerelease if applicable - GitRelease betaRelease = null; - if (stableRelease.IsPrerelease) + // strip 'noinclude' blocks from release description + if (release != null) { - GitRelease result = await this.GitHub.GetLatestReleaseAsync(this.RepositoryName, includePrerelease: false); - if (result != null) - { - betaRelease = stableRelease; - stableRelease = result; - } - } - - // strip 'noinclude' blocks from release descriptions - foreach (GitRelease release in new[] { stableRelease, betaRelease }) - { - if (release == null) - continue; - HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(release.Body); foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//*[@class='noinclude']")?.ToArray() ?? new HtmlNode[0]) @@ -122,10 +102,8 @@ namespace StardewModdingAPI.Web.Controllers } // get versions - ReleaseVersion[] stableVersions = this.ParseReleaseVersions(stableRelease).ToArray(); - ReleaseVersion[] betaVersions = this.ParseReleaseVersions(betaRelease).ToArray(); - return stableVersions - .Concat(betaVersions) + return this + .ParseReleaseVersions(release) .OrderBy(p => p.Version) .ToArray(); }); @@ -146,10 +124,9 @@ namespace StardewModdingAPI.Web.Controllers Match match = Regex.Match(asset.FileName, @"SMAPI-(?[\d\.]+(?:-.+)?)-installer(?-for-developers)?.zip"); if (!match.Success || !SemanticVersion.TryParse(match.Groups["version"].Value, out ISemanticVersion version)) continue; - bool isBeta = version.IsPrerelease(); bool isForDevs = match.Groups["forDevs"].Success; - yield return new ReleaseVersion(release, asset, version, isBeta, isForDevs); + yield return new ReleaseVersion(release, asset, version, isForDevs); } } @@ -168,9 +145,6 @@ namespace StardewModdingAPI.Web.Controllers /// The SMAPI version. public ISemanticVersion Version { get; } - /// Whether this is a beta download. - public bool IsBeta { get; } - /// Whether this is a 'for developers' download. public bool IsForDevs { get; } @@ -182,14 +156,12 @@ namespace StardewModdingAPI.Web.Controllers /// The underlying GitHub release. /// The underlying download asset. /// The SMAPI version. - /// Whether this is a beta download. /// Whether this is a 'for developers' download. - public ReleaseVersion(GitRelease release, GitAsset asset, ISemanticVersion version, bool isBeta, bool isForDevs) + public ReleaseVersion(GitRelease release, GitAsset asset, ISemanticVersion version, bool isForDevs) { this.Release = release; this.Asset = asset; this.Version = version; - this.IsBeta = isBeta; this.IsForDevs = isForDevs; } } diff --git a/src/SMAPI.Web/Framework/ConfigModels/SiteConfig.cs b/src/SMAPI.Web/Framework/ConfigModels/SiteConfig.cs index 43969f51..664dbef3 100644 --- a/src/SMAPI.Web/Framework/ConfigModels/SiteConfig.cs +++ b/src/SMAPI.Web/Framework/ConfigModels/SiteConfig.cs @@ -6,11 +6,8 @@ namespace StardewModdingAPI.Web.Framework.ConfigModels /********* ** Accessors *********/ - /// Whether to show SMAPI beta versions on the main page, if any. - public bool BetaEnabled { get; set; } - - /// A short sentence shown under the beta download button, if any. - public string BetaBlurb { get; set; } + /// A message to show below the download button (e.g. for details on downloading a beta version), in Markdown format. + public string OtherBlurb { get; set; } /// A list of supports to credit on the main page, in Markdown format. public string SupporterList { get; set; } diff --git a/src/SMAPI.Web/ViewModels/IndexModel.cs b/src/SMAPI.Web/ViewModels/IndexModel.cs index 450fdc0e..d8d2d27f 100644 --- a/src/SMAPI.Web/ViewModels/IndexModel.cs +++ b/src/SMAPI.Web/ViewModels/IndexModel.cs @@ -9,11 +9,8 @@ namespace StardewModdingAPI.Web.ViewModels /// The latest stable SMAPI version. public IndexVersionModel StableVersion { get; set; } - /// The latest prerelease SMAPI version (if newer than ). - public IndexVersionModel BetaVersion { get; set; } - - /// A short sentence shown under the beta download button, if any. - public string BetaBlurb { get; set; } + /// A message to show below the download button (e.g. for details on downloading a beta version), in Markdown format. + public string OtherBlurb { get; set; } /// A list of supports to credit on the main page, in Markdown format. public string SupporterList { get; set; } @@ -27,14 +24,12 @@ namespace StardewModdingAPI.Web.ViewModels /// Construct an instance. /// The latest stable SMAPI version. - /// The latest prerelease SMAPI version (if newer than ). - /// A short sentence shown under the beta download button, if any. + /// A message to show below the download button (e.g. for details on downloading a beta version), in Markdown format. /// A list of supports to credit on the main page, in Markdown format. - internal IndexModel(IndexVersionModel stableVersion, IndexVersionModel betaVersion, string betaBlurb, string supporterList) + internal IndexModel(IndexVersionModel stableVersion, string otherBlurb, string supporterList) { this.StableVersion = stableVersion; - this.BetaVersion = betaVersion; - this.BetaBlurb = betaBlurb; + this.OtherBlurb = otherBlurb; this.SupporterList = supporterList; } } diff --git a/src/SMAPI.Web/Views/Index/Index.cshtml b/src/SMAPI.Web/Views/Index/Index.cshtml index 9d6e4bed..669cfd99 100644 --- a/src/SMAPI.Web/Views/Index/Index.cshtml +++ b/src/SMAPI.Web/Views/Index/Index.cshtml @@ -8,9 +8,9 @@ ViewData["ViewTitle"] = string.Empty; } @section Head { - + - + }

@@ -29,25 +29,12 @@ Download from Nexus Direct download -
- - @if (Model.BetaVersion != null) + + + @if (Model.OtherBlurb != null) { -
+
@Html.Raw(Markdig.Markdown.ToHtml(Model.OtherBlurb))
} -
@@ -61,29 +48,11 @@
- @if (Model.BetaVersion == null) - { -

What's new

-
- @Html.Raw(Markdig.Markdown.ToHtml(Model.StableVersion.Description)) -
-

See the release notes and mod compatibility list for more info.

- } - else - { -

What's new in...

-

SMAPI @Model.StableVersion.Version?

-
- @Html.Raw(Markdig.Markdown.ToHtml(Model.StableVersion.Description)) -
-

See the release notes and mod compatibility list for more info.

- -

SMAPI @Model.BetaVersion.Version?

-
- @Html.Raw(Markdig.Markdown.ToHtml(Model.BetaVersion.Description)) -
-

See the release notes and mod compatibility list for more info.

- } +

What's new

+
+ @Html.Raw(Markdig.Markdown.ToHtml(Model.StableVersion.Description)) +
+

See the release notes and mod compatibility list for more info.

@@ -122,10 +91,6 @@

For mod creators

diff --git a/src/SMAPI.Web/appsettings.json b/src/SMAPI.Web/appsettings.json index 22fd7396..1837170b 100644 --- a/src/SMAPI.Web/appsettings.json +++ b/src/SMAPI.Web/appsettings.json @@ -17,8 +17,7 @@ "Site": { "BetaEnabled": false, - "BetaBlurb": null, - "SupporterList": null + "OtherBlurb": null }, "ApiClients": { diff --git a/src/SMAPI.Web/wwwroot/Content/css/index.css b/src/SMAPI.Web/wwwroot/Content/css/index.css index 1cf8d261..150ccc0a 100644 --- a/src/SMAPI.Web/wwwroot/Content/css/index.css +++ b/src/SMAPI.Web/wwwroot/Content/css/index.css @@ -97,6 +97,10 @@ h1 { display: block; } +.cta-blurb { + font-size: 0.85em; +} + .sublinks { font-size: 0.9em; margin-bottom: 1em; -- cgit From 3ca6fb562417748c87567d6bb6915d56b2c1b57c Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 27 Nov 2021 23:59:13 -0500 Subject: automatically include beta versions on Nexus for SMAPI update checks --- src/SMAPI.Web/Controllers/ModsApiController.cs | 7 +++++++ .../Framework/ConfigModels/ModUpdateCheckConfig.cs | 3 +++ src/SMAPI.Web/Framework/ConfigModels/SmapiInfoConfig.cs | 15 +++++++++++++++ src/SMAPI.Web/appsettings.json | 7 ++++++- 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/SMAPI.Web/Framework/ConfigModels/SmapiInfoConfig.cs (limited to 'src') diff --git a/src/SMAPI.Web/Controllers/ModsApiController.cs b/src/SMAPI.Web/Controllers/ModsApiController.cs index dcddaf10..37d763cc 100644 --- a/src/SMAPI.Web/Controllers/ModsApiController.cs +++ b/src/SMAPI.Web/Controllers/ModsApiController.cs @@ -81,6 +81,8 @@ namespace StardewModdingAPI.Web.Controllers if (model?.Mods == null) return new ModEntryModel[0]; + ModUpdateCheckConfig config = this.Config.Value; + // fetch wiki data WikiModEntry[] wikiData = this.WikiCache.GetWikiMods().Select(p => p.Data).ToArray(); IDictionary mods = new Dictionary(StringComparer.CurrentCultureIgnoreCase); @@ -89,6 +91,11 @@ namespace StardewModdingAPI.Web.Controllers if (string.IsNullOrWhiteSpace(mod.ID)) continue; + // special case: if this is an update check for the official SMAPI repo, check the Nexus mod page for beta versions + if (mod.ID == config.SmapiInfo.ID && mod.UpdateKeys?.Any(key => key == config.SmapiInfo.DefaultUpdateKey) == true && mod.InstalledVersion?.IsPrerelease() == true) + mod.UpdateKeys = mod.UpdateKeys.Concat(config.SmapiInfo.AddBetaUpdateKeys).ToArray(); + + // fetch result ModEntryModel result = await this.GetModData(mod, wikiData, model.IncludeExtendedMetadata, model.ApiVersion); if (!model.IncludeExtendedMetadata && (model.ApiVersion == null || mod.InstalledVersion == null)) { diff --git a/src/SMAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs b/src/SMAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs index bd58dba0..aea695b8 100644 --- a/src/SMAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs +++ b/src/SMAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs @@ -14,5 +14,8 @@ namespace StardewModdingAPI.Web.Framework.ConfigModels /// Update-check metadata to override. public ModOverrideConfig[] ModOverrides { get; set; } + + /// The update-check config for SMAPI's own update checks. + public SmapiInfoConfig SmapiInfo { get; set; } } } diff --git a/src/SMAPI.Web/Framework/ConfigModels/SmapiInfoConfig.cs b/src/SMAPI.Web/Framework/ConfigModels/SmapiInfoConfig.cs new file mode 100644 index 00000000..d69fabb3 --- /dev/null +++ b/src/SMAPI.Web/Framework/ConfigModels/SmapiInfoConfig.cs @@ -0,0 +1,15 @@ +namespace StardewModdingAPI.Web.Framework.ConfigModels +{ + /// The update-check config for SMAPI's own update checks. + internal class SmapiInfoConfig + { + /// The mod ID used for SMAPI update checks. + public string ID { get; set; } + + /// The default update key used for SMAPI update checks. + public string DefaultUpdateKey { get; set; } + + /// The update keys to add for SMAPI update checks when the player has a beta version installed. + public string[] AddBetaUpdateKeys { get; set; } + } +} diff --git a/src/SMAPI.Web/appsettings.json b/src/SMAPI.Web/appsettings.json index 1837170b..0265a928 100644 --- a/src/SMAPI.Web/appsettings.json +++ b/src/SMAPI.Web/appsettings.json @@ -75,6 +75,11 @@ "ID": "MartyrPher.SMAPI-Android-Installer", "AllowNonStandardVersions": true } - ] + ], + "SmapiInfo": { + "ID": "Pathoschild.SMAPI", + "DefaultUpdateKey": "GitHub:Pathoschild/SMAPI", + "AddBetaUpdateKeys": [ "Nexus:2400" ] + } } } -- cgit From c8c6b3897cd080ef3261f5642d31d8a51971981b Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 2 Sep 2021 19:31:22 -0400 Subject: update versions for Stardew Valley 1.5.5 and remove 1.5.4-specific checks --- src/SMAPI.Installer/InteractiveInstaller.cs | 20 -------------------- src/SMAPI/Constants.cs | 4 ++-- src/SMAPI/Program.cs | 13 ------------- 3 files changed, 2 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/SMAPI.Installer/InteractiveInstaller.cs b/src/SMAPI.Installer/InteractiveInstaller.cs index 9f49137f..79c3b891 100644 --- a/src/SMAPI.Installer/InteractiveInstaller.cs +++ b/src/SMAPI.Installer/InteractiveInstaller.cs @@ -277,18 +277,6 @@ namespace StardewModdingApi.Installer /********* ** Step 4: validate assumptions *********/ - // not 64-bit on Windows - if (context.Platform == Platform.Windows) - { - FileInfo linuxExecutable = new FileInfo(Path.Combine(paths.GamePath, "StardewValley.exe")); - if (linuxExecutable.Exists && this.Is64Bit(linuxExecutable.FullName)) - { - this.PrintError("Oops! The detected game install path seems to be unofficial 64-bit mode, which is no longer supported. You can update to Stardew Valley 1.5.5 or later instead. See https://stardewvalleywiki.com/Modding:Migrate_to_64-bit_on_Windows for more info."); - Console.ReadLine(); - return; - } - } - // executable exists if (!File.Exists(paths.ExecutablePath)) { @@ -297,14 +285,6 @@ namespace StardewModdingApi.Installer return; } - // not Stardew Valley 1.5.5+ - if (File.Exists(Path.Combine(paths.GamePath, "Stardew Valley.dll"))) - { - this.PrintError("Oops! The detected game install path seems to be Stardew Valley 1.5.5 or later, but this version of SMAPI is only compatible up to Stardew Valley 1.5.4. Please check for a newer version of SMAPI: https://smapi.io."); - Console.ReadLine(); - return; - } - // game folder doesn't contain paths beyond the max limit { string[] tooLongPaths = PathUtilities.GetTooLongPaths(Path.Combine(paths.GamePath, "Mods")).ToArray(); diff --git a/src/SMAPI/Constants.cs b/src/SMAPI/Constants.cs index 42c3b21b..4d6a2a0b 100644 --- a/src/SMAPI/Constants.cs +++ b/src/SMAPI/Constants.cs @@ -70,10 +70,10 @@ namespace StardewModdingAPI public static ISemanticVersion ApiVersion { get; } = new Toolkit.SemanticVersion(EarlyConstants.RawApiVersion); /// The minimum supported version of Stardew Valley. - public static ISemanticVersion MinimumGameVersion { get; } = new GameVersion("1.5.4"); + public static ISemanticVersion MinimumGameVersion { get; } = new GameVersion("1.5.5"); /// The maximum supported version of Stardew Valley. - public static ISemanticVersion MaximumGameVersion { get; } = new GameVersion("1.5.4"); + public static ISemanticVersion MaximumGameVersion { get; } = null; /// The target game platform. public static GamePlatform TargetPlatform { get; } = EarlyConstants.Platform; diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs index 3f97e531..574e781d 100644 --- a/src/SMAPI/Program.cs +++ b/src/SMAPI/Program.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Reflection; using System.Threading; using StardewModdingAPI.Framework; -using StardewModdingAPI.Toolkit.Framework; using StardewModdingAPI.Toolkit.Serialization.Models; namespace StardewModdingAPI @@ -84,22 +83,10 @@ namespace StardewModdingAPI } catch (Exception ex) { - // unofficial 64-bit - if (EarlyConstants.Platform == GamePlatform.Windows) - { - FileInfo linuxExecutable = new FileInfo(Path.Combine(EarlyConstants.ExecutionPath, "StardewValley.exe")); - if (linuxExecutable.Exists && LowLevelEnvironmentUtility.Is64BitAssembly(linuxExecutable.FullName)) - Program.PrintErrorAndExit("Oops! You're running Stardew Valley in unofficial 64-bit mode, which is no longer supported. You can update to Stardew Valley 1.5.5 or later instead. See https://stardewvalleywiki.com/Modding:Migrate_to_64-bit_on_Windows for more info."); - } - // file doesn't exist if (!File.Exists(Path.Combine(EarlyConstants.ExecutionPath, $"{EarlyConstants.GameAssemblyName}.exe"))) Program.PrintErrorAndExit("Oops! SMAPI can't find the game. Make sure you're running StardewModdingAPI.exe in your game folder."); - // Stardew Valley 1.5.5+ - if (File.Exists(Path.Combine(EarlyConstants.ExecutionPath, "Stardew Valley.dll"))) - Program.PrintErrorAndExit("Oops! You're running Stardew Valley 1.5.5 or later, but this version of SMAPI is only compatible up to Stardew Valley 1.5.4. Please check for a newer version of SMAPI: https://smapi.io."); - // can't load file Program.PrintErrorAndExit( message: "Oops! SMAPI couldn't load the game executable. The technical details below may have more info.", -- cgit From 6efaa651cb2b026b7bace55ffeba9d7c5a3d0567 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 12 Aug 2021 21:26:01 -0400 Subject: drop support for XNA Framework Stardew Valley 1.5.5 migrates to MonoGame on all platforms. --- docs/technical/smapi.md | 1 - src/SMAPI.ModBuildConfig/build/smapi.targets | 32 +++------ .../SMAPI.Mods.ConsoleCommands.csproj | 18 +---- .../Patches/SpriteBatchPatcher.cs | 9 +-- .../SMAPI.Mods.ErrorHandler.csproj | 18 +---- src/SMAPI/Constants.cs | 82 +++++++--------------- src/SMAPI/Framework/Content/ContentCache.cs | 9 +-- src/SMAPI/Framework/Input/GamePadStateBuilder.cs | 19 ++--- src/SMAPI/Framework/InternalExtensions.cs | 7 +- src/SMAPI/Framework/Logging/LogManager.cs | 8 +-- .../ModLoading/RewriteFacades/SpriteBatchFacade.cs | 10 +-- src/SMAPI/Framework/SCore.cs | 8 +-- src/SMAPI/GameFramework.cs | 7 +- src/SMAPI/Metadata/InstructionMetadata.cs | 8 +-- src/SMAPI/SMAPI.csproj | 19 +---- 15 files changed, 60 insertions(+), 195 deletions(-) (limited to 'src') diff --git a/docs/technical/smapi.md b/docs/technical/smapi.md index f454e99c..29fa43a8 100644 --- a/docs/technical/smapi.md +++ b/docs/technical/smapi.md @@ -57,7 +57,6 @@ 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`. ## For SMAPI developers ### Compiling from source diff --git a/src/SMAPI.ModBuildConfig/build/smapi.targets b/src/SMAPI.ModBuildConfig/build/smapi.targets index 698765ad..664ba7df 100644 --- a/src/SMAPI.ModBuildConfig/build/smapi.targets +++ b/src/SMAPI.ModBuildConfig/build/smapi.targets @@ -43,38 +43,24 @@ - + + + + + - + + - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/SMAPI.Mods.ErrorHandler/Patches/SpriteBatchPatcher.cs b/src/SMAPI.Mods.ErrorHandler/Patches/SpriteBatchPatcher.cs index 6860a4ec..f243c6d1 100644 --- a/src/SMAPI.Mods.ErrorHandler/Patches/SpriteBatchPatcher.cs +++ b/src/SMAPI.Mods.ErrorHandler/Patches/SpriteBatchPatcher.cs @@ -19,9 +19,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches public override void Apply(Harmony harmony, IMonitor monitor) { harmony.Patch( - original: Constants.GameFramework == GameFramework.Xna - ? this.RequireMethod("InternalDraw") - : this.RequireMethod("CheckValid", new[] { typeof(Texture2D) }), + original: this.RequireMethod("CheckValid", new[] { typeof(Texture2D) }), postfix: this.GetHarmonyMethod(nameof(SpriteBatchPatcher.After_CheckValid)) ); } @@ -30,13 +28,8 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches /********* ** Private methods *********/ -#if SMAPI_FOR_XNA - /// The method to call after . - /// The texture to validate. -#else /// The method to call after . /// The texture to validate. -#endif private static void After_CheckValid(Texture2D texture) { if (texture?.IsDisposed == true) diff --git a/src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj b/src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj index 182a978e..27b9144f 100644 --- a/src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj +++ b/src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj @@ -15,6 +15,7 @@ + @@ -24,23 +25,6 @@ - - - - - - - - - - - - - - - - - diff --git a/src/SMAPI/Constants.cs b/src/SMAPI/Constants.cs index 4d6a2a0b..72456ae4 100644 --- a/src/SMAPI/Constants.cs +++ b/src/SMAPI/Constants.cs @@ -40,12 +40,7 @@ namespace StardewModdingAPI internal static GamePlatform Platform { get; } = (GamePlatform)Enum.Parse(typeof(GamePlatform), LowLevelEnvironmentUtility.DetectPlatform()); /// The game framework running the game. - internal static GameFramework GameFramework { get; } = -#if SMAPI_FOR_XNA - GameFramework.Xna; -#else - GameFramework.MonoGame; -#endif + internal static GameFramework GameFramework { get; } = GameFramework.MonoGame; /// The game's assembly name. internal static string GameAssemblyName => EarlyConstants.Platform == GamePlatform.Windows ? "Stardew Valley" : "StardewValley"; @@ -260,61 +255,32 @@ namespace StardewModdingAPI removeAssemblyReferences.Add("StardewModdingAPI.Toolkit.CoreInterfaces"); targetAssemblies.Add(typeof(StardewModdingAPI.IManifest).Assembly); - // get changes for platform - if (Constants.Platform != Platform.Windows) + // XNA Framework before Stardew Valley 1.5.5 + removeAssemblyReferences.AddRange(new[] { - removeAssemblyReferences.AddRange(new[] - { - "Netcode", - "Stardew Valley" - }); - targetAssemblies.Add( - typeof(StardewValley.Game1).Assembly // note: includes Netcode types on Linux/macOS - ); - } - else - { - removeAssemblyReferences.Add( - "StardewValley" - ); - targetAssemblies.AddRange(new[] - { - typeof(Netcode.NetBool).Assembly, - typeof(StardewValley.Game1).Assembly - }); - } + "Microsoft.Xna.Framework", + "Microsoft.Xna.Framework.Game", + "Microsoft.Xna.Framework.Graphics", + "Microsoft.Xna.Framework.Xact" + }); + targetAssemblies.Add( + typeof(Microsoft.Xna.Framework.Vector2).Assembly + ); - // get changes for game framework - switch (framework) - { - case GameFramework.MonoGame: - removeAssemblyReferences.AddRange(new[] - { - "Microsoft.Xna.Framework", - "Microsoft.Xna.Framework.Game", - "Microsoft.Xna.Framework.Graphics", - "Microsoft.Xna.Framework.Xact" - }); - targetAssemblies.Add( - typeof(Microsoft.Xna.Framework.Vector2).Assembly - ); - break; - - case GameFramework.Xna: - removeAssemblyReferences.Add( - "MonoGame.Framework" - ); - targetAssemblies.AddRange(new[] - { - typeof(Microsoft.Xna.Framework.Vector2).Assembly, - typeof(Microsoft.Xna.Framework.Game).Assembly, - typeof(Microsoft.Xna.Framework.Graphics.SpriteBatch).Assembly - }); - break; + // `Netcode.dll` merged into the game assembly in Stardew Valley 1.5.5 + removeAssemblyReferences.Add( + "Netcode" + ); - default: - throw new InvalidOperationException($"Unknown game framework '{framework}'."); - } + // Stardew Valley reference + removeAssemblyReferences.Add( + Constants.Platform == Platform.Windows + ? "StardewValley" + : "Stardew Valley" + ); + targetAssemblies.Add( + typeof(StardewValley.Game1).Assembly + ); return new PlatformAssemblyMap(targetPlatform, removeAssemblyReferences.ToArray(), targetAssemblies.ToArray()); } diff --git a/src/SMAPI/Framework/Content/ContentCache.cs b/src/SMAPI/Framework/Content/ContentCache.cs index 7edc9ab9..87d15e32 100644 --- a/src/SMAPI/Framework/Content/ContentCache.cs +++ b/src/SMAPI/Framework/Content/ContentCache.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.Diagnostics.Contracts; using System.Linq; -using Microsoft.Xna.Framework; using StardewModdingAPI.Framework.Reflection; using StardewModdingAPI.Toolkit.Utilities; using StardewValley; @@ -52,13 +51,7 @@ namespace StardewModdingAPI.Framework.Content this.Cache = reflection.GetField>(contentManager, "loadedAssets").GetValue(); // get key normalization logic - if (Constants.GameFramework == GameFramework.Xna) - { - IReflectedMethod method = reflection.GetMethod(typeof(TitleContainer), "GetCleanPath"); - this.NormalizeAssetNameForPlatform = path => method.Invoke(path); - } - else - this.NormalizeAssetNameForPlatform = key => key.Replace('\\', '/'); // based on MonoGame's ContentManager.Load logic + this.NormalizeAssetNameForPlatform = PathUtilities.NormalizePath; //this.NormalizeAssetNameForPlatform = key => key.Replace('\\', '/'); // based on MonoGame's ContentManager.Load logic } /**** diff --git a/src/SMAPI/Framework/Input/GamePadStateBuilder.cs b/src/SMAPI/Framework/Input/GamePadStateBuilder.cs index f5f2d916..b0bb7f80 100644 --- a/src/SMAPI/Framework/Input/GamePadStateBuilder.cs +++ b/src/SMAPI/Framework/Input/GamePadStateBuilder.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input; @@ -157,11 +158,8 @@ namespace StardewModdingAPI.Framework.Input yield break; // buttons - foreach (var pair in this.ButtonStates) - { - if (pair.Value == ButtonState.Pressed && pair.Key.TryGetController(out Buttons button)) - yield return button.ToSButton(); - } + foreach (Buttons button in this.GetPressedGamePadButtons()) + yield return button.ToSButton(); // triggers if (this.LeftTrigger > 0.2f) @@ -201,7 +199,7 @@ namespace StardewModdingAPI.Framework.Input rightThumbStick: this.RightStickPos, leftTrigger: this.LeftTrigger, rightTrigger: this.RightTrigger, - buttons: this.GetButtonBitmask() // MonoGame requires one bitmask here; don't specify multiple values + buttons: this.GetPressedGamePadButtons().ToArray() ); return this.State.Value; @@ -211,17 +209,14 @@ namespace StardewModdingAPI.Framework.Input /********* ** Private methods *********/ - /// Get a bitmask representing the pressed buttons. - private Buttons GetButtonBitmask() + /// Get the pressed gamepad buttons. + private IEnumerable GetPressedGamePadButtons() { - Buttons flag = 0; foreach (var pair in this.ButtonStates) { if (pair.Value == ButtonState.Pressed && pair.Key.TryGetController(out Buttons button)) - flag |= button; + yield return button; } - - return flag; } } } diff --git a/src/SMAPI/Framework/InternalExtensions.cs b/src/SMAPI/Framework/InternalExtensions.cs index 6c9a5f3b..4cb77a45 100644 --- a/src/SMAPI/Framework/InternalExtensions.cs +++ b/src/SMAPI/Framework/InternalExtensions.cs @@ -6,7 +6,6 @@ using System.Threading; using Microsoft.Xna.Framework.Graphics; using StardewModdingAPI.Framework.Events; using StardewModdingAPI.Framework.Reflection; -using StardewValley; using StardewValley.Menus; namespace StardewModdingAPI.Framework @@ -150,11 +149,7 @@ namespace StardewModdingAPI.Framework /// The reflection helper with which to access private fields. public static bool IsOpen(this SpriteBatch spriteBatch, Reflector reflection) { - string fieldName = Constants.GameFramework == GameFramework.Xna - ? "inBeginEndPair" - : "_beginCalled"; - - return reflection.GetField(Game1.spriteBatch, fieldName).GetValue(); + return reflection.GetField(spriteBatch, "_beginCalled").GetValue(); } } } diff --git a/src/SMAPI/Framework/Logging/LogManager.cs b/src/SMAPI/Framework/Logging/LogManager.cs index f2876146..2e25a94a 100644 --- a/src/SMAPI/Framework/Logging/LogManager.cs +++ b/src/SMAPI/Framework/Logging/LogManager.cs @@ -253,10 +253,10 @@ namespace StardewModdingAPI.Framework.Logging switch (exception) { // audio crash - case InvalidOperationException ex when ex.Source == "Microsoft.Xna.Framework.Xact" && ex.StackTrace.Contains("Microsoft.Xna.Framework.Audio.AudioEngine..ctor"): - this.Monitor.Log("The game couldn't load audio. Do you have speakers or headphones plugged in?", LogLevel.Error); - this.Monitor.Log($"Technical details: {ex.GetLogSummary()}"); - break; + //case InvalidOperationException ex when ex.Source == "Microsoft.Xna.Framework.Xact" && ex.StackTrace.Contains("Microsoft.Xna.Framework.Audio.AudioEngine..ctor"): + // this.Monitor.Log("The game couldn't load audio. Do you have speakers or headphones plugged in?", LogLevel.Error); + // this.Monitor.Log($"Technical details: {ex.GetLogSummary()}"); + // break; // missing content folder exception case FileNotFoundException ex when ex.Message == "Couldn't find file 'C:\\Program Files (x86)\\Steam\\SteamApps\\common\\Stardew Valley\\Content\\XACT\\FarmerSounds.xgs'.": // path in error is hardcoded regardless of install path diff --git a/src/SMAPI/Framework/ModLoading/RewriteFacades/SpriteBatchFacade.cs b/src/SMAPI/Framework/ModLoading/RewriteFacades/SpriteBatchFacade.cs index aefd1c20..a064f503 100644 --- a/src/SMAPI/Framework/ModLoading/RewriteFacades/SpriteBatchFacade.cs +++ b/src/SMAPI/Framework/ModLoading/RewriteFacades/SpriteBatchFacade.cs @@ -4,7 +4,7 @@ using Microsoft.Xna.Framework.Graphics; namespace StardewModdingAPI.Framework.ModLoading.RewriteFacades { - /// Provides method signatures that can be injected into mod code for compatibility between Linux/macOS or Windows. + /// Provides method signatures that can be injected into mod code for compatibility with mods written for XNA Framework before Stardew Valley 1.5.5. /// This is public to support SMAPI rewriting and should not be referenced directly by mods. [SuppressMessage("ReSharper", "UnusedMember.Global", Justification = "Used via assembly rewriting")] [SuppressMessage("ReSharper", "CS0109", Justification = "The 'new' modifier applies when compiled on Linux/macOS.")] @@ -18,14 +18,6 @@ namespace StardewModdingAPI.Framework.ModLoading.RewriteFacades public SpriteBatchFacade(GraphicsDevice graphicsDevice) : base(graphicsDevice) { } - /**** - ** MonoGame signatures - ****/ - public new void Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect, Matrix? matrix) - { - base.Begin(sortMode, blendState, samplerState, depthStencilState, rasterizerState, effect, matrix ?? Matrix.Identity); - } - /**** ** XNA signatures ****/ diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 6dffb1de..b049e868 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -16,9 +16,7 @@ using Microsoft.Xna.Framework; #if SMAPI_FOR_WINDOWS using Microsoft.Win32; #endif -#if SMAPI_FOR_XNA -using System.Windows.Forms; -#endif +using Microsoft.Xna.Framework; using Newtonsoft.Json; using StardewModdingAPI.Enums; using StardewModdingAPI.Events; @@ -224,10 +222,6 @@ namespace StardewModdingAPI.Framework this.Toolkit.JsonHelper.JsonSettings.Converters.Add(converter); // add error handlers -#if SMAPI_FOR_XNA - Application.ThreadException += (sender, e) => this.Monitor.Log($"Critical thread exception: {e.Exception.GetLogSummary()}", LogLevel.Error); - Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); -#endif AppDomain.CurrentDomain.UnhandledException += (sender, e) => this.Monitor.Log($"Critical app domain exception: {e.ExceptionObject}", LogLevel.Error); // add more lenient assembly resolver diff --git a/src/SMAPI/GameFramework.cs b/src/SMAPI/GameFramework.cs index 7670ce8f..a0154329 100644 --- a/src/SMAPI/GameFramework.cs +++ b/src/SMAPI/GameFramework.cs @@ -1,12 +1,15 @@ +using System; + namespace StardewModdingAPI { /// The game framework running the game. public enum GameFramework { - /// The XNA Framework on Windows. + /// The XNA Framework, previously used on Windows. + [Obsolete("Stardew Valley no longer uses XNA Framework on any supported platform.")] Xna, - /// The MonoGame framework, usually on non-Windows platforms. + /// The MonoGame framework. MonoGame } } diff --git a/src/SMAPI/Metadata/InstructionMetadata.cs b/src/SMAPI/Metadata/InstructionMetadata.cs index 76371e50..368306a1 100644 --- a/src/SMAPI/Metadata/InstructionMetadata.cs +++ b/src/SMAPI/Metadata/InstructionMetadata.cs @@ -36,9 +36,6 @@ namespace StardewModdingAPI.Metadata // rewrite for crossplatform compatibility if (rewriteMods) { - if (platformChanged) - yield return new MethodParentRewriter(typeof(SpriteBatch), typeof(SpriteBatchFacade)); - // rewrite for Stardew Valley 1.5 yield return new FieldReplaceRewriter(typeof(DecoratableLocation), "furniture", typeof(GameLocation), nameof(GameLocation.furniture)); yield return new FieldReplaceRewriter(typeof(Farm), "resourceClumps", typeof(GameLocation), nameof(GameLocation.resourceClumps)); @@ -48,8 +45,9 @@ namespace StardewModdingAPI.Metadata yield return new HeuristicFieldRewriter(this.ValidateReferencesToAssemblies); yield return new HeuristicMethodRewriter(this.ValidateReferencesToAssemblies); - // rewrite for 64-bit mode - // re-enable in Stardew Valley 1.5.5 + // rewrite for Stardew Valley 1.5.5 + if (platformChanged) + yield return new MethodParentRewriter(typeof(SpriteBatch), typeof(SpriteBatchFacade)); //yield return new ArchitectureAssemblyRewriter(); // detect Harmony & rewrite for SMAPI 3.12 (Harmony 1.x => 2.0 update) diff --git a/src/SMAPI/SMAPI.csproj b/src/SMAPI/SMAPI.csproj index c147e7dc..7fb40722 100644 --- a/src/SMAPI/SMAPI.csproj +++ b/src/SMAPI/SMAPI.csproj @@ -30,32 +30,15 @@ + - - - - - - - - - - - - - - - - - - -- cgit From 2b922a71a2a4f85712ab1e84b85c9229185a131a Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 12 Aug 2021 21:26:09 -0400 Subject: update for Netcode now merged into game assembly on all platforms --- src/SMAPI.ModBuildConfig/build/smapi.targets | 3 --- src/SMAPI.Mods.ConsoleCommands/SMAPI.Mods.ConsoleCommands.csproj | 5 ----- src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj | 5 ----- src/SMAPI/Constants.cs | 8 ++------ src/SMAPI/SMAPI.csproj | 5 ----- 5 files changed, 2 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/SMAPI.ModBuildConfig/build/smapi.targets b/src/SMAPI.ModBuildConfig/build/smapi.targets index 664ba7df..be10481b 100644 --- a/src/SMAPI.ModBuildConfig/build/smapi.targets +++ b/src/SMAPI.ModBuildConfig/build/smapi.targets @@ -56,9 +56,6 @@ - - - diff --git a/src/SMAPI.Mods.ConsoleCommands/SMAPI.Mods.ConsoleCommands.csproj b/src/SMAPI.Mods.ConsoleCommands/SMAPI.Mods.ConsoleCommands.csproj index abde4162..fa192073 100644 --- a/src/SMAPI.Mods.ConsoleCommands/SMAPI.Mods.ConsoleCommands.csproj +++ b/src/SMAPI.Mods.ConsoleCommands/SMAPI.Mods.ConsoleCommands.csproj @@ -18,11 +18,6 @@ - - - - - diff --git a/src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj b/src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj index 27b9144f..7ba6025b 100644 --- a/src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj +++ b/src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj @@ -20,11 +20,6 @@ - - - - - diff --git a/src/SMAPI/Constants.cs b/src/SMAPI/Constants.cs index 72456ae4..776b3e3c 100644 --- a/src/SMAPI/Constants.cs +++ b/src/SMAPI/Constants.cs @@ -235,12 +235,8 @@ namespace StardewModdingAPI // The game assembly can have one of three names depending how the mod was compiled: // - 'StardewValley': assembly name on Linux/macOS; // - 'Stardew Valley': assembly name on Windows; - // - 'Netcode': an assembly that's separate on Windows only. - resolver.AddWithExplicitNames(AssemblyDefinition.ReadAssembly(typeof(Game1).Assembly.Location), "StardewValley", "Stardew Valley" -#if !SMAPI_FOR_WINDOWS - , "Netcode" -#endif - ); + // - 'Netcode': an assembly that was separate on Windows only before Stardew Valley 1.5.5. + resolver.AddWithExplicitNames(AssemblyDefinition.ReadAssembly(typeof(Game1).Assembly.Location), "StardewValley", "Stardew Valley", "Netcode"); } /// Get metadata for mapping assemblies to the current platform. diff --git a/src/SMAPI/SMAPI.csproj b/src/SMAPI/SMAPI.csproj index 7fb40722..e5cc8da6 100644 --- a/src/SMAPI/SMAPI.csproj +++ b/src/SMAPI/SMAPI.csproj @@ -34,11 +34,6 @@ - - - - - -- cgit From 40b74398ace748a565199fb91325815804011a98 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 12 Aug 2021 21:26:09 -0400 Subject: update for game assembly name now consistent on all platforms --- build/find-game-folder.targets | 5 ----- src/SMAPI/Constants.cs | 12 +++--------- src/SMAPI/Program.cs | 2 +- 3 files changed, 4 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/build/find-game-folder.targets b/build/find-game-folder.targets index 7a9bfc50..3341226d 100644 --- a/build/find-game-folder.targets +++ b/build/find-game-folder.targets @@ -44,11 +44,6 @@ - Stardew Valley - StardewValley - - - StardewValley diff --git a/src/SMAPI/Constants.cs b/src/SMAPI/Constants.cs index 776b3e3c..2c16052b 100644 --- a/src/SMAPI/Constants.cs +++ b/src/SMAPI/Constants.cs @@ -43,7 +43,7 @@ namespace StardewModdingAPI internal static GameFramework GameFramework { get; } = GameFramework.MonoGame; /// The game's assembly name. - internal static string GameAssemblyName => EarlyConstants.Platform == GamePlatform.Windows ? "Stardew Valley" : "StardewValley"; + internal static string GameAssemblyName { get; } = "Stardew Valley"; /// The value which should appear in the SMAPI log, if any. internal static int? LogScreenId { get; set; } @@ -269,14 +269,8 @@ namespace StardewModdingAPI ); // Stardew Valley reference - removeAssemblyReferences.Add( - Constants.Platform == Platform.Windows - ? "StardewValley" - : "Stardew Valley" - ); - targetAssemblies.Add( - typeof(StardewValley.Game1).Assembly - ); + removeAssemblyReferences.Add("StardewValley"); + targetAssemblies.Add(typeof(StardewValley.Game1).Assembly); return new PlatformAssemblyMap(targetPlatform, removeAssemblyReferences.ToArray(), targetAssemblies.ToArray()); } diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs index 574e781d..3e2213ba 100644 --- a/src/SMAPI/Program.cs +++ b/src/SMAPI/Program.cs @@ -35,7 +35,7 @@ namespace StardewModdingAPI Program.AssertSmapiVersions(); Program.Start(args); } - catch (BadImageFormatException ex) when (ex.FileName == "StardewValley" || ex.FileName == "Stardew Valley") // don't use EarlyConstants.GameAssemblyName, since we want to check both possible names + catch (BadImageFormatException ex) when (ex.FileName == EarlyConstants.GameAssemblyName) { Console.WriteLine($"SMAPI failed to initialize because your game's {ex.FileName}.exe seems to be invalid.\nThis may be a pirated version which modified the executable in an incompatible way; if so, you can try a different download or buy a legitimate version.\n\nTechnical details:\n{ex}"); } -- cgit From 727d75ae728ba6cc8fc070524264c454aac8404f Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 12 Aug 2021 21:26:10 -0400 Subject: update to .NET 5 and official 64-bit --- build/common.targets | 25 ++++-- build/prepare-install-package.targets | 66 +++++--------- docs/release-notes.md | 14 +++ docs/technical/mod-package.md | 1 + docs/technical/web.md | 2 +- src/SMAPI.Installer/Framework/InstallerContext.cs | 45 ---------- src/SMAPI.Installer/Framework/InstallerPaths.cs | 44 +++++----- src/SMAPI.Installer/InteractiveInstaller.cs | 81 ++++++----------- src/SMAPI.Installer/SMAPI.Installer.csproj | 2 +- src/SMAPI.Installer/assets/System.Numerics.dll | Bin 54272 -> 0 bytes .../assets/System.Runtime.Caching.dll | Bin 71168 -> 0 bytes src/SMAPI.Installer/assets/unix-install.sh | 18 +--- src/SMAPI.Installer/assets/unix-launcher.sh | 96 +++++---------------- .../SMAPI.ModBuildConfig.Analyzer.Tests.csproj | 13 +-- .../SMAPI.ModBuildConfig.Analyzer.csproj | 3 +- .../SMAPI.ModBuildConfig.csproj | 16 ++-- src/SMAPI.ModBuildConfig/build/smapi.targets | 8 +- .../SMAPI.Mods.ConsoleCommands.csproj | 4 +- .../SMAPI.Mods.ErrorHandler.csproj | 4 +- .../SMAPI.Mods.SaveBackup.csproj | 4 +- src/SMAPI.Tests/SMAPI.Tests.csproj | 5 +- .../SMAPI.Toolkit.CoreInterfaces.csproj | 2 +- src/SMAPI.Toolkit/Framework/Constants.cs | 9 ++ .../Framework/GameScanning/GameScanner.cs | 5 +- .../Framework/LowLevelEnvironmentUtility.cs | 9 -- src/SMAPI.Toolkit/SMAPI.Toolkit.csproj | 6 +- src/SMAPI.Toolkit/Utilities/EnvironmentUtility.cs | 7 -- src/SMAPI.Toolkit/Utilities/PathUtilities.cs | 15 ++-- src/SMAPI/Framework/Logging/LogManager.cs | 2 +- .../Framework/Reflection/InterfaceProxyFactory.cs | 2 +- src/SMAPI/Framework/SCore.cs | 9 +- src/SMAPI/Metadata/InstructionMetadata.cs | 2 +- src/SMAPI/SMAPI.csproj | 14 +-- 33 files changed, 192 insertions(+), 341 deletions(-) delete mode 100644 src/SMAPI.Installer/assets/System.Numerics.dll delete mode 100644 src/SMAPI.Installer/assets/System.Runtime.Caching.dll create mode 100644 src/SMAPI.Toolkit/Framework/Constants.cs (limited to 'src') diff --git a/build/common.targets b/build/common.targets index 02142351..a74002a6 100644 --- a/build/common.targets +++ b/build/common.targets @@ -7,7 +7,7 @@ $(AssemblySearchPaths);{GAC} - $(DefineConstants);SMAPI_FOR_WINDOWS;SMAPI_FOR_XNA + $(DefineConstants);SMAPI_FOR_WINDOWS @@ -27,20 +27,31 @@ - + + + + + + + + + - - - + + + + + + @@ -54,13 +65,13 @@ - + - + diff --git a/build/prepare-install-package.targets b/build/prepare-install-package.targets index 601f6496..bc1716a3 100644 --- a/build/prepare-install-package.targets +++ b/build/prepare-install-package.targets @@ -14,7 +14,7 @@ $(SolutionDir)\..\bin $(BuildRootPath)\SMAPI\bin\$(Configuration) - $(BuildRootPath)\SMAPI.Toolkit\bin\$(Configuration)\net452 + $(BuildRootPath)\SMAPI.Toolkit\bin\$(Configuration)\net5.0 $(BuildRootPath)\SMAPI.Mods.ConsoleCommands\bin\$(Configuration) $(BuildRootPath)\SMAPI.Mods.ErrorHandler\bin\$(Configuration) $(BuildRootPath)\SMAPI.Mods.SaveBackup\bin\$(Configuration) @@ -35,12 +35,17 @@ - - - + + + + + + - + + + @@ -61,11 +66,16 @@ - - + + + + + + + @@ -78,63 +88,33 @@ - - - - - - + + + - + - + - - - - - - - - - - - - - - - - + - diff --git a/docs/release-notes.md b/docs/release-notes.md index efda7267..43370409 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -3,8 +3,22 @@ # Release notes ## Upcoming release * For players: + * Updated for Stardew Valley 1.5.5. * Added `set_farm_type` [console command](https://stardewvalleywiki.com/Modding:Console_commands#Console_commands) to change the current farm type. +* For mod authors: + * Migrated to 64-bit MonoGame and .NET 5 on all platforms (see [migration guide for mod authors](https://stardewvalleywiki.com/Modding:Migrate_to_Stardew_Valley_1.5.5)). + +**Update note for players with older systems:** +The game now has two branches: the _main branch_ which you'll get by default, and an optional +_compatibility branch_ for [older systems](https://www.stardewvalley.net/compatibility/). The two +branches have identical content, but use [different technologies](https://stardewvalleywiki.com/Modding:Migrate_to_Stardew_Valley_1.5.5#Stardew_Valley_compatibility_branch). + +Unfortunately **SMAPI only supports the main branch of the game**. There are formidable difficulties +across all mods in supporting all three variations, the [Steam hardware stats](https://store.steampowered.com/hwsurvey) +show that 99.69% of players have 64-bit, and 32-bit imposes significant restrictions on what mods +can do. + * For the web UI: * Updated the JSON validator/schema for Content Patcher 1.24.0. diff --git a/docs/technical/mod-package.md b/docs/technical/mod-package.md index 7eefc7a4..a3ce8761 100644 --- a/docs/technical/mod-package.md +++ b/docs/technical/mod-package.md @@ -366,6 +366,7 @@ when you compile it. ## Release notes ## Upcoming release +* Updated for Stardew Valley 1.5.5 and SMAPI 3.13.0. **The older versions are no longer supported.** * Improved analyzer performance by enabling parallel execution. ## 3.3.0 diff --git a/docs/technical/web.md b/docs/technical/web.md index 50237bfe..f0d43fb1 100644 --- a/docs/technical/web.md +++ b/docs/technical/web.md @@ -367,7 +367,7 @@ accordingly. Initial setup: 1. Create an Azure Blob storage account for uploaded files. -2. Create an Azure App Services environment running the latest .NET Core on Linux or Windows. +2. Create an Azure App Services environment running the latest .NET on Linux or Windows. 3. Add these application settings in the new App Services environment: property name | description diff --git a/src/SMAPI.Installer/Framework/InstallerContext.cs b/src/SMAPI.Installer/Framework/InstallerContext.cs index 88e57760..95df32ca 100644 --- a/src/SMAPI.Installer/Framework/InstallerContext.cs +++ b/src/SMAPI.Installer/Framework/InstallerContext.cs @@ -1,6 +1,4 @@ -using System; using System.IO; -using Microsoft.Win32; using StardewModdingAPI.Toolkit; using StardewModdingAPI.Toolkit.Framework.GameScanning; using StardewModdingAPI.Toolkit.Utilities; @@ -13,9 +11,6 @@ namespace StardewModdingAPI.Installer.Framework /********* ** Fields *********/ - /// The value that represents Windows 7. - private readonly Version Windows7Version = new Version(6, 1); - /// The underlying toolkit game scanner. private readonly GameScanner GameScanner = new GameScanner(); @@ -29,9 +24,6 @@ namespace StardewModdingAPI.Installer.Framework /// The human-readable OS name and version. public string PlatformName { get; } - /// The name of the Stardew Valley executable. - public string ExecutableName { get; } - /// Whether the installer is running on Windows. public bool IsWindows => this.Platform == Platform.Windows; @@ -47,7 +39,6 @@ namespace StardewModdingAPI.Installer.Framework { this.Platform = EnvironmentUtility.DetectPlatform(); this.PlatformName = EnvironmentUtility.GetFriendlyPlatformName(this.Platform); - this.ExecutableName = EnvironmentUtility.GetExecutableName(this.Platform); } /// Get the installer's version number. @@ -57,42 +48,6 @@ namespace StardewModdingAPI.Installer.Framework return new SemanticVersion(raw); } - /// Get whether the current system has .NET Framework 4.5 or later installed. This only applies on Windows. - /// The current platform is not Windows. - public bool HasNetFramework45() - { - switch (this.Platform) - { - case Platform.Windows: - using (RegistryKey versionKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full")) - return versionKey?.GetValue("Release") != null; // .NET Framework 4.5+ - - default: - throw new NotSupportedException("The installed .NET Framework version can only be checked on Windows."); - } - } - - /// Get whether the current system has XNA Framework installed. This only applies on Windows. - /// The current platform is not Windows. - public bool HasXna() - { - switch (this.Platform) - { - case Platform.Windows: - using (RegistryKey key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(@"SOFTWARE\Microsoft\XNA\Framework")) - return key != null; // XNA Framework 4.0+ - - default: - throw new NotSupportedException("The installed XNA Framework version can only be checked on Windows."); - } - } - - /// Whether the current OS supports newer versions of .NET Framework. - public bool CanInstallLatestNetFramework() - { - return Environment.OSVersion.Version >= this.Windows7Version; // Windows 7+ - } - /// Get whether a folder seems to contain the game files. /// The folder to check. public bool LooksLikeGameFolder(DirectoryInfo dir) diff --git a/src/SMAPI.Installer/Framework/InstallerPaths.cs b/src/SMAPI.Installer/Framework/InstallerPaths.cs index 6ba5fa5f..0976eceb 100644 --- a/src/SMAPI.Installer/Framework/InstallerPaths.cs +++ b/src/SMAPI.Installer/Framework/InstallerPaths.cs @@ -1,4 +1,5 @@ using System.IO; +using StardewModdingAPI.Toolkit.Framework; namespace StardewModdingAPI.Installer.Framework { @@ -44,17 +45,20 @@ namespace StardewModdingAPI.Installer.Framework /// The full path to the user's config overrides file. public string ApiUserConfigPath { get; } - /// The full path to the installed game executable file. - public string ExecutablePath { get; private set; } + /// The full path to the installed game DLL. + public string GameDllPath { get; } - /// The full path to the vanilla game launcher on Linux/macOS. - public string UnixLauncherPath { get; } + /// The full path to the installed SMAPI executable file. + public string UnixSmapiExecutablePath { get; } - /// The full path to the installed SMAPI launcher on Linux/macOS before it's renamed. - public string UnixSmapiLauncherPath { get; } + /// The full path to the vanilla game launch script on Linux/macOS. + public string VanillaLaunchScriptPath { get; } - /// The full path to the vanilla game launcher on Linux/macOS after SMAPI is installed. - public string UnixBackupLauncherPath { get; } + /// The full path to the installed SMAPI launch script on Linux/macOS before it's renamed. + public string NewLaunchScriptPath { get; } + + /// The full path to the backed up game launch script on Linux/macOS after SMAPI is installed. + public string BackupLaunchScriptPath { get; } /********* @@ -63,28 +67,24 @@ namespace StardewModdingAPI.Installer.Framework /// Construct an instance. /// The directory path containing the files to copy into the game folder. /// The directory path for the installed game. - /// The name of the game's executable file for the current platform. - public InstallerPaths(DirectoryInfo bundleDir, DirectoryInfo gameDir, string gameExecutableName) + public InstallerPaths(DirectoryInfo bundleDir, DirectoryInfo gameDir) { + // base paths this.BundleDir = bundleDir; this.GameDir = gameDir; this.ModsDir = new DirectoryInfo(Path.Combine(gameDir.FullName, "Mods")); + this.GameDllPath = Path.Combine(gameDir.FullName, Constants.GameDllName); - this.BundleApiUserConfigPath = Path.Combine(bundleDir.FullName, "smapi-internal", "config.user.json"); + // launch scripts + this.VanillaLaunchScriptPath = Path.Combine(gameDir.FullName, "StardewValley"); + this.NewLaunchScriptPath = Path.Combine(gameDir.FullName, "unix-launcher.sh"); + this.BackupLaunchScriptPath = Path.Combine(gameDir.FullName, "StardewValley-original"); + this.UnixSmapiExecutablePath = Path.Combine(gameDir.FullName, "StardewModdingAPI"); - this.ExecutablePath = Path.Combine(gameDir.FullName, gameExecutableName); - this.UnixLauncherPath = Path.Combine(gameDir.FullName, "StardewValley"); - this.UnixSmapiLauncherPath = Path.Combine(gameDir.FullName, "StardewModdingAPI"); - this.UnixBackupLauncherPath = Path.Combine(gameDir.FullName, "StardewValley-original"); + // internal files + this.BundleApiUserConfigPath = Path.Combine(bundleDir.FullName, "smapi-internal", "config.user.json"); this.ApiConfigPath = Path.Combine(gameDir.FullName, "smapi-internal", "config.json"); this.ApiUserConfigPath = Path.Combine(gameDir.FullName, "smapi-internal", "config.user.json"); } - - /// Override the filename for the . - /// the file name. - public void SetExecutableFileName(string filename) - { - this.ExecutablePath = Path.Combine(this.GamePath, filename); - } } } diff --git a/src/SMAPI.Installer/InteractiveInstaller.cs b/src/SMAPI.Installer/InteractiveInstaller.cs index 79c3b891..34285cf7 100644 --- a/src/SMAPI.Installer/InteractiveInstaller.cs +++ b/src/SMAPI.Installer/InteractiveInstaller.cs @@ -41,12 +41,13 @@ namespace StardewModdingApi.Installer // current files yield return GetInstallPath("libgdiplus.dylib"); // Linux/macOS only yield return GetInstallPath("StardewModdingAPI"); // Linux/macOS only + yield return GetInstallPath("StardewModdingAPI.dll"); yield return GetInstallPath("StardewModdingAPI.exe"); yield return GetInstallPath("StardewModdingAPI.exe.config"); yield return GetInstallPath("StardewModdingAPI.exe.mdb"); // Linux/macOS only yield return GetInstallPath("StardewModdingAPI.pdb"); // Windows only + yield return GetInstallPath("StardewModdingAPI.runtimeconfig.json"); yield return GetInstallPath("StardewModdingAPI.xml"); - yield return GetInstallPath("StardewModdingAPI-x64.exe"); // not normally added to game folder, but may be mistakenly added by a manual install yield return GetInstallPath("smapi-internal"); yield return GetInstallPath("steam_appid.txt"); @@ -70,9 +71,7 @@ namespace StardewModdingApi.Installer yield return GetInstallPath("StardewModdingAPI.Toolkit.CoreInterfaces.dll"); // moved in 2.8 yield return GetInstallPath("StardewModdingAPI.Toolkit.CoreInterfaces.pdb"); // moved in 2.8 yield return GetInstallPath("StardewModdingAPI.Toolkit.CoreInterfaces.xml"); // moved in 2.8 - yield return GetInstallPath("System.Numerics.dll"); // moved in 2.8 - yield return GetInstallPath("System.Runtime.Caching.dll"); // moved in 2.8 - yield return GetInstallPath("System.ValueTuple.dll"); // moved in 2.8 + yield return GetInstallPath("StardewModdingAPI-x64.exe"); // 3.13 if (modsDir.Exists) { @@ -149,30 +148,6 @@ namespace StardewModdingApi.Installer } #endif - /**** - ** Check Windows dependencies - ****/ - if (context.IsWindows) - { - // .NET Framework 4.5+ - if (!context.HasNetFramework45()) - { - this.PrintError(context.CanInstallLatestNetFramework() - ? "Please install the latest version of .NET Framework before installing SMAPI." - : "Please install .NET Framework 4.5 before installing SMAPI." - ); - this.PrintError("See the download page at https://www.microsoft.com/net/download/framework for details."); - Console.ReadLine(); - return; - } - if (!context.HasXna()) - { - this.PrintError("You don't seem to have XNA Framework installed. Please run the game at least once before installing SMAPI, so it can perform its first-time setup."); - Console.ReadLine(); - return; - } - } - /**** ** read command-line arguments ****/ @@ -270,7 +245,7 @@ namespace StardewModdingApi.Installer // get folders DirectoryInfo bundleDir = new DirectoryInfo(this.BundlePath); - paths = new InstallerPaths(bundleDir, installDir, context.ExecutableName); + paths = new InstallerPaths(bundleDir, installDir); } @@ -278,7 +253,7 @@ namespace StardewModdingApi.Installer ** Step 4: validate assumptions *********/ // executable exists - if (!File.Exists(paths.ExecutablePath)) + if (!File.Exists(paths.GameDllPath)) { this.PrintError("The detected game install path doesn't contain a Stardew Valley executable."); Console.ReadLine(); @@ -367,11 +342,11 @@ namespace StardewModdingApi.Installer ** Always uninstall old files ****/ // restore game launcher - if (context.IsUnix && File.Exists(paths.UnixBackupLauncherPath)) + if (context.IsUnix && File.Exists(paths.BackupLaunchScriptPath)) { this.PrintDebug("Removing SMAPI launcher..."); - this.InteractivelyDelete(paths.UnixLauncherPath); - File.Move(paths.UnixBackupLauncherPath, paths.UnixLauncherPath); + this.InteractivelyDelete(paths.VanillaLaunchScriptPath); + File.Move(paths.BackupLaunchScriptPath, paths.VanillaLaunchScriptPath); } // remove old files @@ -419,28 +394,31 @@ namespace StardewModdingApi.Installer this.PrintDebug("Safely replacing game launcher..."); // back up & remove current launcher - if (File.Exists(paths.UnixLauncherPath)) + if (File.Exists(paths.VanillaLaunchScriptPath)) { - if (!File.Exists(paths.UnixBackupLauncherPath)) - File.Move(paths.UnixLauncherPath, paths.UnixBackupLauncherPath); + if (!File.Exists(paths.BackupLaunchScriptPath)) + File.Move(paths.VanillaLaunchScriptPath, paths.BackupLaunchScriptPath); else - this.InteractivelyDelete(paths.UnixLauncherPath); + this.InteractivelyDelete(paths.VanillaLaunchScriptPath); } // add new launcher - File.Move(paths.UnixSmapiLauncherPath, paths.UnixLauncherPath); + File.Move(paths.NewLaunchScriptPath, paths.VanillaLaunchScriptPath); - // mark file executable + // mark files executable // (MSBuild doesn't keep permission flags for files zipped in a build task.) - new Process + foreach (string path in new[] { paths.VanillaLaunchScriptPath, paths.UnixSmapiExecutablePath }) { - StartInfo = new ProcessStartInfo + new Process { - FileName = "chmod", - Arguments = $"755 \"{paths.UnixLauncherPath}\"", - CreateNoWindow = true - } - }.Start(); + StartInfo = new ProcessStartInfo + { + FileName = "chmod", + Arguments = $"755 \"{path}\"", + CreateNoWindow = true + } + }.Start(); + } } // create mods directory (if needed) @@ -507,7 +485,7 @@ namespace StardewModdingApi.Installer /********* - ** Step 6: final instructions + ** Step 7: final instructions *********/ if (context.IsWindows) { @@ -536,13 +514,6 @@ namespace StardewModdingApi.Installer /********* ** Private methods *********/ - /// Get whether an executable is 64-bit. - /// The absolute path to the executable file. - private bool Is64Bit(string executablePath) - { - return LowLevelEnvironmentUtility.Is64BitAssembly(executablePath); - } - /// Get the display text for a color scheme. /// The color scheme. private string GetDisplayText(MonitorColorScheme scheme) @@ -705,7 +676,7 @@ namespace StardewModdingApi.Installer { // get path from user Console.WriteLine(); - this.PrintInfo($"Type the file path to the game directory (the one containing '{context.ExecutableName}'), then press enter."); + this.PrintInfo($"Type the file path to the game directory (the one containing '{Constants.GameDllName}'), then press enter."); string path = Console.ReadLine()?.Trim(); if (string.IsNullOrWhiteSpace(path)) { diff --git a/src/SMAPI.Installer/SMAPI.Installer.csproj b/src/SMAPI.Installer/SMAPI.Installer.csproj index c47f3e6e..e3e01467 100644 --- a/src/SMAPI.Installer/SMAPI.Installer.csproj +++ b/src/SMAPI.Installer/SMAPI.Installer.csproj @@ -2,7 +2,7 @@ StardewModdingAPI.Installer The SMAPI installer for players. - net452 + net5.0 Exe false diff --git a/src/SMAPI.Installer/assets/System.Numerics.dll b/src/SMAPI.Installer/assets/System.Numerics.dll deleted file mode 100644 index fed0f92c..00000000 Binary files a/src/SMAPI.Installer/assets/System.Numerics.dll and /dev/null differ diff --git a/src/SMAPI.Installer/assets/System.Runtime.Caching.dll b/src/SMAPI.Installer/assets/System.Runtime.Caching.dll deleted file mode 100644 index a062391d..00000000 Binary files a/src/SMAPI.Installer/assets/System.Runtime.Caching.dll and /dev/null differ diff --git a/src/SMAPI.Installer/assets/unix-install.sh b/src/SMAPI.Installer/assets/unix-install.sh index 311c5469..a830a22d 100644 --- a/src/SMAPI.Installer/assets/unix-install.sh +++ b/src/SMAPI.Installer/assets/unix-install.sh @@ -1,24 +1,10 @@ #!/bin/bash -# Run the SMAPI installer through Mono on Linux or macOS. # Move to script's directory cd "`dirname "$0"`" -# get cross-distro version of POSIX command -COMMAND="" -if command -v command >/dev/null 2>&1; then - COMMAND="command -v" -elif type type >/dev/null 2>&1; then - COMMAND="type" -fi - # if $TERM is not set to xterm, mono will bail out when attempting to write to the console. export TERM=xterm -# validate Mono & run installer -if $COMMAND mono >/dev/null 2>&1; then - mono internal/unix-install.exe -else - echo "Oops! Looks like Mono isn't installed. Please install Mono from https://mono-project.com, reboot, and run this installer again." - read -fi +# run installer +./internal/unix-install diff --git a/src/SMAPI.Installer/assets/unix-launcher.sh b/src/SMAPI.Installer/assets/unix-launcher.sh index d309f750..21bed803 100644 --- a/src/SMAPI.Installer/assets/unix-launcher.sh +++ b/src/SMAPI.Installer/assets/unix-launcher.sh @@ -1,34 +1,17 @@ #!/usr/bin/env bash -# MonoKickstart Shell Script -# Written by Ethan "flibitijibibo" Lee -# Modified for SMAPI by various contributors # Move to script's directory cd "$(dirname "$0")" || exit $? -# Get the system architecture -UNAME=$(uname) -ARCH=$(uname -m) +# validate script is being run from the game folder +if [ ! -f "Stardew Valley.dll" ]; then + echo "Oops! SMAPI must be placed in the Stardew Valley game folder.\nSee instructions: https://stardewvalleywiki.com/Modding:Player_Guide"; + read + exit 1 +fi -# MonoKickstart picks the right libfolder, so just execute the right binary. +# macOS if [ "$UNAME" == "Darwin" ]; then - # ... Except on OSX. - export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:./osx/ - - # El Capitan is a total idiot and wipes this variable out, making the - # Steam overlay disappear. This sidesteps "System Integrity Protection" - # and resets the variable with Valve's own variable (they provided this - # fix by the way, thanks Valve!). Note that you will need to update your - # launch configuration to the script location, NOT just the app location - # (i.e. Kick.app/Contents/MacOS/Kick, not just Kick.app). - # -flibit - if [ "$STEAM_DYLD_INSERT_LIBRARIES" != "" ] && [ "$DYLD_INSERT_LIBRARIES" == "" ]; then - export DYLD_INSERT_LIBRARIES="$STEAM_DYLD_INSERT_LIBRARIES" - fi - - # this was here before - ln -sf mcs.bin.osx mcs - # fix "DllNotFoundException: libgdiplus.dylib" errors when loading images in SMAPI if [ -f libgdiplus.dylib ]; then rm libgdiplus.dylib @@ -37,52 +20,13 @@ if [ "$UNAME" == "Darwin" ]; then ln -s /Library/Frameworks/Mono.framework/Versions/Current/lib/libgdiplus.dylib libgdiplus.dylib fi - # create bin file - # Note: don't overwrite if it's identical, to avoid resetting permission flags - if [ ! -x StardewModdingAPI.bin.osx ] || ! cmp StardewValley.bin.osx StardewModdingAPI.bin.osx >/dev/null 2>&1; then - cp -p StardewValley.bin.osx StardewModdingAPI.bin.osx - fi - - # Make sure we're running in Terminal (so the user can see errors/warnings/update alerts). - # Previously we would just use `open -a Terminal` to launch the .bin.osx file, but that - # doesn't let us set environment variables. - if [ ! -t 1 ]; then # https://stackoverflow.com/q/911168/262123 - # sanity check to make sure we don't have an infinite loop of opening windows - SKIP_TERMINAL=false - for argument in "$@"; do - if [ "$argument" == "--no-reopen-terminal" ]; then - SKIP_TERMINAL=true - break - fi - done - - # reopen in Terminal if needed - # https://stackoverflow.com/a/29511052/262123 - if [ "$SKIP_TERMINAL" == "false" ]; then - echo "Reopening in the Terminal app..." - echo "\"$0\" $@ --no-reopen-terminal" > /tmp/open-smapi-terminal.sh - chmod +x /tmp/open-smapi-terminal.sh - cat /tmp/open-smapi-terminal.sh - open -W -a Terminal /tmp/open-smapi-terminal.sh - rm /tmp/open-smapi-terminal.sh - exit 0 - fi - fi + # launch smapi + open -a Terminal ./StardewModdingAPI "$@" - # launch SMAPI - LC_ALL="C" ./StardewModdingAPI.bin.osx "$@" +# Linux else # choose binary file to launch - LAUNCH_FILE="" - if [ "$ARCH" == "x86_64" ]; then - ln -sf mcs.bin.x86_64 mcs - cp StardewValley.bin.x86_64 StardewModdingAPI.bin.x86_64 - LAUNCH_FILE="./StardewModdingAPI.bin.x86_64" - else - ln -sf mcs.bin.x86 mcs - cp StardewValley.bin.x86 StardewModdingAPI.bin.x86 - LAUNCH_FILE="./StardewModdingAPI.bin.x86" - fi + LAUNCH_FILE="./StardewModdingAPI" export LAUNCH_FILE # select terminal (prefer xterm for best compatibility, then known supported terminals) @@ -105,44 +49,44 @@ else terminal|termite) # consumes only one argument after -e # options containing space characters are unsupported - exec $TERMINAL_NAME -e "env TERM=xterm LC_ALL=\"C\" $LAUNCH_FILE $@" + exec $TERMINAL_NAME -e "env TERM=xterm $LAUNCH_FILE $@" ;; xterm|konsole|alacritty) # consumes all arguments after -e - exec $TERMINAL_NAME -e env TERM=xterm LC_ALL="C" $LAUNCH_FILE "$@" + exec $TERMINAL_NAME -e env TERM=xterm $LAUNCH_FILE "$@" ;; terminator|xfce4-terminal|mate-terminal) # consumes all arguments after -x - exec $TERMINAL_NAME -x env TERM=xterm LC_ALL="C" $LAUNCH_FILE "$@" + exec $TERMINAL_NAME -x env TERM=xterm $LAUNCH_FILE "$@" ;; gnome-terminal) # consumes all arguments after -- - exec $TERMINAL_NAME -- env TERM=xterm LC_ALL="C" $LAUNCH_FILE "$@" + exec $TERMINAL_NAME -- env TERM=xterm $LAUNCH_FILE "$@" ;; kitty) # consumes all trailing arguments - exec $TERMINAL_NAME env TERM=xterm LC_ALL="C" $LAUNCH_FILE "$@" + exec $TERMINAL_NAME env TERM=xterm $LAUNCH_FILE "$@" ;; *) # If we don't know the terminal, just try to run it in the current shell. # If THAT fails, launch with no output. - env TERM=xterm LC_ALL="C" $LAUNCH_FILE "$@" + env TERM=xterm $LAUNCH_FILE "$@" if [ $? -eq 127 ]; then - exec LC_ALL="C" $LAUNCH_FILE --no-terminal "$@" + exec $LAUNCH_FILE --no-terminal "$@" fi esac ## terminal isn't executable; fallback to current shell or no terminal else echo "The '$TERMINAL_NAME' terminal isn't executable. SMAPI might be running in a sandbox or the system might be misconfigured? Falling back to current shell." - env TERM=xterm LC_ALL="C" $LAUNCH_FILE "$@" + env TERM=xterm $LAUNCH_FILE "$@" if [ $? -eq 127 ]; then - exec LC_ALL="C" $LAUNCH_FILE --no-terminal "$@" + exec $LAUNCH_FILE --no-terminal "$@" fi fi fi diff --git a/src/SMAPI.ModBuildConfig.Analyzer.Tests/SMAPI.ModBuildConfig.Analyzer.Tests.csproj b/src/SMAPI.ModBuildConfig.Analyzer.Tests/SMAPI.ModBuildConfig.Analyzer.Tests.csproj index dc3d8320..264932e4 100644 --- a/src/SMAPI.ModBuildConfig.Analyzer.Tests/SMAPI.ModBuildConfig.Analyzer.Tests.csproj +++ b/src/SMAPI.ModBuildConfig.Analyzer.Tests/SMAPI.ModBuildConfig.Analyzer.Tests.csproj @@ -1,18 +1,14 @@  - - netcoreapp2.0 + net5.0 latest - - + + - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + @@ -20,5 +16,4 @@ - diff --git a/src/SMAPI.ModBuildConfig.Analyzer/SMAPI.ModBuildConfig.Analyzer.csproj b/src/SMAPI.ModBuildConfig.Analyzer/SMAPI.ModBuildConfig.Analyzer.csproj index 0d109b83..3fadc37a 100644 --- a/src/SMAPI.ModBuildConfig.Analyzer/SMAPI.ModBuildConfig.Analyzer.csproj +++ b/src/SMAPI.ModBuildConfig.Analyzer/SMAPI.ModBuildConfig.Analyzer.csproj @@ -9,8 +9,7 @@ - - + diff --git a/src/SMAPI.ModBuildConfig/SMAPI.ModBuildConfig.csproj b/src/SMAPI.ModBuildConfig/SMAPI.ModBuildConfig.csproj index 93769650..33356413 100644 --- a/src/SMAPI.ModBuildConfig/SMAPI.ModBuildConfig.csproj +++ b/src/SMAPI.ModBuildConfig/SMAPI.ModBuildConfig.csproj @@ -2,28 +2,28 @@ StardewModdingAPI.ModBuildConfig - net452 + netstandard2.0 latest true Pathoschild.Stardew.ModBuildConfig Build package for SMAPI mods - 3.3.0 + 3.4.0 Pathoschild - Automates the build configuration for crossplatform Stardew Valley SMAPI mods. For SMAPI 3.0 or later. + Automates the build configuration for crossplatform Stardew Valley SMAPI mods. For SMAPI 3.13.0 or later. MIT images/icon.png https://smapi.io/package/readme false + + + true - - - - - + + diff --git a/src/SMAPI.ModBuildConfig/build/smapi.targets b/src/SMAPI.ModBuildConfig/build/smapi.targets index be10481b..a3cd6c45 100644 --- a/src/SMAPI.ModBuildConfig/build/smapi.targets +++ b/src/SMAPI.ModBuildConfig/build/smapi.targets @@ -45,13 +45,13 @@ **********************************************--> - + - + @@ -68,8 +68,8 @@ - - + + diff --git a/src/SMAPI.Mods.ConsoleCommands/SMAPI.Mods.ConsoleCommands.csproj b/src/SMAPI.Mods.ConsoleCommands/SMAPI.Mods.ConsoleCommands.csproj index fa192073..65d54599 100644 --- a/src/SMAPI.Mods.ConsoleCommands/SMAPI.Mods.ConsoleCommands.csproj +++ b/src/SMAPI.Mods.ConsoleCommands/SMAPI.Mods.ConsoleCommands.csproj @@ -2,7 +2,7 @@ ConsoleCommands StardewModdingAPI.Mods.ConsoleCommands - net452 + net5.0 false @@ -13,7 +13,7 @@ - + diff --git a/src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj b/src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj index 7ba6025b..2ad19df7 100644 --- a/src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj +++ b/src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj @@ -2,7 +2,7 @@ ErrorHandler StardewModdingAPI.Mods.ErrorHandler - net452 + net5.0 false @@ -14,7 +14,7 @@ - + diff --git a/src/SMAPI.Mods.SaveBackup/SMAPI.Mods.SaveBackup.csproj b/src/SMAPI.Mods.SaveBackup/SMAPI.Mods.SaveBackup.csproj index 079beb08..f8908c7d 100644 --- a/src/SMAPI.Mods.SaveBackup/SMAPI.Mods.SaveBackup.csproj +++ b/src/SMAPI.Mods.SaveBackup/SMAPI.Mods.SaveBackup.csproj @@ -2,7 +2,7 @@ SaveBackup StardewModdingAPI.Mods.SaveBackup - net452 + net5.0 false @@ -13,7 +13,7 @@ - + diff --git a/src/SMAPI.Tests/SMAPI.Tests.csproj b/src/SMAPI.Tests/SMAPI.Tests.csproj index 8f7bfab4..e19105ff 100644 --- a/src/SMAPI.Tests/SMAPI.Tests.csproj +++ b/src/SMAPI.Tests/SMAPI.Tests.csproj @@ -2,7 +2,7 @@ SMAPI.Tests SMAPI.Tests - net452 + net5.0 false latest @@ -16,6 +16,7 @@ + @@ -23,7 +24,7 @@ - $(GamePath)\$(GameExecutableName).exe + $(GamePath)\$(GameExecutableName).dll True diff --git a/src/SMAPI.Toolkit.CoreInterfaces/SMAPI.Toolkit.CoreInterfaces.csproj b/src/SMAPI.Toolkit.CoreInterfaces/SMAPI.Toolkit.CoreInterfaces.csproj index 0e1e40b2..4c92b4db 100644 --- a/src/SMAPI.Toolkit.CoreInterfaces/SMAPI.Toolkit.CoreInterfaces.csproj +++ b/src/SMAPI.Toolkit.CoreInterfaces/SMAPI.Toolkit.CoreInterfaces.csproj @@ -2,7 +2,7 @@ StardewModdingAPI Provides toolkit interfaces which are available to SMAPI mods. - net452;netstandard2.0 + net5.0; netstandard2.0 true diff --git a/src/SMAPI.Toolkit/Framework/Constants.cs b/src/SMAPI.Toolkit/Framework/Constants.cs new file mode 100644 index 00000000..55f26582 --- /dev/null +++ b/src/SMAPI.Toolkit/Framework/Constants.cs @@ -0,0 +1,9 @@ +namespace StardewModdingAPI.Toolkit.Framework +{ + /// Contains the SMAPI installer's constants and assumptions. + internal static class Constants + { + /// The name of the game's main DLL, used to detect game folders. + public const string GameDllName = "Stardew Valley.dll"; + } +} diff --git a/src/SMAPI.Toolkit/Framework/GameScanning/GameScanner.cs b/src/SMAPI.Toolkit/Framework/GameScanning/GameScanner.cs index c90fc1d3..7553c07f 100644 --- a/src/SMAPI.Toolkit/Framework/GameScanning/GameScanner.cs +++ b/src/SMAPI.Toolkit/Framework/GameScanning/GameScanner.cs @@ -56,10 +56,7 @@ namespace StardewModdingAPI.Toolkit.Framework.GameScanning { return dir.Exists - && ( - dir.EnumerateFiles("StardewValley.exe").Any() - || dir.EnumerateFiles("Stardew Valley.exe").Any() - ); + && dir.EnumerateFiles("Stardew Valley.dll").Any(); } diff --git a/src/SMAPI.Toolkit/Framework/LowLevelEnvironmentUtility.cs b/src/SMAPI.Toolkit/Framework/LowLevelEnvironmentUtility.cs index 2636aae0..8b6eb5fb 100644 --- a/src/SMAPI.Toolkit/Framework/LowLevelEnvironmentUtility.cs +++ b/src/SMAPI.Toolkit/Framework/LowLevelEnvironmentUtility.cs @@ -80,15 +80,6 @@ namespace StardewModdingAPI.Toolkit.Framework return name; } - /// Get the name of the Stardew Valley executable. - /// The current platform. - public static string GetExecutableName(string platform) - { - return platform == nameof(Platform.Windows) - ? "Stardew Valley.exe" - : "StardewValley.exe"; - } - /// Get whether an executable is 64-bit. /// The absolute path to the assembly file. public static bool Is64BitAssembly(string path) diff --git a/src/SMAPI.Toolkit/SMAPI.Toolkit.csproj b/src/SMAPI.Toolkit/SMAPI.Toolkit.csproj index 3d87c169..ec27bf79 100644 --- a/src/SMAPI.Toolkit/SMAPI.Toolkit.csproj +++ b/src/SMAPI.Toolkit/SMAPI.Toolkit.csproj @@ -2,7 +2,7 @@ StardewModdingAPI.Toolkit A library which encapsulates mod-handling logic for mod managers and tools. Not intended for use by mods. - net452;netstandard2.0 + net5.0; netstandard2.0 true @@ -12,8 +12,8 @@ - - + + diff --git a/src/SMAPI.Toolkit/Utilities/EnvironmentUtility.cs b/src/SMAPI.Toolkit/Utilities/EnvironmentUtility.cs index 6de79a85..7536337a 100644 --- a/src/SMAPI.Toolkit/Utilities/EnvironmentUtility.cs +++ b/src/SMAPI.Toolkit/Utilities/EnvironmentUtility.cs @@ -40,13 +40,6 @@ namespace StardewModdingAPI.Toolkit.Utilities return LowLevelEnvironmentUtility.GetFriendlyPlatformName(platform.ToString()); } - /// Get the name of the Stardew Valley executable. - /// The current platform. - public static string GetExecutableName(Platform platform) - { - return LowLevelEnvironmentUtility.GetExecutableName(platform.ToString()); - } - /// Get whether an executable is 64-bit. /// The absolute path to the assembly file. public static bool Is64BitAssembly(string path) diff --git a/src/SMAPI.Toolkit/Utilities/PathUtilities.cs b/src/SMAPI.Toolkit/Utilities/PathUtilities.cs index 020ebc6d..c17bb354 100644 --- a/src/SMAPI.Toolkit/Utilities/PathUtilities.cs +++ b/src/SMAPI.Toolkit/Utilities/PathUtilities.cs @@ -88,14 +88,18 @@ namespace StardewModdingAPI.Toolkit.Utilities /// Get a directory or file path relative to a given source path. If no relative path is possible (e.g. the paths are on different drives), an absolute path is returned. /// The source folder path. /// The target folder or file path. - /// - /// - /// NOTE: this is a heuristic implementation that works in the cases SMAPI needs it for, but it doesn't handle all edge cases (e.g. case-sensitivity on Linux, or traversing between UNC paths on Windows). This should be replaced with the more comprehensive Path.GetRelativePath if the game ever migrates to .NET Core. - /// - /// [Pure] public static string GetRelativePath(string sourceDir, string targetPath) { +#if NET5_0 + return Path.GetRelativePath(sourceDir, targetPath); +#else + // NOTE: + // this is a heuristic implementation that works in the cases SMAPI needs it for, but it + // doesn't handle all edge cases (e.g. case-sensitivity on Linux, or traversing between + // UNC paths on Windows). SMAPI and mods will use the more robust .NET 5 version anyway + // though, this is only for compatibility with the mod build package. + // convert to URIs Uri from = new Uri(sourceDir.TrimEnd(PathUtilities.PossiblePathSeparators) + "/"); Uri to = new Uri(targetPath.TrimEnd(PathUtilities.PossiblePathSeparators) + "/"); @@ -123,6 +127,7 @@ namespace StardewModdingAPI.Toolkit.Utilities } return relative; +#endif } /// Get whether a path is relative and doesn't try to climb out of its containing folder (e.g. doesn't contain ../). diff --git a/src/SMAPI/Framework/Logging/LogManager.cs b/src/SMAPI/Framework/Logging/LogManager.cs index 2e25a94a..abcb2f64 100644 --- a/src/SMAPI/Framework/Logging/LogManager.cs +++ b/src/SMAPI/Framework/Logging/LogManager.cs @@ -290,7 +290,7 @@ namespace StardewModdingAPI.Framework.Logging /// The custom SMAPI settings. public void LogIntro(string modsPath, IDictionary customSettings) { - // log platform & patches + // log platform this.Monitor.Log($"SMAPI {Constants.ApiVersion} with Stardew Valley {Constants.GameVersion} on {EnvironmentUtility.GetFriendlyPlatformName(Constants.Platform)}", LogLevel.Info); // log basic info diff --git a/src/SMAPI/Framework/Reflection/InterfaceProxyFactory.cs b/src/SMAPI/Framework/Reflection/InterfaceProxyFactory.cs index 8d1b6034..5acba569 100644 --- a/src/SMAPI/Framework/Reflection/InterfaceProxyFactory.cs +++ b/src/SMAPI/Framework/Reflection/InterfaceProxyFactory.cs @@ -24,7 +24,7 @@ namespace StardewModdingAPI.Framework.Reflection /// Construct an instance. public InterfaceProxyFactory() { - AssemblyBuilder assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName($"StardewModdingAPI.Proxies, Version={this.GetType().Assembly.GetName().Version}, Culture=neutral"), AssemblyBuilderAccess.Run); + AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName($"StardewModdingAPI.Proxies, Version={this.GetType().Assembly.GetName().Version}, Culture=neutral"), AssemblyBuilderAccess.Run); this.ModuleBuilder = assemblyBuilder.DefineDynamicModule("StardewModdingAPI.Proxies"); } diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index b049e868..95a7ace6 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -16,7 +16,6 @@ using Microsoft.Xna.Framework; #if SMAPI_FOR_WINDOWS using Microsoft.Win32; #endif -using Microsoft.Xna.Framework; using Newtonsoft.Json; using StardewModdingAPI.Enums; using StardewModdingAPI.Events; @@ -1298,9 +1297,6 @@ namespace StardewModdingAPI.Framework { // create client string url = this.Settings.WebApiBaseUrl; -#if !SMAPI_FOR_WINDOWS - url = url.Replace("https://", "http://"); // workaround for OpenSSL issues with the game's bundled Mono on Linux/macOS -#endif WebApiClient client = new WebApiClient(url, Constants.ApiVersion); this.Monitor.Log("Checking for updates..."); @@ -1695,9 +1691,8 @@ namespace StardewModdingAPI.Framework catch (Exception ex) { errorReasonPhrase = "its DLL couldn't be loaded."; - // re-enable in Stardew Valley 1.5.5 - //if (ex is BadImageFormatException && !EnvironmentUtility.Is64BitAssembly(assemblyPath)) - // errorReasonPhrase = "it needs to be updated for 64-bit mode."; + if (ex is BadImageFormatException && !EnvironmentUtility.Is64BitAssembly(assemblyPath)) + errorReasonPhrase = "it needs to be updated for 64-bit mode."; errorDetails = $"Error: {ex.GetLogSummary()}"; failReason = ModFailReason.LoadFailed; diff --git a/src/SMAPI/Metadata/InstructionMetadata.cs b/src/SMAPI/Metadata/InstructionMetadata.cs index 368306a1..232e54ce 100644 --- a/src/SMAPI/Metadata/InstructionMetadata.cs +++ b/src/SMAPI/Metadata/InstructionMetadata.cs @@ -48,7 +48,7 @@ namespace StardewModdingAPI.Metadata // rewrite for Stardew Valley 1.5.5 if (platformChanged) yield return new MethodParentRewriter(typeof(SpriteBatch), typeof(SpriteBatchFacade)); - //yield return new ArchitectureAssemblyRewriter(); + yield return new ArchitectureAssemblyRewriter(); // detect Harmony & rewrite for SMAPI 3.12 (Harmony 1.x => 2.0 update) yield return new HarmonyRewriter(); diff --git a/src/SMAPI/SMAPI.csproj b/src/SMAPI/SMAPI.csproj index e5cc8da6..a04dd1b6 100644 --- a/src/SMAPI/SMAPI.csproj +++ b/src/SMAPI/SMAPI.csproj @@ -3,13 +3,16 @@ StardewModdingAPI StardewModdingAPI The modding API for Stardew Valley. - net452 - x86 + net5.0 + x64 Exe true false true icon.ico + + + true @@ -19,15 +22,16 @@ - + + + - + - -- cgit From 8321cbf6eba7ca3fa46d6e452fd9ebff6baa99d0 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 12 Aug 2021 21:26:10 -0400 Subject: update for asset name format change MonoGame uses Linux-style paths for assets on all platforms, which breaks the previous equivalence between path and asset name formats. --- src/SMAPI.Tests/Utilities/PathUtilitiesTests.cs | 8 ++------ src/SMAPI.Toolkit/Utilities/PathUtilities.cs | 2 +- src/SMAPI/Framework/Content/ContentCache.cs | 14 ++++---------- 3 files changed, 7 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/SMAPI.Tests/Utilities/PathUtilitiesTests.cs b/src/SMAPI.Tests/Utilities/PathUtilitiesTests.cs index c18f47a5..ab4c2618 100644 --- a/src/SMAPI.Tests/Utilities/PathUtilitiesTests.cs +++ b/src/SMAPI.Tests/Utilities/PathUtilitiesTests.cs @@ -182,18 +182,14 @@ namespace SMAPI.Tests.Utilities [TestCaseSource(nameof(PathUtilitiesTests.SamplePaths))] public void NormalizeAssetName(SamplePath path) { - if (Path.IsPathRooted(path.OriginalPath) || path.OriginalPath.StartsWith("/") || path.OriginalPath.StartsWith("\\")) + if (Path.IsPathRooted(path.OriginalPath) || path.OriginalPath.StartsWith('/') || path.OriginalPath.StartsWith('\\')) Assert.Ignore("Absolute paths can't be used as asset names."); // act string normalized = PathUtilities.NormalizeAssetName(path.OriginalPath); // assert -#if SMAPI_FOR_WINDOWS - Assert.AreEqual(path.NormalizedOnWindows, normalized); -#else - Assert.AreEqual(path.NormalizedOnUnix, normalized); -#endif + Assert.AreEqual(path.NormalizedOnUnix, normalized); // MonoGame uses the Linux format } /**** diff --git a/src/SMAPI.Toolkit/Utilities/PathUtilities.cs b/src/SMAPI.Toolkit/Utilities/PathUtilities.cs index c17bb354..1d378042 100644 --- a/src/SMAPI.Toolkit/Utilities/PathUtilities.cs +++ b/src/SMAPI.Toolkit/Utilities/PathUtilities.cs @@ -27,7 +27,7 @@ namespace StardewModdingAPI.Toolkit.Utilities public static readonly char PreferredPathSeparator = Path.DirectorySeparatorChar; /// The preferred directory separator character in an asset key. - public static readonly char PreferredAssetSeparator = PathUtilities.PreferredPathSeparator; + public static readonly char PreferredAssetSeparator = '/'; /********* diff --git a/src/SMAPI/Framework/Content/ContentCache.cs b/src/SMAPI/Framework/Content/ContentCache.cs index 87d15e32..8e0c6228 100644 --- a/src/SMAPI/Framework/Content/ContentCache.cs +++ b/src/SMAPI/Framework/Content/ContentCache.cs @@ -17,9 +17,6 @@ namespace StardewModdingAPI.Framework.Content /// The underlying asset cache. private readonly IDictionary Cache; - /// Applies platform-specific asset key normalization so it's consistent with the underlying cache. - private readonly Func NormalizeAssetNameForPlatform; - /********* ** Accessors @@ -47,11 +44,7 @@ namespace StardewModdingAPI.Framework.Content /// Simplifies access to private game code. public ContentCache(LocalizedContentManager contentManager, Reflector reflection) { - // init this.Cache = reflection.GetField>(contentManager, "loadedAssets").GetValue(); - - // get key normalization logic - this.NormalizeAssetNameForPlatform = PathUtilities.NormalizePath; //this.NormalizeAssetNameForPlatform = key => key.Replace('\\', '/'); // based on MonoGame's ContentManager.Load logic } /**** @@ -68,23 +61,24 @@ namespace StardewModdingAPI.Framework.Content /**** ** Normalize ****/ - /// Normalize path separators in a file path. For asset keys, see instead. + /// Normalize path separators in an asset name. /// The file path to normalize. [Pure] public string NormalizePathSeparators(string path) { - return PathUtilities.NormalizePath(path); + return PathUtilities.NormalizeAssetName(path); } /// Normalize a cache key so it's consistent with the underlying cache. /// The asset key. + /// This is equivalent to with added file extension logic. [Pure] public string NormalizeKey(string key) { key = this.NormalizePathSeparators(key); return key.EndsWith(".xnb", StringComparison.OrdinalIgnoreCase) ? key.Substring(0, key.Length - 4) - : this.NormalizeAssetNameForPlatform(key); + : key; } /**** -- cgit From b2520feeaeccf0dd9f52239f7e978c22d72a032a Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 12 Aug 2021 21:26:11 -0400 Subject: update for other changes in SDV 1.5.5 --- src/SMAPI/Framework/SGame.cs | 162 +++++++++++++++++++++---------------------- 1 file changed, 79 insertions(+), 83 deletions(-) (limited to 'src') diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs index 4e134455..898ed1f5 100644 --- a/src/SMAPI/Framework/SGame.cs +++ b/src/SMAPI/Framework/SGame.cs @@ -252,7 +252,7 @@ namespace StardewModdingAPI.Framework /// Replicate the game's draw logic with some changes for SMAPI. /// A snapshot of the game timing state. /// The render target, if any. - /// This implementation is identical to , except for try..catch around menu draw code, private field references replaced by wrappers, and added events. + /// This implementation is identical to , except for try..catch around menu draw code, private field references replaced by wrappers, and added events. [SuppressMessage("ReSharper", "CompareOfFloatsByEqualityOperator", Justification = "copied from game code as-is")] [SuppressMessage("ReSharper", "InconsistentNaming", Justification = "copied from game code as-is")] [SuppressMessage("ReSharper", "LocalVariableHidesMember", Justification = "copied from game code as-is")] @@ -286,7 +286,7 @@ namespace StardewModdingAPI.Framework IClickableMenu menu = Game1.activeClickableMenu; if (menu != null) { - Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); + Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp); events.Rendering.RaiseEmpty(); try { @@ -304,7 +304,7 @@ namespace StardewModdingAPI.Framework } if (Game1.overlayMenu != null) { - Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); + Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp); Game1.overlayMenu.draw(Game1.spriteBatch); Game1.spriteBatch.End(); } @@ -315,7 +315,7 @@ namespace StardewModdingAPI.Framework if (Game1.activeClickableMenu != null && Game1.options.showMenuBackground && Game1.activeClickableMenu.showWithoutTransparencyIfOptionIsSet() && !this.takingMapScreenshot) { Game1.PushUIMode(); - Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); + Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp); events.Rendering.RaiseEmpty(); IClickableMenu curMenu = null; @@ -346,11 +346,11 @@ namespace StardewModdingAPI.Framework } if (Game1.gameMode == 11) { - Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); + Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp); events.Rendering.RaiseEmpty(); - Game1.spriteBatch.DrawString(Game1.dialogueFont, Game1.content.LoadString("Strings\\StringsFromCSFiles:Game1.cs.3685"), new Vector2(16f, 16f), Microsoft.Xna.Framework.Color.HotPink); - Game1.spriteBatch.DrawString(Game1.dialogueFont, Game1.content.LoadString("Strings\\StringsFromCSFiles:Game1.cs.3686"), new Vector2(16f, 32f), new Microsoft.Xna.Framework.Color(0, 255, 0)); - Game1.spriteBatch.DrawString(Game1.dialogueFont, Game1.parseText(Game1.errorMessage, Game1.dialogueFont, Game1.graphics.GraphicsDevice.Viewport.Width), new Vector2(16f, 48f), Microsoft.Xna.Framework.Color.White); + Game1.spriteBatch.DrawString(Game1.dialogueFont, Game1.content.LoadString("Strings\\StringsFromCSFiles:Game1.cs.3685"), new Vector2(16f, 16f), Color.HotPink); + Game1.spriteBatch.DrawString(Game1.dialogueFont, Game1.content.LoadString("Strings\\StringsFromCSFiles:Game1.cs.3686"), new Vector2(16f, 32f), new Color(0, 255, 0)); + Game1.spriteBatch.DrawString(Game1.dialogueFont, Game1.parseText(Game1.errorMessage, Game1.dialogueFont, Game1.graphics.GraphicsDevice.Viewport.Width), new Vector2(16f, 48f), Color.White); events.Rendered.RaiseEmpty(); Game1.spriteBatch.End(); return; @@ -368,8 +368,8 @@ namespace StardewModdingAPI.Framework if (Game1.globalFade && !Game1.menuUp && (!Game1.nameSelectUp || Game1.messagePause)) { Game1.PushUIMode(); - Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); - Game1.spriteBatch.Draw(Game1.fadeToBlackRect, Game1.graphics.GraphicsDevice.Viewport.Bounds, Microsoft.Xna.Framework.Color.Black * ((Game1.gameMode == 0) ? (1f - Game1.fadeToBlackAlpha) : Game1.fadeToBlackAlpha)); + Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp); + Game1.spriteBatch.Draw(Game1.fadeToBlackRect, Game1.graphics.GraphicsDevice.Viewport.Bounds, Color.Black * ((Game1.gameMode == 0) ? (1f - Game1.fadeToBlackAlpha) : Game1.fadeToBlackAlpha)); Game1.spriteBatch.End(); Game1.PopUIMode(); } @@ -388,7 +388,7 @@ namespace StardewModdingAPI.Framework if (Game1.showingEndOfNightStuff) { Game1.PushUIMode(); - Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); + Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp); events.Rendering.RaiseEmpty(); if (Game1.activeClickableMenu != null) { @@ -417,16 +417,16 @@ namespace StardewModdingAPI.Framework { Game1.PushUIMode(); base.GraphicsDevice.Clear(Game1.bgColor); - Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); + Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp); events.Rendering.RaiseEmpty(); string addOn = ""; for (int i = 0; (double)i < gameTime.TotalGameTime.TotalMilliseconds % 999.0 / 333.0; i++) { addOn += "."; } - string str = Game1.content.LoadString("Strings\\StringsFromCSFiles:Game1.cs.3688"); - string msg = str + addOn; - string largestMessage = str + "... "; + string text = Game1.content.LoadString("Strings\\StringsFromCSFiles:Game1.cs.3688"); + string msg = text + addOn; + string largestMessage = text + "... "; int msgw = SpriteText.getWidthOfString(largestMessage); int msgh = 64; int msgx = 64; @@ -442,7 +442,7 @@ namespace StardewModdingAPI.Framework byte batchOpens = 0; // used for rendering event if (Game1.gameMode == 0) { - Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); + Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp); if (++batchOpens == 1) events.Rendering.RaiseEmpty(); } @@ -456,7 +456,7 @@ namespace StardewModdingAPI.Framework if (Game1.drawLighting) { Game1.SetRenderTarget(Game1.lightmap); - base.GraphicsDevice.Clear(Microsoft.Xna.Framework.Color.White * 0f); + base.GraphicsDevice.Clear(Color.White * 0f); Matrix lighting_matrix = Matrix.Identity; if (this.useUnscaledLighting) { @@ -465,13 +465,13 @@ namespace StardewModdingAPI.Framework Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, null, null, null, lighting_matrix); if (++batchOpens == 1) events.Rendering.RaiseEmpty(); - Microsoft.Xna.Framework.Color lighting = (Game1.currentLocation.Name.StartsWith("UndergroundMine") && Game1.currentLocation is MineShaft) ? (Game1.currentLocation as MineShaft).getLightingColor(gameTime) : ((Game1.ambientLight.Equals(Microsoft.Xna.Framework.Color.White) || (Game1.IsRainingHere() && (bool)Game1.currentLocation.isOutdoors)) ? Game1.outdoorLight : Game1.ambientLight); + Color lighting = ((Game1.currentLocation.Name.StartsWith("UndergroundMine") && Game1.currentLocation is MineShaft) ? (Game1.currentLocation as MineShaft).getLightingColor(gameTime) : ((Game1.ambientLight.Equals(Color.White) || (Game1.IsRainingHere() && (bool)Game1.currentLocation.isOutdoors)) ? Game1.outdoorLight : Game1.ambientLight)); float light_multiplier = 1f; if (Game1.player.hasBuff(26)) { - if (lighting == Microsoft.Xna.Framework.Color.White) + if (lighting == Color.White) { - lighting = new Microsoft.Xna.Framework.Color(0.75f, 0.75f, 0.75f); + lighting = new Color(0.75f, 0.75f, 0.75f); } else { @@ -504,12 +504,8 @@ namespace StardewModdingAPI.Framework Game1.spriteBatch.End(); Game1.SetRenderTarget(target_screen); } - if (Game1.bloomDay && Game1.bloom != null) - { - Game1.bloom.BeginDraw(); - } base.GraphicsDevice.Clear(Game1.bgColor); - Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); + Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp); if (++batchOpens == 1) events.Rendering.RaiseEmpty(); events.RenderingWorld.RaiseEmpty(); @@ -522,10 +518,10 @@ namespace StardewModdingAPI.Framework Game1.currentLocation.Map.GetLayer("Back").Draw(Game1.mapDisplayDevice, Game1.viewport, Location.Origin, wrapAround: false, 4); Game1.currentLocation.drawWater(Game1.spriteBatch); Game1.spriteBatch.End(); - Game1.spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); + Game1.spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.PointClamp); Game1.currentLocation.drawFloorDecorations(Game1.spriteBatch); Game1.spriteBatch.End(); - Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); + Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp); this._farmerShadows.Clear(); if (Game1.currentLocation.currentEvent != null && !Game1.currentLocation.currentEvent.isFestival && Game1.currentLocation.currentEvent.farmerActors.Count > 0) { @@ -555,17 +551,17 @@ namespace StardewModdingAPI.Framework { if (!k.swimming && !k.HideShadow && !k.IsInvisible && !this.checkCharacterTilesForShadowDrawFlag(k)) { - Game1.spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(Game1.viewport, k.GetShadowOffset() + k.Position + new Vector2((float)(k.GetSpriteWidthForPositioning() * 4) / 2f, k.GetBoundingBox().Height + ((!k.IsMonster) ? 12 : 0))), Game1.shadowTexture.Bounds, Microsoft.Xna.Framework.Color.White, 0f, new Vector2(Game1.shadowTexture.Bounds.Center.X, Game1.shadowTexture.Bounds.Center.Y), Math.Max(0f, (4f + (float)k.yJumpOffset / 40f) * (float)k.scale), SpriteEffects.None, Math.Max(0f, (float)k.getStandingY() / 10000f) - 1E-06f); + Game1.spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(Game1.viewport, k.GetShadowOffset() + k.Position + new Vector2((float)(k.GetSpriteWidthForPositioning() * 4) / 2f, k.GetBoundingBox().Height + ((!k.IsMonster) ? 12 : 0))), Game1.shadowTexture.Bounds, Color.White, 0f, new Vector2(Game1.shadowTexture.Bounds.Center.X, Game1.shadowTexture.Bounds.Center.Y), Math.Max(0f, (4f + (float)k.yJumpOffset / 40f) * (float)k.scale), SpriteEffects.None, Math.Max(0f, (float)k.getStandingY() / 10000f) - 1E-06f); } } } else { - foreach (NPC m in Game1.CurrentEvent.actors) + foreach (NPC l in Game1.CurrentEvent.actors) { - if ((Game1.CurrentEvent == null || !Game1.CurrentEvent.ShouldHideCharacter(m)) && !m.swimming && !m.HideShadow && !this.checkCharacterTilesForShadowDrawFlag(m)) + if ((Game1.CurrentEvent == null || !Game1.CurrentEvent.ShouldHideCharacter(l)) && !l.swimming && !l.HideShadow && !this.checkCharacterTilesForShadowDrawFlag(l)) { - Game1.spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(Game1.viewport, m.GetShadowOffset() + m.Position + new Vector2((float)(m.GetSpriteWidthForPositioning() * 4) / 2f, m.GetBoundingBox().Height + ((!m.IsMonster) ? ((m.Sprite.SpriteHeight <= 16) ? (-4) : 12) : 0))), Game1.shadowTexture.Bounds, Microsoft.Xna.Framework.Color.White, 0f, new Vector2(Game1.shadowTexture.Bounds.Center.X, Game1.shadowTexture.Bounds.Center.Y), Math.Max(0f, 4f + (float)m.yJumpOffset / 40f) * (float)m.scale, SpriteEffects.None, Math.Max(0f, (float)m.getStandingY() / 10000f) - 1E-06f); + Game1.spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(Game1.viewport, l.GetShadowOffset() + l.Position + new Vector2((float)(l.GetSpriteWidthForPositioning() * 4) / 2f, l.GetBoundingBox().Height + ((!l.IsMonster) ? ((l.Sprite.SpriteHeight <= 16) ? (-4) : 12) : 0))), Game1.shadowTexture.Bounds, Color.White, 0f, new Vector2(Game1.shadowTexture.Bounds.Center.X, Game1.shadowTexture.Bounds.Center.Y), Math.Max(0f, 4f + (float)l.yJumpOffset / 40f) * (float)l.scale, SpriteEffects.None, Math.Max(0f, (float)l.getStandingY() / 10000f) - 1E-06f); } } } @@ -573,7 +569,7 @@ namespace StardewModdingAPI.Framework { if (!Game1.multiplayer.isDisconnecting(f3.UniqueMultiplayerID) && !f3.swimming && !f3.isRidingHorse() && !f3.IsSitting() && (Game1.currentLocation == null || !this.checkCharacterTilesForShadowDrawFlag(f3))) { - Game1.spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(f3.GetShadowOffset() + f3.Position + new Vector2(32f, 24f)), Game1.shadowTexture.Bounds, Microsoft.Xna.Framework.Color.White, 0f, new Vector2(Game1.shadowTexture.Bounds.Center.X, Game1.shadowTexture.Bounds.Center.Y), 4f - (((f3.running || f3.UsingTool) && f3.FarmerSprite.currentAnimationIndex > 1) ? ((float)Math.Abs(FarmerRenderer.featureYOffsetPerFrame[f3.FarmerSprite.CurrentFrame]) * 0.5f) : 0f), SpriteEffects.None, 0f); + Game1.spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(f3.GetShadowOffset() + f3.Position + new Vector2(32f, 24f)), Game1.shadowTexture.Bounds, Color.White, 0f, new Vector2(Game1.shadowTexture.Bounds.Center.X, Game1.shadowTexture.Bounds.Center.Y), 4f - (((f3.running || f3.UsingTool) && f3.FarmerSprite.currentAnimationIndex > 1) ? ((float)Math.Abs(FarmerRenderer.featureYOffsetPerFrame[f3.FarmerSprite.CurrentFrame]) * 0.5f) : 0f), SpriteEffects.None, 0f); } } } @@ -581,26 +577,26 @@ namespace StardewModdingAPI.Framework building_layer.Draw(Game1.mapDisplayDevice, Game1.viewport, Location.Origin, wrapAround: false, 4); Game1.mapDisplayDevice.EndScene(); Game1.spriteBatch.End(); - Game1.spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); + Game1.spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.PointClamp); if (!Game1.currentLocation.shouldHideCharacters()) { if (Game1.CurrentEvent == null) { - foreach (NPC n in Game1.currentLocation.characters) + foreach (NPC m in Game1.currentLocation.characters) { - if (!n.swimming && !n.HideShadow && !n.isInvisible && this.checkCharacterTilesForShadowDrawFlag(n)) + if (!m.swimming && !m.HideShadow && !m.isInvisible && this.checkCharacterTilesForShadowDrawFlag(m)) { - Game1.spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(Game1.viewport, n.GetShadowOffset() + n.Position + new Vector2((float)(n.GetSpriteWidthForPositioning() * 4) / 2f, n.GetBoundingBox().Height + ((!n.IsMonster) ? 12 : 0))), Game1.shadowTexture.Bounds, Microsoft.Xna.Framework.Color.White, 0f, new Vector2(Game1.shadowTexture.Bounds.Center.X, Game1.shadowTexture.Bounds.Center.Y), Math.Max(0f, (4f + (float)n.yJumpOffset / 40f) * (float)n.scale), SpriteEffects.None, Math.Max(0f, (float)n.getStandingY() / 10000f) - 1E-06f); + Game1.spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(Game1.viewport, m.GetShadowOffset() + m.Position + new Vector2((float)(m.GetSpriteWidthForPositioning() * 4) / 2f, m.GetBoundingBox().Height + ((!m.IsMonster) ? 12 : 0))), Game1.shadowTexture.Bounds, Color.White, 0f, new Vector2(Game1.shadowTexture.Bounds.Center.X, Game1.shadowTexture.Bounds.Center.Y), Math.Max(0f, (4f + (float)m.yJumpOffset / 40f) * (float)m.scale), SpriteEffects.None, Math.Max(0f, (float)m.getStandingY() / 10000f) - 1E-06f); } } } else { - foreach (NPC n2 in Game1.CurrentEvent.actors) + foreach (NPC n in Game1.CurrentEvent.actors) { - if ((Game1.CurrentEvent == null || !Game1.CurrentEvent.ShouldHideCharacter(n2)) && !n2.swimming && !n2.HideShadow && this.checkCharacterTilesForShadowDrawFlag(n2)) + if ((Game1.CurrentEvent == null || !Game1.CurrentEvent.ShouldHideCharacter(n)) && !n.swimming && !n.HideShadow && this.checkCharacterTilesForShadowDrawFlag(n)) { - Game1.spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(Game1.viewport, n2.GetShadowOffset() + n2.Position + new Vector2((float)(n2.GetSpriteWidthForPositioning() * 4) / 2f, n2.GetBoundingBox().Height + ((!n2.IsMonster) ? 12 : 0))), Game1.shadowTexture.Bounds, Microsoft.Xna.Framework.Color.White, 0f, new Vector2(Game1.shadowTexture.Bounds.Center.X, Game1.shadowTexture.Bounds.Center.Y), Math.Max(0f, (4f + (float)n2.yJumpOffset / 40f) * (float)n2.scale), SpriteEffects.None, Math.Max(0f, (float)n2.getStandingY() / 10000f) - 1E-06f); + Game1.spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(Game1.viewport, n.GetShadowOffset() + n.Position + new Vector2((float)(n.GetSpriteWidthForPositioning() * 4) / 2f, n.GetBoundingBox().Height + ((!n.IsMonster) ? 12 : 0))), Game1.shadowTexture.Bounds, Color.White, 0f, new Vector2(Game1.shadowTexture.Bounds.Center.X, Game1.shadowTexture.Bounds.Center.Y), Math.Max(0f, (4f + (float)n.yJumpOffset / 40f) * (float)n.scale), SpriteEffects.None, Math.Max(0f, (float)n.getStandingY() / 10000f) - 1E-06f); } } } @@ -609,7 +605,7 @@ namespace StardewModdingAPI.Framework float draw_layer = Math.Max(0.0001f, f4.getDrawLayer() + 0.00011f) - 0.0001f; if (!f4.swimming && !f4.isRidingHorse() && !f4.IsSitting() && Game1.currentLocation != null && this.checkCharacterTilesForShadowDrawFlag(f4)) { - Game1.spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(f4.GetShadowOffset() + f4.Position + new Vector2(32f, 24f)), Game1.shadowTexture.Bounds, Microsoft.Xna.Framework.Color.White, 0f, new Vector2(Game1.shadowTexture.Bounds.Center.X, Game1.shadowTexture.Bounds.Center.Y), 4f - (((f4.running || f4.UsingTool) && f4.FarmerSprite.currentAnimationIndex > 1) ? ((float)Math.Abs(FarmerRenderer.featureYOffsetPerFrame[f4.FarmerSprite.CurrentFrame]) * 0.5f) : 0f), SpriteEffects.None, draw_layer); + Game1.spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(f4.GetShadowOffset() + f4.Position + new Vector2(32f, 24f)), Game1.shadowTexture.Bounds, Color.White, 0f, new Vector2(Game1.shadowTexture.Bounds.Center.X, Game1.shadowTexture.Bounds.Center.Y), 4f - (((f4.running || f4.UsingTool) && f4.FarmerSprite.currentAnimationIndex > 1) ? ((float)Math.Abs(FarmerRenderer.featureYOffsetPerFrame[f4.FarmerSprite.CurrentFrame]) * 0.5f) : 0f), SpriteEffects.None, draw_layer); } } } @@ -619,7 +615,7 @@ namespace StardewModdingAPI.Framework } if (Game1.player.currentUpgrade != null && Game1.player.currentUpgrade.daysLeftTillUpgradeDone <= 3 && Game1.currentLocation.Name.Equals("Farm")) { - Game1.spriteBatch.Draw(Game1.player.currentUpgrade.workerTexture, Game1.GlobalToLocal(Game1.viewport, Game1.player.currentUpgrade.positionOfCarpenter), Game1.player.currentUpgrade.getSourceRectangle(), Microsoft.Xna.Framework.Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, (Game1.player.currentUpgrade.positionOfCarpenter.Y + 48f) / 10000f); + Game1.spriteBatch.Draw(Game1.player.currentUpgrade.workerTexture, Game1.GlobalToLocal(Game1.viewport, Game1.player.currentUpgrade.positionOfCarpenter), Game1.player.currentUpgrade.getSourceRectangle(), Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, (Game1.player.currentUpgrade.positionOfCarpenter.Y + 48f) / 10000f); } Game1.currentLocation.draw(Game1.spriteBatch); foreach (Vector2 tile_position in Game1.crabPotOverlayTiles.Keys) @@ -646,14 +642,14 @@ namespace StardewModdingAPI.Framework } if (Game1.tvStation >= 0) { - Game1.spriteBatch.Draw(Game1.tvStationTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2(400f, 160f)), new Microsoft.Xna.Framework.Rectangle(Game1.tvStation * 24, 0, 24, 15), Microsoft.Xna.Framework.Color.White, 0f, Vector2.Zero, 4f, SpriteEffects.None, 1E-08f); + Game1.spriteBatch.Draw(Game1.tvStationTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2(400f, 160f)), new Microsoft.Xna.Framework.Rectangle(Game1.tvStation * 24, 0, 24, 15), Color.White, 0f, Vector2.Zero, 4f, SpriteEffects.None, 1E-08f); } if (Game1.panMode) { - Game1.spriteBatch.Draw(Game1.fadeToBlackRect, new Microsoft.Xna.Framework.Rectangle((int)Math.Floor((double)(Game1.getOldMouseX() + Game1.viewport.X) / 64.0) * 64 - Game1.viewport.X, (int)Math.Floor((double)(Game1.getOldMouseY() + Game1.viewport.Y) / 64.0) * 64 - Game1.viewport.Y, 64, 64), Microsoft.Xna.Framework.Color.Lime * 0.75f); + Game1.spriteBatch.Draw(Game1.fadeToBlackRect, new Microsoft.Xna.Framework.Rectangle((int)Math.Floor((double)(Game1.getOldMouseX() + Game1.viewport.X) / 64.0) * 64 - Game1.viewport.X, (int)Math.Floor((double)(Game1.getOldMouseY() + Game1.viewport.Y) / 64.0) * 64 - Game1.viewport.Y, 64, 64), Color.Lime * 0.75f); foreach (Warp w in Game1.currentLocation.warps) { - Game1.spriteBatch.Draw(Game1.fadeToBlackRect, new Microsoft.Xna.Framework.Rectangle(w.X * 64 - Game1.viewport.X, w.Y * 64 - Game1.viewport.Y, 64, 64), Microsoft.Xna.Framework.Color.Red * 0.75f); + Game1.spriteBatch.Draw(Game1.fadeToBlackRect, new Microsoft.Xna.Framework.Rectangle(w.X * 64 - Game1.viewport.X, w.Y * 64 - Game1.viewport.Y, 64, 64), Color.Red * 0.75f); } } Game1.mapDisplayDevice.BeginScene(Game1.spriteBatch); @@ -661,7 +657,7 @@ namespace StardewModdingAPI.Framework Game1.mapDisplayDevice.EndScene(); Game1.currentLocation.drawAboveFrontLayer(Game1.spriteBatch); Game1.spriteBatch.End(); - Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); + Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp); if (Game1.currentLocation.Map.GetLayer("AlwaysFront") != null) { Game1.mapDisplayDevice.BeginScene(Game1.spriteBatch); @@ -670,7 +666,7 @@ namespace StardewModdingAPI.Framework } if (Game1.toolHold > 400f && Game1.player.CurrentTool.UpgradeLevel >= 1 && Game1.player.canReleaseTool) { - Microsoft.Xna.Framework.Color barColor = Microsoft.Xna.Framework.Color.White; + Color barColor = Color.White; switch ((int)(Game1.toolHold / 600f) + 2) { case 1: @@ -686,7 +682,7 @@ namespace StardewModdingAPI.Framework barColor = Tool.iridiumColor; break; } - Game1.spriteBatch.Draw(Game1.littleEffect, new Microsoft.Xna.Framework.Rectangle((int)Game1.player.getLocalPosition(Game1.viewport).X - 2, (int)Game1.player.getLocalPosition(Game1.viewport).Y - ((!Game1.player.CurrentTool.Name.Equals("Watering Can")) ? 64 : 0) - 2, (int)(Game1.toolHold % 600f * 0.08f) + 4, 12), Microsoft.Xna.Framework.Color.Black); + Game1.spriteBatch.Draw(Game1.littleEffect, new Microsoft.Xna.Framework.Rectangle((int)Game1.player.getLocalPosition(Game1.viewport).X - 2, (int)Game1.player.getLocalPosition(Game1.viewport).Y - ((!Game1.player.CurrentTool.Name.Equals("Watering Can")) ? 64 : 0) - 2, (int)(Game1.toolHold % 600f * 0.08f) + 4, 12), Color.Black); Game1.spriteBatch.Draw(Game1.littleEffect, new Microsoft.Xna.Framework.Rectangle((int)Game1.player.getLocalPosition(Game1.viewport).X, (int)Game1.player.getLocalPosition(Game1.viewport).Y - ((!Game1.player.CurrentTool.Name.Equals("Watering Can")) ? 64 : 0), (int)(Game1.toolHold % 600f * 0.08f), 8), barColor); } if (!Game1.IsFakedBlackScreen()) @@ -699,7 +695,7 @@ namespace StardewModdingAPI.Framework } if (Game1.currentLocation.LightLevel > 0f && Game1.timeOfDay < 2000) { - Game1.spriteBatch.Draw(Game1.fadeToBlackRect, Game1.graphics.GraphicsDevice.Viewport.Bounds, Microsoft.Xna.Framework.Color.Black * Game1.currentLocation.LightLevel); + Game1.spriteBatch.Draw(Game1.fadeToBlackRect, Game1.graphics.GraphicsDevice.Viewport.Bounds, Color.Black * Game1.currentLocation.LightLevel); } if (Game1.screenGlow) { @@ -711,51 +707,51 @@ namespace StardewModdingAPI.Framework Game1.player.CurrentTool.draw(Game1.spriteBatch); } Game1.spriteBatch.End(); - Game1.spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); + Game1.spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.PointClamp); if (Game1.eventUp && Game1.currentLocation.currentEvent != null) { - foreach (NPC l in Game1.currentLocation.currentEvent.actors) + foreach (NPC n2 in Game1.currentLocation.currentEvent.actors) { - if (l.isEmoting) + if (n2.isEmoting) { - Vector2 emotePosition = l.getLocalPosition(Game1.viewport); - if (l.NeedsBirdieEmoteHack()) + Vector2 emotePosition = n2.getLocalPosition(Game1.viewport); + if (n2.NeedsBirdieEmoteHack()) { emotePosition.X += 64f; } emotePosition.Y -= 140f; - if (l.Age == 2) + if (n2.Age == 2) { emotePosition.Y += 32f; } - else if (l.Gender == 1) + else if (n2.Gender == 1) { emotePosition.Y += 10f; } - Game1.spriteBatch.Draw(Game1.emoteSpriteSheet, emotePosition, new Microsoft.Xna.Framework.Rectangle(l.CurrentEmoteIndex * 16 % Game1.emoteSpriteSheet.Width, l.CurrentEmoteIndex * 16 / Game1.emoteSpriteSheet.Width * 16, 16, 16), Microsoft.Xna.Framework.Color.White, 0f, Vector2.Zero, 4f, SpriteEffects.None, (float)l.getStandingY() / 10000f); + Game1.spriteBatch.Draw(Game1.emoteSpriteSheet, emotePosition, new Microsoft.Xna.Framework.Rectangle(n2.CurrentEmoteIndex * 16 % Game1.emoteSpriteSheet.Width, n2.CurrentEmoteIndex * 16 / Game1.emoteSpriteSheet.Width * 16, 16, 16), Color.White, 0f, Vector2.Zero, 4f, SpriteEffects.None, (float)n2.getStandingY() / 10000f); } } } Game1.spriteBatch.End(); if (Game1.drawLighting && !Game1.IsFakedBlackScreen()) { - Game1.spriteBatch.Begin(SpriteSortMode.Deferred, this.lightingBlend, SamplerState.LinearClamp, null, null); + Game1.spriteBatch.Begin(SpriteSortMode.Deferred, this.lightingBlend, SamplerState.LinearClamp); Viewport vp = base.GraphicsDevice.Viewport; - vp.Bounds = (target_screen?.Bounds ?? base.GraphicsDevice.PresentationParameters.Bounds); + vp.Bounds = target_screen?.Bounds ?? base.GraphicsDevice.PresentationParameters.Bounds; base.GraphicsDevice.Viewport = vp; float render_zoom = Game1.options.lightingQuality / 2; if (this.useUnscaledLighting) { render_zoom /= Game1.options.zoomLevel; } - Game1.spriteBatch.Draw(Game1.lightmap, Vector2.Zero, Game1.lightmap.Bounds, Microsoft.Xna.Framework.Color.White, 0f, Vector2.Zero, render_zoom, SpriteEffects.None, 1f); + Game1.spriteBatch.Draw(Game1.lightmap, Vector2.Zero, Game1.lightmap.Bounds, Color.White, 0f, Vector2.Zero, render_zoom, SpriteEffects.None, 1f); if (Game1.IsRainingHere() && (bool)Game1.currentLocation.isOutdoors && !(Game1.currentLocation is Desert)) { - Game1.spriteBatch.Draw(Game1.staminaRect, vp.Bounds, Microsoft.Xna.Framework.Color.OrangeRed * 0.45f); + Game1.spriteBatch.Draw(Game1.staminaRect, vp.Bounds, Color.OrangeRed * 0.45f); } Game1.spriteBatch.End(); } - Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); + Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp); events.RenderedWorld.RaiseEmpty(); if (Game1.drawGrid) { @@ -763,11 +759,11 @@ namespace StardewModdingAPI.Framework float startingY = -Game1.viewport.Y % 64; for (int x = startingX; x < Game1.graphics.GraphicsDevice.Viewport.Width; x += 64) { - Game1.spriteBatch.Draw(Game1.staminaRect, new Microsoft.Xna.Framework.Rectangle(x, (int)startingY, 1, Game1.graphics.GraphicsDevice.Viewport.Height), Microsoft.Xna.Framework.Color.Red * 0.5f); + Game1.spriteBatch.Draw(Game1.staminaRect, new Microsoft.Xna.Framework.Rectangle(x, (int)startingY, 1, Game1.graphics.GraphicsDevice.Viewport.Height), Color.Red * 0.5f); } for (float y = startingY; y < (float)Game1.graphics.GraphicsDevice.Viewport.Height; y += 64f) { - Game1.spriteBatch.Draw(Game1.staminaRect, new Microsoft.Xna.Framework.Rectangle(startingX, (int)y, Game1.graphics.GraphicsDevice.Viewport.Width, 1), Microsoft.Xna.Framework.Color.Red * 0.5f); + Game1.spriteBatch.Draw(Game1.staminaRect, new Microsoft.Xna.Framework.Rectangle(startingX, (int)y, Game1.graphics.GraphicsDevice.Viewport.Width, 1), Color.Red * 0.5f); } } if (Game1.ShouldShowOnscreenUsernames() && Game1.currentLocation != null) @@ -780,14 +776,14 @@ namespace StardewModdingAPI.Framework } if (!Game1.eventUp && Game1.farmEvent == null && Game1.currentBillboard == 0 && Game1.gameMode == 3 && !this.takingMapScreenshot && Game1.isOutdoorMapSmallerThanViewport()) { - Game1.spriteBatch.Draw(Game1.fadeToBlackRect, new Microsoft.Xna.Framework.Rectangle(0, 0, -Math.Min(Game1.viewport.X, GameRunner.MaxTextureSize), Game1.graphics.GraphicsDevice.Viewport.Height), Microsoft.Xna.Framework.Color.Black); - Game1.spriteBatch.Draw(Game1.fadeToBlackRect, new Microsoft.Xna.Framework.Rectangle(-Game1.viewport.X + Game1.currentLocation.map.Layers[0].LayerWidth * 64, 0, Math.Min(GameRunner.MaxTextureSize, Game1.graphics.GraphicsDevice.Viewport.Width - (-Game1.viewport.X + Game1.currentLocation.map.Layers[0].LayerWidth * 64)), Game1.graphics.GraphicsDevice.Viewport.Height), Microsoft.Xna.Framework.Color.Black); - Game1.spriteBatch.Draw(Game1.fadeToBlackRect, new Microsoft.Xna.Framework.Rectangle(0, 0, Game1.graphics.GraphicsDevice.Viewport.Width, -Math.Min(Game1.viewport.Y, GameRunner.MaxTextureSize)), Microsoft.Xna.Framework.Color.Black); - Game1.spriteBatch.Draw(Game1.fadeToBlackRect, new Microsoft.Xna.Framework.Rectangle(0, -Game1.viewport.Y + Game1.currentLocation.map.Layers[0].LayerHeight * 64, Game1.graphics.GraphicsDevice.Viewport.Width, Math.Min(GameRunner.MaxTextureSize, Game1.graphics.GraphicsDevice.Viewport.Height - (-Game1.viewport.Y + Game1.currentLocation.map.Layers[0].LayerHeight * 64))), Microsoft.Xna.Framework.Color.Black); + Game1.spriteBatch.Draw(Game1.fadeToBlackRect, new Microsoft.Xna.Framework.Rectangle(0, 0, -Math.Min(Game1.viewport.X, GameRunner.MaxTextureSize), Game1.graphics.GraphicsDevice.Viewport.Height), Color.Black); + Game1.spriteBatch.Draw(Game1.fadeToBlackRect, new Microsoft.Xna.Framework.Rectangle(-Game1.viewport.X + Game1.currentLocation.map.Layers[0].LayerWidth * 64, 0, Math.Min(GameRunner.MaxTextureSize, Game1.graphics.GraphicsDevice.Viewport.Width - (-Game1.viewport.X + Game1.currentLocation.map.Layers[0].LayerWidth * 64)), Game1.graphics.GraphicsDevice.Viewport.Height), Color.Black); + Game1.spriteBatch.Draw(Game1.fadeToBlackRect, new Microsoft.Xna.Framework.Rectangle(0, 0, Game1.graphics.GraphicsDevice.Viewport.Width, -Math.Min(Game1.viewport.Y, GameRunner.MaxTextureSize)), Color.Black); + Game1.spriteBatch.Draw(Game1.fadeToBlackRect, new Microsoft.Xna.Framework.Rectangle(0, -Game1.viewport.Y + Game1.currentLocation.map.Layers[0].LayerHeight * 64, Game1.graphics.GraphicsDevice.Viewport.Width, Math.Min(GameRunner.MaxTextureSize, Game1.graphics.GraphicsDevice.Viewport.Height - (-Game1.viewport.Y + Game1.currentLocation.map.Layers[0].LayerHeight * 64))), Color.Black); } Game1.spriteBatch.End(); Game1.PushUIMode(); - Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); + Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp); if ((Game1.displayHUD || Game1.eventUp) && Game1.currentBillboard == 0 && Game1.gameMode == 3 && !Game1.freezeControls && !Game1.panMode && !Game1.HostPaused && !this.takingMapScreenshot) { events.RenderingHud.RaiseEmpty(); @@ -807,13 +803,13 @@ namespace StardewModdingAPI.Framework } Game1.spriteBatch.End(); Game1.PopUIMode(); - Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); + Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp); } if (Game1.farmEvent != null) { Game1.farmEvent.draw(Game1.spriteBatch); Game1.spriteBatch.End(); - Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); + Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp); } Game1.PushUIMode(); if (Game1.dialogueUp && !Game1.nameSelectUp && !Game1.messagePause && (Game1.activeClickableMenu == null || !(Game1.activeClickableMenu is DialogueBox)) && !this.takingMapScreenshot) @@ -822,35 +818,35 @@ namespace StardewModdingAPI.Framework } if (Game1.progressBar && !this.takingMapScreenshot) { - Game1.spriteBatch.Draw(Game1.fadeToBlackRect, new Microsoft.Xna.Framework.Rectangle((Game1.graphics.GraphicsDevice.Viewport.GetTitleSafeArea().Width - Game1.dialogueWidth) / 2, Game1.graphics.GraphicsDevice.Viewport.GetTitleSafeArea().Bottom - 128, Game1.dialogueWidth, 32), Microsoft.Xna.Framework.Color.LightGray); - Game1.spriteBatch.Draw(Game1.staminaRect, new Microsoft.Xna.Framework.Rectangle((Game1.graphics.GraphicsDevice.Viewport.GetTitleSafeArea().Width - Game1.dialogueWidth) / 2, Game1.graphics.GraphicsDevice.Viewport.GetTitleSafeArea().Bottom - 128, (int)(Game1.pauseAccumulator / Game1.pauseTime * (float)Game1.dialogueWidth), 32), Microsoft.Xna.Framework.Color.DimGray); + Game1.spriteBatch.Draw(Game1.fadeToBlackRect, new Microsoft.Xna.Framework.Rectangle((Game1.graphics.GraphicsDevice.Viewport.GetTitleSafeArea().Width - Game1.dialogueWidth) / 2, Game1.graphics.GraphicsDevice.Viewport.GetTitleSafeArea().Bottom - 128, Game1.dialogueWidth, 32), Color.LightGray); + Game1.spriteBatch.Draw(Game1.staminaRect, new Microsoft.Xna.Framework.Rectangle((Game1.graphics.GraphicsDevice.Viewport.GetTitleSafeArea().Width - Game1.dialogueWidth) / 2, Game1.graphics.GraphicsDevice.Viewport.GetTitleSafeArea().Bottom - 128, (int)(Game1.pauseAccumulator / Game1.pauseTime * (float)Game1.dialogueWidth), 32), Color.DimGray); } Game1.spriteBatch.End(); Game1.PopUIMode(); - Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); + Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp); if (Game1.eventUp && Game1.currentLocation != null && Game1.currentLocation.currentEvent != null) { Game1.currentLocation.currentEvent.drawAfterMap(Game1.spriteBatch); } if (!Game1.IsFakedBlackScreen() && Game1.IsRainingHere() && Game1.currentLocation != null && (bool)Game1.currentLocation.isOutdoors && !(Game1.currentLocation is Desert)) { - Game1.spriteBatch.Draw(Game1.staminaRect, Game1.graphics.GraphicsDevice.Viewport.Bounds, Microsoft.Xna.Framework.Color.Blue * 0.2f); + Game1.spriteBatch.Draw(Game1.staminaRect, Game1.graphics.GraphicsDevice.Viewport.Bounds, Color.Blue * 0.2f); } if ((Game1.fadeToBlack || Game1.globalFade) && !Game1.menuUp && (!Game1.nameSelectUp || Game1.messagePause) && !this.takingMapScreenshot) { Game1.spriteBatch.End(); Game1.PushUIMode(); - Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); - Game1.spriteBatch.Draw(Game1.fadeToBlackRect, Game1.graphics.GraphicsDevice.Viewport.Bounds, Microsoft.Xna.Framework.Color.Black * ((Game1.gameMode == 0) ? (1f - Game1.fadeToBlackAlpha) : Game1.fadeToBlackAlpha)); + Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp); + Game1.spriteBatch.Draw(Game1.fadeToBlackRect, Game1.graphics.GraphicsDevice.Viewport.Bounds, Color.Black * ((Game1.gameMode == 0) ? (1f - Game1.fadeToBlackAlpha) : Game1.fadeToBlackAlpha)); Game1.spriteBatch.End(); Game1.PopUIMode(); - Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); + Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp); } else if (Game1.flashAlpha > 0f && !this.takingMapScreenshot) { if (Game1.options.screenFlash) { - Game1.spriteBatch.Draw(Game1.fadeToBlackRect, Game1.graphics.GraphicsDevice.Viewport.Bounds, Microsoft.Xna.Framework.Color.White * Math.Min(1f, Game1.flashAlpha)); + Game1.spriteBatch.Draw(Game1.fadeToBlackRect, Game1.graphics.GraphicsDevice.Viewport.Bounds, Color.White * Math.Min(1f, Game1.flashAlpha)); } Game1.flashAlpha -= 0.1f; } @@ -866,14 +862,14 @@ namespace StardewModdingAPI.Framework } Game1.spriteBatch.End(); Game1.PushUIMode(); - Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); + Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp); foreach (TemporaryAnimatedSprite uiOverlayTempSprite in Game1.uiOverlayTempSprites) { uiOverlayTempSprite.draw(Game1.spriteBatch, localPosition: true); } Game1.spriteBatch.End(); Game1.PopUIMode(); - Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); + Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp); } if (Game1.debugMode) { @@ -905,14 +901,14 @@ namespace StardewModdingAPI.Framework sb.Append(Game1.getMouseY() + Game1.viewport.Y); sb.Append(" debugOutput: "); sb.Append(Game1.debugOutput); - Game1.spriteBatch.DrawString(Game1.smallFont, sb, new Vector2(base.GraphicsDevice.Viewport.GetTitleSafeArea().X, base.GraphicsDevice.Viewport.GetTitleSafeArea().Y + Game1.smallFont.LineSpacing * 8), Microsoft.Xna.Framework.Color.Red, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0.9999999f); + Game1.spriteBatch.DrawString(Game1.smallFont, sb, new Vector2(base.GraphicsDevice.Viewport.GetTitleSafeArea().X, base.GraphicsDevice.Viewport.GetTitleSafeArea().Y + Game1.smallFont.LineSpacing * 8), Color.Red, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0.9999999f); } Game1.spriteBatch.End(); Game1.PushUIMode(); - Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); + Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp); if (Game1.showKeyHelp && !this.takingMapScreenshot) { - Game1.spriteBatch.DrawString(Game1.smallFont, Game1.keyHelpString, new Vector2(64f, (float)(Game1.viewport.Height - 64 - (Game1.dialogueUp ? (192 + (Game1.isQuestion ? (Game1.questionChoices.Count * 64) : 0)) : 0)) - Game1.smallFont.MeasureString(Game1.keyHelpString).Y), Microsoft.Xna.Framework.Color.LightGray, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0.9999999f); + Game1.spriteBatch.DrawString(Game1.smallFont, Game1.keyHelpString, new Vector2(64f, (float)(Game1.viewport.Height - 64 - (Game1.dialogueUp ? (192 + (Game1.isQuestion ? (Game1.questionChoices.Count * 64) : 0)) : 0)) - Game1.smallFont.MeasureString(Game1.keyHelpString).Y), Color.LightGray, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0.9999999f); } if (Game1.activeClickableMenu != null && !this.takingMapScreenshot) { -- cgit From 3a3688e09448b95f8b412154de743df6b2297fe9 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 12 Aug 2021 21:26:12 -0400 Subject: use new mod hooks to synchronize tasks --- src/SMAPI/Framework/SCore.cs | 12 ++---------- src/SMAPI/Framework/SModHooks.cs | 30 +++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 95a7ace6..947284a8 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -11,7 +11,6 @@ using System.Runtime.ExceptionServices; using System.Security; using System.Text; using System.Threading; -using System.Threading.Tasks; using Microsoft.Xna.Framework; #if SMAPI_FOR_WINDOWS using Microsoft.Win32; @@ -236,7 +235,7 @@ namespace StardewModdingAPI.Framework monitor: this.Monitor, reflection: this.Reflection, eventManager: this.EventManager, - modHooks: new SModHooks(this.OnNewDayAfterFade), + modHooks: new SModHooks(this.OnNewDayAfterFade, this.Monitor), multiplayer: this.Multiplayer, exitGameImmediately: this.ExitGameImmediately, @@ -650,13 +649,6 @@ namespace StardewModdingAPI.Framework this.Monitor.Log("Game loader done."); } - if (instance.NewDayTask?.Status == TaskStatus.Created) - { - this.Monitor.Log("New day task synchronizing..."); - instance.NewDayTask.RunSynchronously(); - this.Monitor.Log("New day task done."); - } - // While a background task is in progress, the game may make changes to the game // state while mods are running their code. This is risky, because data changes can // conflict (e.g. collection changed during enumeration errors) and data may change @@ -666,7 +658,7 @@ namespace StardewModdingAPI.Framework // a small chance that the task will finish after we defer but before the game checks, // which means technically events should be raised, but the effects of missing one // update tick are negligible and not worth the complications of bypassing Game1.Update. - if (instance.NewDayTask != null || Game1.gameMode == Game1.loadingMode) + if (Game1.gameMode == Game1.loadingMode) { events.UnvalidatedUpdateTicking.RaiseEmpty(); runUpdate(); diff --git a/src/SMAPI/Framework/SModHooks.cs b/src/SMAPI/Framework/SModHooks.cs index 7dafc746..101e022a 100644 --- a/src/SMAPI/Framework/SModHooks.cs +++ b/src/SMAPI/Framework/SModHooks.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using StardewValley; namespace StardewModdingAPI.Framework @@ -12,15 +13,20 @@ namespace StardewModdingAPI.Framework /// A callback to invoke before runs. private readonly Action BeforeNewDayAfterFade; + /// Writes messages to the console. + private readonly IMonitor Monitor; + /********* ** Public methods *********/ /// Construct an instance. /// A callback to invoke before runs. - public SModHooks(Action beforeNewDayAfterFade) + /// Writes messages to the console. + public SModHooks(Action beforeNewDayAfterFade, IMonitor monitor) { this.BeforeNewDayAfterFade = beforeNewDayAfterFade; + this.Monitor = monitor; } /// A hook invoked when is called. @@ -30,5 +36,27 @@ namespace StardewModdingAPI.Framework this.BeforeNewDayAfterFade?.Invoke(); action(); } + + /// Start an asynchronous task for the game. + /// The task to start. + /// A unique key which identifies the task. + public override Task StartTask(Task task, string id) + { + this.Monitor.Log($"Synchronizing '{id}' task..."); + task.RunSynchronously(); + this.Monitor.Log(" task complete."); + return task; + } + + /// Start an asynchronous task for the game. + /// The task to start. + /// A unique key which identifies the task. + public override Task StartTask(Task task, string id) + { + this.Monitor.Log($"Synchronizing '{id}' task..."); + task.RunSynchronously(); + this.Monitor.Log(" task complete."); + return task; + } } } -- cgit From e10a7858a0f3720dca1caf3e0f17db720bd69965 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 12 Aug 2021 21:26:12 -0400 Subject: fix error reading console title on Linux with .NET 5 The console title is now write-only on Linux. --- src/SMAPI/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs index 3e2213ba..0417697b 100644 --- a/src/SMAPI/Program.cs +++ b/src/SMAPI/Program.cs @@ -25,7 +25,7 @@ namespace StardewModdingAPI /// The command-line arguments. public static void Main(string[] args) { - Console.Title = $"SMAPI {EarlyConstants.RawApiVersion} - {Console.Title}"; + Console.Title = $"SMAPI {EarlyConstants.RawApiVersion}"; try { -- cgit From 897edd7ff0c4a69289330e086b9b03e7a756b15c Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 13 Aug 2021 18:56:59 -0400 Subject: update for accessibility change in Stardew Valley 1.5.5 --- src/SMAPI/Metadata/CoreAssetPropagator.cs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/SMAPI/Metadata/CoreAssetPropagator.cs b/src/SMAPI/Metadata/CoreAssetPropagator.cs index 7efd99a0..1780b280 100644 --- a/src/SMAPI/Metadata/CoreAssetPropagator.cs +++ b/src/SMAPI/Metadata/CoreAssetPropagator.cs @@ -226,13 +226,8 @@ namespace StardewModdingAPI.Metadata ** Buildings ****/ case "buildings\\houses": // Farm - { - var field = reflection.GetField(typeof(Farm), nameof(Farm.houseTextures)); - field.SetValue( - this.LoadAndDisposeIfNeeded(field.GetValue(), key) - ); - return true; - } + Farm.houseTextures = this.LoadAndDisposeIfNeeded(Farm.houseTextures, key); + return true; case "buildings\\houses_paintmask": // Farm { -- cgit From ce80c68135b08fea7caaa9581b3c4eba61c3ec65 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 16 Aug 2021 19:43:55 -0400 Subject: fix segfault on Linux/macOS after .NET 5 update Harmony doesn't seem to support tiered compilation on Linux/macOS, but the vanilla game disables that too anyway. The bundled runtimeconfig files match the ones used by the vanilla game. Thanks to 0x0ade for identifying the cause! --- build/prepare-install-package.targets | 3 ++- src/SMAPI.Installer/assets/runtimeconfig.unix.json | 14 ++++++++++++++ src/SMAPI.Installer/assets/runtimeconfig.windows.json | 12 ++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/SMAPI.Installer/assets/runtimeconfig.unix.json create mode 100644 src/SMAPI.Installer/assets/runtimeconfig.windows.json (limited to 'src') diff --git a/build/prepare-install-package.targets b/build/prepare-install-package.targets index bc1716a3..21b02b87 100644 --- a/build/prepare-install-package.targets +++ b/build/prepare-install-package.targets @@ -36,13 +36,14 @@ + - + diff --git a/src/SMAPI.Installer/assets/runtimeconfig.unix.json b/src/SMAPI.Installer/assets/runtimeconfig.unix.json new file mode 100644 index 00000000..8a01ceb1 --- /dev/null +++ b/src/SMAPI.Installer/assets/runtimeconfig.unix.json @@ -0,0 +1,14 @@ +{ + "runtimeOptions": { + "tfm": "net5.0", + "includedFrameworks": [ + { + "name": "Microsoft.NETCore.App", + "version": "5.0.7" + } + ], + "configProperties": { + "System.Runtime.TieredCompilation": false + } + } +} diff --git a/src/SMAPI.Installer/assets/runtimeconfig.windows.json b/src/SMAPI.Installer/assets/runtimeconfig.windows.json new file mode 100644 index 00000000..b693d809 --- /dev/null +++ b/src/SMAPI.Installer/assets/runtimeconfig.windows.json @@ -0,0 +1,12 @@ +{ + "runtimeOptions": { + "tfm": "net5.0", + "framework": { + "name": "Microsoft.NETCore.App", + "version": "5.0.0" + }, + "configProperties": { + "System.Runtime.TieredCompilation": false + } + } +} -- cgit From f6479ea2b61ebcc4eda434d7d5cb664534a99801 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 17 Aug 2021 16:42:04 -0400 Subject: restructure installer for .NET 5 changes --- build/prepare-install-package.targets | 14 +++++++------- src/SMAPI.Installer/Program.cs | 3 +-- src/SMAPI.Installer/assets/README.txt | 2 +- src/SMAPI.Installer/assets/unix-install.sh | 2 +- src/SMAPI.Installer/assets/windows-install.bat | 2 +- 5 files changed, 11 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/build/prepare-install-package.targets b/build/prepare-install-package.targets index 21b02b87..dd28266d 100644 --- a/build/prepare-install-package.targets +++ b/build/prepare-install-package.targets @@ -36,11 +36,11 @@ - - - - - + + + + + @@ -99,12 +99,12 @@ - + - + diff --git a/src/SMAPI.Installer/Program.cs b/src/SMAPI.Installer/Program.cs index d9c31dd6..45cfea75 100644 --- a/src/SMAPI.Installer/Program.cs +++ b/src/SMAPI.Installer/Program.cs @@ -31,8 +31,7 @@ namespace StardewModdingApi.Installer public static void Main(string[] args) { // find install bundle - PlatformID platform = Environment.OSVersion.Platform; - FileInfo zipFile = new FileInfo(Path.Combine(Program.InstallerPath, $"{(platform == PlatformID.Win32NT ? "windows" : "unix")}-install.dat")); + FileInfo zipFile = new FileInfo(Path.Combine(Program.InstallerPath, "install.dat")); if (!zipFile.Exists) { Console.WriteLine($"Oops! Some of the installer files are missing; try re-downloading the installer. (Missing file: {zipFile.FullName})"); diff --git a/src/SMAPI.Installer/assets/README.txt b/src/SMAPI.Installer/assets/README.txt index c3a7e271..5c20529a 100644 --- a/src/SMAPI.Installer/assets/README.txt +++ b/src/SMAPI.Installer/assets/README.txt @@ -24,7 +24,7 @@ Manual install THIS IS NOT RECOMMENDED FOR MOST PLAYERS. See instructions above instead. If you really want to install SMAPI manually, here's how. -1. Unzip "internal/windows-install.dat" (on Windows) or "internal/unix-install.dat" (on +1. Unzip "internal/windows/install.dat" (on Windows) or "internal/unix/install.dat" (on Linux/macOS). You can change '.dat' to '.zip', it's just a normal zip file renamed to prevent confusion. 2. Copy the files from the folder you just unzipped into your game folder. The diff --git a/src/SMAPI.Installer/assets/unix-install.sh b/src/SMAPI.Installer/assets/unix-install.sh index a830a22d..f5de7b16 100644 --- a/src/SMAPI.Installer/assets/unix-install.sh +++ b/src/SMAPI.Installer/assets/unix-install.sh @@ -7,4 +7,4 @@ cd "`dirname "$0"`" export TERM=xterm # run installer -./internal/unix-install +./internal/unix/install diff --git a/src/SMAPI.Installer/assets/windows-install.bat b/src/SMAPI.Installer/assets/windows-install.bat index 2cd98554..3ca13528 100644 --- a/src/SMAPI.Installer/assets/windows-install.bat +++ b/src/SMAPI.Installer/assets/windows-install.bat @@ -4,5 +4,5 @@ if not errorlevel 1 ( echo Oops! It looks like you're running the installer from inside a zip file. Make sure you unzip the download first. pause ) else ( - start /WAIT /B internal\windows-install.exe + start /WAIT /B internal\windows\install.exe ) -- cgit From 7c5c63d6846d93f772dfda37f394b5f501f49f25 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 17 Aug 2021 20:11:30 -0400 Subject: fix SMAPI not working on macOS, improve installer validation --- build/prepare-install-package.targets | 2 -- src/SMAPI.Installer/assets/unix-install.sh | 10 ++++--- src/SMAPI.Installer/assets/unix-launcher.sh | 36 ++++++++++++++++++++++++-- src/SMAPI.Installer/assets/windows-install.bat | 29 +++++++++++++++++---- 4 files changed, 65 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/build/prepare-install-package.targets b/build/prepare-install-package.targets index dd28266d..ef5624ad 100644 --- a/build/prepare-install-package.targets +++ b/build/prepare-install-package.targets @@ -38,8 +38,6 @@ - - diff --git a/src/SMAPI.Installer/assets/unix-install.sh b/src/SMAPI.Installer/assets/unix-install.sh index f5de7b16..07df4e6c 100644 --- a/src/SMAPI.Installer/assets/unix-install.sh +++ b/src/SMAPI.Installer/assets/unix-install.sh @@ -3,8 +3,12 @@ # Move to script's directory cd "`dirname "$0"`" -# if $TERM is not set to xterm, mono will bail out when attempting to write to the console. -export TERM=xterm +# make sure .NET 5 is installed +if ! command -v dotnet >/dev/null 2>&1; then + echo "Oops! You must have .NET 5 installed to use SMAPI: https://dotnet.microsoft.com/download"; + read + exit 1 +fi # run installer -./internal/unix/install +dotnet internal/unix/SMAPI.Installer.dll diff --git a/src/SMAPI.Installer/assets/unix-launcher.sh b/src/SMAPI.Installer/assets/unix-launcher.sh index 21bed803..0e700b61 100644 --- a/src/SMAPI.Installer/assets/unix-launcher.sh +++ b/src/SMAPI.Installer/assets/unix-launcher.sh @@ -10,7 +10,15 @@ if [ ! -f "Stardew Valley.dll" ]; then exit 1 fi +# make sure .NET 5 is installed +if ! command -v dotnet >/dev/null 2>&1; then + echo "Oops! You must have .NET 5 installed to use SMAPI: https://dotnet.microsoft.com/download"; + read + exit 1 +fi + # macOS +UNAME=$(uname) if [ "$UNAME" == "Darwin" ]; then # fix "DllNotFoundException: libgdiplus.dylib" errors when loading images in SMAPI if [ -f libgdiplus.dylib ]; then @@ -20,8 +28,32 @@ if [ "$UNAME" == "Darwin" ]; then ln -s /Library/Frameworks/Mono.framework/Versions/Current/lib/libgdiplus.dylib libgdiplus.dylib fi - # launch smapi - open -a Terminal ./StardewModdingAPI "$@" + # Make sure we're running in Terminal (so the user can see errors/warnings/update alerts). + if [ ! -t 1 ]; then # https://stackoverflow.com/q/911168/262123 + # sanity check to make sure we don't have an infinite loop of opening windows + SKIP_TERMINAL=false + for argument in "$@"; do + if [ "$argument" == "--no-reopen-terminal" ]; then + SKIP_TERMINAL=true + break + fi + done + + # reopen in Terminal if needed + # https://stackoverflow.com/a/29511052/262123 + if [ "$SKIP_TERMINAL" == "false" ]; then + echo "Reopening in the Terminal app..." + echo "\"$0\" $@ --no-reopen-terminal" > /tmp/open-smapi-terminal.sh + chmod +x /tmp/open-smapi-terminal.sh + cat /tmp/open-smapi-terminal.sh + open -W -a Terminal /tmp/open-smapi-terminal.sh + rm /tmp/open-smapi-terminal.sh + exit 0 + fi + fi + + # launch SMAPI + dotnet StardewModdingAPI.dll "$@" # Linux else diff --git a/src/SMAPI.Installer/assets/windows-install.bat b/src/SMAPI.Installer/assets/windows-install.bat index 3ca13528..8623f321 100644 --- a/src/SMAPI.Installer/assets/windows-install.bat +++ b/src/SMAPI.Installer/assets/windows-install.bat @@ -1,8 +1,27 @@ @echo off + +REM make sure we're not running within a zip folder echo "%~dp0" | findstr /C:"%TEMP%" 1>nul -if not errorlevel 1 ( - echo Oops! It looks like you're running the installer from inside a zip file. Make sure you unzip the download first. - pause -) else ( - start /WAIT /B internal\windows\install.exe +if %ERRORLEVEL% EQU 0 ( + echo "Oops! It looks like you're running the installer from inside a zip file. Make sure you unzip the download first." + pause + exit ) + +REM make sure .NET 5 is installed +WHERE dotnet /q +if %ERRORLEVEL% NEQ 0 ( + echo "Oops! You must have .NET 5 (desktop x64) installed to use SMAPI: https://dotnet.microsoft.com/download/dotnet/5.0/runtime" + pause + exit +) + +REM make sure an antivirus hasn't deleted the installer DLL +if not exist internal\windows\SMAPI.Installer.dll ( + echo "Oops! SMAPI can't find its 'internal\windows\SMAPI.Installer.dll' file. Your antivirus might have deleted the file." + pause + exit +) + +REM start installer +dotnet internal\windows\SMAPI.Installer.dll -- cgit From 0f508c755aa679dc63b78507c54b5530d5b972d3 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 17 Aug 2021 21:41:23 -0400 Subject: reorganize install script This fixes an issue where Steam messes with the PATH, so dotnet isn't available until the terminal window is opened. --- src/SMAPI.Installer/assets/unix-launcher.sh | 70 ++++++++++++++++++----------- 1 file changed, 44 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/SMAPI.Installer/assets/unix-launcher.sh b/src/SMAPI.Installer/assets/unix-launcher.sh index 0e700b61..7e892fca 100644 --- a/src/SMAPI.Installer/assets/unix-launcher.sh +++ b/src/SMAPI.Installer/assets/unix-launcher.sh @@ -1,34 +1,19 @@ #!/usr/bin/env bash -# Move to script's directory +########## +## Initial setup +########## +# move to script's directory cd "$(dirname "$0")" || exit $? -# validate script is being run from the game folder -if [ ! -f "Stardew Valley.dll" ]; then - echo "Oops! SMAPI must be placed in the Stardew Valley game folder.\nSee instructions: https://stardewvalleywiki.com/Modding:Player_Guide"; - read - exit 1 -fi - -# make sure .NET 5 is installed -if ! command -v dotnet >/dev/null 2>&1; then - echo "Oops! You must have .NET 5 installed to use SMAPI: https://dotnet.microsoft.com/download"; - read - exit 1 -fi -# macOS -UNAME=$(uname) -if [ "$UNAME" == "Darwin" ]; then - # fix "DllNotFoundException: libgdiplus.dylib" errors when loading images in SMAPI - if [ -f libgdiplus.dylib ]; then - rm libgdiplus.dylib - fi - if [ -f /Library/Frameworks/Mono.framework/Versions/Current/lib/libgdiplus.dylib ]; then - ln -s /Library/Frameworks/Mono.framework/Versions/Current/lib/libgdiplus.dylib libgdiplus.dylib - fi - - # Make sure we're running in Terminal (so the user can see errors/warnings/update alerts). +########## +## Open terminal if needed +########## +# on macOS, make sure we're running in a Terminal +# Besides letting the player see errors/warnings/alerts in the console, this is also needed because +# Steam messes with the PATH. +if [ "$(uname)" == "Darwin" ]; then if [ ! -t 1 ]; then # https://stackoverflow.com/q/911168/262123 # sanity check to make sure we don't have an infinite loop of opening windows SKIP_TERMINAL=false @@ -51,6 +36,39 @@ if [ "$UNAME" == "Darwin" ]; then exit 0 fi fi +fi + + +########## +## Validate assumptions +########## +# script must be run from the game folder +if [ ! -f "Stardew Valley.dll" ]; then + echo "Oops! SMAPI must be placed in the Stardew Valley game folder.\nSee instructions: https://stardewvalleywiki.com/Modding:Player_Guide"; + read + exit 1 +fi + +# .NET 5 must be installed +if ! command -v dotnet >/dev/null 2>&1; then + echo "Oops! You must have .NET 5 installed to use SMAPI: https://dotnet.microsoft.com/download"; + read + exit 1 +fi + + +########## +## Launch SMAPI +########## +# macOS +if [ "$(uname)" == "Darwin" ]; then + # fix "DllNotFoundException: libgdiplus.dylib" errors when loading images in SMAPI + if [ -f libgdiplus.dylib ]; then + rm libgdiplus.dylib + fi + if [ -f /Library/Frameworks/Mono.framework/Versions/Current/lib/libgdiplus.dylib ]; then + ln -s /Library/Frameworks/Mono.framework/Versions/Current/lib/libgdiplus.dylib libgdiplus.dylib + fi # launch SMAPI dotnet StardewModdingAPI.dll "$@" -- cgit From 33c7a0392cc9f39f885f50774e980a0bf3643fd6 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 17 Aug 2021 23:25:09 -0400 Subject: remove libgdiplus workaround on macOS This is no longer needed after the .NET 5 migration. --- src/SMAPI.Installer/InteractiveInstaller.cs | 4 ++-- src/SMAPI.Installer/assets/unix-launcher.sh | 9 --------- src/SMAPI/Framework/ContentManagers/ModContentManager.cs | 3 --- 3 files changed, 2 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/SMAPI.Installer/InteractiveInstaller.cs b/src/SMAPI.Installer/InteractiveInstaller.cs index 34285cf7..896017d3 100644 --- a/src/SMAPI.Installer/InteractiveInstaller.cs +++ b/src/SMAPI.Installer/InteractiveInstaller.cs @@ -39,7 +39,6 @@ namespace StardewModdingApi.Installer string GetInstallPath(string path) => Path.Combine(installDir.FullName, path); // current files - yield return GetInstallPath("libgdiplus.dylib"); // Linux/macOS only yield return GetInstallPath("StardewModdingAPI"); // Linux/macOS only yield return GetInstallPath("StardewModdingAPI.dll"); yield return GetInstallPath("StardewModdingAPI.exe"); @@ -52,6 +51,7 @@ namespace StardewModdingApi.Installer yield return GetInstallPath("steam_appid.txt"); // obsolete + yield return GetInstallPath("libgdiplus.dylib"); // before 3.13 (macOS only) yield return GetInstallPath(Path.Combine("Mods", ".cache")); // 1.3-1.4 yield return GetInstallPath(Path.Combine("Mods", "TrainerMod")); // *–2.0 (renamed to ConsoleCommands) yield return GetInstallPath("Mono.Cecil.Rocks.dll"); // 1.3–1.8 @@ -71,7 +71,7 @@ namespace StardewModdingApi.Installer yield return GetInstallPath("StardewModdingAPI.Toolkit.CoreInterfaces.dll"); // moved in 2.8 yield return GetInstallPath("StardewModdingAPI.Toolkit.CoreInterfaces.pdb"); // moved in 2.8 yield return GetInstallPath("StardewModdingAPI.Toolkit.CoreInterfaces.xml"); // moved in 2.8 - yield return GetInstallPath("StardewModdingAPI-x64.exe"); // 3.13 + yield return GetInstallPath("StardewModdingAPI-x64.exe"); // before 3.13 if (modsDir.Exists) { diff --git a/src/SMAPI.Installer/assets/unix-launcher.sh b/src/SMAPI.Installer/assets/unix-launcher.sh index 7e892fca..58f7a5ae 100644 --- a/src/SMAPI.Installer/assets/unix-launcher.sh +++ b/src/SMAPI.Installer/assets/unix-launcher.sh @@ -62,15 +62,6 @@ fi ########## # macOS if [ "$(uname)" == "Darwin" ]; then - # fix "DllNotFoundException: libgdiplus.dylib" errors when loading images in SMAPI - if [ -f libgdiplus.dylib ]; then - rm libgdiplus.dylib - fi - if [ -f /Library/Frameworks/Mono.framework/Versions/Current/lib/libgdiplus.dylib ]; then - ln -s /Library/Frameworks/Mono.framework/Versions/Current/lib/libgdiplus.dylib libgdiplus.dylib - fi - - # launch SMAPI dotnet StardewModdingAPI.dll "$@" # Linux diff --git a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs index d24ffb81..bf0b54b9 100644 --- a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs @@ -7,7 +7,6 @@ using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using StardewModdingAPI.Framework.Exceptions; using StardewModdingAPI.Framework.Reflection; -using StardewModdingAPI.Internal; using StardewModdingAPI.Toolkit.Serialization; using StardewModdingAPI.Toolkit.Utilities; using StardewValley; @@ -177,8 +176,6 @@ namespace StardewModdingAPI.Framework.ContentManagers } catch (Exception ex) when (!(ex is SContentLoadException)) { - if (ex.GetInnermostException() is DllNotFoundException dllEx && dllEx.Message == "libgdiplus.dylib") - throw GetContentError("couldn't find libgdiplus, which is needed to load mod images. Make sure Mono is installed and you're running the game through the normal launcher."); throw new SContentLoadException($"The content manager failed loading content asset '{assetName}' from {this.Name}.", ex); } -- cgit From 3c6549db3e2716b1ebc1f2f9e970fb0dc15613eb Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 18 Aug 2021 23:34:34 -0400 Subject: remove reference no longer needed in .NET 5 --- src/SMAPI/SMAPI.csproj | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/SMAPI/SMAPI.csproj b/src/SMAPI/SMAPI.csproj index a04dd1b6..16ddb92a 100644 --- a/src/SMAPI/SMAPI.csproj +++ b/src/SMAPI/SMAPI.csproj @@ -31,7 +31,6 @@ - -- cgit From b349e956c6bb4608b4e158282700bf39e0072817 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 18 Aug 2021 23:50:01 -0400 Subject: remove handling for exception no longer thrown by the game --- src/SMAPI/Framework/Logging/LogManager.cs | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'src') diff --git a/src/SMAPI/Framework/Logging/LogManager.cs b/src/SMAPI/Framework/Logging/LogManager.cs index abcb2f64..dbcf8934 100644 --- a/src/SMAPI/Framework/Logging/LogManager.cs +++ b/src/SMAPI/Framework/Logging/LogManager.cs @@ -252,18 +252,6 @@ namespace StardewModdingAPI.Framework.Logging { switch (exception) { - // audio crash - //case InvalidOperationException ex when ex.Source == "Microsoft.Xna.Framework.Xact" && ex.StackTrace.Contains("Microsoft.Xna.Framework.Audio.AudioEngine..ctor"): - // this.Monitor.Log("The game couldn't load audio. Do you have speakers or headphones plugged in?", LogLevel.Error); - // this.Monitor.Log($"Technical details: {ex.GetLogSummary()}"); - // break; - - // missing content folder exception - case FileNotFoundException ex when ex.Message == "Couldn't find file 'C:\\Program Files (x86)\\Steam\\SteamApps\\common\\Stardew Valley\\Content\\XACT\\FarmerSounds.xgs'.": // path in error is hardcoded regardless of install path - this.Monitor.Log("The game can't find its Content\\XACT\\FarmerSounds.xgs file. You can usually fix this by resetting your content files (see https://smapi.io/troubleshoot#reset-content ), or by uninstalling and reinstalling the game.", LogLevel.Error); - this.Monitor.Log($"Technical details: {ex.GetLogSummary()}"); - break; - // path too long exception case PathTooLongException _: { -- cgit From 89c98223ebf6bfeee5ef587ab748995e09dd4310 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 18 Aug 2021 23:55:43 -0400 Subject: remove path-too-long exception handling The path length limit no longer applies in .NET 5. --- src/SMAPI.Installer/InteractiveInstaller.cs | 11 ----------- src/SMAPI.Toolkit/Utilities/PathUtilities.cs | 28 ---------------------------- src/SMAPI/Framework/Logging/LogManager.cs | 19 +------------------ 3 files changed, 1 insertion(+), 57 deletions(-) (limited to 'src') diff --git a/src/SMAPI.Installer/InteractiveInstaller.cs b/src/SMAPI.Installer/InteractiveInstaller.cs index 896017d3..714a959b 100644 --- a/src/SMAPI.Installer/InteractiveInstaller.cs +++ b/src/SMAPI.Installer/InteractiveInstaller.cs @@ -259,17 +259,6 @@ namespace StardewModdingApi.Installer Console.ReadLine(); return; } - - // game folder doesn't contain paths beyond the max limit - { - string[] tooLongPaths = PathUtilities.GetTooLongPaths(Path.Combine(paths.GamePath, "Mods")).ToArray(); - if (tooLongPaths.Any()) - { - this.PrintError($"SMAPI can't install to the detected game folder, because some of its files exceed the maximum {context.Platform} path length.\nIf you need help fixing this error, see https://smapi.io/help\n\nAffected paths:\n {string.Join("\n ", tooLongPaths)}"); - Console.ReadLine(); - return; - } - } Console.Clear(); diff --git a/src/SMAPI.Toolkit/Utilities/PathUtilities.cs b/src/SMAPI.Toolkit/Utilities/PathUtilities.cs index 1d378042..2e9e5eac 100644 --- a/src/SMAPI.Toolkit/Utilities/PathUtilities.cs +++ b/src/SMAPI.Toolkit/Utilities/PathUtilities.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Diagnostics.Contracts; using System.IO; using System.Linq; @@ -150,32 +149,5 @@ namespace StardewModdingAPI.Toolkit.Utilities { return !Regex.IsMatch(str, "[^a-z0-9_.-]", RegexOptions.IgnoreCase); } - - /// Get the paths which exceed the OS length limit. - /// The root path to search. - internal static IEnumerable GetTooLongPaths(string rootPath) - { - if (!Directory.Exists(rootPath)) - return new string[0]; - - return Directory - .EnumerateFileSystemEntries(rootPath, "*.*", SearchOption.AllDirectories) - .Where(PathUtilities.IsPathTooLong); - } - - /// Get whether a file or directory path exceeds the OS path length limit. - /// The path to test. - internal static bool IsPathTooLong(string path) - { - try - { - _ = Path.GetFullPath(path); - return false; - } - catch (PathTooLongException) - { - return true; - } - } } } diff --git a/src/SMAPI/Framework/Logging/LogManager.cs b/src/SMAPI/Framework/Logging/LogManager.cs index dbcf8934..5a291d0a 100644 --- a/src/SMAPI/Framework/Logging/LogManager.cs +++ b/src/SMAPI/Framework/Logging/LogManager.cs @@ -250,24 +250,7 @@ namespace StardewModdingAPI.Framework.Logging /// The exception details. public void LogFatalLaunchError(Exception exception) { - switch (exception) - { - // path too long exception - case PathTooLongException _: - { - string[] affectedPaths = PathUtilities.GetTooLongPaths(Constants.ModsPath).ToArray(); - string message = affectedPaths.Any() - ? $"SMAPI can't launch because some of your mod files exceed the maximum path length on {Constants.Platform}.\nIf you need help fixing this error, see https://smapi.io/help\n\nAffected paths:\n {string.Join("\n ", affectedPaths)}" - : $"The game failed to launch: {exception.GetLogSummary()}"; - this.MonitorForGame.Log(message, LogLevel.Error); - } - break; - - // generic exception - default: - this.MonitorForGame.Log($"The game failed to launch: {exception.GetLogSummary()}", LogLevel.Error); - break; - } + this.MonitorForGame.Log($"The game failed to launch: {exception.GetLogSummary()}", LogLevel.Error); } /**** -- cgit From 294f2a311ea2cfb590529522c0afae8e5a4f44fd Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 19 Aug 2021 00:40:12 -0400 Subject: fix error resolving native DLLs like libSkiaSharp --- src/SMAPI.Installer/InteractiveInstaller.cs | 8 ++++++++ src/SMAPI.Toolkit/Utilities/FileUtilities.cs | 13 +++++++++++++ src/SMAPI/Program.cs | 16 ++++++++++++++++ 3 files changed, 37 insertions(+) (limited to 'src') diff --git a/src/SMAPI.Installer/InteractiveInstaller.cs b/src/SMAPI.Installer/InteractiveInstaller.cs index 714a959b..d8c27a2d 100644 --- a/src/SMAPI.Installer/InteractiveInstaller.cs +++ b/src/SMAPI.Installer/InteractiveInstaller.cs @@ -410,6 +410,14 @@ namespace StardewModdingApi.Installer } } + // copy the game's deps.json file + // (This is needed to resolve native DLLs like libSkiaSharp.) + File.Copy( + sourceFileName: Path.Combine(paths.GamePath, "Stardew Valley.deps.json"), + destFileName: Path.Combine(paths.GamePath, "StardewModdingAPI.deps.json"), + overwrite: true + ); + // create mods directory (if needed) if (!paths.ModsDir.Exists) { diff --git a/src/SMAPI.Toolkit/Utilities/FileUtilities.cs b/src/SMAPI.Toolkit/Utilities/FileUtilities.cs index 7856fdb1..a6bf5929 100644 --- a/src/SMAPI.Toolkit/Utilities/FileUtilities.cs +++ b/src/SMAPI.Toolkit/Utilities/FileUtilities.cs @@ -1,4 +1,6 @@ +using System; using System.IO; +using System.Security.Cryptography; using System.Threading; namespace StardewModdingAPI.Toolkit.Utilities @@ -42,5 +44,16 @@ namespace StardewModdingAPI.Toolkit.Utilities if (entry.Exists) throw new IOException($"Timed out trying to delete {entry.FullName}"); } + + /// Get the MD5 hash for a file. + /// The absolute file path. + public static string GetFileHash(string absolutePath) + { + using FileStream stream = File.OpenRead(absolutePath); + using MD5 md5 = MD5.Create(); + + byte[] hash = md5.ComputeHash(stream); + return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); + } } } diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs index 0417697b..67ff8322 100644 --- a/src/SMAPI/Program.cs +++ b/src/SMAPI/Program.cs @@ -5,6 +5,7 @@ using System.Reflection; using System.Threading; using StardewModdingAPI.Framework; using StardewModdingAPI.Toolkit.Serialization.Models; +using StardewModdingAPI.Toolkit.Utilities; namespace StardewModdingAPI { @@ -33,6 +34,7 @@ namespace StardewModdingAPI Program.AssertGamePresent(); Program.AssertGameVersion(); Program.AssertSmapiVersions(); + Program.AssertDepsJson(); Program.Start(args); } catch (BadImageFormatException ex) when (ex.FileName == EarlyConstants.GameAssemblyName) @@ -130,6 +132,20 @@ namespace StardewModdingAPI } } + /// Assert that SMAPI's StardewModdingAPI.deps.json matches Stardew Valley.deps.json, fixing it if necessary. + /// This is needed to resolve native DLLs like libSkiaSharp. + private static void AssertDepsJson() + { + string sourcePath = Path.Combine(Constants.ExecutionPath, "Stardew Valley.deps.json"); + string targetPath = Path.Combine(Constants.ExecutionPath, "StardewModdingAPI.deps.json"); + + if (!File.Exists(targetPath) || FileUtilities.GetFileHash(sourcePath) != FileUtilities.GetFileHash(targetPath)) + { + File.Copy(sourcePath, targetPath, overwrite: true); + Program.PrintErrorAndExit($"The '{Path.GetFileName(targetPath)}' file didn't match the game's version. SMAPI fixed it automatically, but you must restart SMAPI for the change to take effect."); + } + } + /// Initialize SMAPI and launch the game. /// The command-line arguments. /// This method is separate from because that can't contain any references to assemblies loaded by (e.g. via ), or Mono will incorrectly show an assembly resolution error before assembly resolution is set up. -- cgit From 1ab0420b6d2371095756e5049fd28d419bfe31f0 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 30 Aug 2021 23:42:59 -0400 Subject: update compatibility list --- docs/release-notes.md | 1 + src/SMAPI.Web/wwwroot/SMAPI.metadata.json | 65 +++++++++++++++++++++++++------ 2 files changed, 55 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/docs/release-notes.md b/docs/release-notes.md index 43370409..d6e22af4 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -4,6 +4,7 @@ ## Upcoming release * For players: * Updated for Stardew Valley 1.5.5. + * Updated compatibility list. * Added `set_farm_type` [console command](https://stardewvalleywiki.com/Modding:Console_commands#Console_commands) to change the current farm type. * For mod authors: diff --git a/src/SMAPI.Web/wwwroot/SMAPI.metadata.json b/src/SMAPI.Web/wwwroot/SMAPI.metadata.json index dcdd6298..bb166017 100644 --- a/src/SMAPI.Web/wwwroot/SMAPI.metadata.json +++ b/src/SMAPI.Web/wwwroot/SMAPI.metadata.json @@ -167,6 +167,60 @@ "~ | StatusReasonPhrase": "split-screen mode was added in Stardew Valley 1.5" }, + /********* + ** Broke in SDV 1.5.5 + *********/ + "Animated Portrait Framework": { + "ID": "akai.AnimatedPortrait", + "~1.0.0 | Status": "AssumeBroken", + "~1.0.0 | StatusReasonDetails": "requires the 'System.Windows.Forms' API, which isn't available in .NET 5" + }, + "Audio Devices": { + "ID": "maxvollmer.audiodevices", + "~3.0.1 | Status": "AssumeBroken", + "~3.0.1 | StatusReasonDetails": "fails to load due to an outdated implementation of the game's 'IAudioEngine' interface" + }, + "Battery Warning": { + "ID": "Husky110.BatteryWarningMod", + "~1.0.4 | Status": "AssumeBroken", + "~1.0.4 | StatusReasonDetails": "requires the 'System.Management' API, which is a different DLL in .NET 5" + }, + "Junimo Studio": { + "ID": "Becks723.JunimoStudio", + "~2.0.1 | Status": "AssumeBroken", + "~2.0.1 | StatusReasonDetails": "requires 'Microsoft.Xna.Framework.Audio.AudioCategory' which doesn't exist in MonoGame" + }, + "Skip Intro": { + "ID": "Pathoschild.SkipIntro", + "~1.9.1 | Status": "AssumeBroken", + "~1.9.1 | StatusReasonDetails": "causes freeze during game launch" + }, + "Stardew Hack": { + "ID": "bcmpinc.StardewHack", + "~5.1.0 | Status": "AssumeBroken", + "~5.1.0 | StatusReasonDetails": "runtime error when initializing due to an API change between .NET Framework and .NET 5" + }, + "Stardew Valley Expanded": { + "ID": "FlashShifter.SVECode", + "~1.13.11 | Status": "AssumeBroken", + "~1.13.11 | StatusReasonDetails": "fails to load due to an outdated implementation of the game's 'ICue' interface" + }, + "Stardew Web": { + "ID": "prism99.stardewweb", + "~0.7.2 | Status": "AssumeBroken", + "~0.7.2 | StatusReasonDetails": "requires the 'System.Drawing' API, which isn't available in .NET 5" + }, + "Sundrop City": { + "ID": "SundropTeam.SundropCity", + "~0.4.1 | Status": "AssumeBroken", + "~0.4.1 | StatusReasonDetails": "causes freeze during game launch" + }, + "Video Player": { + "ID": "aedenthorn.VideoPlayer", + "~0.2.5 | Status": "AssumeBroken", + "~0.2.5 | StatusReasonDetails": "requires an XNA Framework API that's not available in MonoGame and causes a crash to desktop" + }, + /********* ** Broke in SMAPI 3.12.0 *********/ @@ -205,11 +259,6 @@ "~1.9.3 | Status": "AssumeBroken", "~1.9.3 | StatusReasonDetails": "fails to load with 'ReflectionTypeLoadException' error" }, - "Stardew Hack": { - "ID": "bcmpinc.StardewHack", - "~5.0.0 | Status": "AssumeBroken", - "~5.0.0 | StatusReasonDetails": "causes Harmony patching errors for other mods" - }, "Tilled Soil Decay": { "ID": "bcmpinc.TilledSoilDecay", "~4.1.0 | Status": "AssumeBroken", @@ -238,12 +287,6 @@ /********* ** Broke in SDV 1.5 (SMAPI mods) *********/ - "Audio Devices": { - "ID": "maxvollmer.audiodevices", - "~2.0.0 | Status": "AssumeBroken", - "~2.0.0 | StatusReasonDetails": "causes crash to desktop when starting the game" - }, - "ChestEx": { "ID": "berkayylmao.ChestEx", "~1.3.4 | Status": "AssumeBroken", -- cgit From 25384ce6bc1b05cb5150915ab40effe7749f683b Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 15 Sep 2021 00:27:17 -0400 Subject: update for custom languages --- src/SMAPI/Framework/ContentCoordinator.cs | 41 ++++++++++++++++++++++ .../ContentManagers/BaseContentManager.cs | 17 +-------- .../ContentManagers/GameContentManager.cs | 2 +- src/SMAPI/Framework/SCore.cs | 4 +-- 4 files changed, 45 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/SMAPI/Framework/ContentCoordinator.cs b/src/SMAPI/Framework/ContentCoordinator.cs index d0e759c2..b6f1669a 100644 --- a/src/SMAPI/Framework/ContentCoordinator.cs +++ b/src/SMAPI/Framework/ContentCoordinator.cs @@ -64,6 +64,9 @@ namespace StardewModdingAPI.Framework /// An unmodified content manager which doesn't intercept assets, used to compare asset data. private readonly LocalizedContentManager VanillaContentManager; + /// The language enum values indexed by locale code. + private Lazy> LocaleCodes; + /********* ** Accessors @@ -133,6 +136,7 @@ namespace StardewModdingAPI.Framework this.ContentManagers.Add(contentManagerForAssetPropagation); this.VanillaContentManager = new LocalizedContentManager(serviceProvider, rootDirectory); this.CoreAssets = new CoreAssetPropagator(this.MainContentManager, contentManagerForAssetPropagation, this.Monitor, reflection, aggressiveMemoryOptimizations); + this.LocaleCodes = new Lazy>(this.GetLocaleCodes); } /// Get a new content manager which handles reading files from the game content folder with support for interception. @@ -195,6 +199,10 @@ namespace StardewModdingAPI.Framework /// Perform any cleanup needed when the locale changes. public void OnLocaleChanged() { + // rebuild locale cache (which may change due to custom mod languages) + this.LocaleCodes = new Lazy>(this.GetLocaleCodes); + + // reload affected content this.ContentManagerLock.InReadLock(() => { foreach (IContentManager contentManager in this.ContentManagers) @@ -408,6 +416,25 @@ namespace StardewModdingAPI.Framework return tilesheets ?? new TilesheetReference[0]; } + /// Get the language enum which corresponds to a locale code (e.g. given fr-FR). + /// The locale code to search. This must exactly match the language; no fallback is performed. + /// The matched language enum, if any. + /// Returns whether a valid language was found. + public bool TryGetLanguageEnum(string locale, out LocalizedContentManager.LanguageCode language) + { + return this.LocaleCodes.Value.TryGetValue(locale, out language); + } + + /// Get the locale code which corresponds to a language enum (e.g. fr-FR given ). + /// The language enum to search. + public string GetLocaleCode(LocalizedContentManager.LanguageCode language) + { + if (language == LocalizedContentManager.LanguageCode.mod && LocalizedContentManager.CurrentModLanguage == null) + return null; + + return Game1.content.LanguageCodeString(language); + } + /// Dispose held resources. public void Dispose() { @@ -457,5 +484,19 @@ namespace StardewModdingAPI.Framework return false; } } + + /// Get the language enums (like ) indexed by locale code (like ja-JP). + private IDictionary GetLocaleCodes() + { + IDictionary map = new Dictionary(); + foreach (LocalizedContentManager.LanguageCode code in Enum.GetValues(typeof(LocalizedContentManager.LanguageCode))) + { + string locale = this.GetLocaleCode(code); + if (locale != null) + map[locale] = code; + } + + return map; + } } } diff --git a/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs b/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs index 7244a534..5645c0fa 100644 --- a/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs @@ -38,9 +38,6 @@ namespace StardewModdingAPI.Framework.ContentManagers /// A callback to invoke when the content manager is being disposed. private readonly Action OnDisposing; - /// The language enum values indexed by locale code. - protected IDictionary LanguageCodes { get; } - /// A list of disposable assets. private readonly List> Disposables = new List>(); @@ -92,7 +89,6 @@ namespace StardewModdingAPI.Framework.ContentManagers this.AggressiveMemoryOptimizations = aggressiveMemoryOptimizations; // get asset data - this.LanguageCodes = this.GetKeyLocales().ToDictionary(p => p.Value, p => p.Key, StringComparer.OrdinalIgnoreCase); this.BaseDisposableReferences = reflection.GetField>(this, "disposableAssets").GetValue(); } @@ -292,7 +288,7 @@ namespace StardewModdingAPI.Framework.ContentManagers if (lastSepIndex >= 0) { string suffix = cacheKey.Substring(lastSepIndex + 1, cacheKey.Length - lastSepIndex - 1); - if (this.LanguageCodes.ContainsKey(suffix)) + if (this.Coordinator.TryGetLanguageEnum(suffix, out _)) { assetName = cacheKey.Substring(0, lastSepIndex); localeCode = cacheKey.Substring(lastSepIndex + 1, cacheKey.Length - lastSepIndex - 1); @@ -311,17 +307,6 @@ namespace StardewModdingAPI.Framework.ContentManagers /// The language to check. protected abstract bool IsNormalizedKeyLoaded(string normalizedAssetName, LanguageCode language); - /// Get the locale codes (like ja-JP) used in asset keys. - private IDictionary GetKeyLocales() - { - // create locale => code map - IDictionary map = new Dictionary(); - foreach (LanguageCode code in Enum.GetValues(typeof(LanguageCode))) - map[code] = this.GetLocale(code); - - return map; - } - /// Get the asset name from a cache key. /// The input cache key. private string GetAssetName(string cacheKey) diff --git a/src/SMAPI/Framework/ContentManagers/GameContentManager.cs b/src/SMAPI/Framework/ContentManagers/GameContentManager.cs index 38bcf153..7a49dd36 100644 --- a/src/SMAPI/Framework/ContentManagers/GameContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/GameContentManager.cs @@ -249,7 +249,7 @@ namespace StardewModdingAPI.Framework.ContentManagers // extract language code int splitIndex = rawAsset.LastIndexOf('.'); - if (splitIndex != -1 && this.LanguageCodes.TryGetValue(rawAsset.Substring(splitIndex + 1), out language)) + if (splitIndex != -1 && this.Coordinator.TryGetLanguageEnum(rawAsset.Substring(splitIndex + 1), out language)) { assetName = rawAsset.Substring(0, splitIndex); return true; diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 947284a8..a0467daa 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -751,7 +751,7 @@ namespace StardewModdingAPI.Framework ** Locale changed events *********/ if (state.Locale.IsChanged) - this.Monitor.Log($"Context: locale set to {state.Locale.New}."); + this.Monitor.Log($"Context: locale set to {state.Locale.New} ({this.ContentCore.GetLocaleCode(state.Locale.New)})."); /********* ** Load / return-to-title events @@ -761,7 +761,7 @@ namespace StardewModdingAPI.Framework else if (Context.IsWorldReady && Context.LoadStage != LoadStage.Ready) { // print context - string context = $"Context: loaded save '{Constants.SaveFolderName}', starting {Game1.currentSeason} {Game1.dayOfMonth} Y{Game1.year}, locale set to {this.ContentCore.Language}."; + string context = $"Context: loaded save '{Constants.SaveFolderName}', starting {Game1.currentSeason} {Game1.dayOfMonth} Y{Game1.year}, locale set to {this.ContentCore.GetLocale()}."; if (Context.IsMultiplayer) { int onlineCount = Game1.getOnlineFarmers().Count(); -- cgit From 32dcdfe18c634804983f130c0b7bac4bddca93f7 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 16 Sep 2021 17:27:27 -0400 Subject: tweak assembly ignore logic in mod build package --- .../Framework/ModFileManager.cs | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs b/src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs index 6dd595e5..7a1ed7a4 100644 --- a/src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs +++ b/src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs @@ -152,22 +152,22 @@ namespace StardewModdingAPI.ModBuildConfig.Framework /// Custom regex patterns matching files to ignore when deploying or zipping the mod. private bool ShouldIgnore(FileInfo file, string relativePath, Regex[] ignoreFilePatterns) { + bool IsAssemblyFile(string baseName) + { + return + this.EqualsInvariant(file.Name, $"{baseName}.dll") + || this.EqualsInvariant(file.Name, $"{baseName}.pdb") + || this.EqualsInvariant(file.Name, $"{baseName}.xnb"); + } + return // release zips this.EqualsInvariant(file.Extension, ".zip") - // Harmony (bundled into SMAPI) - || this.EqualsInvariant(file.Name, "0Harmony.dll") - - // Json.NET (bundled into SMAPI) - || this.EqualsInvariant(file.Name, "Newtonsoft.Json.dll") - || this.EqualsInvariant(file.Name, "Newtonsoft.Json.pdb") - || this.EqualsInvariant(file.Name, "Newtonsoft.Json.xml") - - // mod translation class builder (not used at runtime) - || this.EqualsInvariant(file.Name, "Pathoschild.Stardew.ModTranslationClassBuilder.dll") - || this.EqualsInvariant(file.Name, "Pathoschild.Stardew.ModTranslationClassBuilder.pdb") - || this.EqualsInvariant(file.Name, "Pathoschild.Stardew.ModTranslationClassBuilder.xml") + // dependencies bundled with SMAPI + || IsAssemblyFile("0Harmony") + || IsAssemblyFile("Newtonsoft.Json") + || IsAssemblyFile("Pathoschild.Stardew.ModTranslationClassBuilder") // not used at runtime // code analysis files || file.Name.EndsWith(".CodeAnalysisLog.xml", StringComparison.OrdinalIgnoreCase) -- cgit From 60c0e4fc31475847cbf94d201f0bd394c537d9c0 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 16 Sep 2021 17:29:22 -0400 Subject: ignore reference assemblies and *.deps.json when building a mod These aren't useful for mods since they aren't the entry app. --- src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs | 3 +++ src/SMAPI.ModBuildConfig/build/smapi.targets | 3 +++ 2 files changed, 6 insertions(+) (limited to 'src') diff --git a/src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs b/src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs index 7a1ed7a4..3d9b206b 100644 --- a/src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs +++ b/src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs @@ -164,6 +164,9 @@ namespace StardewModdingAPI.ModBuildConfig.Framework // release zips this.EqualsInvariant(file.Extension, ".zip") + // unneeded *.deps.json (only SMAPI's top-level one is used) + || file.Name.EndsWith(".deps.json") + // dependencies bundled with SMAPI || IsAssemblyFile("0Harmony") || IsAssemblyFile("Newtonsoft.Json") diff --git a/src/SMAPI.ModBuildConfig/build/smapi.targets b/src/SMAPI.ModBuildConfig/build/smapi.targets index a3cd6c45..74ac56e6 100644 --- a/src/SMAPI.ModBuildConfig/build/smapi.targets +++ b/src/SMAPI.ModBuildConfig/build/smapi.targets @@ -15,6 +15,9 @@ $(AssemblySearchPaths);{GAC} + + false + None -- cgit From 217cc7af21a501daabea16dc7331401a19706bf4 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 16 Sep 2021 17:34:31 -0400 Subject: add IgnoreModFilePaths option to package --- docs/technical/mod-package.md | 17 +++++++++++- src/SMAPI.ModBuildConfig/DeployModTask.cs | 32 ++++++++++++++++++++-- .../Framework/ModFileManager.cs | 9 ++++-- src/SMAPI.ModBuildConfig/build/smapi.targets | 1 + 4 files changed, 53 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/docs/technical/mod-package.md b/docs/technical/mod-package.md index a3ce8761..0fdd4c4a 100644 --- a/docs/technical/mod-package.md +++ b/docs/technical/mod-package.md @@ -222,6 +222,20 @@ Whether to configure the project so you can launch or debug the game through the Visual Studio (default `true`). There's usually no reason to change this, unless it's a unit test project. + + + +IgnoreModFilePaths + + +A comma-delimited list of literal file paths to ignore, relative to the mod's `bin` folder. Paths +are case-sensitive, but path delimiters are normalized automatically. For example, this ignores a +set of tilesheets: + +```xml +assets/paths.png, assets/springobjects.png +``` + @@ -366,7 +380,8 @@ when you compile it. ## Release notes ## Upcoming release -* Updated for Stardew Valley 1.5.5 and SMAPI 3.13.0. **The older versions are no longer supported.** +* Updated for Stardew Valley 1.5.5 and SMAPI 3.13.0. **Older versions are no longer supported.** +* Added `IgnoreModFilePaths` option to ignore literal paths. * Improved analyzer performance by enabling parallel execution. ## 3.3.0 diff --git a/src/SMAPI.ModBuildConfig/DeployModTask.cs b/src/SMAPI.ModBuildConfig/DeployModTask.cs index 9ee6be12..0c64aed3 100644 --- a/src/SMAPI.ModBuildConfig/DeployModTask.cs +++ b/src/SMAPI.ModBuildConfig/DeployModTask.cs @@ -8,6 +8,7 @@ using System.Text.RegularExpressions; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using StardewModdingAPI.ModBuildConfig.Framework; +using StardewModdingAPI.Toolkit.Utilities; namespace StardewModdingAPI.ModBuildConfig { @@ -45,9 +46,12 @@ namespace StardewModdingAPI.ModBuildConfig [Required] public bool EnableModZip { get; set; } - /// Custom comma-separated regex patterns matching files to ignore when deploying or zipping the mod. + /// A comma-separated list of regex patterns matching files to ignore when deploying or zipping the mod. public string IgnoreModFilePatterns { get; set; } + /// A comma-separated list of relative file paths to ignore when deploying or zipping the mod. + public string IgnoreModFilePaths { get; set; } + /********* ** Public methods @@ -70,10 +74,11 @@ namespace StardewModdingAPI.ModBuildConfig try { // parse ignore patterns + string[] ignoreFilePaths = this.GetCustomIgnoreFilePaths().ToArray(); Regex[] ignoreFilePatterns = this.GetCustomIgnorePatterns().ToArray(); // get mod info - ModFileManager package = new ModFileManager(this.ProjectDir, this.TargetDir, ignoreFilePatterns, validateRequiredModFiles: this.EnableModDeploy || this.EnableModZip); + ModFileManager package = new ModFileManager(this.ProjectDir, this.TargetDir, ignoreFilePaths, ignoreFilePatterns, validateRequiredModFiles: this.EnableModDeploy || this.EnableModZip); // deploy mod files if (this.EnableModDeploy) @@ -157,6 +162,29 @@ namespace StardewModdingAPI.ModBuildConfig } } + /// Get the custom relative file paths provided by the user to ignore. + private IEnumerable GetCustomIgnoreFilePaths() + { + if (string.IsNullOrWhiteSpace(this.IgnoreModFilePaths)) + yield break; + + foreach (string raw in this.IgnoreModFilePaths.Split(',')) + { + string path; + try + { + path = PathUtilities.NormalizePath(raw); + } + catch (Exception ex) + { + this.Log.LogWarning($"[mod build package] Ignored invalid <{nameof(this.IgnoreModFilePaths)}> path {raw}:\n{ex}"); + continue; + } + + yield return path; + } + } + /// Copy the mod files into the game's mod folder. /// The files to include. /// The folder path to create with the mod files. diff --git a/src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs b/src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs index 3d9b206b..fbb91193 100644 --- a/src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs +++ b/src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs @@ -28,10 +28,11 @@ namespace StardewModdingAPI.ModBuildConfig.Framework /// Construct an instance. /// The folder containing the project files. /// The folder containing the build output. + /// The custom relative file paths provided by the user to ignore. /// Custom regex patterns matching files to ignore when deploying or zipping the mod. /// Whether to validate that required mod files like the manifest are present. /// The mod package isn't valid. - public ModFileManager(string projectDir, string targetDir, Regex[] ignoreFilePatterns, bool validateRequiredModFiles) + public ModFileManager(string projectDir, string targetDir, string[] ignoreFilePaths, Regex[] ignoreFilePatterns, bool validateRequiredModFiles) { this.Files = new Dictionary(StringComparer.OrdinalIgnoreCase); @@ -47,7 +48,7 @@ namespace StardewModdingAPI.ModBuildConfig.Framework string relativePath = entry.Item1; FileInfo file = entry.Item2; - if (!this.ShouldIgnore(file, relativePath, ignoreFilePatterns)) + if (!this.ShouldIgnore(file, relativePath, ignoreFilePaths, ignoreFilePatterns)) this.Files[relativePath] = file; } @@ -149,8 +150,9 @@ namespace StardewModdingAPI.ModBuildConfig.Framework /// Get whether a build output file should be ignored. /// The file to check. /// The file's relative path in the package. + /// The custom relative file paths provided by the user to ignore. /// Custom regex patterns matching files to ignore when deploying or zipping the mod. - private bool ShouldIgnore(FileInfo file, string relativePath, Regex[] ignoreFilePatterns) + private bool ShouldIgnore(FileInfo file, string relativePath, string[] ignoreFilePaths, Regex[] ignoreFilePatterns) { bool IsAssemblyFile(string baseName) { @@ -181,6 +183,7 @@ namespace StardewModdingAPI.ModBuildConfig.Framework || this.EqualsInvariant(file.Name, "Thumbs.db") // custom ignore patterns + || ignoreFilePaths.Any(p => p == relativePath) || ignoreFilePatterns.Any(p => p.IsMatch(relativePath)); } diff --git a/src/SMAPI.ModBuildConfig/build/smapi.targets b/src/SMAPI.ModBuildConfig/build/smapi.targets index 74ac56e6..b254dd7c 100644 --- a/src/SMAPI.ModBuildConfig/build/smapi.targets +++ b/src/SMAPI.ModBuildConfig/build/smapi.targets @@ -94,6 +94,7 @@ TargetDir="$(TargetDir)" GameModsDir="$(GameModsPath)" IgnoreModFilePatterns="$(IgnoreModFilePatterns)" + IgnoreModFilePaths="$(IgnoreModFilePaths)" /> -- cgit From 4a26c96fbe600a4a229a1e63abb716a62dc7f450 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 16 Sep 2021 18:48:59 -0400 Subject: remove GameExecutableName build property from package --- build/find-game-folder.targets | 5 ----- docs/technical/mod-package.md | 24 +++++++++++----------- src/SMAPI.ModBuildConfig/build/smapi.targets | 4 ++-- .../SMAPI.Mods.ConsoleCommands.csproj | 2 +- .../SMAPI.Mods.ErrorHandler.csproj | 2 +- .../SMAPI.Mods.SaveBackup.csproj | 2 +- src/SMAPI.Tests/SMAPI.Tests.csproj | 5 +---- src/SMAPI/SMAPI.csproj | 2 +- 8 files changed, 19 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/build/find-game-folder.targets b/build/find-game-folder.targets index 3341226d..3164b071 100644 --- a/build/find-game-folder.targets +++ b/build/find-game-folder.targets @@ -41,9 +41,4 @@ - - - - Stardew Valley - diff --git a/docs/technical/mod-package.md b/docs/technical/mod-package.md index 0fdd4c4a..5eff3d2e 100644 --- a/docs/technical/mod-package.md +++ b/docs/technical/mod-package.md @@ -29,7 +29,7 @@ change how these work): * **Detect game path:** The package automatically finds your game folder by scanning the default install paths and Windows registry. It adds two MSBuild properties for use in your `.csproj` file if needed: - `$(GamePath)` and `$(GameExecutableName)`. + `$(GamePath)` and `$(GameModsPath)`. * **Add assembly references:** The package adds assembly references to SMAPI, Stardew Valley, xTile, and the game framework @@ -126,15 +126,6 @@ change it. The absolute path to the folder containing the game's installed mods (defaults to `$(GamePath)/Mods`), used when deploying the mod files. - - - -GameExecutableName - - -The filename for the game's executable (i.e. `StardewValley.exe` on Linux/macOS or -`Stardew Valley.exe` on Windows). This is auto-detected, and you should almost never change this. - @@ -382,13 +373,21 @@ when you compile it. ## Upcoming release * Updated for Stardew Valley 1.5.5 and SMAPI 3.13.0. **Older versions are no longer supported.** * Added `IgnoreModFilePaths` option to ignore literal paths. +* Removed the `GameExecutableName` build property (since it now has the same value on all platforms). * Improved analyzer performance by enabling parallel execution. +**Migration guide for mod authors:** +1. See [_migrate to 64-bit_](https://stardewvalleywiki.com/Modding:Migrate_to_64-bit_on_Windows) and + [_migrate to Stardew Valley 1.5.5_](https://stardewvalleywiki.com/Modding:Migrate_to_Stardew_Valley_1.5.5). +2. Possible changes in your `.csproj` or `.targets` files: + * If you use `$(GameExecutableName)`, replace it with `Stardew Valley`. + ## 3.3.0 Released 30 March 2021. * Added a build warning when the mod isn't compiled for `Any CPU`. -* Added a `GameFramework` build property set to `MonoGame` or `Xna` based on the platform. This can be overridden to change which framework it references. +* Added a `GameFramework` build property set to `MonoGame` or `Xna` based on the platform. This can + be overridden to change which framework it references. * Added support for building mods against the 64-bit Linux version of the game on Windows. * The package now suppresses the misleading 'processor architecture mismatch' warnings. @@ -396,7 +395,8 @@ Released 30 March 2021. Released 23 September 2020. * Reworked and streamlined how the package is compiled. -* Added [SMAPI-ModTranslationClassBuilder](https://github.com/Pathoschild/SMAPI-ModTranslationClassBuilder) files to the ignore list. +* Added [SMAPI-ModTranslationClassBuilder](https://github.com/Pathoschild/SMAPI-ModTranslationClassBuilder) + files to the ignore list. ### 3.2.1 Released 11 September 2020. diff --git a/src/SMAPI.ModBuildConfig/build/smapi.targets b/src/SMAPI.ModBuildConfig/build/smapi.targets index b254dd7c..6fc62046 100644 --- a/src/SMAPI.ModBuildConfig/build/smapi.targets +++ b/src/SMAPI.ModBuildConfig/build/smapi.targets @@ -48,7 +48,7 @@ **********************************************--> - + @@ -71,7 +71,7 @@ - + diff --git a/src/SMAPI.Mods.ConsoleCommands/SMAPI.Mods.ConsoleCommands.csproj b/src/SMAPI.Mods.ConsoleCommands/SMAPI.Mods.ConsoleCommands.csproj index 65d54599..52439c41 100644 --- a/src/SMAPI.Mods.ConsoleCommands/SMAPI.Mods.ConsoleCommands.csproj +++ b/src/SMAPI.Mods.ConsoleCommands/SMAPI.Mods.ConsoleCommands.csproj @@ -13,8 +13,8 @@ - + diff --git a/src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj b/src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj index 2ad19df7..78cdb315 100644 --- a/src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj +++ b/src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj @@ -14,8 +14,8 @@ - + diff --git a/src/SMAPI.Mods.SaveBackup/SMAPI.Mods.SaveBackup.csproj b/src/SMAPI.Mods.SaveBackup/SMAPI.Mods.SaveBackup.csproj index f8908c7d..a8b0dfdb 100644 --- a/src/SMAPI.Mods.SaveBackup/SMAPI.Mods.SaveBackup.csproj +++ b/src/SMAPI.Mods.SaveBackup/SMAPI.Mods.SaveBackup.csproj @@ -13,7 +13,7 @@ - + diff --git a/src/SMAPI.Tests/SMAPI.Tests.csproj b/src/SMAPI.Tests/SMAPI.Tests.csproj index e19105ff..8329b2e1 100644 --- a/src/SMAPI.Tests/SMAPI.Tests.csproj +++ b/src/SMAPI.Tests/SMAPI.Tests.csproj @@ -23,10 +23,7 @@ - - $(GamePath)\$(GameExecutableName).dll - True - + diff --git a/src/SMAPI/SMAPI.csproj b/src/SMAPI/SMAPI.csproj index 16ddb92a..4f9aa9b1 100644 --- a/src/SMAPI/SMAPI.csproj +++ b/src/SMAPI/SMAPI.csproj @@ -29,7 +29,7 @@ - + -- cgit From bf10aeef0afae20e1d79f0772ba41a38fcb572ae Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 16 Sep 2021 18:59:25 -0400 Subject: remove GameFramework build property from package --- docs/technical/mod-package.md | 20 +++++++------------- src/SMAPI.ModBuildConfig/build/smapi.targets | 3 --- src/SMAPI/Constants.cs | 3 +-- src/SMAPI/Framework/ModLoading/AssemblyLoader.cs | 5 ++--- src/SMAPI/Framework/SCore.cs | 2 +- 5 files changed, 11 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/docs/technical/mod-package.md b/docs/technical/mod-package.md index 5eff3d2e..2e26275b 100644 --- a/docs/technical/mod-package.md +++ b/docs/technical/mod-package.md @@ -32,10 +32,10 @@ change how these work): `$(GamePath)` and `$(GameModsPath)`. * **Add assembly references:** - The package adds assembly references to SMAPI, Stardew Valley, xTile, and the game framework - (MonoGame on Linux/macOS, XNA Framework on Windows). It automatically adjusts depending on which OS - you're compiling it on. If you use [Harmony](https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Harmony), - it can optionally add a reference to that too. + The package adds assembly references to MonoGame, SMAPI, Stardew Valley, and xTile. It + automatically adjusts depending on which OS you're compiling it on. If you use + [Harmony](https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Harmony), it can optionally add + a reference to that too. * **Copy files into the `Mods` folder:** The package automatically copies your mod's DLL and PDB files, `manifest.json`, [`i18n` @@ -129,14 +129,6 @@ The absolute path to the folder containing the game's installed mods (defaults t -GameFramework - - -The game framework for which the mod is being compiled (one of `Xna` or `MonoGame`). This is -auto-detected based on the platform, and you should almost never change this. - - - @@ -373,7 +365,8 @@ when you compile it. ## Upcoming release * Updated for Stardew Valley 1.5.5 and SMAPI 3.13.0. **Older versions are no longer supported.** * Added `IgnoreModFilePaths` option to ignore literal paths. -* Removed the `GameExecutableName` build property (since it now has the same value on all platforms). +* Removed the `GameExecutableName` and `GameFramework` build properties (since they now have the + same value on all platforms). * Improved analyzer performance by enabling parallel execution. **Migration guide for mod authors:** @@ -381,6 +374,7 @@ when you compile it. [_migrate to Stardew Valley 1.5.5_](https://stardewvalleywiki.com/Modding:Migrate_to_Stardew_Valley_1.5.5). 2. Possible changes in your `.csproj` or `.targets` files: * If you use `$(GameExecutableName)`, replace it with `Stardew Valley`. + * If you use `$(GameFramework)`, replace it with `MonoGame` and remove any XNA-specific logic. ## 3.3.0 Released 30 March 2021. diff --git a/src/SMAPI.ModBuildConfig/build/smapi.targets b/src/SMAPI.ModBuildConfig/build/smapi.targets index 6fc62046..8ad298d0 100644 --- a/src/SMAPI.ModBuildConfig/build/smapi.targets +++ b/src/SMAPI.ModBuildConfig/build/smapi.targets @@ -30,9 +30,6 @@ false true false - - Xna - MonoGame diff --git a/src/SMAPI/Constants.cs b/src/SMAPI/Constants.cs index 2c16052b..3ae8661a 100644 --- a/src/SMAPI/Constants.cs +++ b/src/SMAPI/Constants.cs @@ -241,8 +241,7 @@ namespace StardewModdingAPI /// Get metadata for mapping assemblies to the current platform. /// The target game platform. - /// The game framework running the game. - internal static PlatformAssemblyMap GetAssemblyMap(Platform targetPlatform, GameFramework framework) + internal static PlatformAssemblyMap GetAssemblyMap(Platform targetPlatform) { var removeAssemblyReferences = new List(); var targetAssemblies = new List(); diff --git a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs index 57a76a35..cb5fa2ae 100644 --- a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs +++ b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs @@ -53,16 +53,15 @@ namespace StardewModdingAPI.Framework.ModLoading *********/ /// Construct an instance. /// The current game platform. - /// The game framework running the game. /// Encapsulates monitoring and logging. /// Whether to detect paranoid mode issues. /// Whether to rewrite mods for compatibility. - public AssemblyLoader(Platform targetPlatform, GameFramework framework, IMonitor monitor, bool paranoidMode, bool rewriteMods) + public AssemblyLoader(Platform targetPlatform, IMonitor monitor, bool paranoidMode, bool rewriteMods) { this.Monitor = monitor; this.ParanoidMode = paranoidMode; this.RewriteMods = rewriteMods; - this.AssemblyMap = this.TrackForDisposal(Constants.GetAssemblyMap(targetPlatform, framework)); + this.AssemblyMap = this.TrackForDisposal(Constants.GetAssemblyMap(targetPlatform)); // init resolver this.AssemblyDefinitionResolver = this.TrackForDisposal(new AssemblyDefinitionResolver()); diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index a0467daa..55a7f083 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -1473,7 +1473,7 @@ namespace StardewModdingAPI.Framework // load mods IList skippedMods = new List(); - using (AssemblyLoader modAssemblyLoader = new AssemblyLoader(Constants.Platform, Constants.GameFramework, this.Monitor, this.Settings.ParanoidWarnings, this.Settings.RewriteMods)) + using (AssemblyLoader modAssemblyLoader = new AssemblyLoader(Constants.Platform, this.Monitor, this.Settings.ParanoidWarnings, this.Settings.RewriteMods)) { // init HashSet suppressUpdateChecks = new HashSet(this.Settings.SuppressUpdateChecks, StringComparer.OrdinalIgnoreCase); -- cgit From f5807e22be157d908e3b8c65f19acaa16c3588e7 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 16 Sep 2021 22:47:05 -0400 Subject: add BundleExtraAssemblies package option for new .NET 5 reference model --- docs/technical/mod-package.md | 100 +++++++++++++---- src/SMAPI.ModBuildConfig/DeployModTask.cs | 34 +++++- .../Framework/ExtraAssemblyType.cs | 21 ++++ .../Framework/ModFileManager.cs | 124 ++++++++++++++++----- src/SMAPI.ModBuildConfig/build/smapi.targets | 22 ++-- 5 files changed, 244 insertions(+), 57 deletions(-) create mode 100644 src/SMAPI.ModBuildConfig/Framework/ExtraAssemblyType.cs (limited to 'src') diff --git a/docs/technical/mod-package.md b/docs/technical/mod-package.md index 2e26275b..93e0009d 100644 --- a/docs/technical/mod-package.md +++ b/docs/technical/mod-package.md @@ -39,10 +39,9 @@ change how these work): * **Copy files into the `Mods` folder:** The package automatically copies your mod's DLL and PDB files, `manifest.json`, [`i18n` - files](https://stardewvalleywiki.com/Modding:Translations) (if any), the `assets` folder (if - any), and [build output](https://stackoverflow.com/a/10828462/262123) into your game's `Mods` - folder when you rebuild the code, with a subfolder matching the mod's project name. That lets you - try the mod in-game right after building it. + files](https://stardewvalleywiki.com/Modding:Translations) (if any), and the `assets` folder (if + any) into the `Mods` folder when you rebuild the code, with a subfolder matching the mod's project + name. That lets you try the mod in-game right after building it. * **Create release zip:** The package adds a zip file in your project's `bin` folder when you rebuild the code, in the @@ -189,11 +188,63 @@ The folder path where the release zip is created (defaults to the project's `bin effect -CopyModReferencesToBuildOutput +BundleExtraAssemblies -Whether to copy game and framework DLLs into the mod folder (default `false`). This is useful for -unit test projects, but not needed for mods that'll be run through SMAPI. +**Most mods should not change this option.** + +By default (when this is _not_ enabled), only the mod files [normally considered part of the +mod](#Features) will be added to the release `.zip` and copied into the `Mods` folder (i.e. +"deployed"). That includes the assembly files (`*.dll`, `*.pdb`, and `*.xml`) for your mod project, +but any other DLLs won't be deployed. + +Enabling this option will add _all_ dependencies to the build output, then deploy _some_ of them +depending on the comma-separated value(s) you set: + + + + + + + + + + + + + + + + + + + + + + +
optionresult
ThirdParty + +Assembly files which don't match any other category. + +
System + +Assembly files whose names start with `Microsoft.*` or `System.*`. + +
Game + +Assembly files which are part of MonoGame, SMAPI, or Stardew Valley. + +
All + +Equivalent to `System, Game, ThirdParty`. + +
+ +Most mods should omit the option. Some mods may need `ThirdParty` if they bundle third-party DLLs +with their mod. The other options are mainly useful for unit tests. + +When enabling this option, you should **manually review which files get deployed** and use the +`IgnoreModFilePaths` or `IgnoreModFilePatterns` options to exclude files as needed. @@ -327,16 +378,15 @@ The configuration will check your custom path first, then fall back to the defau still compile on a different computer). ### How do I change which files are included in the mod deploy/zip? -For custom files, you can [add/remove them in the build output](https://stackoverflow.com/a/10828462/262123). -(If your project references another mod, make sure the reference is [_not_ marked 'copy -local'](https://msdn.microsoft.com/en-us/library/t1zz5y8c(v=vs.100).aspx).) - -To exclude a file the package copies by default, see `IgnoreModFilePatterns` under -[_configure_](#configure). +* For normal files, you can [add/remove them in the build output](https://stackoverflow.com/a/10828462/262123). +* For assembly files (`*.dll`, `*.exe`, `*.pdb`, or `*.xml`), see the + [`BundleExtraAssemblies` option](#configure). +* To exclude a file which the package copies by default, see the [`IgnoreModFilePaths` or + `IgnoreModFilePatterns` options](#configure). ### Can I use the package for non-mod projects? -You can use the package in non-mod projects too (e.g. unit tests or framework DLLs). Just disable -the mod-related package features (see [_configure_](#configure)): +Yep, this works in unit tests and framework projects too. Just disable the mod-related package +features (see [_configure_](#configure)): ```xml false @@ -344,9 +394,9 @@ the mod-related package features (see [_configure_](#configure)): false ``` -If you need to copy the referenced DLLs into your build output, add this too: +To copy referenced DLLs into your build output for unit tests, add this too: ```xml -true +All ``` ## For SMAPI developers @@ -363,18 +413,24 @@ when you compile it. ## Release notes ## Upcoming release -* Updated for Stardew Valley 1.5.5 and SMAPI 3.13.0. **Older versions are no longer supported.** +* Updated for Stardew Valley 1.5.5 and SMAPI 3.13.0. (Older versions are no longer supported.) * Added `IgnoreModFilePaths` option to ignore literal paths. -* Removed the `GameExecutableName` and `GameFramework` build properties (since they now have the - same value on all platforms). +* Added `BundleExtraAssemblies` option to copy bundled DLLs into the mod zip/folder. +* Removed the `GameExecutableName` and `GameFramework` options (since they now have the same value + on all platforms). +* Removed the `CopyModReferencesToBuildOutput` option (superseded by `BundleExtraAssemblies`). * Improved analyzer performance by enabling parallel execution. **Migration guide for mod authors:** 1. See [_migrate to 64-bit_](https://stardewvalleywiki.com/Modding:Migrate_to_64-bit_on_Windows) and [_migrate to Stardew Valley 1.5.5_](https://stardewvalleywiki.com/Modding:Migrate_to_Stardew_Valley_1.5.5). 2. Possible changes in your `.csproj` or `.targets` files: - * If you use `$(GameExecutableName)`, replace it with `Stardew Valley`. - * If you use `$(GameFramework)`, replace it with `MonoGame` and remove any XNA-specific logic. + * Replace `$(GameExecutableName)` with `Stardew Valley`. + * Replace `$(GameFramework)` with `MonoGame` and remove any XNA Framework-specific logic. + * Replace `true` with + `Game`. + * If you need to bundle extra DLLs besides your mod DLL, see the [`BundleExtraAssemblies` + documentation](#configure). ## 3.3.0 Released 30 March 2021. diff --git a/src/SMAPI.ModBuildConfig/DeployModTask.cs b/src/SMAPI.ModBuildConfig/DeployModTask.cs index 0c64aed3..140933bd 100644 --- a/src/SMAPI.ModBuildConfig/DeployModTask.cs +++ b/src/SMAPI.ModBuildConfig/DeployModTask.cs @@ -18,6 +18,10 @@ namespace StardewModdingAPI.ModBuildConfig /********* ** Accessors *********/ + /// The name (without extension or path) of the current mod's DLL. + [Required] + public string ModDllName { get; set; } + /// The name of the mod folder. [Required] public string ModFolderName { get; set; } @@ -52,6 +56,9 @@ namespace StardewModdingAPI.ModBuildConfig /// A comma-separated list of relative file paths to ignore when deploying or zipping the mod. public string IgnoreModFilePaths { get; set; } + /// A comma-separated list of values which indicate which extra DLLs to bundle. + public string BundleExtraAssemblies { get; set; } + /********* ** Public methods @@ -73,12 +80,15 @@ namespace StardewModdingAPI.ModBuildConfig try { + // parse extra DLLs to bundle + ExtraAssemblyTypes bundleAssemblyTypes = this.GetExtraAssembliesToBundleOption(); + // parse ignore patterns string[] ignoreFilePaths = this.GetCustomIgnoreFilePaths().ToArray(); Regex[] ignoreFilePatterns = this.GetCustomIgnorePatterns().ToArray(); // get mod info - ModFileManager package = new ModFileManager(this.ProjectDir, this.TargetDir, ignoreFilePaths, ignoreFilePatterns, validateRequiredModFiles: this.EnableModDeploy || this.EnableModZip); + ModFileManager package = new ModFileManager(this.ProjectDir, this.TargetDir, ignoreFilePaths, ignoreFilePatterns, bundleAssemblyTypes, this.ModDllName, validateRequiredModFiles: this.EnableModDeploy || this.EnableModZip); // deploy mod files if (this.EnableModDeploy) @@ -139,6 +149,28 @@ namespace StardewModdingAPI.ModBuildConfig } } + /// Parse the extra assembly types which should be bundled with the mod. + private ExtraAssemblyTypes GetExtraAssembliesToBundleOption() + { + ExtraAssemblyTypes flags = ExtraAssemblyTypes.None; + + if (!string.IsNullOrWhiteSpace(this.BundleExtraAssemblies)) + { + foreach (string raw in this.BundleExtraAssemblies.Split(',')) + { + if (!Enum.TryParse(raw, out ExtraAssemblyTypes type)) + { + this.Log.LogWarning($"[mod build package] Ignored invalid <{nameof(this.BundleExtraAssemblies)}> value '{raw}', expected one of '{string.Join("', '", Enum.GetNames(typeof(ExtraAssemblyTypes)))}'."); + continue; + } + + flags |= type; + } + } + + return flags; + } + /// Get the custom ignore patterns provided by the user. private IEnumerable GetCustomIgnorePatterns() { diff --git a/src/SMAPI.ModBuildConfig/Framework/ExtraAssemblyType.cs b/src/SMAPI.ModBuildConfig/Framework/ExtraAssemblyType.cs new file mode 100644 index 00000000..571bf7c7 --- /dev/null +++ b/src/SMAPI.ModBuildConfig/Framework/ExtraAssemblyType.cs @@ -0,0 +1,21 @@ +using System; + +namespace StardewModdingAPI.ModBuildConfig.Framework +{ + /// An extra assembly type for the field. + [Flags] + internal enum ExtraAssemblyTypes + { + /// Don't include extra assemblies. + None = 0, + + /// Assembly files which are part of MonoGame, SMAPI, or Stardew Valley. + Game = 1, + + /// Assembly files whose names start with Microsoft.* or System.*. + System = 2, + + /// Assembly files which don't match any other category. + ThirdParty = 4 + } +} diff --git a/src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs b/src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs index fbb91193..ad4ffdf9 100644 --- a/src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs +++ b/src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs @@ -21,6 +21,45 @@ namespace StardewModdingAPI.ModBuildConfig.Framework /// The files that are part of the package. private readonly IDictionary Files; + /// The file extensions used by assembly files. + private readonly ISet AssemblyFileExtensions = new HashSet(StringComparer.OrdinalIgnoreCase) + { + ".dll", + ".exe", + ".pdb", + ".xml" + }; + + /// The DLLs which match the type. + private readonly ISet GameDllNames = new HashSet + { + // SMAPI + "0Harmony", + "Mono.Cecil", + "Mono.Cecil.Mdb", + "Mono.Cecil.Pdb", + "MonoMod.Common", + "Newtonsoft.Json", + "StardewModdingAPI", + "SMAPI.Toolkit", + "SMAPI.Toolkit.CoreInterfaces", + "TMXTile", + + // game + framework + "BmFont", + "FAudio-CS", + "GalaxyCSharp", + "GalaxyCSharpGlue", + "Lidgren.Network", + "MonoGame.Framework", + "SkiaSharp", + "Stardew Valley", + "StardewValley.GameData", + "Steamworks.NET", + "TextCopy", + "xTile" + }; + /********* ** Public methods @@ -30,9 +69,11 @@ namespace StardewModdingAPI.ModBuildConfig.Framework /// The folder containing the build output. /// The custom relative file paths provided by the user to ignore. /// Custom regex patterns matching files to ignore when deploying or zipping the mod. + /// The extra assembly types which should be bundled with the mod. + /// The name (without extension or path) for the current mod's DLL. /// Whether to validate that required mod files like the manifest are present. /// The mod package isn't valid. - public ModFileManager(string projectDir, string targetDir, string[] ignoreFilePaths, Regex[] ignoreFilePatterns, bool validateRequiredModFiles) + public ModFileManager(string projectDir, string targetDir, string[] ignoreFilePaths, Regex[] ignoreFilePatterns, ExtraAssemblyTypes bundleAssemblyTypes, string modDllName, bool validateRequiredModFiles) { this.Files = new Dictionary(StringComparer.OrdinalIgnoreCase); @@ -48,7 +89,7 @@ namespace StardewModdingAPI.ModBuildConfig.Framework string relativePath = entry.Item1; FileInfo file = entry.Item2; - if (!this.ShouldIgnore(file, relativePath, ignoreFilePaths, ignoreFilePatterns)) + if (!this.ShouldIgnore(file, relativePath, ignoreFilePaths, ignoreFilePatterns, bundleAssemblyTypes, modDllName)) this.Files[relativePath] = file; } @@ -152,39 +193,70 @@ namespace StardewModdingAPI.ModBuildConfig.Framework /// The file's relative path in the package. /// The custom relative file paths provided by the user to ignore. /// Custom regex patterns matching files to ignore when deploying or zipping the mod. - private bool ShouldIgnore(FileInfo file, string relativePath, string[] ignoreFilePaths, Regex[] ignoreFilePatterns) + /// The extra assembly types which should be bundled with the mod. + /// The name (without extension or path) for the current mod's DLL. + private bool ShouldIgnore(FileInfo file, string relativePath, string[] ignoreFilePaths, Regex[] ignoreFilePatterns, ExtraAssemblyTypes bundleAssemblyTypes, string modDllName) { - bool IsAssemblyFile(string baseName) + // apply custom patterns + if (ignoreFilePaths.Any(p => p == relativePath) || ignoreFilePatterns.Any(p => p.IsMatch(relativePath))) + return true; + + // ignore unneeded files + { + bool shouldIgnore = + // release zips + this.EqualsInvariant(file.Extension, ".zip") + + // *.deps.json (only SMAPI's top-level one is used) + || file.Name.EndsWith(".deps.json") + + // code analysis files + || file.Name.EndsWith(".CodeAnalysisLog.xml", StringComparison.OrdinalIgnoreCase) + || file.Name.EndsWith(".lastcodeanalysissucceeded", StringComparison.OrdinalIgnoreCase) + + // translation class builder (not used at runtime) + || ( + file.Name.StartsWith("Pathoschild.Stardew.ModTranslationClassBuilder") + && this.AssemblyFileExtensions.Contains(file.Extension) + ) + + // OS metadata files + || this.EqualsInvariant(file.Name, ".DS_Store") + || this.EqualsInvariant(file.Name, "Thumbs.db"); + if (shouldIgnore) + return true; + } + + // check for bundled assembly types + // When bundleAssemblyTypes is set, *all* dependencies are copied into the build output but only those which match the given assembly types should be bundled. + if (bundleAssemblyTypes != ExtraAssemblyTypes.None) { - return - this.EqualsInvariant(file.Name, $"{baseName}.dll") - || this.EqualsInvariant(file.Name, $"{baseName}.pdb") - || this.EqualsInvariant(file.Name, $"{baseName}.xnb"); + var type = this.GetExtraAssemblyType(file, modDllName); + if (type != ExtraAssemblyTypes.None && !bundleAssemblyTypes.HasFlag(type)) + return true; } - return - // release zips - this.EqualsInvariant(file.Extension, ".zip") + return false; + } - // unneeded *.deps.json (only SMAPI's top-level one is used) - || file.Name.EndsWith(".deps.json") + /// Get the extra assembly type for a file, assuming that the user specified one or more extra types to bundle. + /// The file to check. + /// The name (without extension or path) for the current mod's DLL. + private ExtraAssemblyTypes GetExtraAssemblyType(FileInfo file, string modDllName) + { + string baseName = Path.GetFileNameWithoutExtension(file.Name); + string extension = file.Extension; - // dependencies bundled with SMAPI - || IsAssemblyFile("0Harmony") - || IsAssemblyFile("Newtonsoft.Json") - || IsAssemblyFile("Pathoschild.Stardew.ModTranslationClassBuilder") // not used at runtime + if (baseName == modDllName || !this.AssemblyFileExtensions.Contains(extension)) + return ExtraAssemblyTypes.None; - // code analysis files - || file.Name.EndsWith(".CodeAnalysisLog.xml", StringComparison.OrdinalIgnoreCase) - || file.Name.EndsWith(".lastcodeanalysissucceeded", StringComparison.OrdinalIgnoreCase) + if (this.GameDllNames.Contains(baseName)) + return ExtraAssemblyTypes.Game; - // OS metadata files - || this.EqualsInvariant(file.Name, ".DS_Store") - || this.EqualsInvariant(file.Name, "Thumbs.db") + if (baseName.StartsWith("System.", StringComparison.OrdinalIgnoreCase) || baseName.StartsWith("Microsoft.", StringComparison.OrdinalIgnoreCase)) + return ExtraAssemblyTypes.System; - // custom ignore patterns - || ignoreFilePaths.Any(p => p == relativePath) - || ignoreFilePatterns.Any(p => p.IsMatch(relativePath)); + return ExtraAssemblyTypes.ThirdParty; } /// Get whether a string is equal to another case-insensitively. diff --git a/src/SMAPI.ModBuildConfig/build/smapi.targets b/src/SMAPI.ModBuildConfig/build/smapi.targets index 8ad298d0..de00cbe8 100644 --- a/src/SMAPI.ModBuildConfig/build/smapi.targets +++ b/src/SMAPI.ModBuildConfig/build/smapi.targets @@ -29,7 +29,10 @@ true false true - false + + + + true
@@ -45,17 +48,17 @@ **********************************************--> - - - - + + + + - - + + - + @@ -81,6 +84,7 @@ **********************************************--> -- cgit From 3beb2a99402b9f0e570e9c46cac7667044f736d3 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 16 Sep 2021 22:51:25 -0400 Subject: remove package workaround no longer needed with MonoGame --- src/SMAPI.ModBuildConfig/build/smapi.targets | 3 --- 1 file changed, 3 deletions(-) (limited to 'src') diff --git a/src/SMAPI.ModBuildConfig/build/smapi.targets b/src/SMAPI.ModBuildConfig/build/smapi.targets index de00cbe8..b66ec27b 100644 --- a/src/SMAPI.ModBuildConfig/build/smapi.targets +++ b/src/SMAPI.ModBuildConfig/build/smapi.targets @@ -12,9 +12,6 @@ pdbonly true - - $(AssemblySearchPaths);{GAC} - false -- cgit From 50a492f6e96ff596dd1642429fa7e3bd2adf975b Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 16 Sep 2021 22:52:29 -0400 Subject: bump upcoming mod build package version --- src/SMAPI.ModBuildConfig/SMAPI.ModBuildConfig.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/SMAPI.ModBuildConfig/SMAPI.ModBuildConfig.csproj b/src/SMAPI.ModBuildConfig/SMAPI.ModBuildConfig.csproj index 33356413..0bc8c45e 100644 --- a/src/SMAPI.ModBuildConfig/SMAPI.ModBuildConfig.csproj +++ b/src/SMAPI.ModBuildConfig/SMAPI.ModBuildConfig.csproj @@ -9,7 +9,7 @@ Pathoschild.Stardew.ModBuildConfig Build package for SMAPI mods - 3.4.0 + 4.0.0 Pathoschild Automates the build configuration for crossplatform Stardew Valley SMAPI mods. For SMAPI 3.13.0 or later. MIT -- cgit From f3626992cf17cfab6e9be65dd30f4a446c30c071 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 22 Sep 2021 00:36:31 -0400 Subject: remove walls_and_floors asset propagation This is now added as a regular map tilesheet, so it'll be handled by the tilesheet asset propagation. --- src/SMAPI/Metadata/CoreAssetPropagator.cs | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src') diff --git a/src/SMAPI/Metadata/CoreAssetPropagator.cs b/src/SMAPI/Metadata/CoreAssetPropagator.cs index 1780b280..552bc000 100644 --- a/src/SMAPI/Metadata/CoreAssetPropagator.cs +++ b/src/SMAPI/Metadata/CoreAssetPropagator.cs @@ -442,10 +442,6 @@ namespace StardewModdingAPI.Metadata Game1.objectSpriteSheet = content.Load(key); return true; - case "maps\\walls_and_floors": // Wallpaper - Wallpaper.wallpaperTexture = content.Load(key); - return true; - /**** ** Content\Minigames ****/ -- cgit From 65046c3c409df9c2cd4897f8358b259726ff496a Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 22 Sep 2021 00:38:42 -0400 Subject: remove outdated note in config.json --- src/SMAPI/SMAPI.config.json | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/SMAPI/SMAPI.config.json b/src/SMAPI/SMAPI.config.json index 7b5625d6..e62c8880 100644 --- a/src/SMAPI/SMAPI.config.json +++ b/src/SMAPI/SMAPI.config.json @@ -76,8 +76,6 @@ copy all the settings, or you may cause bugs due to overridden changes in future /** * The base URL for SMAPI's web API, used to perform update checks. - * Note: the protocol will be changed to http:// on Linux/macOS due to OpenSSL issues with the - * game's bundled Mono. */ "WebApiBaseUrl": "https://smapi.io/api/", -- cgit From b791e854c1f2117f0cc218485ec767a493a3d847 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 23 Sep 2021 23:11:54 -0400 Subject: fix installer precheck errors showing quotes, tweak readability --- src/SMAPI.Installer/assets/windows-install.bat | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/SMAPI.Installer/assets/windows-install.bat b/src/SMAPI.Installer/assets/windows-install.bat index 8623f321..00a2c6fb 100644 --- a/src/SMAPI.Installer/assets/windows-install.bat +++ b/src/SMAPI.Installer/assets/windows-install.bat @@ -3,7 +3,8 @@ REM make sure we're not running within a zip folder echo "%~dp0" | findstr /C:"%TEMP%" 1>nul if %ERRORLEVEL% EQU 0 ( - echo "Oops! It looks like you're running the installer from inside a zip file. Make sure you unzip the download first." + echo Oops! It looks like you're running the installer from inside a zip file. Make sure you unzip the download first. + echo. pause exit ) @@ -11,14 +12,17 @@ if %ERRORLEVEL% EQU 0 ( REM make sure .NET 5 is installed WHERE dotnet /q if %ERRORLEVEL% NEQ 0 ( - echo "Oops! You must have .NET 5 (desktop x64) installed to use SMAPI: https://dotnet.microsoft.com/download/dotnet/5.0/runtime" + echo Oops! You must have .NET 5 ^(desktop x64^) installed to use SMAPI: https://dotnet.microsoft.com/download/dotnet/5.0/runtime + echo. pause exit ) REM make sure an antivirus hasn't deleted the installer DLL if not exist internal\windows\SMAPI.Installer.dll ( - echo "Oops! SMAPI can't find its 'internal\windows\SMAPI.Installer.dll' file. Your antivirus might have deleted the file." + echo Oops! SMAPI is missing one of its files. Your antivirus might have deleted it. + echo Missing file: %installerDir%internal\windows\SMAPI.Installer.dll + echo. pause exit ) -- cgit From 32ccc8e87294fae4caaf7878ee852ab89b9cfdfd Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 23 Sep 2021 23:12:43 -0400 Subject: fix installer file precheck failing for some users --- src/SMAPI.Installer/assets/windows-install.bat | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/SMAPI.Installer/assets/windows-install.bat b/src/SMAPI.Installer/assets/windows-install.bat index 00a2c6fb..bd6da962 100644 --- a/src/SMAPI.Installer/assets/windows-install.bat +++ b/src/SMAPI.Installer/assets/windows-install.bat @@ -1,7 +1,9 @@ @echo off +SET installerDir=%~dp0 + REM make sure we're not running within a zip folder -echo "%~dp0" | findstr /C:"%TEMP%" 1>nul +echo %installerDir% | findstr /C:"%TEMP%" 1>nul if %ERRORLEVEL% EQU 0 ( echo Oops! It looks like you're running the installer from inside a zip file. Make sure you unzip the download first. echo. @@ -19,7 +21,7 @@ if %ERRORLEVEL% NEQ 0 ( ) REM make sure an antivirus hasn't deleted the installer DLL -if not exist internal\windows\SMAPI.Installer.dll ( +if not exist "%installerDir%internal\windows\SMAPI.Installer.dll" ( echo Oops! SMAPI is missing one of its files. Your antivirus might have deleted it. echo Missing file: %installerDir%internal\windows\SMAPI.Installer.dll echo. -- cgit From 51c6ef9443c9d53448d39a97afde8a0fd23eec46 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 23 Sep 2021 23:13:17 -0400 Subject: fix .NET 5 precheck passing if player has .NET Core installed --- src/SMAPI.Installer/assets/windows-install.bat | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/SMAPI.Installer/assets/windows-install.bat b/src/SMAPI.Installer/assets/windows-install.bat index bd6da962..cb96fc19 100644 --- a/src/SMAPI.Installer/assets/windows-install.bat +++ b/src/SMAPI.Installer/assets/windows-install.bat @@ -19,6 +19,13 @@ if %ERRORLEVEL% NEQ 0 ( pause exit ) +dotnet --info | findstr /C:"Microsoft.WindowsDesktop.App 5." 1>nul +if %ERRORLEVEL% NEQ 0 ( + echo Oops! You must have .NET 5 ^(desktop x64^) installed to use SMAPI: https://dotnet.microsoft.com/download/dotnet/5.0/runtime + echo. + pause + exit +) REM make sure an antivirus hasn't deleted the installer DLL if not exist "%installerDir%internal\windows\SMAPI.Installer.dll" ( -- cgit From cb378a1c558dc2c5de9f2ab1ae9ba38b17d2ac7c Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 23 Sep 2021 23:25:51 -0400 Subject: keep installer window open if it crashes --- docs/release-notes.md | 1 + src/SMAPI.Installer/assets/windows-install.bat | 9 +++++++++ 2 files changed, 10 insertions(+) (limited to 'src') diff --git a/docs/release-notes.md b/docs/release-notes.md index d6e22af4..f8c1b495 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -6,6 +6,7 @@ * Updated for Stardew Valley 1.5.5. * Updated compatibility list. * Added `set_farm_type` [console command](https://stardewvalleywiki.com/Modding:Console_commands#Console_commands) to change the current farm type. + * Fixed installer window closing immediately if the installer crashed. * For mod authors: * Migrated to 64-bit MonoGame and .NET 5 on all platforms (see [migration guide for mod authors](https://stardewvalleywiki.com/Modding:Migrate_to_Stardew_Valley_1.5.5)). diff --git a/src/SMAPI.Installer/assets/windows-install.bat b/src/SMAPI.Installer/assets/windows-install.bat index cb96fc19..2e0be906 100644 --- a/src/SMAPI.Installer/assets/windows-install.bat +++ b/src/SMAPI.Installer/assets/windows-install.bat @@ -38,3 +38,12 @@ if not exist "%installerDir%internal\windows\SMAPI.Installer.dll" ( REM start installer dotnet internal\windows\SMAPI.Installer.dll + +REM keep window open if it failed +if %ERRORLEVEL% NEQ 0 ( + echo. + echo Oops! The SMAPI installer seems to have failed. The error details may be shown above. + echo. + pause + exit +) -- cgit From fe675540b5c3a48764e70c596132a3ed65a790fb Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 25 Sep 2021 01:28:15 -0400 Subject: add map overlay patches --- docs/release-notes.md | 1 + src/SMAPI/Framework/Content/AssetDataForMap.cs | 90 ++++++++++++++++---------- src/SMAPI/IAssetDataForMap.cs | 3 +- src/SMAPI/PatchMapMode.cs | 15 +++++ 4 files changed, 73 insertions(+), 36 deletions(-) create mode 100644 src/SMAPI/PatchMapMode.cs (limited to 'src') diff --git a/docs/release-notes.md b/docs/release-notes.md index f8c1b495..69eab3ec 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -10,6 +10,7 @@ * For mod authors: * Migrated to 64-bit MonoGame and .NET 5 on all platforms (see [migration guide for mod authors](https://stardewvalleywiki.com/Modding:Migrate_to_Stardew_Valley_1.5.5)). + * Added support for [map overlays via `asset.AsMap().PatchMap`](https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Content#Edit_a_map). **Update note for players with older systems:** The game now has two branches: the _main branch_ which you'll get by default, and an optional diff --git a/src/SMAPI/Framework/Content/AssetDataForMap.cs b/src/SMAPI/Framework/Content/AssetDataForMap.cs index 4f810948..0a5fa7e7 100644 --- a/src/SMAPI/Framework/Content/AssetDataForMap.cs +++ b/src/SMAPI/Framework/Content/AssetDataForMap.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using StardewModdingAPI.Toolkit.Utilities; +using StardewValley; using xTile; using xTile.Layers; using xTile.Tiles; @@ -25,18 +26,17 @@ namespace StardewModdingAPI.Framework.Content : base(locale, assetName, data, getNormalizedPath, onDataReplaced) { } /// - /// Derived from with a few changes: + /// Derived from with a few changes: /// - can be applied directly to the maps when loading, before the location is created; - /// - added support for source/target areas; + /// - added support for patch modes (overlay, replace by layer, or fully replace); /// - added disambiguation if source has a modified version of the same tilesheet, instead of copying tiles into the target tilesheet; - /// - changed to always overwrite tiles within the target area (to avoid edge cases where some tiles are only partly applied); /// - fixed copying tilesheets (avoid "The specified TileSheet was not created for use with this map" error); /// - fixed tilesheets not added at the end (via z_ prefix), which can cause crashes in game code which depends on hardcoded tilesheet indexes; /// - fixed issue where different tilesheets are linked by ID. /// - public void PatchMap(Map source, Rectangle? sourceArea = null, Rectangle? targetArea = null) + public void PatchMap(Map source, Rectangle? sourceArea = null, Rectangle? targetArea = null, PatchMapMode patchMode = PatchMapMode.Overlay) { - var target = this.Data; + Map target = this.Data; // get areas { @@ -84,10 +84,13 @@ namespace StardewModdingAPI.Framework.Content tilesheetMap[sourceSheet] = targetSheet; } - // get layer map - IDictionary layerMap = source.Layers.ToDictionary(p => p, p => target.GetLayer(p.Id)); + // get target layers + IDictionary sourceToTargetLayers = source.Layers.ToDictionary(p => p, p => target.GetLayer(p.Id)); + HashSet orphanedTargetLayers = new HashSet(target.Layers.Except(sourceToTargetLayers.Values)); // apply tiles + bool replaceAll = patchMode == PatchMapMode.Replace; + bool replaceByLayer = patchMode == PatchMapMode.ReplaceByLayer; for (int x = 0; x < sourceArea.Value.Width; x++) { for (int y = 0; y < sourceArea.Value.Height; y++) @@ -96,47 +99,37 @@ namespace StardewModdingAPI.Framework.Content Point sourcePos = new Point(sourceArea.Value.X + x, sourceArea.Value.Y + y); Point targetPos = new Point(targetArea.Value.X + x, targetArea.Value.Y + y); + // replace tiles on target-only layers + if (replaceAll) + { + foreach (Layer targetLayer in orphanedTargetLayers) + targetLayer.Tiles[targetPos.X, targetPos.Y] = null; + } + // merge layers foreach (Layer sourceLayer in source.Layers) { // get layer - Layer targetLayer = layerMap[sourceLayer]; + Layer targetLayer = sourceToTargetLayers[sourceLayer]; if (targetLayer == null) { target.AddLayer(targetLayer = new Layer(sourceLayer.Id, target, target.Layers[0].LayerSize, Layer.m_tileSize)); - layerMap[sourceLayer] = target.GetLayer(sourceLayer.Id); + sourceToTargetLayers[sourceLayer] = target.GetLayer(sourceLayer.Id); } // copy layer properties targetLayer.Properties.CopyFrom(sourceLayer.Properties); - // copy tiles + // create new tile Tile sourceTile = sourceLayer.Tiles[sourcePos.X, sourcePos.Y]; - Tile targetTile; - switch (sourceTile) - { - case StaticTile _: - targetTile = new StaticTile(targetLayer, tilesheetMap[sourceTile.TileSheet], sourceTile.BlendMode, sourceTile.TileIndex); - break; - - case AnimatedTile animatedTile: - { - StaticTile[] tileFrames = new StaticTile[animatedTile.TileFrames.Length]; - for (int frame = 0; frame < animatedTile.TileFrames.Length; ++frame) - { - StaticTile frameTile = animatedTile.TileFrames[frame]; - tileFrames[frame] = new StaticTile(targetLayer, tilesheetMap[frameTile.TileSheet], frameTile.BlendMode, frameTile.TileIndex); - } - targetTile = new AnimatedTile(targetLayer, tileFrames, animatedTile.FrameInterval); - } - break; - - default: // null or unhandled type - targetTile = null; - break; - } - targetTile?.Properties.CopyFrom(sourceTile.Properties); - targetLayer.Tiles[targetPos.X, targetPos.Y] = targetTile; + Tile newTile = sourceTile != null + ? this.CreateTile(sourceTile, targetLayer, tilesheetMap[sourceTile.TileSheet]) + : null; + newTile?.Properties.CopyFrom(sourceTile.Properties); + + // replace tile + if (newTile != null || replaceByLayer || replaceAll) + targetLayer.Tiles[targetPos.X, targetPos.Y] = newTile; } } } @@ -146,6 +139,33 @@ namespace StardewModdingAPI.Framework.Content /********* ** Private methods *********/ + /// Create a new tile for the target map. + /// The source tile to copy. + /// The target layer. + /// The target tilesheet. + private Tile CreateTile(Tile sourceTile, Layer targetLayer, TileSheet targetSheet) + { + switch (sourceTile) + { + case StaticTile _: + return new StaticTile(targetLayer, targetSheet, sourceTile.BlendMode, sourceTile.TileIndex); + + case AnimatedTile animatedTile: + { + StaticTile[] tileFrames = new StaticTile[animatedTile.TileFrames.Length]; + for (int frame = 0; frame < animatedTile.TileFrames.Length; ++frame) + { + StaticTile frameTile = animatedTile.TileFrames[frame]; + tileFrames[frame] = new StaticTile(targetLayer, targetSheet, frameTile.BlendMode, frameTile.TileIndex); + } + + return new AnimatedTile(targetLayer, tileFrames, animatedTile.FrameInterval); + } + + default: // null or unhandled type + return null; + } + } /// Normalize a map tilesheet path for comparison. This value should *not* be used as the actual tilesheet path. /// The path to normalize. private string NormalizeTilesheetPathForComparison(string path) diff --git a/src/SMAPI/IAssetDataForMap.cs b/src/SMAPI/IAssetDataForMap.cs index bfaba9ba..47a33de8 100644 --- a/src/SMAPI/IAssetDataForMap.cs +++ b/src/SMAPI/IAssetDataForMap.cs @@ -13,6 +13,7 @@ namespace StardewModdingAPI /// The map from which to copy. /// The tile area within the source map to copy, or null for the entire source map size. This must be within the bounds of the map. /// The tile area within the target map to overwrite, or null to patch the whole map. The original content within this area will be erased. This must be within the bounds of the existing map. - void PatchMap(Map source, Rectangle? sourceArea = null, Rectangle? targetArea = null); + /// Indicates how the map should be patched. + void PatchMap(Map source, Rectangle? sourceArea = null, Rectangle? targetArea = null, PatchMapMode patchMode = PatchMapMode.Overlay); } } diff --git a/src/SMAPI/PatchMapMode.cs b/src/SMAPI/PatchMapMode.cs new file mode 100644 index 00000000..1f1ac6a9 --- /dev/null +++ b/src/SMAPI/PatchMapMode.cs @@ -0,0 +1,15 @@ +namespace StardewModdingAPI +{ + /// Indicates how a map should be patched. + public enum PatchMapMode + { + /// Replace matching tiles. Target tiles missing in the source area are kept as-is. + Overlay, + + /// Replace all tiles on layers that exist in the source map. + ReplaceByLayer, + + /// Replace all tiles with the source map. + Replace + } +} -- cgit From f87e65caf5a71b3ab129c7a0cfd14d49f68dd9c1 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 30 Oct 2021 21:23:28 -0400 Subject: update 'set_farm_type' console command for custom farm types --- .../Commands/Player/SetFarmTypeCommand.cs | 180 ++++++++++++++++++--- .../SMAPI.Mods.ConsoleCommands.csproj | 1 + 2 files changed, 156 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/SetFarmTypeCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/SetFarmTypeCommand.cs index 0bebd2b7..6b3b27cd 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/SetFarmTypeCommand.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/SetFarmTypeCommand.cs @@ -1,27 +1,23 @@ +using System; +using System.Collections; using System.Collections.Generic; using System.Linq; +using System.Reflection; +using System.Text; using StardewValley; +using StardewValley.GameData; namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player { /// A command which changes the player's farm type. internal class SetFarmTypeCommand : ConsoleCommand { - /********* - ** Fields - *********/ - /// The vanilla farm type IDs. - private static readonly ISet VanillaFarmTypes = new HashSet( - Enumerable.Range(0, Farm.layout_max + 1) - ); - - /********* ** Public methods *********/ /// Construct an instance. public SetFarmTypeCommand() - : base("set_farm_type", $"Sets the current player's farm type.\n\nUsage: set_farm_type \n- farm type: one of {string.Join(", ", SetFarmTypeCommand.VanillaFarmTypes.Select(id => $"{id} ({SetFarmTypeCommand.GetFarmLabel(id)})"))}.") { } + : base("set_farm_type", "Sets the current player's farm type.\n\nUsage: set_farm_type \n- farm type: the farm type to set. Enter `set_farm_type list` for a list of available farm types.") { } /// Handle the command. /// Writes messages to the console and log file. @@ -29,47 +25,141 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player /// The command arguments. public override void Handle(IMonitor monitor, string command, ArgumentParser args) { - // validation checks + // validate if (!Context.IsWorldReady) { monitor.Log("You must load a save to use this command.", LogLevel.Error); return; } - // parse argument - if (!args.TryGetInt(0, "farm type", out int farmType, min: 0, max: Farm.layout_max)) + // parse arguments + if (!args.TryGet(0, "farm type", out string farmType)) return; + bool isVanillaId = int.TryParse(farmType, out int vanillaId) && vanillaId is (>= 0 and < Farm.layout_max); - // handle - if (Game1.whichFarm == farmType) + // handle argument + if (farmType == "list") + this.HandleList(monitor); + else if (isVanillaId) + this.HandleVanillaFarmType(vanillaId, monitor); + else + this.HandleCustomFarmType(farmType, monitor); + } + + + /********* + ** Private methods + *********/ + /**** + ** Handlers + ****/ + /// Print a list of available farm types. + /// Writes messages to the console and log file. + private void HandleList(IMonitor monitor) + { + StringBuilder result = new(); + + // list vanilla types + result.AppendLine("The farm type can be one of these vanilla types:"); + foreach (var type in this.GetVanillaFarmTypes()) + result.AppendLine($" - {type.Key} ({type.Value})"); + result.AppendLine(); + + // list custom types { - monitor.Log($"Your current farm is already set to {farmType} ({SetFarmTypeCommand.GetFarmLabel(farmType)}).", LogLevel.Info); + var customTypes = this.GetCustomFarmTypes(); + if (customTypes.Any()) + { + result.AppendLine("Or one of these custom farm types:"); + foreach (var type in customTypes.Values.OrderBy(p => p.ID)) + result.AppendLine($" - {type.ID} ({this.GetCustomName(type)})"); + } + else + result.AppendLine("Or a custom farm type (though none is loaded currently)."); + } + + // print + monitor.Log(result.ToString(), LogLevel.Info); + } + + /// Set a vanilla farm type. + /// The farm type. + /// Writes messages to the console and log file. + private void HandleVanillaFarmType(int type, IMonitor monitor) + { + if (Game1.whichFarm == type) + { + monitor.Log($"Your current farm is already set to {type} ({this.GetVanillaName(type)}).", LogLevel.Info); return; } - this.SetFarmType(farmType); - monitor.Log($"Your current farm has been converted to {farmType} ({SetFarmTypeCommand.GetFarmLabel(farmType)}).", LogLevel.Warn); - monitor.Log("Saving and reloading is recommended to make sure everything is updated for the change.", LogLevel.Warn); + this.SetFarmType(type, null); + this.PrintSuccess(monitor, $"{type} ({this.GetVanillaName(type)}"); } + /// Set a custom farm type. + /// The farm type ID. + /// Writes messages to the console and log file. + private void HandleCustomFarmType(string id, IMonitor monitor) + { + if (Game1.whichModFarm?.ID == id) + { + monitor.Log($"Your current farm is already set to {id} ({this.GetCustomName(Game1.whichModFarm)}).", LogLevel.Info); + return; + } - /********* - ** Private methods - *********/ - /// Change the farm type to the given value. + if (!this.GetCustomFarmTypes().TryGetValue(id, out ModFarmType customFarmType)) + { + monitor.Log($"Invalid farm type '{id}'. Enter `help set_farm_type` for more info.", LogLevel.Error); + return; + } + + this.SetFarmType(Farm.mod_layout, customFarmType); + this.PrintSuccess(monitor, $"{id} ({this.GetCustomName(customFarmType)})"); + } + + /// Change the farm type. /// The farm type ID. - private void SetFarmType(int type) + /// The custom farm type data, if applicable. + private void SetFarmType(int type, ModFarmType customFarmData) { + // set flags Game1.whichFarm = type; + Game1.whichModFarm = customFarmData; + // update farm map Farm farm = Game1.getFarm(); farm.mapPath.Value = $@"Maps\{Farm.getMapNameFromTypeInt(Game1.whichFarm)}"; farm.reloadMap(); + + // clear spouse area cache to avoid errors + FieldInfo cacheField = farm.GetType().GetField("_baseSpouseAreaTiles", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); + if (cacheField == null) + throw new InvalidOperationException("Failed to access '_baseSpouseAreaTiles' field to clear spouse area cache."); + if (cacheField.GetValue(farm) is not IDictionary cache) + throw new InvalidOperationException($"The farm's '_baseSpouseAreaTiles' field didn't match the expected {nameof(IDictionary)} type."); + cache.Clear(); } + private void PrintSuccess(IMonitor monitor, string label) + { + StringBuilder result = new(); + result.AppendLine($"Your current farm has been converted to {label}. Saving and reloading is recommended to make sure everything is updated for the change."); + result.AppendLine(); + result.AppendLine("This doesn't move items that are out of bounds on the new map. If you need to clean up, you can..."); + result.AppendLine(" - temporarily switch back to the previous farm type;"); + result.AppendLine(" - or use a mod like Noclip Mode: https://www.nexusmods.com/stardewvalley/mods/3900 ;"); + result.AppendLine(" - or use the world_clear console command (enter `help world_clear` for details)."); + + monitor.Log(result.ToString(), LogLevel.Warn); + } + + /**** + ** Vanilla farm types + ****/ /// Get the display name for a vanilla farm type. /// The farm type. - private static string GetFarmLabel(int type) + private string GetVanillaName(int type) { string translationKey = type switch { @@ -87,5 +177,45 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player ? Game1.content.LoadString(@$"Strings\UI:{translationKey}").Split('_')[0] : type.ToString(); } + + /// Get the available vanilla farm types by ID. + private IDictionary GetVanillaFarmTypes() + { + IDictionary farmTypes = new Dictionary(); + + foreach (int id in Enumerable.Range(0, Farm.layout_max)) + farmTypes[id] = this.GetVanillaName(id); + + return farmTypes; + } + + /**** + ** Custom farm types + ****/ + /// Get the display name for a custom farm type. + /// The custom farm type. + private string GetCustomName(ModFarmType farmType) + { + if (string.IsNullOrWhiteSpace(farmType?.TooltipStringPath)) + return farmType?.ID; + + return Game1.content.LoadString(farmType.TooltipStringPath)?.Split('_')[0] ?? farmType.ID; + } + + /// Get the available custom farm types by ID. + private IDictionary GetCustomFarmTypes() + { + IDictionary farmTypes = new Dictionary(StringComparer.OrdinalIgnoreCase); + + foreach (ModFarmType farmType in Game1.content.Load>("Data\\AdditionalFarms")) + { + if (string.IsNullOrWhiteSpace(farmType.ID)) + continue; + + farmTypes[farmType.ID] = farmType; + } + + return farmTypes; + } } } diff --git a/src/SMAPI.Mods.ConsoleCommands/SMAPI.Mods.ConsoleCommands.csproj b/src/SMAPI.Mods.ConsoleCommands/SMAPI.Mods.ConsoleCommands.csproj index 52439c41..e3db8b47 100644 --- a/src/SMAPI.Mods.ConsoleCommands/SMAPI.Mods.ConsoleCommands.csproj +++ b/src/SMAPI.Mods.ConsoleCommands/SMAPI.Mods.ConsoleCommands.csproj @@ -16,6 +16,7 @@ +
-- cgit From d1d09ae1df63826dd453aa0347d668f420754ed7 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 25 Nov 2021 23:01:14 -0500 Subject: add support for loading BmFont files for custom languages --- docs/release-notes.md | 1 + src/SMAPI/Framework/ContentManagers/ModContentManager.cs | 11 ++++++++++- src/SMAPI/SMAPI.csproj | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/docs/release-notes.md b/docs/release-notes.md index 69eab3ec..d60156d5 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -5,6 +5,7 @@ * For players: * Updated for Stardew Valley 1.5.5. * Updated compatibility list. + * Added support for loading BmFont `.fnt` files for [custom languages](https://stardewvalleywiki.com/Modding:Custom_languages) through the [content API](https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Content). * Added `set_farm_type` [console command](https://stardewvalleywiki.com/Modding:Console_commands#Console_commands) to change the current farm type. * Fixed installer window closing immediately if the installer crashed. diff --git a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs index bf0b54b9..beb90a5d 100644 --- a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs @@ -2,6 +2,7 @@ using System; using System.Globalization; using System.IO; using System.Linq; +using BmFont; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; @@ -129,6 +130,14 @@ namespace StardewModdingAPI.Framework.ContentManagers } break; + // unpacked Bitmap font + case ".fnt": + { + string source = File.ReadAllText(file.FullName); + asset = (T)(object)new XmlSource(source); + } + break; + // unpacked data case ".json": { @@ -171,7 +180,7 @@ namespace StardewModdingAPI.Framework.ContentManagers break; default: - throw GetContentError($"unknown file extension '{file.Extension}'; must be one of '.json', '.png', '.tbin', or '.xnb'."); + throw GetContentError($"unknown file extension '{file.Extension}'; must be one of '.fnt', '.json', '.png', '.tbin', or '.xnb'."); } } catch (Exception ex) when (!(ex is SContentLoadException)) diff --git a/src/SMAPI/SMAPI.csproj b/src/SMAPI/SMAPI.csproj index 4f9aa9b1..b99028da 100644 --- a/src/SMAPI/SMAPI.csproj +++ b/src/SMAPI/SMAPI.csproj @@ -31,6 +31,7 @@ + -- cgit From b294ac1203aa78575f8c72f0be1ee9d3edff15ab Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 30 Nov 2021 17:13:53 -0500 Subject: prepare for release --- build/common.targets | 2 +- docs/release-notes.md | 24 +++++++++++++----------- src/SMAPI.Mods.ConsoleCommands/manifest.json | 4 ++-- src/SMAPI.Mods.ErrorHandler/manifest.json | 4 ++-- src/SMAPI.Mods.SaveBackup/manifest.json | 4 ++-- src/SMAPI/Constants.cs | 2 +- 6 files changed, 21 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/build/common.targets b/build/common.targets index a74002a6..9dd6f7a2 100644 --- a/build/common.targets +++ b/build/common.targets @@ -1,7 +1,7 @@ - 3.12.8 + 3.13.0 SMAPI latest $(AssemblySearchPaths);{GAC} diff --git a/docs/release-notes.md b/docs/release-notes.md index d60156d5..08cc832c 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -1,30 +1,32 @@ ← [README](README.md) # Release notes -## Upcoming release +## 3.13.0 +Released 30 November 2021 for Stardew Valley 1.5.5 or later. + * For players: * Updated for Stardew Valley 1.5.5. - * Updated compatibility list. - * Added support for loading BmFont `.fnt` files for [custom languages](https://stardewvalleywiki.com/Modding:Custom_languages) through the [content API](https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Content). * Added `set_farm_type` [console command](https://stardewvalleywiki.com/Modding:Console_commands#Console_commands) to change the current farm type. * Fixed installer window closing immediately if the installer crashed. + * Updated compatibility list. * For mod authors: * Migrated to 64-bit MonoGame and .NET 5 on all platforms (see [migration guide for mod authors](https://stardewvalleywiki.com/Modding:Migrate_to_Stardew_Valley_1.5.5)). * Added support for [map overlays via `asset.AsMap().PatchMap`](https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Content#Edit_a_map). + * Added support for loading BmFont `.fnt` files for [custom languages](https://stardewvalleywiki.com/Modding:Custom_languages) through the [content API](https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Content). + +* For the web UI: + * Updated the JSON validator/schema for Content Patcher 1.24.0. **Update note for players with older systems:** The game now has two branches: the _main branch_ which you'll get by default, and an optional -_compatibility branch_ for [older systems](https://www.stardewvalley.net/compatibility/). The two -branches have identical content, but use [different technologies](https://stardewvalleywiki.com/Modding:Migrate_to_Stardew_Valley_1.5.5#Stardew_Valley_compatibility_branch). +[_compatibility branch_ for older systems](https://www.stardewvalley.net/compatibility/). The two +branches have identical content, but use [different technologies](https://stardewvalleywiki.com/Modding:Migrate_to_Stardew_Valley_1.5.5#Game_compatibility_branch). Unfortunately **SMAPI only supports the main branch of the game**. There are formidable difficulties -across all mods in supporting all three variations, the [Steam hardware stats](https://store.steampowered.com/hwsurvey) -show that 99.69% of players have 64-bit, and 32-bit imposes significant restrictions on what mods -can do. - -* For the web UI: - * Updated the JSON validator/schema for Content Patcher 1.24.0. +across all mods in supporting all three variations, 32-bit imposes significant restrictions on what +mods can do, and the [Steam hardware stats](https://store.steampowered.com/hwsurvey) show that 99.69% +of players now have 64-bit. ## 3.12.8 Released 18 October 2021 for Stardew Valley 1.5.4. diff --git a/src/SMAPI.Mods.ConsoleCommands/manifest.json b/src/SMAPI.Mods.ConsoleCommands/manifest.json index 9af3ce5d..85653a7d 100644 --- a/src/SMAPI.Mods.ConsoleCommands/manifest.json +++ b/src/SMAPI.Mods.ConsoleCommands/manifest.json @@ -1,9 +1,9 @@ { "Name": "Console Commands", "Author": "SMAPI", - "Version": "3.12.8", + "Version": "3.13.0", "Description": "Adds SMAPI console commands that let you manipulate the game.", "UniqueID": "SMAPI.ConsoleCommands", "EntryDll": "ConsoleCommands.dll", - "MinimumApiVersion": "3.12.8" + "MinimumApiVersion": "3.13.0" } diff --git a/src/SMAPI.Mods.ErrorHandler/manifest.json b/src/SMAPI.Mods.ErrorHandler/manifest.json index cfbaa661..da8306d1 100644 --- a/src/SMAPI.Mods.ErrorHandler/manifest.json +++ b/src/SMAPI.Mods.ErrorHandler/manifest.json @@ -1,9 +1,9 @@ { "Name": "Error Handler", "Author": "SMAPI", - "Version": "3.12.8", + "Version": "3.13.0", "Description": "Handles some common vanilla errors to log more useful info or avoid breaking the game.", "UniqueID": "SMAPI.ErrorHandler", "EntryDll": "ErrorHandler.dll", - "MinimumApiVersion": "3.12.8" + "MinimumApiVersion": "3.13.0" } diff --git a/src/SMAPI.Mods.SaveBackup/manifest.json b/src/SMAPI.Mods.SaveBackup/manifest.json index 1efd1d89..4c57bd49 100644 --- a/src/SMAPI.Mods.SaveBackup/manifest.json +++ b/src/SMAPI.Mods.SaveBackup/manifest.json @@ -1,9 +1,9 @@ { "Name": "Save Backup", "Author": "SMAPI", - "Version": "3.12.8", + "Version": "3.13.0", "Description": "Automatically backs up all your saves once per day into its folder.", "UniqueID": "SMAPI.SaveBackup", "EntryDll": "SaveBackup.dll", - "MinimumApiVersion": "3.12.8" + "MinimumApiVersion": "3.13.0" } diff --git a/src/SMAPI/Constants.cs b/src/SMAPI/Constants.cs index 3ae8661a..cf4bb677 100644 --- a/src/SMAPI/Constants.cs +++ b/src/SMAPI/Constants.cs @@ -49,7 +49,7 @@ namespace StardewModdingAPI internal static int? LogScreenId { get; set; } /// SMAPI's current raw semantic version. - internal static string RawApiVersion = "3.12.8"; + internal static string RawApiVersion = "3.13.0"; } /// Contains SMAPI's constants and assumptions. -- cgit