Merge branch 'develop' into stable

This commit is contained in:
Jesse Plamondon-Willard 2023-01-09 12:27:49 -05:00
commit b4e95a92b3
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
19 changed files with 229 additions and 106 deletions

View File

@ -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>

View File

@ -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.

View File

@ -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.

View File

@ -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>

View File

@ -215,13 +215,24 @@ namespace StardewModdingAPI.ModBuildConfig.Framework
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;

View File

@ -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>
@ -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

View File

@ -104,12 +104,18 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework
// 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);
});
}
}

View File

@ -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"
}

View File

@ -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"
}

View File

@ -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;
@ -81,7 +79,7 @@ namespace StardewModdingAPI.Mods.SaveBackup
}
// 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
@ -136,19 +134,16 @@ namespace StardewModdingAPI.Mods.SaveBackup
}
}
/// <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;
@ -160,48 +155,6 @@ namespace StardewModdingAPI.Mods.SaveBackup
}
}
/// <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>

View File

@ -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"
}

View File

@ -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>

View File

@ -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'" />

View File

@ -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>
@ -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" />

View File

@ -52,7 +52,7 @@ namespace StardewModdingAPI
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>

View File

@ -258,7 +258,11 @@ namespace StardewModdingAPI.Framework
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,
@ -1795,7 +1799,7 @@ namespace StardewModdingAPI.Framework
// call entry method
try
{
mod.Entry(mod.Helper!);
mod.Entry(mod.Helper);
}
catch (Exception ex)
{
@ -1822,7 +1826,7 @@ namespace StardewModdingAPI.Framework
}
// 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 _);

View File

@ -1,11 +1,12 @@
using System;
using System.Threading.Tasks;
using StardewModdingAPI.Utilities;
using StardewValley;
namespace StardewModdingAPI.Framework
{
/// <summary>Invokes callbacks for mod hooks provided by the game.</summary>
internal class SModHooks : ModHooks
internal class SModHooks : DelegatingModHooks
{
/*********
** Fields
@ -21,25 +22,24 @@ namespace StardewModdingAPI.Framework
** Public methods
*********/
/// <summary>Construct an instance.</summary>
/// <param name="parent">The underlying hooks to call by default.</param>
/// <param name="beforeNewDayAfterFade">A callback to invoke before <see cref="Game1.newDayAfterFade"/> runs.</param>
/// <param name="monitor">Writes messages to the console.</param>
public SModHooks(Action beforeNewDayAfterFade, IMonitor monitor)
public SModHooks(ModHooks parent, Action beforeNewDayAfterFade, IMonitor monitor)
: base(parent)
{
this.BeforeNewDayAfterFade = beforeNewDayAfterFade;
this.Monitor = monitor;
}
/// <summary>A hook invoked when <see cref="Game1.newDayAfterFade"/> is called.</summary>
/// <param name="action">The vanilla <see cref="Game1.newDayAfterFade"/> logic.</param>
/// <inheritdoc />
public override void OnGame1_NewDayAfterFade(Action action)
{
this.BeforeNewDayAfterFade();
action();
}
/// <summary>Start an asynchronous task for the game.</summary>
/// <param name="task">The task to start.</param>
/// <param name="id">A unique key which identifies the task.</param>
/// <inheritdoc />
public override Task StartTask(Task task, string id)
{
this.Monitor.Log($"Synchronizing '{id}' task...");
@ -48,9 +48,7 @@ namespace StardewModdingAPI.Framework
return task;
}
/// <summary>Start an asynchronous task for the game.</summary>
/// <param name="task">The task to start.</param>
/// <param name="id">A unique key which identifies the task.</param>
/// <inheritdoc />
public override Task<T> StartTask<T>(Task<T> task, string id)
{
this.Monitor.Log($"Synchronizing '{id}' task...");

View File

@ -22,12 +22,12 @@
<Import Project="..\..\build\common.targets" />
<ItemGroup>
<PackageReference Include="LargeAddressAware" Version="1.0.5" />
<PackageReference Include="LargeAddressAware" Version="1.0.6" />
<PackageReference Include="Mono.Cecil" Version="0.11.4" />
<PackageReference Include="MonoMod.Common" Version="22.3.5.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="Pathoschild.Http.FluentClient" Version="4.2.0" />
<PackageReference Include="Pintail" Version="2.2.1" />
<PackageReference Include="Pintail" Version="2.2.2" />
<PackageReference Include="Platonymous.TMXTile" Version="1.5.9" />
<PackageReference Include="System.Reflection.Emit" Version="4.7.0" />

View File

@ -0,0 +1,137 @@
using System;
using System.Threading.Tasks;
using Microsoft.Xna.Framework.Input;
using StardewModdingAPI.Events;
using StardewModdingAPI.Framework;
using StardewValley;
using StardewValley.Events;
namespace StardewModdingAPI.Utilities
{
/// <summary>An implementation of <see cref="ModHooks"/> which automatically calls the parent instance for any method that's not overridden.</summary>
/// <remarks>The mod hooks are primarily meant for SMAPI to use. Using this directly in mods is a last resort, since it's very easy to break SMAPI this way. This class requires that SMAPI is present in the parent chain.</remarks>
public class DelegatingModHooks : ModHooks
{
/*********
** Accessors
*********/
/// <summary>The underlying instance to delegate to by default.</summary>
public ModHooks Parent { get; }
/*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
/// <param name="modHooks">The underlying instance to delegate to by default.</param>
public DelegatingModHooks(ModHooks modHooks)
{
this.AssertSmapiInChain(modHooks);
this.Parent = modHooks;
}
/// <summary>Raised before the in-game clock changes.</summary>
/// <param name="action">Run the vanilla update logic.</param>
/// <remarks>In mods, consider using <see cref="IGameLoopEvents.TimeChanged"/> instead.</remarks>
public override void OnGame1_PerformTenMinuteClockUpdate(Action action)
{
this.Parent.OnGame1_PerformTenMinuteClockUpdate(action);
}
/// <summary>Raised before initializing the new day and saving.</summary>
/// <param name="action">Run the vanilla update logic.</param>
/// <remarks>In mods, consider using <see cref="IGameLoopEvents.DayEnding"/> or <see cref="IGameLoopEvents.Saving"/> instead.</remarks>
public override void OnGame1_NewDayAfterFade(Action action)
{
this.Parent.OnGame1_NewDayAfterFade(action);
}
/// <summary>Raised before showing the end-of-day menus (e.g. shipping menus, level-up screen, etc).</summary>
/// <param name="action">Run the vanilla update logic.</param>
public override void OnGame1_ShowEndOfNightStuff(Action action)
{
this.Parent.OnGame1_ShowEndOfNightStuff(action);
}
/// <summary>Raised before updating the gamepad, mouse, and keyboard input state.</summary>
/// <param name="keyboardState">The keyboard state.</param>
/// <param name="mouseState">The mouse state.</param>
/// <param name="gamePadState">The gamepad state.</param>
/// <param name="action">Run the vanilla update logic.</param>
/// <remarks>In mods, consider using <see cref="IInputEvents"/> instead.</remarks>
public override void OnGame1_UpdateControlInput(ref KeyboardState keyboardState, ref MouseState mouseState, ref GamePadState gamePadState, Action action)
{
this.Parent.OnGame1_UpdateControlInput(ref keyboardState, ref mouseState, ref gamePadState, action);
}
/// <summary>Raised before a location is updated for the local player entering it.</summary>
/// <param name="location">The location that will be updated.</param>
/// <param name="action">Run the vanilla update logic.</param>
/// <remarks>In mods, consider using <see cref="IPlayerEvents.Warped"/> instead.</remarks>
public override void OnGameLocation_ResetForPlayerEntry(GameLocation location, Action action)
{
this.Parent.OnGameLocation_ResetForPlayerEntry(location, action);
}
/// <summary>Raised before the game checks for an action to trigger for a player interaction with a tile.</summary>
/// <param name="location">The location being checked.</param>
/// <param name="tileLocation">The tile position being checked.</param>
/// <param name="viewport">The game's current position and size within the map, measured in pixels.</param>
/// <param name="who">The player interacting with the tile.</param>
/// <param name="action">Run the vanilla update logic.</param>
/// <returns>Returns whether the interaction was handled.</returns>
public override bool OnGameLocation_CheckAction(GameLocation location, xTile.Dimensions.Location tileLocation, xTile.Dimensions.Rectangle viewport, Farmer who, Func<bool> action)
{
return this.Parent.OnGameLocation_CheckAction(location, tileLocation, viewport, who, action);
}
/// <summary>Raised before the game picks a night event to show on the farm after the player sleeps.</summary>
/// <param name="action">Run the vanilla update logic.</param>
/// <returns>Returns the selected farm event.</returns>
public override FarmEvent OnUtility_PickFarmEvent(Func<FarmEvent> action)
{
return this.Parent.OnUtility_PickFarmEvent(action);
}
/// <summary>Start an asynchronous task for the game.</summary>
/// <param name="task">The task to start.</param>
/// <param name="id">A unique key which identifies the task.</param>
public override Task StartTask(Task task, string id)
{
return this.Parent.StartTask(task, id);
}
/// <summary>Start an asynchronous task for the game.</summary>
/// <typeparam name="T">The type returned by the task when it completes.</typeparam>
/// <param name="task">The task to start.</param>
/// <param name="id">A unique key which identifies the task.</param>
public override Task<T> StartTask<T>(Task<T> task, string id)
{
return this.Parent.StartTask<T>(task, id);
}
/*********
** Private methods
*********/
/// <summary>Assert that SMAPI's mod hook implementation is in the inheritance chain.</summary>
/// <param name="hooks">The mod hooks to check.</param>
private void AssertSmapiInChain(ModHooks hooks)
{
// this is SMAPI
if (this is SModHooks)
return;
// SMAPI in delegated chain
for (ModHooks? cur = hooks; cur != null; cur = (cur as DelegatingModHooks)?.Parent)
{
if (cur is SModHooks)
return;
}
// SMAPI not found
throw new InvalidOperationException($"Can't create a {nameof(DelegatingModHooks)} instance without SMAPI's mod hooks in the parent chain.");
}
}
}