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>GOOGLE_LEGACY</BUILD_FOR_MOBILE>-->
<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>
</Project>

View File

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

View File

@ -1,7 +1,5 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Android.App;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information

View File

@ -35,9 +35,9 @@ namespace StardewModdingAPI
*********/
#if SMAPI_FOR_MOBILE
/// <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>
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>
public static string ExecutionPath { get; } = Path.Combine(EarlyConstants.StardewValleyBasePath, "smapi-internal");

View File

@ -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)
{

View File

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

View File

@ -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<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.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