2019-05-13 22:33:45 +08:00
|
|
|
using System;
|
2019-05-27 14:18:32 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2019-05-13 22:33:45 +08:00
|
|
|
using System.Reflection;
|
2019-05-27 14:18:32 +08:00
|
|
|
using System.Threading.Tasks;
|
2019-05-13 22:33:45 +08:00
|
|
|
using Android.App;
|
2019-05-27 14:18:32 +08:00
|
|
|
using Android.Content;
|
2019-05-13 22:33:45 +08:00
|
|
|
using Android.Content.PM;
|
|
|
|
using Android.OS;
|
2019-05-16 18:02:59 +08:00
|
|
|
using Android.Provider;
|
2019-05-13 22:33:45 +08:00
|
|
|
using Android.Views;
|
2019-05-16 18:02:59 +08:00
|
|
|
using Google.Android.Vending.Licensing;
|
2019-05-27 14:18:32 +08:00
|
|
|
using ModLoader.Common;
|
2019-05-13 22:33:45 +08:00
|
|
|
using StardewModdingAPI;
|
|
|
|
using StardewModdingAPI.Framework;
|
|
|
|
using StardewValley;
|
|
|
|
using Constants = ModLoader.Common.Constants;
|
|
|
|
|
|
|
|
namespace ModLoader
|
|
|
|
{
|
|
|
|
[Activity(Label = "Stardew Valley", Icon = "@drawable/icon", Theme = "@style/Theme.Splash", MainLauncher = false, AlwaysRetainTaskState = true, LaunchMode = LaunchMode.SingleInstance, ScreenOrientation = ScreenOrientation.SensorLandscape, ConfigurationChanges = (ConfigChanges.Keyboard | ConfigChanges.KeyboardHidden | ConfigChanges.Orientation | ConfigChanges.ScreenLayout | ConfigChanges.ScreenSize | ConfigChanges.UiMode))]
|
2019-05-27 14:18:32 +08:00
|
|
|
[SuppressMessage("ReSharper", "ArrangeThisQualifier")]
|
|
|
|
public class SMainActivity : MainActivity, ILicenseCheckerCallback
|
2019-05-13 22:33:45 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
protected override void OnCreate(Bundle bundle)
|
|
|
|
{
|
|
|
|
instance = this;
|
|
|
|
base.RequestWindowFeature(WindowFeatures.NoTitle);
|
|
|
|
if (Build.VERSION.SdkInt >= BuildVersionCodes.P)
|
|
|
|
{
|
|
|
|
this.Window.Attributes.LayoutInDisplayCutoutMode = LayoutInDisplayCutoutMode.ShortEdges;
|
|
|
|
}
|
|
|
|
this.Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen);
|
|
|
|
this.Window.SetFlags(WindowManagerFlags.KeepScreenOn, WindowManagerFlags.KeepScreenOn);
|
|
|
|
PowerManager.WakeLock wakeLock = ((PowerManager)this.GetSystemService("power")).NewWakeLock(WakeLockFlags.Full, "StardewWakeLock");
|
|
|
|
wakeLock.Acquire();
|
|
|
|
typeof(MainActivity).GetField("_wakeLock", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(this, wakeLock);
|
|
|
|
base.OnCreate(bundle);
|
|
|
|
this.OnCreatePartTwo();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnCreatePartTwo()
|
|
|
|
{
|
|
|
|
typeof(MainActivity).GetMethod("SetZoomScaleAndMenuButtonScale", BindingFlags.Instance | BindingFlags.NonPublic)?.Invoke(this, null);
|
|
|
|
typeof(MainActivity).GetMethod("SetSavesPath", BindingFlags.Instance | BindingFlags.NonPublic)?.Invoke(this, null);
|
|
|
|
this.SetPaddingForMenus();
|
|
|
|
new GameConsole();
|
|
|
|
SCore core = new SCore(Constants.ModPath, false);
|
2019-05-27 14:18:32 +08:00
|
|
|
if (Build.VERSION.SdkInt <= BuildVersionCodes.LollipopMr1)
|
|
|
|
{
|
|
|
|
core.HarmonyDetourBridgeFailed = true;
|
|
|
|
}
|
2019-05-13 22:33:45 +08:00
|
|
|
core.RunInteractively();
|
|
|
|
Game1 game1 = StardewValley.Program.gamePtr;
|
|
|
|
typeof(MainActivity).GetField("_game1", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(this, game1);
|
|
|
|
this.SetContentView((View)game1.Services.GetService(typeof(View)));
|
2019-05-16 18:02:59 +08:00
|
|
|
this.CheckUsingServerManagedPolicy();
|
|
|
|
}
|
|
|
|
private void CheckUsingServerManagedPolicy()
|
|
|
|
{
|
|
|
|
string packageName = Constants.GamePackageName;
|
|
|
|
string deviceId = Settings.Secure.GetString(this.ContentResolver, "android_id");
|
|
|
|
AESObfuscator obfuscator = new AESObfuscator(new byte[] { 0x2e, 0x41, 30, 0x80, 0x67, 0x39, 0x4a, 0x40, 0x33, 0x58, 0x5f, 0x2d, 0x4d, 0x75, 0x24 }, packageName, deviceId);
|
|
|
|
ServerManagedPolicy policy = new ServerManagedPolicy(this, obfuscator);
|
|
|
|
LicenseChecker licenseChecker = new LicenseChecker(this, policy, "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAry4fecehDpCohQk4XhiIZX9ylIGUThWZxfN9qwvQyTh53hvnpQl/lCrjfflKoPz6gz5jJn6JI1PTnoBy/iXVx1+kbO99qBgJE2V8PS5pq+Usbeqqmqqzx4lEzhiYQ2um92v4qkldNYZFwbTODYPIMbSbaLm7eK9ZyemaRbg9ssAl4QYs0EVxzDK1DjuXilRk28WxiK3lNJTz4cT38bfs4q6Zvuk1vWUvnMqcxiugox6c/9j4zZS5C4+k+WY6mHjUMuwssjCY3G+aImWDSwnU3w9G41q8EoPvJ1049PIi7GJXErusTYZITmqfonyejmSFLPt8LHtux9AmJgFSrC3UhwIDAQAB");
|
|
|
|
typeof(MainActivity).GetField("_licenseChecker", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(this, licenseChecker);
|
|
|
|
licenseChecker.CheckAccess(this);
|
2019-05-13 22:33:45 +08:00
|
|
|
}
|
2019-05-27 14:18:32 +08:00
|
|
|
public new void Allow(PolicyResponse response)
|
|
|
|
{
|
|
|
|
typeof(MainActivity).GetMethod("CheckToDownloadExpansion", BindingFlags.Instance | BindingFlags.NonPublic)?.Invoke(this, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public new void DontAllow(PolicyResponse response)
|
|
|
|
{
|
|
|
|
if (response == PolicyResponse.Retry)
|
|
|
|
this.WaitThenCheckForValidLicense();
|
|
|
|
else if (response == PolicyResponse.Licensed)
|
|
|
|
{
|
|
|
|
typeof(MainActivity).GetMethod("CheckToDownloadExpansion", BindingFlags.Instance | BindingFlags.NonPublic)?.Invoke(this, null);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Utils.OpenInPlayStore();
|
|
|
|
this.Finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private async void WaitThenCheckForValidLicense()
|
|
|
|
{
|
|
|
|
await Task.Delay(TimeSpan.FromSeconds(30.0));
|
|
|
|
this.CheckUsingServerManagedPolicy();
|
|
|
|
}
|
2019-05-13 22:33:45 +08:00
|
|
|
}
|
|
|
|
}
|