Compatibility improvement, bug fix

This commit is contained in:
ZaneYork 2020-03-28 15:07:22 +08:00
parent 399eec451f
commit ffd5fa7832
7 changed files with 116 additions and 2 deletions

View File

@ -20,7 +20,7 @@ namespace StardewModdingAPI
** Public ** Public
****/ ****/
/// <summary>SMAPI's current semantic version.</summary> /// <summary>SMAPI's current semantic version.</summary>
public static ISemanticVersion ApiVersion { get; } = new Toolkit.SemanticVersion("3.4.1"); public static ISemanticVersion ApiVersion { get; } = new Toolkit.SemanticVersion("3.4.1.1", allowNonStandard: true);
/// <summary>The minimum supported version of Stardew Valley.</summary> /// <summary>The minimum supported version of Stardew Valley.</summary>
public static ISemanticVersion MinimumGameVersion { get; } = new GameVersion("1.4.5"); public static ISemanticVersion MinimumGameVersion { get; } = new GameVersion("1.4.5");

View File

@ -92,5 +92,19 @@ namespace StardewModdingAPI.Framework.RewriteFacades
return true; return true;
}); });
} }
public static void randomizeDebrisWeatherPositions(List<WeatherDebris> debris)
{
if (debris != null)
{
using (List<WeatherDebris>.Enumerator enumerator = debris.GetEnumerator())
{
while (enumerator.MoveNext())
{
enumerator.Current.position = Utility.getRandomPositionOnScreen();
}
}
}
}
} }
} }

View File

@ -0,0 +1,13 @@
using System.Collections.Generic;
using StardewValley;
namespace StardewModdingAPI.Framework.RewriteFacades
{
public class SaveGameMethods : SaveGame
{
public static IEnumerator<int> Save()
{
return SaveGame.Save(false, false);
}
}
}

View File

@ -273,6 +273,7 @@ namespace StardewModdingAPI.Framework
new ScheduleErrorPatch(this.MonitorForGame), new ScheduleErrorPatch(this.MonitorForGame),
new SaveBackupPatch(this.EventManager), new SaveBackupPatch(this.EventManager),
new JunimoHarvesterPatch(this.Monitor), new JunimoHarvesterPatch(this.Monitor),
new LocationSwitchPatch(this.Monitor),
new SpriteFontPatch(this.Monitor) new SpriteFontPatch(this.Monitor)
); );

View File

@ -88,6 +88,7 @@ namespace StardewModdingAPI.Metadata
yield return new MethodParentRewriter(typeof(NPC), typeof(NPCMethods)); yield return new MethodParentRewriter(typeof(NPC), typeof(NPCMethods));
yield return new MethodParentRewriter(typeof(Utility), typeof(UtilityMethods)); yield return new MethodParentRewriter(typeof(Utility), typeof(UtilityMethods));
yield return new MethodParentRewriter(typeof(DayTimeMoneyBox), typeof(DayTimeMoneyBoxMethods)); yield return new MethodParentRewriter(typeof(DayTimeMoneyBox), typeof(DayTimeMoneyBoxMethods));
yield return new MethodParentRewriter(typeof(SaveGame), typeof(SaveGameMethods));
//Constructor Rewrites //Constructor Rewrites
yield return new MethodParentRewriter(typeof(HUDMessage), typeof(HUDMessageMethods)); yield return new MethodParentRewriter(typeof(HUDMessage), typeof(HUDMessageMethods));

View File

@ -0,0 +1,83 @@
using System;
using System.Diagnostics.CodeAnalysis;
using Harmony;
using StardewModdingAPI.Framework.Patching;
using StardewValley;
using StardewValley.Characters;
namespace StardewModdingAPI.Patches
{
/// <summary>A Harmony patch for <see cref="StardewValley.Game1"/> which detect location switch and add tapToMove if possible.</summary>
/// <remarks>Patch methods must be static for Harmony to work correctly. See the Harmony documentation before renaming patch arguments.</remarks>
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Argument names are defined by Harmony and methods are named for clarity.")]
[SuppressMessage("ReSharper", "IdentifierTypo", Justification = "Argument names are defined by Harmony and methods are named for clarity.")]
internal class LocationSwitchPatch : IHarmonyPatch
{
/*********
** Fields
*********/
/*********
** Fields
*********/
/// <summary>Writes messages to the console and log file.</summary>
private static IMonitor Monitor;
/*********
** Accessors
*********/
/// <summary>A unique name for this patch.</summary>
public string Name => nameof(LocationSwitchPatch);
/*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
/// <param name="monitorForGame">Writes messages to the console and log file on behalf of the game.</param>
public LocationSwitchPatch(IMonitor monitor)
{
Monitor = monitor;
}
/// <summary>Apply the Harmony patch.</summary>
/// <param name="harmony">The Harmony instance.</param>
public void Apply(HarmonyInstance harmony)
{
harmony.Patch(
original: AccessTools.Property(typeof(Game1), "currentLocation").SetMethod,
prefix: new HarmonyMethod(this.GetType(), nameof(LocationSwitchPatch.Before_currentLocation_set))
);
}
/*********
** Private methods
*********/
/// <summary>The method to call instead of <see cref="JunimoHarvester.ctor"/>.</summary>
/// <param name="__instance">The instance being patched.</param>
/// <param name="__originalMethod">The method being wrapped.</param>
/// <returns>Returns whether to execute the original method.</returns>
private static void Before_currentLocation_set(GameLocation value)
{
try
{
if (value.tapToMove == null)
{
if (value.map != null)
{
value.tapToMove = new StardewValley.Mobile.TapToMove(value);
}
else
{
value.tapToMove = Game1.currentLocation.tapToMove;
}
}
}
catch (Exception ex)
{
LocationSwitchPatch.Monitor.Log($"Failed to add tapToMove for currentLocation {value.Name}:\n{ex.InnerException ?? ex}", LogLevel.Error);
}
}
}
}

View File

@ -24,7 +24,7 @@
<DebugType>portable</DebugType> <DebugType>portable</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath> <OutputPath>bin\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG</DefineConstants> <DefineConstants>TRACE;DEBUG;ANDROID_TARGET_SAMSUNG</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
@ -321,6 +321,7 @@
<Compile Include="Framework\RewriteFacades\SpriteTextMethods.cs" /> <Compile Include="Framework\RewriteFacades\SpriteTextMethods.cs" />
<Compile Include="Framework\RewriteFacades\TextBoxMethods.cs" /> <Compile Include="Framework\RewriteFacades\TextBoxMethods.cs" />
<Compile Include="Framework\RewriteFacades\UtilityMethods.cs" /> <Compile Include="Framework\RewriteFacades\UtilityMethods.cs" />
<Compile Include="Framework\RewriteFacades\SaveGameMethods.cs" />
<Compile Include="Framework\RewriteFacades\WeatherDebrisMethods.cs" /> <Compile Include="Framework\RewriteFacades\WeatherDebrisMethods.cs" />
<Compile Include="Framework\SCore.cs" /> <Compile Include="Framework\SCore.cs" />
<Compile Include="Framework\Serialization\ColorConverter.cs" /> <Compile Include="Framework\Serialization\ColorConverter.cs" />
@ -398,6 +399,7 @@
<Compile Include="Mod.cs" /> <Compile Include="Mod.cs" />
<Compile Include="Patches\DialogueErrorPatch.cs" /> <Compile Include="Patches\DialogueErrorPatch.cs" />
<Compile Include="Patches\EventErrorPatch.cs" /> <Compile Include="Patches\EventErrorPatch.cs" />
<Compile Include="Patches\LocationSwitchPatch.cs" />
<Compile Include="Patches\SpriteFontPatch.cs" /> <Compile Include="Patches\SpriteFontPatch.cs" />
<Compile Include="Patches\LoadContextPatch.cs" /> <Compile Include="Patches\LoadContextPatch.cs" />
<Compile Include="Patches\LoadErrorPatch.cs" /> <Compile Include="Patches\LoadErrorPatch.cs" />