Compatibility fix

This commit is contained in:
yangzhi 2023-06-26 16:41:39 +08:00
parent 68a88ef3ba
commit bf0903b173
5 changed files with 44 additions and 82 deletions

View File

@ -1,53 +0,0 @@
#if SMAPI_FOR_MOBILE
using System.Linq;
using System.Reflection;
using StardewValley;
using StardewValley.Mobile;
namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Other
{
/// <summary>A command which sends a debug command to the game.</summary>
internal class ZoomCommand : TrainerCommand
{
/*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
public ZoomCommand()
: base("zoom", "Modify game's zoom level.\n\nUsage: zoom <zoomLevel>\n- zoomLevel: the target zoomLevel (a number).\nFor example, 'zoom 1.5' set zoom level to 1.5 * NativeZoomLevel.") { }
/// <summary>Handle the command.</summary>
/// <param name="monitor">Writes messages to the console and log file.</param>
/// <param name="command">The command name.</param>
/// <param name="args">The command arguments.</param>
public override void Handle(IMonitor monitor, string command, ArgumentParser args)
{
// submit command
decimal zoomLevel;
if (!args.Any())
{
zoomLevel = 1.0m;
}
else if (!args.TryGetDecimal(0, "zoomLevel", out zoomLevel, min: 0.1m, max: 10m))
return;
object viewport = typeof(Game1).GetField("viewport", BindingFlags.Static | BindingFlags.Public).GetValue(null);
PropertyInfo x = viewport.GetType().GetProperty("X");
PropertyInfo y = viewport.GetType().GetProperty("Y");
int oldX = (int)x.GetValue(viewport);
int oldY = (int)y.GetValue(viewport);
FieldInfo _lastPinchZoomLevel = typeof(PinchZoom).GetField("_lastPinchZoomLevel", BindingFlags.Instance | BindingFlags.NonPublic);
FieldInfo _pinchZoomLevel = typeof(PinchZoom).GetField("_pinchZoomLevel", BindingFlags.Instance | BindingFlags.NonPublic);
Game1.options.zoomLevel = Game1.NativeZoomLevel * (float)zoomLevel;
float oldZoom = (float)_lastPinchZoomLevel.GetValue(PinchZoom.Instance);
_lastPinchZoomLevel.SetValue(PinchZoom.Instance, _pinchZoomLevel.GetValue(PinchZoom.Instance));
_pinchZoomLevel.SetValue(PinchZoom.Instance, Game1.options.zoomLevel);
Game1.game1.refreshWindowSettings();
PinchZoom.Instance.Center();
WeatherDebrisManager.Instance.RepositionOnZoomChange(oldX, oldY, (int)x.GetValue(viewport), (int)y.GetValue(viewport), oldZoom, Game1.options.zoomLevel);
RainManager.Instance.UpdateRainPositionForPinchZoom((float)(oldX - (int)x.GetValue(viewport)), (float)(oldY - (int)y.GetValue(viewport)));
// show result
monitor.Log("Zoom level changed.", LogLevel.Info);
}
}
}
#endif

View File

@ -30,16 +30,16 @@
<ItemGroup Condition="'$(BUILD_FOR_MOBILE)' != ''"> <ItemGroup Condition="'$(BUILD_FOR_MOBILE)' != ''">
<Reference Include="MonoGame.Framework"> <Reference Include="MonoGame.Framework">
<HintPath>..\..\build\StardewValleyAndroidStuff\base_1.4.5.145\assemblies\MonoGame.Framework.dll</HintPath> <HintPath>..\..\build\StardewValleyAndroidStuff\base_1.5.6.39\assemblies\MonoGame.Framework.dll</HintPath>
</Reference> </Reference>
<Reference Include="StardewModdingAPI"> <Reference Include="StardewModdingAPI">
<HintPath>..\SMAPI\bin\Release\StardewModdingAPI.dll</HintPath> <HintPath>..\SMAPI\bin\Debug\StardewModdingAPI.dll</HintPath>
</Reference> </Reference>
<Reference Include="StardewValley"> <Reference Include="StardewValley">
<HintPath>..\..\build\StardewValleyAndroidStuff\base_1.4.5.151\assemblies_decrypt\StardewValley.dll</HintPath> <HintPath>..\..\build\StardewValleyAndroidStuff\base_1.5.6.39\assemblies\StardewValley.dll</HintPath>
</Reference> </Reference>
<Reference Include="StardewValley.GameData"> <Reference Include="StardewValley.GameData">
<HintPath>..\..\build\StardewValleyAndroidStuff\base_1.4.5.151\assemblies_decrypt\StardewValley.GameData.dll</HintPath> <HintPath>..\..\build\StardewValleyAndroidStuff\base_1.5.6.39\assemblies\StardewValley.GameData.dll</HintPath>
</Reference> </Reference>
</ItemGroup> </ItemGroup>

View File

@ -1,24 +0,0 @@
using System.Reflection;
using Microsoft.Xna.Framework.Audio;
using StardewValley;
namespace StardewModdingAPI.Framework.ModLoading.RewriteFacades;
public interface ISoundBankMethods : ISoundBank
{
void AddCue(CueDefinition cueDefinition)
{
SoundBank soundBank = (SoundBank)this.GetType()
.GetField("soundBank", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
?.GetValue(this);
soundBank?.AddCue(cueDefinition);
}
CueDefinition GetCueDefinition(string name)
{
SoundBank soundBank = (SoundBank)this.GetType()
.GetField("soundBank", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
?.GetValue(this);
return soundBank?.GetCueDefinition(name);
}
}

View File

@ -0,0 +1,37 @@
using System.Reflection;
using HarmonyLib;
using Microsoft.Xna.Framework.Audio;
using StardewValley;
namespace StardewModdingAPI.Framework.ModLoading.RewriteFacades;
public static class SoundBankMethods
{
public static void AddCue(this ISoundBank iSoundBank, CueDefinition cueDefinition)
{
if (iSoundBank is SoundBankWrapper soundBankWrapper)
{
SoundBank soundBank = (SoundBank)typeof(SoundBankWrapper)
.GetField("soundBank", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
?.GetValue(soundBankWrapper);
soundBank?.AddCue(cueDefinition);
}
else
AccessTools.Method(iSoundBank.GetType(), "AddCue", new[] { typeof(CueDefinition) })
?.Invoke(iSoundBank, new[] { cueDefinition });
}
public static CueDefinition GetCueDefinition(this ISoundBank iSoundBank, string name)
{
if (iSoundBank is SoundBankWrapper soundBankWrapper)
{
SoundBank soundBank = (SoundBank)typeof(SoundBankWrapper)
.GetField("soundBank", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
?.GetValue(soundBankWrapper);
return soundBank?.GetCueDefinition(name);
}
return (CueDefinition)AccessTools.Method(iSoundBank.GetType(), "GetCueDefinition", new[] { typeof(string) })
?.Invoke(iSoundBank, new[] { name });
}
}

View File

@ -94,7 +94,9 @@ namespace StardewModdingAPI.Metadata
yield return new MethodParentRewriter(typeof(SpriteText), typeof(SpriteTextMethods)); yield return new MethodParentRewriter(typeof(SpriteText), typeof(SpriteTextMethods));
yield return new MethodParentRewriter(typeof(Utility), typeof(UtilityMethods)); yield return new MethodParentRewriter(typeof(Utility), typeof(UtilityMethods));
yield return new MethodParentRewriter(typeof(OptionsElement), typeof(OptionsElementMethods)); yield return new MethodParentRewriter(typeof(OptionsElement), typeof(OptionsElementMethods));
yield return new MethodParentRewriter(typeof(ISoundBank), typeof(ISoundBankMethods));
yield return new MethodToAnotherStaticMethodRewriter(typeof(ISoundBank), (method) => method.Name == nameof(SoundBankMethods.AddCue), typeof(SoundBankMethods), "AddCue");
yield return new MethodToAnotherStaticMethodRewriter(typeof(ISoundBank), (method) => method.Name == nameof(SoundBankMethods.GetCueDefinition), typeof(SoundBankMethods), "GetCueDefinition");
//Constructor Rewrites //Constructor Rewrites
yield return new MethodParentRewriter(typeof(MapPage), typeof(MapPageMethods)); yield return new MethodParentRewriter(typeof(MapPage), typeof(MapPageMethods));