Example #1
0
        /*********
        ** Public methods
        *********/
        /// <summary>The main entry point which hooks into and launches the game.</summary>
        /// <param name="args">The command-line arguments.</param>
        public static void Main(string[] args)
        {
            try
            {
                AppDomain.CurrentDomain.AssemblyResolve += Program.CurrentDomain_AssemblyResolve;
#if SMAPI_FOR_MOBILE
                Program.AssertAndroidGameVersion();
#else
                Program.AssertGamePresent();
                Program.AssertGameVersion();
                Program.Start(args);
#endif
            }
            catch (BadImageFormatException ex) when(ex.FileName == "StardewValley" || ex.FileName == "Stardew Valley")  // don't use EarlyConstants.GameAssemblyName, since we want to check both possible names
            {
#if SMAPI_FOR_MOBILE
                SAlertDialogUtil.AlertMessage(
                    $"SMAPI failed to initialize because your game's {ex.FileName}.exe seems to be invalid.\nThis may be a pirated version which modified the executable in an incompatible way; if so, you can try a different download or buy a legitimate version.\n\nTechnical details:\n{ex}",
                    callback: type => { SMainActivity.Instance.Finish(); });
#else
                Console.WriteLine($"SMAPI failed to initialize because your game's {ex.FileName}.exe seems to be invalid.\nThis may be a pirated version which modified the executable in an incompatible way; if so, you can try a different download or buy a legitimate version.\n\nTechnical details:\n{ex}");
#endif
            }
            catch (Exception ex)
            {
#if SMAPI_FOR_MOBILE
                SAlertDialogUtil.AlertMessage($"SMAPI failed to initialize: {ex}",
                                              callback: type => { SMainActivity.Instance.Finish(); });
#else
                Console.WriteLine($"SMAPI failed to initialize: {ex}");
                Program.PressAnyKeyToExit(true);
#endif
            }
        }
Example #2
0
        /*********
        ** Private methods
        *********/
#if SMAPI_FOR_MOBILE
        private static void AssertAndroidGameVersion()
        {
            if (Constants.GameVersion.IsOlderThan(Constants.MinimumGameVersion))
            {
                SAlertDialogUtil.AlertMessage($"Oops! You're running Stardew Valley {Constants.GameVersion}, but the oldest supported version is {Constants.MinimumGameVersion}. Please update your game before using SMAPI.",
                                              callback: type => SMainActivity.Instance.Finish());
            }
        }
Example #3
0
 public static void AlertMessage(string message, string title = "Error",
                                 string positive = null, string negative = null,
                                 Action <ActionType> callback = null)
 {
     try
     {
         SMainActivity.Instance.RunOnUiThread(() => SAlertDialogUtil.ShowDialog(message, title, positive, negative, callback));
     }
     catch (Exception)
     {
         // ignored
     }
 }
Example #4
0
        protected override void OnCreate(Bundle bundle)
        {
            MainActivity.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);

            SMainActivity.Instance = this;
            try
            {
                File errorLog = this.FilesDir.ListFiles().FirstOrDefault(f => f.IsDirectory && f.Name == "error")?.ListFiles().FirstOrDefault(f => f.Name.EndsWith(".dat"));
                if (errorLog != null)
                {
                    try
                    {
                        Handler handler = new Handler((msg) => throw new RuntimeException());
                        SAlertDialogUtil.ShowDialog(System.IO.File.ReadAllText(errorLog.AbsolutePath), "Crash Detected", null, null, callback: (type =>
                        {
                            errorLog.Delete();
                            handler.SendEmptyMessage(0);
                        }));
                        try
                        {
                            Looper.Prepare();
                        }
                        catch (Exception) { }
                        Looper.Loop();
                    }
                    catch (Exception) { }
                }
                Type[] services = { typeof(Microsoft.AppCenter.Analytics.Analytics), typeof(Microsoft.AppCenter.Crashes.Crashes) };
                AppCenter.Start(Constants.MicrosoftAppSecret, services);
                AppCenter.SetUserId(Constants.ApiVersion.ToString());
            }
            catch
            {
                // ignored
            }
            base.OnCreate(bundle);
            this.CheckAppPermissions();
        }