android branch 2.11.2 Upgrade

This commit is contained in:
Chris 2019-05-24 03:21:08 -04:00
parent e22a542121
commit 0de5f433d1
9 changed files with 123 additions and 13 deletions

View File

@ -38,6 +38,9 @@ namespace StardewModdingAPI.Framework.ContentManagers
/// <summary>The language enum values indexed by locale code.</summary>
protected IDictionary<string, LanguageCode> LanguageCodes { get; }
/// <summary>Reflector.</summary>
protected readonly Reflector Reflector;
/*********
** Accessors
@ -77,6 +80,7 @@ namespace StardewModdingAPI.Framework.ContentManagers
this.Cache = new ContentCache(this, reflection);
this.Monitor = monitor ?? throw new ArgumentNullException(nameof(monitor));
this.OnDisposing = onDisposing;
this.Reflector = reflection;
this.IsModContentManager = isModFolder;
// get asset data

View File

@ -7,6 +7,9 @@ using StardewModdingAPI.Framework.Exceptions;
using StardewModdingAPI.Framework.Reflection;
using StardewModdingAPI.Toolkit.Serialisation;
using StardewValley;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.Xna.Framework.Content;
namespace StardewModdingAPI.Framework.ContentManagers
{
@ -105,7 +108,7 @@ namespace StardewModdingAPI.Framework.ContentManagers
{
// XNB file
case ".xnb":
return base.Load<T>(relativePath, language);
return this.ModedLoad<T>(relativePath, language);
// unpacked data
case ".json":
@ -186,5 +189,97 @@ namespace StardewModdingAPI.Framework.ContentManagers
texture.SetData(data);
return texture;
}
public T ModedLoad<T>(string assetName, LanguageCode language)
{
if (language != LanguageCode.en)
{
string key = assetName + "." + this.LanguageCodeString(language);
Dictionary<string, bool> _localizedAsset = this.Reflector.GetField<Dictionary<string, bool>>(this, "_localizedAsset").GetValue();
if (!_localizedAsset.TryGetValue(key, out bool flag) | flag)
{
try
{
_localizedAsset[key] = true;
return this.ModedLoad<T>(key);
}
catch (ContentLoadException)
{
_localizedAsset[key] = false;
}
}
}
return this.ModedLoad<T>(assetName);
}
public T ModedLoad<T>(string assetName)
{
if (string.IsNullOrEmpty(assetName))
{
throw new ArgumentNullException("assetName");
}
T local = default(T);
string key = assetName.Replace('\\', '/');
Dictionary<string, object> loadedAssets = this.Reflector.GetField<Dictionary<string, object>>(this, "loadedAssets").GetValue();
if (loadedAssets.TryGetValue(key, out object obj2) && (obj2 is T))
{
return (T)obj2;
}
local = this.ReadAsset<T>(assetName, null);
loadedAssets[key] = local;
return local;
}
protected override Stream OpenStream(string assetName)
{
Stream stream;
try
{
stream = new FileStream(Path.Combine(this.RootDirectory, assetName) + ".xnb", FileMode.Open, FileAccess.Read);
MemoryStream destination = new MemoryStream();
stream.CopyTo(destination);
destination.Seek(0L, SeekOrigin.Begin);
stream.Close();
stream = destination;
}
catch (Exception exception3)
{
throw new ContentLoadException("Opening stream error.", exception3);
}
return stream;
}
protected new T ReadAsset<T>(string assetName, Action<IDisposable> recordDisposableObject)
{
if (string.IsNullOrEmpty(assetName))
{
throw new ArgumentNullException("assetName");
}
;
string str = assetName;
object obj2 = null;
if (this.Reflector.GetField<IGraphicsDeviceService>(this, "graphicsDeviceService").GetValue() == null)
{
this.Reflector.GetField<IGraphicsDeviceService>(this, "graphicsDeviceService").SetValue(this.ServiceProvider.GetService(typeof(IGraphicsDeviceService)) as IGraphicsDeviceService);
}
Stream input = this.OpenStream(assetName);
using (BinaryReader reader = new BinaryReader(input))
{
using (ContentReader reader2 = this.Reflector.GetMethod(this, "GetContentReaderFromXnb").Invoke<ContentReader>(assetName, input, reader, recordDisposableObject))
{
MethodInfo method = reader2.GetType().GetMethod("ReadAsset", BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.NonPublic, null, new Type[] { }, new ParameterModifier[] { });
obj2 = method.MakeGenericMethod(new Type[] { typeof(T) }).Invoke(reader2, null);
if (obj2 is GraphicsResource graphics)
{
graphics.Name = str;
}
}
}
if (obj2 == null)
{
throw new Exception("Could not load " + str + " asset!");
}
return (T)obj2;
}
}
}

View File

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using Mono.Cecil;
@ -12,7 +13,6 @@ namespace StardewModdingAPI.Framework.ModLoading
/// <summary>The known assemblies.</summary>
private readonly IDictionary<string, AssemblyDefinition> Lookup = new Dictionary<string, AssemblyDefinition>();
/*********
** Public methods
*********/
@ -31,6 +31,7 @@ namespace StardewModdingAPI.Framework.ModLoading
/// <summary>Resolve an assembly reference.</summary>
/// <param name="name">The assembly name.</param>
public override AssemblyDefinition Resolve(AssemblyNameReference name) => this.ResolveName(name.Name) ?? base.Resolve(name);
/// <summary>Resolve an assembly reference.</summary>
/// <param name="name">The assembly name.</param>

View File

@ -281,7 +281,7 @@ namespace StardewModdingAPI.Framework.ModLoading
// find (and optionally rewrite) incompatible instructions
bool anyRewritten = false;
IInstructionHandler[] handlers = new InstructionMetadata().GetHandlers(this.ParanoidMode).ToArray();
IInstructionHandler[] handlers = new InstructionMetadata().GetHandlers(this.ParanoidMode, this.Monitor).ToArray();
foreach (MethodDefinition method in this.GetMethods(module))
{
// check method definition

View File

@ -78,7 +78,7 @@ namespace StardewModdingAPI.Framework.ModLoading
/// <summary>Get whether a method definition matches the signature expected by a method reference.</summary>
/// <param name="definition">The method definition.</param>
/// <param name="reference">The method reference.</param>
public static bool HasMatchingSignature(MethodInfo definition, MethodReference reference)
public static bool HasMatchingSignature(MethodBase definition, MethodReference reference)
{
// same name
if (definition.Name != reference.Name)
@ -103,8 +103,12 @@ namespace StardewModdingAPI.Framework.ModLoading
public static bool HasMatchingSignature(Type type, MethodReference reference)
{
return type
.GetMethods(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public)
.Any(method => RewriteHelper.HasMatchingSignature(method, reference));
.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.Public)
.Any(method => RewriteHelper.HasMatchingSignature(method, reference))
||
type
.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)
.Any(method => RewriteHelper.HasMatchingSignature(method, reference));
}
}
}

View File

@ -17,7 +17,6 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters
/// <summary>The property name.</summary>
private readonly string PropertyName;
/*********
** Public methods
*********/

View File

@ -1,5 +1,6 @@
using System;
using Harmony;
using MonoMod.RuntimeDetour;
namespace StardewModdingAPI.Framework.Patching
{
@ -27,6 +28,8 @@ namespace StardewModdingAPI.Framework.Patching
/// <param name="patches">The patches to apply.</param>
public void Apply(params IHarmonyPatch[] patches)
{
HarmonyDetourBridge.Init();
HarmonyInstance harmony = HarmonyInstance.Create("io.smapi");
foreach (IHarmonyPatch patch in patches)
{

View File

@ -20,7 +20,7 @@ namespace StardewModdingAPI
/// <summary>The absolute path to search for SMAPI's internal DLLs.</summary>
/// <remarks>We can't use <see cref="Constants.ExecutionPath"/> directly, since <see cref="Constants"/> depends on DLLs loaded from this folder.</remarks>
[SuppressMessage("ReSharper", "AssignNullToNotNullAttribute", Justification = "The assembly location is never null in this context.")]
internal static readonly string DllSearchPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "smapi-internal");
internal static readonly string DllSearchPath = Path.Combine(Android.OS.Environment.ExternalStorageDirectory.Path, "StardewValley/smapi-internal");
/*********
@ -31,9 +31,9 @@ namespace StardewModdingAPI
public static void Main(string[] args)
{
AppDomain.CurrentDomain.AssemblyResolve += Program.CurrentDomain_AssemblyResolve;
Program.AssertGamePresent();
Program.AssertGameVersion();
Program.Start(args);
//Program.AssertGamePresent();
//Program.AssertGameVersion();
//Program.Start(args);
}
@ -51,13 +51,16 @@ namespace StardewModdingAPI
foreach (FileInfo dll in new DirectoryInfo(Program.DllSearchPath).EnumerateFiles("*.dll"))
{
if (name.Name.Equals(AssemblyName.GetAssemblyName(dll.FullName).Name, StringComparison.InvariantCultureIgnoreCase))
{
Android.Util.Log.Error("Program", $"Resolving assembly: {dll.FullName}");
return Assembly.LoadFrom(dll.FullName);
}
}
return null;
}
catch (Exception ex)
{
Console.WriteLine($"Error resolving assembly: {ex}");
return null;
}
}

View File

@ -586,7 +586,8 @@ namespace StardewModdingAPI
Z = Keys.Z,
/// <summary>The Zoom button on a keyboard.</summary>
Zoom = Keys.Zoom
Zoom = Keys.Zoom,
}
/// <summary>Provides extension methods for <see cref="SButton"/>.</summary>