From e511ad28a8a1123a0bcfd2dd24758751a1e74bc0 Mon Sep 17 00:00:00 2001 From: yangzhi <@4F!xZpJwly&KbWq> Date: Mon, 27 May 2019 14:18:32 +0800 Subject: [PATCH] Modloader 1.4.2 1.CustomAttribute rewrite support 2.Update MonoMod to latest code 3.UI change --- ModLoader/Activity1.cs | 393 ++++++++--- ModLoader/Common/MethodPatcher.cs | 27 + ModLoader/Common/ModInfo.cs | 5 +- ModLoader/Common/ModListAdapter.cs | 31 + ModLoader/Common/Utils.cs | 63 ++ ModLoader/Common/ZipHelper.cs | 42 +- ModLoader/Harmony/PatchProcessor.cs | 7 +- ModLoader/ModLoader.csproj | 20 +- ModLoader/MonoMod/RuntimeDetour/Detour.cs | 3 + .../MonoMod/RuntimeDetour/DetourHelper.cs | 37 +- .../RuntimeDetour/HarmonyDetourBridge.cs | 107 ++- .../RuntimeDetour/IDetourNativePlatform.cs | 5 +- .../MonoMod/RuntimeDetour/NativeDetour.cs | 1 + .../Native/DetourNativeARMPlatform.cs | 79 ++- .../Native/DetourNativeMonoPlatform.cs | 17 +- .../Native/DetourNativeMonoPosixPlatform.cs | 15 +- .../Native/DetourNativeWindowsPlatform.cs | 23 +- .../Native/DetourNativeX86Platform.cs | 10 +- .../Runtime/DetourRuntimeILPlatform.cs | 1 + .../MonoMod/Utils/Cil/ILPatternMatchingExt.cs | 57 +- .../Utils/DynamicMethodDefinition.Cecil.cs | 22 +- ModLoader/MonoMod/Utils/ReflectionHelper.cs | 69 +- .../Utils/UtilsCil/CecilILGenerator.cs | 2 +- .../Utils/UtilsCil/ILGeneratorShim.Proxy.cs | 27 +- ModLoader/Properties/AndroidManifest.xml | 5 +- .../Resources/Drawable/splash_logos_crop.png | Bin 0 -> 14620 bytes .../Resources/Drawable/splash_screen.xml | 9 + .../Resources/Layout/layout_mod_list.axml | 24 +- ModLoader/Resources/Raw/SMDroidFiles.zip | Bin 619307 -> 787864 bytes ModLoader/Resources/Resource.Designer.cs | 642 +++++++++--------- ModLoader/Resources/Values-zh-rCN/Strings.xml | 7 +- ModLoader/Resources/Values/Strings.xml | 3 + ModLoader/Resources/Values/Styles.xml | 3 +- ModLoader/Resources/Xml/file_paths.xml | 4 - ModLoader/SMAPI/Constants.cs | 1 + .../ContentManagers/GameContentManager.cs | 60 -- .../Framework/ModLoading/AssemblyLoader.cs | 41 ++ .../Rewriters/TypeFieldToTypeFieldRewriter.cs | 78 +++ ModLoader/SMAPI/Framework/SCore.cs | 16 +- ModLoader/SMAPI/Framework/SGame.cs | 23 +- ModLoader/SMAPI/Patches/DialogueErrorPatch.cs | 5 +- ModLoader/SMAPI/Patches/EventErrorPatch.cs | 85 +++ ModLoader/SMAPI/Patches/LoadContextPatch.cs | 88 +++ .../SMAPI/Patches/LoadForNewGamePatch.cs | 114 ---- ModLoader/SMAPI/Patches/ObjectErrorPatch.cs | 23 +- ModLoader/SMDroidFiles.zip | Bin 619307 -> 787864 bytes ModLoader/SMainActivity.cs | 38 +- 47 files changed, 1520 insertions(+), 812 deletions(-) create mode 100644 ModLoader/Resources/Drawable/splash_logos_crop.png create mode 100644 ModLoader/Resources/Drawable/splash_screen.xml delete mode 100644 ModLoader/Resources/Xml/file_paths.xml create mode 100644 ModLoader/SMAPI/Framework/ModLoading/Rewriters/TypeFieldToTypeFieldRewriter.cs create mode 100644 ModLoader/SMAPI/Patches/EventErrorPatch.cs create mode 100644 ModLoader/SMAPI/Patches/LoadContextPatch.cs delete mode 100644 ModLoader/SMAPI/Patches/LoadForNewGamePatch.cs diff --git a/ModLoader/Activity1.cs b/ModLoader/Activity1.cs index 92f09d81..edb54b31 100644 --- a/ModLoader/Activity1.cs +++ b/ModLoader/Activity1.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using System.Net.Http; @@ -9,10 +10,12 @@ using Android.Content; using Android.Content.PM; using Android.OS; using Android.Support.V4.App; +using Android.Support.V4.Content; using Android.Views; using Android.Widget; using Com.Pgyersdk.Update; using DllRewrite; +using Java.Lang; using Microsoft.AppCenter; using Microsoft.AppCenter.Analytics; using Microsoft.AppCenter.Crashes; @@ -25,7 +28,11 @@ using StardewModdingAPI.Framework.ModLoading; using StardewModdingAPI.Toolkit; using StardewModdingAPI.Toolkit.Framework.ModData; using StardewModdingAPI.Toolkit.Serialisation; +using static ModLoader.Common.Utils; +using Exception = System.Exception; using File = Java.IO.File; +using Object = System.Object; +using Thread = System.Threading.Thread; using Uri = Android.Net.Uri; namespace ModLoader @@ -36,40 +43,94 @@ namespace ModLoader , Theme = "@style/Theme.Splash" , AlwaysRetainTaskState = true , LaunchMode = LaunchMode.SingleInstance - , ScreenOrientation = ScreenOrientation.SensorLandscape , ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.Keyboard | ConfigChanges.KeyboardHidden | ConfigChanges.ScreenSize | ConfigChanges.ScreenLayout)] + [SuppressMessage("ReSharper", "ArrangeThisQualifier")] public class Activity1 : AndroidGameActivity { private string[] requiredPermissions => new[] { "android.permission.ACCESS_NETWORK_STATE", "android.permission.ACCESS_WIFI_STATE", "android.permission.INTERNET", "android.permission.READ_EXTERNAL_STORAGE", "android.permission.VIBRATE", "android.permission.WAKE_LOCK", "android.permission.WRITE_EXTERNAL_STORAGE", "com.android.vending.CHECK_LICENSE" }; - private string[] deniedPermissionsArray + private string[] DeniedPermissionsArray { get { List list = new List(); - string[] requiredPermissions = this.requiredPermissions; - for (int i = 0; i < requiredPermissions.Length; i++) + foreach (string permission in this.requiredPermissions) { - if (this.PackageManager.CheckPermission(requiredPermissions[i], this.PackageName) != Permission.Granted) + if (this.PackageManager.CheckPermission(permission, this.PackageName) != Permission.Granted) { - list.Add(requiredPermissions[i]); + list.Add(permission); } } return list.ToArray(); } } - public bool HasPermissions => ((((this.PackageManager.CheckPermission("android.permission.ACCESS_NETWORK_STATE", this.PackageName) == Permission.Granted) && (this.PackageManager.CheckPermission("android.permission.ACCESS_WIFI_STATE", this.PackageName) == Permission.Granted)) && ((this.PackageManager.CheckPermission("android.permission.INTERNET", this.PackageName) == Permission.Granted) && (this.PackageManager.CheckPermission("android.permission.READ_EXTERNAL_STORAGE", this.PackageName) == Permission.Granted))) && (((this.PackageManager.CheckPermission("android.permission.VIBRATE", this.PackageName) == Permission.Granted) && (this.PackageManager.CheckPermission("android.permission.WAKE_LOCK", this.PackageName) == Permission.Granted)) && ((this.PackageManager.CheckPermission("android.permission.WRITE_EXTERNAL_STORAGE", this.PackageName) == Permission.Granted) && (this.PackageManager.CheckPermission("com.android.vending.CHECK_LICENSE", this.PackageName) == Permission.Granted)))); + public bool HasPermissions => this.PackageManager.CheckPermission("android.permission.ACCESS_NETWORK_STATE", this.PackageName) == Permission.Granted && this.PackageManager.CheckPermission("android.permission.ACCESS_WIFI_STATE", this.PackageName) == Permission.Granted && this.PackageManager.CheckPermission("android.permission.INTERNET", this.PackageName) == Permission.Granted && this.PackageManager.CheckPermission("android.permission.READ_EXTERNAL_STORAGE", this.PackageName) == Permission.Granted && this.PackageManager.CheckPermission("android.permission.VIBRATE", this.PackageName) == Permission.Granted && this.PackageManager.CheckPermission("android.permission.WAKE_LOCK", this.PackageName) == Permission.Granted && this.PackageManager.CheckPermission("android.permission.WRITE_EXTERNAL_STORAGE", this.PackageName) == Permission.Granted && this.PackageManager.CheckPermission("com.android.vending.CHECK_LICENSE", this.PackageName) == Permission.Granted; public void PromptForPermissions() { - ActivityCompat.RequestPermissions(this, this.deniedPermissionsArray, 0); + ActivityCompat.RequestPermissions(this, this.DeniedPermissionsArray, 0); } + public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Android.Content.PM.Permission[] grantResults) + { + if (permissions.Length == 0) + { + } + else + { + string languageCode = Java.Util.Locale.Default.Language.Substring(0, 2); + int num = 0; + if (requestCode == 0) + { + for (int index = 0; index < grantResults.Length; ++index) + { + if (grantResults[index] == Android.Content.PM.Permission.Granted) + ++num; + else if (grantResults[index] == Android.Content.PM.Permission.Denied) + { + try + { + AlertDialog.Builder builder = new AlertDialog.Builder((Context)this); + if (ActivityCompat.ShouldShowRequestPermissionRationale((Activity)this, permissions[index])) + { + builder.SetMessage(this.PermissionMessageA(languageCode)); + builder.SetPositiveButton(this.GetOKString(languageCode), (EventHandler)((senderAlert, args) => + { + this.PromptForPermissions(); + })); + } + else + { + builder.SetMessage(this.PermissionMessageB(languageCode)); + builder.SetPositiveButton(this.GetOKString(languageCode), (EventHandler)((senderAlert, args) => OpenAppSettingsOnPhone(this))); + } + Dialog dialog = (Dialog)builder.Create(); + if (this.IsFinishing) + return; + dialog.Show(); + return; + } + catch (IllegalArgumentException ex) + { + // ISSUE: variable of the null type + Microsoft.AppCenter.Crashes.Crashes.TrackError((System.Exception)ex, null); + OpenInPlayStore(); + this.Finish(); + return; + } + } + } + } + if (num != permissions.Length) + return; + this.OnCreatePartTwo(); + } + } private readonly Mutex _working = new Mutex(false); public static Activity1 Instance { get; private set; } - private HttpClient _httpClient = new HttpClient(); + private readonly HttpClient _httpClient = new HttpClient(); - private static Dictionary MessageHandler = new Dictionary(); + private static readonly Dictionary MessageHandler = new Dictionary(); private readonly Handler _handler = new Handler(message => { if (MessageHandler.ContainsKey(message.What)) @@ -102,12 +163,19 @@ namespace ModLoader this.SetContentView(Resource.Layout.layout_main); if (!this.HasPermissions) this.PromptForPermissions(); - while (!this.HasPermissions) - { - Thread.Sleep(50); - } - new PgyUpdateManager.Builder().SetForced(false).SetUserCanRetry(true).SetDeleteHistroyApk(true).Register(); + else + this.OnCreatePartTwo(); + } + private void OnCreatePartTwo() + { + if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.N) + { + StrictMode.SetVmPolicy(new StrictMode.VmPolicy.Builder().Build()); + } + + new PgyUpdateManager.Builder().SetForced(false).SetUserCanRetry(true).SetDeleteHistroyApk(true).Register(); + this.InitEnvironment(); this.FindViewById