1.Compatibility fix

2.Update SMAPI to 3.4.1.5
3.Compatible with some of device of Android L
This commit is contained in:
ZaneYork 2020-04-15 14:27:00 +08:00
parent 9619e5ecc5
commit fa8d24962f
9 changed files with 115 additions and 53 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.2", allowNonStandard: true); public static ISemanticVersion ApiVersion { get; } = new Toolkit.SemanticVersion("3.4.1.5", 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");
@ -109,6 +109,8 @@ namespace StardewModdingAPI
/// <summary>The language code for non-translated mod assets.</summary> /// <summary>The language code for non-translated mod assets.</summary>
internal static LocalizedContentManager.LanguageCode DefaultLanguage { get; } = LocalizedContentManager.LanguageCode.en; internal static LocalizedContentManager.LanguageCode DefaultLanguage { get; } = LocalizedContentManager.LanguageCode.en;
internal static bool MonoModInit { get; set; } = true;
/********* /*********
** Internal methods ** Internal methods

View File

@ -91,6 +91,12 @@ namespace StardewModdingAPI.Framework.ModLoading
if (definition.Name != reference.Name) if (definition.Name != reference.Name)
return false; return false;
// same return type
if(definition is MethodInfo methodDefinition)
{
if(!RewriteHelper.IsSameType(methodDefinition.ReturnType, reference.ReturnType))
return false;
}
// same arguments // same arguments
ParameterInfo[] definitionParameters = definition.GetParameters(); ParameterInfo[] definitionParameters = definition.GetParameters();
ParameterDefinition[] referenceParameters = reference.Parameters.ToArray(); ParameterDefinition[] referenceParameters = reference.Parameters.ToArray();

View File

@ -29,11 +29,12 @@ namespace StardewModdingAPI.Framework.Patching
/// <param name="patches">The patches to apply.</param> /// <param name="patches">The patches to apply.</param>
public void Apply(params IHarmonyPatch[] patches) public void Apply(params IHarmonyPatch[] patches)
{ {
if (Build.VERSION.SdkInt < BuildVersionCodes.M) if (!HarmonyDetourBridge.Initialized && Constants.MonoModInit)
return;
if (!HarmonyDetourBridge.Initialized)
{ {
HarmonyDetourBridge.Init(); try {
HarmonyDetourBridge.Init();
}
catch { Constants.MonoModInit = false; }
} }
HarmonyInstance harmony = HarmonyInstance.Create("io.smapi"); HarmonyInstance harmony = HarmonyInstance.Create("io.smapi");
@ -41,19 +42,16 @@ namespace StardewModdingAPI.Framework.Patching
{ {
try try
{ {
patch.Apply(harmony); if(Constants.MonoModInit)
patch.Apply(harmony);
} }
catch (Exception ex) catch (Exception ex)
{ {
Constants.MonoModInit = false;
this.Monitor.Log($"Couldn't apply runtime patch '{patch.Name}' to the game. Some SMAPI features may not work correctly. See log file for details.", LogLevel.Error); this.Monitor.Log($"Couldn't apply runtime patch '{patch.Name}' to the game. Some SMAPI features may not work correctly. See log file for details.", LogLevel.Error);
this.Monitor.Log(ex.GetLogSummary(), LogLevel.Trace); this.Monitor.Log(ex.GetLogSummary(), LogLevel.Trace);
} }
} }
//Keeping for reference
//if (Build.VERSION.SdkInt > BuildVersionCodes.LollipopMr1)
//{
//}
} }
} }
} }

View File

@ -1,6 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Reflection; using System.Reflection;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using StardewValley; using StardewValley;
using StardewValley.Menus; using StardewValley.Menus;
@ -106,5 +107,14 @@ namespace StardewModdingAPI.Framework.RewriteFacades
} }
} }
} }
public static new void createItemDebris(Item item, Vector2 origin, int direction, GameLocation location = null, int groundLevel = -1)
{
Game1.createItemDebris(item, origin, direction, location, groundLevel);
}
public static void changeMusicTrack(string newTrackName)
{
Game1.changeMusicTrack(newTrackName, false, MusicContext.Default);
}
} }
} }

View File

@ -1,13 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Netcode;
using StardewValley; using StardewValley;
namespace StardewModdingAPI.Framework.RewriteFacades namespace StardewModdingAPI.Framework.RewriteFacades
{ {
public class GameLocationMethods : GameLocation public class GameLocationMethods : GameLocation
{ {
public void playSound(string audioName)
{
base.playSound(audioName, StardewValley.Network.NetAudio.SoundContext.Default);
}
} }
} }

View File

@ -748,7 +748,7 @@ namespace StardewModdingAPI.Framework
shopMenu.onPurchase, shopMenu.onSell, shopMenu.storeContext); shopMenu.onPurchase, shopMenu.onSell, shopMenu.storeContext);
} }
} }
} }
/********* /*********
** World & player events ** World & player events
@ -977,7 +977,9 @@ namespace StardewModdingAPI.Framework
this.ExitGameImmediately("The game crashed when drawing, and SMAPI was unable to recover the game."); this.ExitGameImmediately("The game crashed when drawing, and SMAPI was unable to recover the game.");
return; return;
} }
}
finally
{
// recover sprite batch // recover sprite batch
try try
{ {

View File

@ -89,6 +89,7 @@ namespace StardewModdingAPI.Metadata
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)); yield return new MethodParentRewriter(typeof(SaveGame), typeof(SaveGameMethods));
yield return new MethodParentRewriter(typeof(GameLocation), typeof(GameLocationMethods));
//Constructor Rewrites //Constructor Rewrites
yield return new MethodParentRewriter(typeof(HUDMessage), typeof(HUDMessageMethods)); yield return new MethodParentRewriter(typeof(HUDMessage), typeof(HUDMessageMethods));

View File

@ -17,7 +17,9 @@ namespace StardewModdingAPI
public bool isVisible; public bool isVisible;
private readonly LinkedList<KeyValuePair<ConsoleLogLevel, string>> consoleMessageQueue = new LinkedList<KeyValuePair<ConsoleLogLevel, string>>(); private readonly LinkedList<KeyValuePair<ConsoleLogLevel, string>> consoleMessageQueue = new LinkedList<KeyValuePair<ConsoleLogLevel, string>>();
private Dictionary<string, LinkedList<string>> parseTextCache = new Dictionary<string, LinkedList<string>>();
private MobileScrollbox scrollbox; private MobileScrollbox scrollbox;
private MobileScrollbar scrollbar;
private ClickableTextureComponent commandButton; private ClickableTextureComponent commandButton;
@ -29,7 +31,8 @@ namespace StardewModdingAPI
private int scrollLastY = 0; private int scrollLastY = 0;
private int MaxScrollBoxHeight => (int)(Game1.graphics.PreferredBackBufferHeight * 20 / Game1.NativeZoomLevel); private int MaxScrollBoxHeight => (int)(Game1.graphics.PreferredBackBufferHeight * 100 / Game1.NativeZoomLevel);
private int ScrollBoxHeight => (int)(Game1.graphics.PreferredBackBufferHeight / Game1.NativeZoomLevel);
private int MaxTextAreaWidth => (int)((Game1.graphics.PreferredBackBufferWidth - 32) / Game1.NativeZoomLevel); private int MaxTextAreaWidth => (int)((Game1.graphics.PreferredBackBufferWidth - 32) / Game1.NativeZoomLevel);
@ -41,9 +44,13 @@ namespace StardewModdingAPI
internal void InitializeContent(LocalizedContentManager content) internal void InitializeContent(LocalizedContentManager content)
{ {
this.scrollbox = new MobileScrollbox(0, 0, this.MaxTextAreaWidth, (int)(Game1.graphics.PreferredBackBufferHeight / Game1.NativeZoomLevel), this.MaxScrollBoxHeight,
new Rectangle(0, 0, (int)(Game1.graphics.PreferredBackBufferWidth / Game1.NativeZoomLevel), (int)(Game1.graphics.PreferredBackBufferHeight / Game1.NativeZoomLevel)));
this.smallFont = content.Load<SpriteFont>(@"Fonts\SmallFont"); this.smallFont = content.Load<SpriteFont>(@"Fonts\SmallFont");
Game1.mobileSpriteSheet = content.Load<Texture2D>(@"LooseSprites\\MobileAtlas_manually_made");
this.scrollbar = new MobileScrollbar(0, 96, 16, this.ScrollBoxHeight - 192);
this.scrollbox = new MobileScrollbox(0, 0, this.MaxTextAreaWidth, this.ScrollBoxHeight, this.MaxScrollBoxHeight,
new Rectangle(0, 0, (int)(Game1.graphics.PreferredBackBufferWidth / Game1.NativeZoomLevel), this.ScrollBoxHeight),
this.scrollbar
);
} }
public void Show() public void Show()
@ -58,6 +65,12 @@ namespace StardewModdingAPI
public override void receiveLeftClick(int x, int y, bool playSound = true) public override void receiveLeftClick(int x, int y, bool playSound = true)
{ {
if (this.scrollbar.sliderContains(x, y) || this.scrollbar.sliderRunnerContains(x, y))
{
float num = this.scrollbar.setY(y);
this.scrollbox.setYOffsetForScroll(-((int)((num * this.scrollbox.getMaxYOffset()) / 100f)));
Game1.playSound("shwip");
}
if (this.upperRightCloseButton.bounds.Contains(x, y)) if (this.upperRightCloseButton.bounds.Contains(x, y))
{ {
@ -126,6 +139,7 @@ namespace StardewModdingAPI
this.consoleMessageQueue.AddFirst(new KeyValuePair<ConsoleLogLevel, string>(level, consoleMessage)); this.consoleMessageQueue.AddFirst(new KeyValuePair<ConsoleLogLevel, string>(level, consoleMessage));
if (this.consoleMessageQueue.Count > 2000) if (this.consoleMessageQueue.Count > 2000)
{ {
this.parseTextCache.Remove(this.consoleMessageQueue.Last.Value.Value);
this.consoleMessageQueue.RemoveLast(); this.consoleMessageQueue.RemoveLast();
} }
} }
@ -136,27 +150,39 @@ namespace StardewModdingAPI
this.scrollbox.update(time); this.scrollbox.update(time);
} }
private string _parseText(string text) private LinkedList<string> _parseText(string text)
{ {
if (this.parseTextCache.TryGetValue(text, out LinkedList<string> returnString))
{
return returnString;
}
returnString = new LinkedList<string>();
string line = string.Empty; string line = string.Empty;
string returnString = string.Empty;
string[] strings = text.Split("\n"); string[] strings = text.Split("\n");
foreach (string t in strings) foreach (string t in strings)
{ {
if (this.smallFont.MeasureString(t).X < this.MaxTextAreaWidth)
{
returnString.AddFirst(t);
continue;
}
string[] wordArray = t.Split(' '); string[] wordArray = t.Split(' ');
Vector2 masureResult = new Vector2(0,0);
foreach (string word in wordArray) foreach (string word in wordArray)
{ {
if (this.smallFont.MeasureString(line + word).X > this.MaxTextAreaWidth) masureResult += this.smallFont.MeasureString(word + " ");
if (masureResult.X > this.MaxTextAreaWidth)
{ {
returnString = returnString + line + '\n'; returnString.AddFirst(line);
line = string.Empty; line = string.Empty;
masureResult = new Vector2(0, 0);
} }
line = line + word + ' '; line = line + word + ' ';
} }
returnString = returnString + line + '\n'; returnString.AddFirst(line);
line = string.Empty; line = string.Empty;
} }
returnString.TrimEnd('\n'); this.parseTextCache.TryAdd(text, returnString);
return returnString; return returnString;
} }
@ -185,39 +211,52 @@ namespace StardewModdingAPI
public override void draw(SpriteBatch b) public override void draw(SpriteBatch b)
{ {
this.scrollbar.draw(b);
this.scrollbox.setUpForScrollBoxDrawing(b); this.scrollbox.setUpForScrollBoxDrawing(b);
lock (this.consoleMessageQueue) lock (this.consoleMessageQueue)
{ {
float offset = 0; float offset = 0;
Vector2 size = this.smallFont.MeasureString("Aa");
foreach (var log in this.consoleMessageQueue) foreach (var log in this.consoleMessageQueue)
{ {
string text = this._parseText(log.Value); LinkedList<string> textArray = this._parseText(log.Value);
Vector2 size = this.smallFont.MeasureString(text); float baseOffset = Game1.game1.screen.Height - this.scrollbox.getYOffsetForScroll();
float y = Game1.game1.screen.Height - size.Y - offset - this.scrollbox.getYOffsetForScroll(); if (baseOffset - size.Y * textArray.Count - offset > this.ScrollBoxHeight)
offset += size.Y;
switch (log.Key)
{ {
case ConsoleLogLevel.Critical: offset += size.Y * textArray.Count;
case ConsoleLogLevel.Error: }
b.DrawString(this.smallFont, text, new Vector2(16, y), Color.Red); else
break; {
case ConsoleLogLevel.Alert: foreach (string text in textArray)
case ConsoleLogLevel.Warn: {
b.DrawString(this.smallFont, text, new Vector2(16, y), Color.Orange); float y = baseOffset - size.Y - offset;
break; if (y < -16)
case ConsoleLogLevel.Info: continue;
case ConsoleLogLevel.Success: offset += size.Y;
b.DrawString(this.smallFont, text, new Vector2(16, y), Color.AntiqueWhite); switch (log.Key)
break; {
case ConsoleLogLevel.Debug: case ConsoleLogLevel.Critical:
case ConsoleLogLevel.Trace: case ConsoleLogLevel.Error:
b.DrawString(this.smallFont, text, new Vector2(16, y), Color.LightGray); b.DrawString(this.smallFont, text, new Vector2(16, y), Color.Red);
break; break;
default: case ConsoleLogLevel.Alert:
b.DrawString(this.smallFont, text, new Vector2(16, y), Color.LightGray); case ConsoleLogLevel.Warn:
break; b.DrawString(this.smallFont, text, new Vector2(16, y), Color.Orange);
break;
case ConsoleLogLevel.Info:
case ConsoleLogLevel.Success:
b.DrawString(this.smallFont, text, new Vector2(16, y), Color.AntiqueWhite);
break;
case ConsoleLogLevel.Debug:
case ConsoleLogLevel.Trace:
b.DrawString(this.smallFont, text, new Vector2(16, y), Color.LightGray);
break;
default:
b.DrawString(this.smallFont, text, new Vector2(16, y), Color.LightGray);
break;
}
}
} }
if (offset > this.MaxScrollBoxHeight) if (offset > this.MaxScrollBoxHeight)
{ {
break; break;

View File

@ -21,6 +21,7 @@ using File = Java.IO.File;
using Microsoft.AppCenter; using Microsoft.AppCenter;
using Newtonsoft.Json; using Newtonsoft.Json;
using Microsoft.AppCenter.Crashes; using Microsoft.AppCenter.Crashes;
using Android.Content;
namespace StardewModdingAPI namespace StardewModdingAPI
{ {
@ -178,7 +179,11 @@ namespace StardewModdingAPI
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults) public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
{ {
base.OnRequestPermissionsResult(requestCode, permissions, grantResults); try
{
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
catch (ActivityNotFoundException) { }
if (this.HasPermissions) if (this.HasPermissions)
this.OnCreatePartTwo(); this.OnCreatePartTwo();
} }