From a797608622bfa3e74d4908005a516bedfd7bac38 Mon Sep 17 00:00:00 2001 From: zhiyang7 Date: Fri, 3 Feb 2023 18:04:44 +0800 Subject: [PATCH] Make it bootable --- build/define-constant.targets | 2 +- src/Loader/Loader.csproj | 16 ++++++------- src/Loader/Properties/AssemblyInfo.cs | 8 +++---- src/SMAPI/Constants.cs | 4 ++-- src/SMAPI/Framework/SCore.cs | 2 ++ src/SMAPI/SMAPI.csproj | 6 ++++- src/SMAPI/SMainActivity.cs | 34 +++++++++++++++------------ 7 files changed, 39 insertions(+), 33 deletions(-) diff --git a/build/define-constant.targets b/build/define-constant.targets index 9bf5fc32..aa790ea9 100644 --- a/build/define-constant.targets +++ b/build/define-constant.targets @@ -8,6 +8,6 @@ False - $(DefineConstants);SMAPI_FOR_MOBILE;ANDROID_TARGET_GOOGLE;MonoAndroid10 + SMAPI_FOR_MOBILE;ANDROID_TARGET_GOOGLE;MonoAndroid10 diff --git a/src/Loader/Loader.csproj b/src/Loader/Loader.csproj index b3a1c551..7c8ab3f5 100644 --- a/src/Loader/Loader.csproj +++ b/src/Loader/Loader.csproj @@ -34,23 +34,24 @@ prompt 4 false - SdkOnly + None True false true armeabi-v7a;x86;arm64-v8a;x86_64 d8 - BmFont;MonoGame.Framework;mscorlib;System.Core;System;System.Drawing.Common;System.Numerics;System.Runtime.Serialization;System.Xml;System.Xml.Linq + + true - True + False portable false bin\Release\ TRACE prompt 4 - true + false false None True @@ -79,6 +80,8 @@ + + ..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.31\assemblies\StardewValley.dll @@ -92,17 +95,12 @@ ..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.31\assemblies\BmFont.dll - - - ..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.31\assemblies\MonoGame.Framework.dll - - diff --git a/src/Loader/Properties/AssemblyInfo.cs b/src/Loader/Properties/AssemblyInfo.cs index 41da4302..7349df30 100644 --- a/src/Loader/Properties/AssemblyInfo.cs +++ b/src/Loader/Properties/AssemblyInfo.cs @@ -1,9 +1,7 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using Android.App; -// General Information about an assembly is controlled through the following +// General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Loader")] @@ -19,11 +17,11 @@ using Android.App; // Version information for an assembly consists of the following four values: // // Major Version -// Minor Version +// Minor Version // Build Number // Revision // -// You can specify all the values or you can default the Build and Revision Numbers +// You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] diff --git a/src/SMAPI/Constants.cs b/src/SMAPI/Constants.cs index d8ad4e2d..387f898f 100644 --- a/src/SMAPI/Constants.cs +++ b/src/SMAPI/Constants.cs @@ -35,9 +35,9 @@ namespace StardewModdingAPI *********/ #if SMAPI_FOR_MOBILE /// The path to the storage base folder. - public static string StorageBasePath { get; } = Android.OS.Environment.ExternalStorageDirectory.Path; + public static string StorageBasePath { get; } = SMainActivity.Instance.GetExternalFilesDir("").AbsolutePath; /// The path to the game's save folder. - public static string StardewValleyBasePath { get; } = Path.Combine(EarlyConstants.StorageBasePath, "StardewValley"); + public static string StardewValleyBasePath { get; } = EarlyConstants.StorageBasePath; /// The path to the internal folder. public static string ExecutionPath { get; } = Path.Combine(EarlyConstants.StardewValleyBasePath, "smapi-internal"); diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index a05beb52..66bcdaa2 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -346,8 +346,10 @@ namespace StardewModdingAPI.Framework { this.IsGameRunning = true; StardewValley.Program.releaseBuild = true; // game's debug logic interferes with SMAPI opening the game window +#if !SMAPI_FOR_MOBILE this.Game.Run(); this.Dispose(isError: false); +#endif } catch (Exception ex) { diff --git a/src/SMAPI/SMAPI.csproj b/src/SMAPI/SMAPI.csproj index 5320ca69..311376d5 100644 --- a/src/SMAPI/SMAPI.csproj +++ b/src/SMAPI/SMAPI.csproj @@ -20,7 +20,7 @@ false v12.0 net5.0-android - true + false $(DefineConstants) @@ -34,6 +34,8 @@ 4 latest armeabi-v7a;x86;arm64-v8a;x86_64 + None + true @@ -47,6 +49,7 @@ armeabi-v7a;x86;arm64-v8a;x86_64 false None + true @@ -135,6 +138,7 @@ + diff --git a/src/SMAPI/SMainActivity.cs b/src/SMAPI/SMainActivity.cs index 7c94fae2..63a13e09 100644 --- a/src/SMAPI/SMainActivity.cs +++ b/src/SMAPI/SMainActivity.cs @@ -21,12 +21,13 @@ using Android.Util; using Java.Lang; using Java.Util; using Exception = System.Exception; +using Object = Java.Lang.Object; using Thread = System.Threading.Thread; namespace StardewModdingAPI { [Activity(Label = "SMAPI Stardew Valley", Icon = "@mipmap/ic_launcher", Theme = "@style/Theme.Splash", MainLauncher = true, AlwaysRetainTaskState = true, LaunchMode = LaunchMode.SingleInstance, ScreenOrientation = ScreenOrientation.SensorLandscape, ConfigurationChanges = (ConfigChanges.Keyboard | ConfigChanges.KeyboardHidden | ConfigChanges.Orientation | ConfigChanges.ScreenLayout | ConfigChanges.ScreenSize | ConfigChanges.UiMode))] - public class SMainActivity: MainActivity + public class SMainActivity : MainActivity { internal SCore core; @@ -108,16 +109,22 @@ namespace StardewModdingAPI { Looper.Prepare(); } - catch (Exception) { } + catch (Exception) + { + } + Looper.Loop(); } - catch (Exception) { } + catch (Exception) + { + } } } catch { // ignored } + base.OnCreate(bundle); this.CheckAppPermissions(); } @@ -126,7 +133,7 @@ namespace StardewModdingAPI { try { - Game1 game1 = (Game1) typeof(MainActivity).GetField("_game1", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(this); + Game1 game1 = (Game1)typeof(MainActivity).GetField("_game1", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(this); if (game1 != null) { // game1.Exit(); @@ -146,16 +153,17 @@ namespace StardewModdingAPI if (string.IsNullOrWhiteSpace(modPath)) { - modPath = "StardewValley/Mods"; + modPath = "Mods"; } - this.core = new SCore(System.IO.Path.Combine(EarlyConstants.StorageBasePath, modPath), false, false); + this.core = new SCore(System.IO.Path.Combine(EarlyConstants.StardewValleyBasePath, modPath), false, false); this.core.RunInteractively(); - typeof(MainActivity).GetField("_game1", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(this, this.core.Game); + typeof(MainActivity).GetMethod("SetZoomScaleAndMenuButtonScale", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(this, Array.Empty()); + this.SetPaddingForMenus(); + typeof(MainActivity).GetField("_game1", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(this, this.core.Game.gamePtr); - this.SetContentView((View) this.core.Game.Services.GetService(typeof(View))); - - this.CheckUsingServerManagedPolicy(); + this.SetContentView((View)this.core.Game.Services.GetService(typeof(View))); + this.core.Game.Run(); } catch when (retry < 3) { @@ -170,10 +178,7 @@ namespace StardewModdingAPI catch (Exception ex) { SAlertDialogUtil.AlertMessage($"SMAPI failed to initialize: {ex}", - callback: type => - { - this.Finish(); - }); + callback: type => { this.Finish(); }); } } @@ -208,7 +213,6 @@ namespace StardewModdingAPI private void CheckUsingServerManagedPolicy() { } - } } #endif