Skip to content

Commit

Permalink
Merge branch 'develop' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
Pathoschild committed Jan 9, 2023
2 parents 368b25b + 25b8e13 commit b4e95a9
Show file tree
Hide file tree
Showing 19 changed files with 229 additions and 106 deletions.
2 changes: 1 addition & 1 deletion build/common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repo. It imports the other MSBuild files as needed.
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!--set general build properties -->
<Version>3.18.1</Version>
<Version>3.18.2</Version>
<Product>SMAPI</Product>
<LangVersion>latest</LangVersion>
<AssemblySearchPaths>$(AssemblySearchPaths);{GAC}</AssemblySearchPaths>
Expand Down
11 changes: 11 additions & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@
_If needed, you can update to SMAPI 3.16.0 first and then install the latest version._
-->

## 3.18.2
Released 09 January 2023 for Stardew Valley 1.5.6 or later.

* For players:
* Fixed empty save backups for some macOS players.
* Fixed `player_add` console command not handling custom slingshots correctly (thanks too DaLion!).

* For mod authors:
* Added `DelegatingModHooks` utility for mods which need to override SMAPI's mod hooks directly.
* Updated to Newtonsoft.Json 13.0.2 (see [changes](https://github.com/JamesNK/Newtonsoft.Json/releases/tag/13.0.2)) and Pintail 2.2.2 (see [changes](https://github.com/Nanoray-pl/Pintail/blob/master/docs/release-notes.md#222)).

## 3.18.1
Released 01 December 2022 for Stardew Valley 1.5.6 or later.

Expand Down
5 changes: 4 additions & 1 deletion docs/technical/mod-package.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,11 @@ The NuGet package is generated automatically in `StardewModdingAPI.ModBuildConfi
when you compile it.

## Release notes
## Upcoming release
### 4.1.0
Released 08 January 2023.

* Added `manifest.json` format validation on build (thanks to tylergibbs2!).
* Fixed game DLLs not excluded from the release zip when they're referenced explicitly but `BundleExtraAssemblies` isn't set.

### 4.0.2
Released 09 October 2022.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.10.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.1" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
</ItemGroup>

<ItemGroup>
Expand Down
23 changes: 17 additions & 6 deletions src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,24 @@ private bool ShouldIgnore(FileInfo file, string relativePath, string[] ignoreFil
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)
// ignore by assembly type
ExtraAssemblyTypes type = this.GetExtraAssemblyType(file, modDllName);
switch (bundleAssemblyTypes)
{
var type = this.GetExtraAssemblyType(file, modDllName);
if (type != ExtraAssemblyTypes.None && !bundleAssemblyTypes.HasFlag(type))
return true;
// Only explicitly-referenced assemblies are in the build output. These should be added to the zip,
// since it's possible the game won't load them (except game assemblies which will always be loaded
// separately). If they're already loaded, SMAPI will just ignore them.
case ExtraAssemblyTypes.None:
if (type is ExtraAssemblyTypes.Game)
return true;
break;

// All assemblies are in the build output (due to how .NET builds references), but only those which
// match the bundled type should be in the zip.
default:
if (type != ExtraAssemblyTypes.None && !bundleAssemblyTypes.HasFlag(type))
return true;
break;
}

return false;
Expand Down
4 changes: 2 additions & 2 deletions src/SMAPI.ModBuildConfig/SMAPI.ModBuildConfig.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<!--NuGet package-->
<PackageId>Pathoschild.Stardew.ModBuildConfig</PackageId>
<Title>Build package for SMAPI mods</Title>
<Version>4.0.2</Version>
<Version>4.1.0</Version>
<Authors>Pathoschild</Authors>
<Description>Automates the build configuration for crossplatform Stardew Valley SMAPI mods. For SMAPI 3.13.0 or later.</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand All @@ -24,7 +24,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="16.10" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />

<!--
This is imported through Microsoft.Build.Utilities.Core. When installed by a mod, NuGet
Expand Down
16 changes: 11 additions & 5 deletions src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,18 @@ public IEnumerable<SearchableItem> GetAll(ItemType[]? itemTypes = null, bool inc
// weapons
if (ShouldGet(ItemType.Weapon))
{
foreach (int id in this.TryLoad<int, string>("Data\\weapons").Keys)
Dictionary<int, string> weaponsData = this.TryLoad<int, string>("Data\\weapons");
foreach (KeyValuePair<int, string> pair in weaponsData)
{
yield return this.TryCreate(ItemType.Weapon, id, p => p.ID is >= 32 and <= 34
? new Slingshot(p.ID)
: new MeleeWeapon(p.ID)
);
string rawFields = pair.Value;
yield return this.TryCreate(ItemType.Weapon, pair.Key, p =>
{
string[] fields = rawFields.Split('/');
bool isSlingshot = fields.Length > 8 && fields[8] == "4";
return isSlingshot
? new Slingshot(p.ID)
: new MeleeWeapon(p.ID);
});
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/SMAPI.Mods.ConsoleCommands/manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"Name": "Console Commands",
"Author": "SMAPI",
"Version": "3.18.1",
"Version": "3.18.2",
"Description": "Adds SMAPI console commands that let you manipulate the game.",
"UniqueID": "SMAPI.ConsoleCommands",
"EntryDll": "ConsoleCommands.dll",
"MinimumApiVersion": "3.18.1"
"MinimumApiVersion": "3.18.2"
}
4 changes: 2 additions & 2 deletions src/SMAPI.Mods.ErrorHandler/manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"Name": "Error Handler",
"Author": "SMAPI",
"Version": "3.18.1",
"Version": "3.18.2",
"Description": "Handles some common vanilla errors to log more useful info or avoid breaking the game.",
"UniqueID": "SMAPI.ErrorHandler",
"EntryDll": "ErrorHandler.dll",
"MinimumApiVersion": "3.18.1"
"MinimumApiVersion": "3.18.2"
}
57 changes: 5 additions & 52 deletions src/SMAPI.Mods.SaveBackup/ModEntry.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using StardewValley;

Expand Down Expand Up @@ -81,7 +79,7 @@ private void CreateBackup(DirectoryInfo backupFolder)
}

// compress backup if possible
if (!this.TryCompress(fallbackDir.FullName, targetFile, out Exception? compressError))
if (!this.TryCompressDir(fallbackDir.FullName, targetFile, out Exception? compressError))
{
this.Monitor.Log(Constants.TargetPlatform != GamePlatform.Android
? $"Backed up to {fallbackDir.FullName}." // expected to fail on Android
Expand Down Expand Up @@ -136,19 +134,16 @@ private void PruneBackups(DirectoryInfo backupFolder, int backupsToKeep)
}
}

/// <summary>Create a zip using the best available method.</summary>
/// <param name="sourcePath">The file or directory path to zip.</param>
/// <summary>Try to create a compressed zip file for a directory.</summary>
/// <param name="sourcePath">The directory path to zip.</param>
/// <param name="destination">The destination file to create.</param>
/// <param name="error">The error which occurred trying to compress, if applicable. This is <see cref="NotSupportedException"/> if compression isn't supported on this platform.</param>
/// <returns>Returns whether compression succeeded.</returns>
private bool TryCompress(string sourcePath, FileInfo destination, [NotNullWhen(false)] out Exception? error)
private bool TryCompressDir(string sourcePath, FileInfo destination, [NotNullWhen(false)] out Exception? error)
{
try
{
if (Constants.TargetPlatform == GamePlatform.Mac)
this.CompressUsingMacProcess(sourcePath, destination); // due to limitations with the bundled Mono on macOS, we can't reference System.IO.Compression
else
this.CompressUsingNetFramework(sourcePath, destination);
ZipFile.CreateFromDirectory(sourcePath, destination.FullName, CompressionLevel.Fastest, false);

error = null;
return true;
Expand All @@ -160,48 +155,6 @@ private bool TryCompress(string sourcePath, FileInfo destination, [NotNullWhen(f
}
}

/// <summary>Create a zip using the .NET compression library.</summary>
/// <param name="sourcePath">The file or directory path to zip.</param>
/// <param name="destination">The destination file to create.</param>
/// <exception cref="NotSupportedException">The compression libraries aren't available on this system.</exception>
private void CompressUsingNetFramework(string sourcePath, FileInfo destination)
{
// get compress method
MethodInfo createFromDirectory;
try
{
// create compressed backup
Assembly coreAssembly = Assembly.Load("System.IO.Compression, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
Assembly fsAssembly = Assembly.Load("System.IO.Compression.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
Type compressionLevelType = coreAssembly.GetType("System.IO.Compression.CompressionLevel") ?? throw new InvalidOperationException("Can't load CompressionLevel type.");
Type zipFileType = fsAssembly.GetType("System.IO.Compression.ZipFile") ?? throw new InvalidOperationException("Can't load ZipFile type.");
createFromDirectory = zipFileType.GetMethod("CreateFromDirectory", new[] { typeof(string), typeof(string), compressionLevelType, typeof(bool) }) ?? throw new InvalidOperationException("Can't load ZipFile.CreateFromDirectory method.");
}
catch (Exception ex)
{
throw new NotSupportedException("Couldn't load the .NET compression libraries on this system.", ex);
}

// compress file
createFromDirectory.Invoke(null, new object[] { sourcePath, destination.FullName, CompressionLevel.Fastest, false });
}

/// <summary>Create a zip using a process command on macOS.</summary>
/// <param name="sourcePath">The file or directory path to zip.</param>
/// <param name="destination">The destination file to create.</param>
private void CompressUsingMacProcess(string sourcePath, FileInfo destination)
{
DirectoryInfo saveFolder = new(sourcePath);
ProcessStartInfo startInfo = new()
{
FileName = "zip",
Arguments = $"-rq \"{destination.FullName}\" \"{saveFolder.Name}\" -x \"*.DS_Store\" -x \"__MACOSX\"",
WorkingDirectory = $"{saveFolder.FullName}/../",
CreateNoWindow = true
};
new Process { StartInfo = startInfo }.Start();
}

/// <summary>Recursively copy a directory or file.</summary>
/// <param name="source">The file or folder to copy.</param>
/// <param name="targetFolder">The folder to copy into.</param>
Expand Down
4 changes: 2 additions & 2 deletions src/SMAPI.Mods.SaveBackup/manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"Name": "Save Backup",
"Author": "SMAPI",
"Version": "3.18.1",
"Version": "3.18.2",
"Description": "Automatically backs up all your saves once per day into its folder.",
"UniqueID": "SMAPI.SaveBackup",
"EntryDll": "SaveBackup.dll",
"MinimumApiVersion": "3.18.1"
"MinimumApiVersion": "3.18.2"
}
10 changes: 5 additions & 5 deletions src/SMAPI.Tests/SMAPI.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="Moq" Version="4.18.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="FluentAssertions" Version="6.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.1" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/SMAPI.Toolkit/SMAPI.Toolkit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<Import Project="..\..\build\common.targets" />

<ItemGroup>
<PackageReference Include="HtmlAgilityPack" Version="1.11.43" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.46" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="Pathoschild.Http.FluentClient" Version="4.2.0" />
<PackageReference Include="System.Management" Version="5.0.0" Condition="'$(OS)' == 'Windows_NT'" />
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" Condition="'$(OS)' == 'Windows_NT'" />
Expand Down
14 changes: 7 additions & 7 deletions src/SMAPI.Web/SMAPI.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<AssemblyName>SMAPI.Web</AssemblyName>
<RootNamespace>StardewModdingAPI.Web</RootNamespace>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

Expand All @@ -15,14 +15,14 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Azure.Storage.Blobs" Version="12.13.0" />
<PackageReference Include="Hangfire.AspNetCore" Version="1.7.29" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.14.1" />
<PackageReference Include="Hangfire.AspNetCore" Version="1.7.32" />
<PackageReference Include="Hangfire.MemoryStorage" Version="1.7.0" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.43" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.46" />
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
<PackageReference Include="JetBrains.Annotations" Version="2022.1.0" />
<PackageReference Include="Markdig" Version="0.30.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.5" />
<PackageReference Include="JetBrains.Annotations" Version="2022.3.1" />
<PackageReference Include="Markdig" Version="0.30.4" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.1" />
<PackageReference Include="Newtonsoft.Json.Schema" Version="3.0.14" />
<PackageReference Include="Pathoschild.FluentNexus" Version="1.0.5" />
<PackageReference Include="Pathoschild.Http.FluentClient" Version="4.2.0" />
Expand Down
2 changes: 1 addition & 1 deletion src/SMAPI/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ internal static class EarlyConstants
internal static int? LogScreenId { get; set; }

/// <summary>SMAPI's current raw semantic version.</summary>
internal static string RawApiVersion = "3.18.1";
internal static string RawApiVersion = "3.18.2";
}

/// <summary>Contains SMAPI's constants and assumptions.</summary>
Expand Down
10 changes: 7 additions & 3 deletions src/SMAPI/Framework/SCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,11 @@ public void RunInteractively()
monitor: this.Monitor,
reflection: this.Reflection,
eventManager: this.EventManager,
modHooks: new SModHooks(this.OnNewDayAfterFade, this.Monitor),
modHooks: new SModHooks(
parent: new ModHooks(),
beforeNewDayAfterFade: this.OnNewDayAfterFade,
monitor: this.Monitor
),
multiplayer: this.Multiplayer,
exitGameImmediately: this.ExitGameImmediately,

Expand Down Expand Up @@ -1795,7 +1799,7 @@ private void LoadMods(IModMetadata[] mods, JsonHelper jsonHelper, ContentCoordin
// call entry method
try
{
mod.Entry(mod.Helper!);
mod.Entry(mod.Helper);
}
catch (Exception ex)
{
Expand All @@ -1822,7 +1826,7 @@ private void LoadMods(IModMetadata[] mods, JsonHelper jsonHelper, ContentCoordin
}

// validate mod doesn't implement both GetApi() and GetApi(mod)
if (metadata.Api != null && mod.GetType().GetMethod(nameof(Mod.GetApi), new Type[] { typeof(IModInfo) })!.DeclaringType != typeof(Mod))
if (metadata.Api != null && mod.GetType().GetMethod(nameof(Mod.GetApi), new[] { typeof(IModInfo) })!.DeclaringType != typeof(Mod))
metadata.LogAsMod($"Mod implements both {nameof(Mod.GetApi)}() and {nameof(Mod.GetApi)}({nameof(IModInfo)}), which isn't allowed. The latter will be ignored.", LogLevel.Error);
}
Context.HeuristicModsRunningCode.TryPop(out _);
Expand Down
Loading

0 comments on commit b4e95a9

Please sign in to comment.