Make it bootable

This commit is contained in:
zhiyang7 2023-02-03 18:04:44 +08:00
parent 7c6fc4cd19
commit a797608622
7 changed files with 39 additions and 33 deletions

View File

@ -8,6 +8,6 @@
<!-- <BUILD_FOR_MOBILE>SAMSUNG</BUILD_FOR_MOBILE>--> <!-- <BUILD_FOR_MOBILE>SAMSUNG</BUILD_FOR_MOBILE>-->
<!-- <BUILD_FOR_MOBILE>GOOGLE_LEGACY</BUILD_FOR_MOBILE>--> <!-- <BUILD_FOR_MOBILE>GOOGLE_LEGACY</BUILD_FOR_MOBILE>-->
<COMPILE_WITH_PLUGIN>False</COMPILE_WITH_PLUGIN> <COMPILE_WITH_PLUGIN>False</COMPILE_WITH_PLUGIN>
<DefineConstants Condition="'$(BUILD_FOR_MOBILE)' == 'GOOGLE'">$(DefineConstants);SMAPI_FOR_MOBILE;ANDROID_TARGET_GOOGLE;MonoAndroid10</DefineConstants> <DefineConstants Condition="'$(BUILD_FOR_MOBILE)' == 'GOOGLE'">SMAPI_FOR_MOBILE;ANDROID_TARGET_GOOGLE;MonoAndroid10</DefineConstants>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View File

@ -34,23 +34,24 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime> <AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
<AndroidLinkMode>SdkOnly</AndroidLinkMode> <AndroidLinkMode>None</AndroidLinkMode>
<EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk> <EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
<AndroidManagedSymbols>false</AndroidManagedSymbols> <AndroidManagedSymbols>false</AndroidManagedSymbols>
<AndroidUseAapt2>true</AndroidUseAapt2> <AndroidUseAapt2>true</AndroidUseAapt2>
<AndroidSupportedAbis>armeabi-v7a;x86;arm64-v8a;x86_64</AndroidSupportedAbis> <AndroidSupportedAbis>armeabi-v7a;x86;arm64-v8a;x86_64</AndroidSupportedAbis>
<AndroidDexTool>d8</AndroidDexTool> <AndroidDexTool>d8</AndroidDexTool>
<AndroidLinkSkip>BmFont;MonoGame.Framework;mscorlib;System.Core;System;System.Drawing.Common;System.Numerics;System.Runtime.Serialization;System.Xml;System.Xml.Linq</AndroidLinkSkip> <!-- <AndroidLinkSkip>Mono.Android;MonoGame.Framework;mscorlib;System.Core;System;System.Drawing.Common;System.Numerics;System.Runtime.Serialization;System.Xml;System.Xml.Linq</AndroidLinkSkip>-->
<AndroidEnableMultiDex>true</AndroidEnableMultiDex>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>True</DebugSymbols> <DebugSymbols>False</DebugSymbols>
<DebugType>portable</DebugType> <DebugType>portable</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>bin\Release\</OutputPath> <OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<AndroidManagedSymbols>true</AndroidManagedSymbols> <AndroidManagedSymbols>false</AndroidManagedSymbols>
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime> <AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
<AndroidLinkMode>None</AndroidLinkMode> <AndroidLinkMode>None</AndroidLinkMode>
<EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk> <EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
@ -79,6 +80,8 @@
<AndroidResource Include="Resources\values\styles.xml" /> <AndroidResource Include="Resources\values\styles.xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Mono.Android" />
<Reference Include="Mono.Security" />
<ProjectReference Include="..\SMAPI\SMAPI.csproj" /> <ProjectReference Include="..\SMAPI\SMAPI.csproj" />
<Reference Include="StardewValley"> <Reference Include="StardewValley">
<HintPath>..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.31\assemblies\StardewValley.dll</HintPath> <HintPath>..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.31\assemblies\StardewValley.dll</HintPath>
@ -92,17 +95,12 @@
<Reference Include="BmFont"> <Reference Include="BmFont">
<HintPath>..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.31\assemblies\BmFont.dll</HintPath> <HintPath>..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.31\assemblies\BmFont.dll</HintPath>
</Reference> </Reference>
<!-- <PackageReference Include="MonoGame.Framework.Android">-->
<!-- <Version>3.6.0.862</Version>-->
<!-- </PackageReference>-->
<Reference Include="MonoGame.Framework"> <Reference Include="MonoGame.Framework">
<HintPath>..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.31\assemblies\MonoGame.Framework.dll</HintPath> <HintPath>..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.31\assemblies\MonoGame.Framework.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="Mono.Android" />
<Reference Include="Mono.Security" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<AndroidResource Include="Resources\mipmap\ic_launcher.png" /> <AndroidResource Include="Resources\mipmap\ic_launcher.png" />

View File

@ -1,7 +1,5 @@
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; 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 // set of attributes. Change these attribute values to modify the information

View File

@ -35,9 +35,9 @@ namespace StardewModdingAPI
*********/ *********/
#if SMAPI_FOR_MOBILE #if SMAPI_FOR_MOBILE
/// <summary>The path to the storage base folder.</summary> /// <summary>The path to the storage base folder.</summary>
public static string StorageBasePath { get; } = Android.OS.Environment.ExternalStorageDirectory.Path; public static string StorageBasePath { get; } = SMainActivity.Instance.GetExternalFilesDir("").AbsolutePath;
/// <summary>The path to the game's save folder.</summary> /// <summary>The path to the game's save folder.</summary>
public static string StardewValleyBasePath { get; } = Path.Combine(EarlyConstants.StorageBasePath, "StardewValley"); public static string StardewValleyBasePath { get; } = EarlyConstants.StorageBasePath;
/// <summary>The path to the internal folder.</summary> /// <summary>The path to the internal folder.</summary>
public static string ExecutionPath { get; } = Path.Combine(EarlyConstants.StardewValleyBasePath, "smapi-internal"); public static string ExecutionPath { get; } = Path.Combine(EarlyConstants.StardewValleyBasePath, "smapi-internal");

View File

@ -346,8 +346,10 @@ namespace StardewModdingAPI.Framework
{ {
this.IsGameRunning = true; this.IsGameRunning = true;
StardewValley.Program.releaseBuild = true; // game's debug logic interferes with SMAPI opening the game window StardewValley.Program.releaseBuild = true; // game's debug logic interferes with SMAPI opening the game window
#if !SMAPI_FOR_MOBILE
this.Game.Run(); this.Game.Run();
this.Dispose(isError: false); this.Dispose(isError: false);
#endif
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -20,7 +20,7 @@
<AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk> <AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v12.0</TargetFrameworkVersion> <TargetFrameworkVersion>v12.0</TargetFrameworkVersion>
<TargetFramework>net5.0-android</TargetFramework> <TargetFramework>net5.0-android</TargetFramework>
<AndroidUseAapt2>true</AndroidUseAapt2> <AndroidUseAapt2>false</AndroidUseAapt2>
<DefineConstants>$(DefineConstants)</DefineConstants> <DefineConstants>$(DefineConstants)</DefineConstants>
</PropertyGroup> </PropertyGroup>
@ -34,6 +34,8 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<AndroidSupportedAbis>armeabi-v7a;x86;arm64-v8a;x86_64</AndroidSupportedAbis> <AndroidSupportedAbis>armeabi-v7a;x86;arm64-v8a;x86_64</AndroidSupportedAbis>
<AndroidLinkMode>None</AndroidLinkMode>
<AndroidUseAapt2>true</AndroidUseAapt2>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU' AND '$(BUILD_FOR_MOBILE)' != ''"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU' AND '$(BUILD_FOR_MOBILE)' != ''">
@ -47,6 +49,7 @@
<AndroidSupportedAbis>armeabi-v7a;x86;arm64-v8a;x86_64</AndroidSupportedAbis> <AndroidSupportedAbis>armeabi-v7a;x86;arm64-v8a;x86_64</AndroidSupportedAbis>
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime> <AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
<AndroidLinkMode>None</AndroidLinkMode> <AndroidLinkMode>None</AndroidLinkMode>
<AndroidUseAapt2>true</AndroidUseAapt2>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(BUILD_FOR_MOBILE)' == ''"> <PropertyGroup Condition="'$(BUILD_FOR_MOBILE)' == ''">
@ -135,6 +138,7 @@
<Reference Include="mscorlib" /> <Reference Include="mscorlib" />
<Reference Include="Mono.Android" /> <Reference Include="Mono.Android" />
<Reference Include="Mono.Security" />
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />

View File

@ -21,12 +21,13 @@ using Android.Util;
using Java.Lang; using Java.Lang;
using Java.Util; using Java.Util;
using Exception = System.Exception; using Exception = System.Exception;
using Object = Java.Lang.Object;
using Thread = System.Threading.Thread; using Thread = System.Threading.Thread;
namespace StardewModdingAPI 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))] [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; internal SCore core;
@ -108,16 +109,22 @@ namespace StardewModdingAPI
{ {
Looper.Prepare(); Looper.Prepare();
} }
catch (Exception) { } catch (Exception)
{
}
Looper.Loop(); Looper.Loop();
} }
catch (Exception) { } catch (Exception)
{
}
} }
} }
catch catch
{ {
// ignored // ignored
} }
base.OnCreate(bundle); base.OnCreate(bundle);
this.CheckAppPermissions(); this.CheckAppPermissions();
} }
@ -126,7 +133,7 @@ namespace StardewModdingAPI
{ {
try 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) if (game1 != null)
{ {
// game1.Exit(); // game1.Exit();
@ -146,16 +153,17 @@ namespace StardewModdingAPI
if (string.IsNullOrWhiteSpace(modPath)) 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(); 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<object>());
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.SetContentView((View)this.core.Game.Services.GetService(typeof(View)));
this.core.Game.Run();
this.CheckUsingServerManagedPolicy();
} }
catch when (retry < 3) catch when (retry < 3)
{ {
@ -170,10 +178,7 @@ namespace StardewModdingAPI
catch (Exception ex) catch (Exception ex)
{ {
SAlertDialogUtil.AlertMessage($"SMAPI failed to initialize: {ex}", SAlertDialogUtil.AlertMessage($"SMAPI failed to initialize: {ex}",
callback: type => callback: type => { this.Finish(); });
{
this.Finish();
});
} }
} }
@ -208,7 +213,6 @@ namespace StardewModdingAPI
private void CheckUsingServerManagedPolicy() private void CheckUsingServerManagedPolicy()
{ {
} }
} }
} }
#endif #endif