From 2be6ad15744e7230030e0b48f775603d83ff14f7 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 26 Oct 2016 20:35:48 -0400 Subject: choose correct references for platform automatically (#126) --- src/StardewModdingAPI/StardewModdingAPI.csproj | 66 +++++++++++++++++--------- src/TrainerMod/TrainerMod.csproj | 50 ++++++++++++++----- 2 files changed, 82 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/StardewModdingAPI/StardewModdingAPI.csproj b/src/StardewModdingAPI/StardewModdingAPI.csproj index 487bd952..ab62bd87 100644 --- a/src/StardewModdingAPI/StardewModdingAPI.csproj +++ b/src/StardewModdingAPI/StardewModdingAPI.csproj @@ -90,28 +90,55 @@ C:\Program Files (x86)\GalaxyClient\Games\Stardew Valley C:\Program Files (x86)\Steam\steamapps\common\Stardew Valley + + + + + False + + + False + + + False + + + False + + + $(GamePath)\Stardew Valley.exe + False + + + $(GamePath)\xTile.dll + False + False + + + + + + + $(GamePath)\MonoGame.Framework.dll + False + False + + + $(GamePath)\StardewValley.exe + False + + + $(GamePath)\xTile.dll + False + + + + - - False - - - False - - - False - - - False - ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll True - - False - $(GamePath)\Stardew Valley.exe - False - @@ -121,11 +148,6 @@ - - False - $(GamePath)\xTile.dll - False - diff --git a/src/TrainerMod/TrainerMod.csproj b/src/TrainerMod/TrainerMod.csproj index a6955c68..77d1c9ef 100644 --- a/src/TrainerMod/TrainerMod.csproj +++ b/src/TrainerMod/TrainerMod.csproj @@ -52,20 +52,49 @@ C:\Program Files (x86)\GalaxyClient\Games\Stardew Valley C:\Program Files (x86)\Steam\steamapps\common\Stardew Valley + + + + + False + + + False + + + $(GamePath)\Stardew Valley.exe + False + + + $(GamePath)\xTile.dll + False + False + + + + + + + $(GamePath)\MonoGame.Framework.dll + False + False + + + $(GamePath)\StardewValley.exe + False + + + $(GamePath)\xTile.dll + False + + + + - - False - - - False - ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll True - - $(GamePath)\Stardew Valley.exe - @@ -74,9 +103,6 @@ - - $(GamePath)\xTile.dll - -- cgit From 57da69c87c9befcba3257af8e47a7e1685f98041 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 26 Oct 2016 21:05:11 -0400 Subject: use platform-agnostic paths (#126) --- src/StardewModdingAPI/Logger.cs | 4 ++-- src/StardewModdingAPI/Mod.cs | 2 +- src/StardewModdingAPI/Program.cs | 11 ++++++++--- 3 files changed, 11 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/StardewModdingAPI/Logger.cs b/src/StardewModdingAPI/Logger.cs index 0d69b6ec..32da124f 100644 --- a/src/StardewModdingAPI/Logger.cs +++ b/src/StardewModdingAPI/Logger.cs @@ -30,7 +30,7 @@ namespace StardewModdingAPI public static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { Console.WriteLine("An exception has been caught"); - File.WriteAllText(Constants.LogDir + "\\MODDED_ErrorLog.Log_" + DateTime.UtcNow.Ticks + ".txt", e.ExceptionObject.ToString()); + File.WriteAllText(Path.Combine(Constants.LogDir, $"MODDED_ErrorLog.Log_{DateTime.UtcNow.Ticks}.txt"), e.ExceptionObject.ToString()); } /// @@ -40,7 +40,7 @@ namespace StardewModdingAPI public static void Application_ThreadException(object sender, ThreadExceptionEventArgs e) { Console.WriteLine("A thread exception has been caught"); - File.WriteAllText(Constants.LogDir + "\\MODDED_ErrorLog.Log_" + Extensions.Random.Next(100000000, 999999999) + ".txt", e.Exception.ToString()); + File.WriteAllText(Path.Combine(Constants.LogDir, $"MODDED_ErrorLog.Log_{Extensions.Random.Next(100000000, 999999999)}.txt"), e.Exception.ToString()); } #endregion diff --git a/src/StardewModdingAPI/Mod.cs b/src/StardewModdingAPI/Mod.cs index 8edfcf7e..e83049de 100644 --- a/src/StardewModdingAPI/Mod.cs +++ b/src/StardewModdingAPI/Mod.cs @@ -17,7 +17,7 @@ namespace StardewModdingAPI /// /// A basic path to store your mod's config at. /// - public string BaseConfigPath => PathOnDisk + "\\config.json"; + public string BaseConfigPath => Path.Combine(this.PathOnDisk, "config.json"); /// /// A basic path to where per-save configs are stored diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index 81e48c7d..5513b23a 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -19,6 +19,11 @@ namespace StardewModdingAPI { public class Program { + /// The full path to the Stardew Valley executable. + private static readonly string GameExecutablePath = File.Exists(Path.Combine(Constants.ExecutionPath, "StardewValley.exe")) + ? Path.Combine(Constants.ExecutionPath, "StardewValley.exe") // Linux or Mac + : Path.Combine(Constants.ExecutionPath, "Stardew Valley.exe"); // Windows + private static List _modPaths; public static SGame gamePtr; @@ -103,9 +108,9 @@ namespace StardewModdingAPI //_modContentPaths.ForEach(path => VerifyPath(path)); VerifyPath(Constants.LogDir); - if (!File.Exists(Constants.ExecutionPath + "\\Stardew Valley.exe")) + if (!File.Exists(GameExecutablePath)) { - throw new FileNotFoundException($"Could not found: {Constants.ExecutionPath}\\Stardew Valley.exe"); + throw new FileNotFoundException($"Could not found: {GameExecutablePath}"); } } @@ -117,7 +122,7 @@ namespace StardewModdingAPI Log.AsyncY("Initializing SDV Assembly..."); // Load in the assembly - ignores security - StardewAssembly = Assembly.UnsafeLoadFrom(Constants.ExecutionPath + "\\Stardew Valley.exe"); + StardewAssembly = Assembly.UnsafeLoadFrom(GameExecutablePath); StardewProgramType = StardewAssembly.GetType("StardewValley.Program", true); StardewGameInfo = StardewProgramType.GetField("gamePtr"); -- cgit From 9436920d91fddd36d5c208299c3fa24b29a909be Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 26 Oct 2016 21:15:34 -0400 Subject: remove broken and unused test code (#126) --- src/StardewModdingAPI/Program.cs | 58 -------------------------- src/StardewModdingAPI/StardewModdingAPI.csproj | 6 +-- src/TrainerMod/TrainerMod.cs | 27 ------------ src/TrainerMod/TrainerMod.csproj | 4 +- 4 files changed, 3 insertions(+), 92 deletions(-) (limited to 'src') diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index 5513b23a..f37f573d 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -81,7 +81,6 @@ namespace StardewModdingAPI private static void ConfigureUI() { Console.Title = Constants.ConsoleTitle; - #if DEBUG Console.Title += " - DEBUG IS NOT FALSE, AUTHOUR NEEDS TO REUPLOAD THIS VERSION"; #endif @@ -149,12 +148,10 @@ namespace StardewModdingAPI // The only command in the API (at least it should be, for now) Command.RegisterCommand("help", "Lists all commands | 'help ' returns command description").CommandFired += help_CommandFired; - //Command.RegisterCommand("crash", "crashes sdv").CommandFired += delegate { Game1.player.draw(null); }; //Subscribe to events ControlEvents.KeyPressed += Events_KeyPressed; GameEvents.LoadContent += Events_LoadContent; - //Events.MenuChanged += Events_MenuChanged; //Idk right now Log.AsyncY("Applying Final SDV Tweaks..."); StardewInvoke(() => @@ -360,8 +357,6 @@ namespace StardewModdingAPI public static void ConsoleInputThread() { - var input = string.Empty; - while (true) { Command.CallCommand(Console.ReadLine()); @@ -373,65 +368,12 @@ namespace StardewModdingAPI Log.AsyncY("Initializing Debug Assets..."); DebugPixel = new Texture2D(Game1.graphics.GraphicsDevice, 1, 1); DebugPixel.SetData(new[] {Color.White}); - -#if DEBUG - StardewModdingAPI.Log.Async("REGISTERING BASE CUSTOM ITEM"); - SObject so = new SObject(); - so.Name = "Mario Block"; - so.CategoryName = "SMAPI Test Mod"; - so.Description = "It's a block from Mario!\nLoaded in realtime by SMAPI."; - so.Texture = Texture2D.FromStream(Game1.graphics.GraphicsDevice, new FileStream(_modContentPaths[0] + "\\Test.png", FileMode.Open)); - so.IsPassable = true; - so.IsPlaceable = true; - StardewModdingAPI.Log.Async("REGISTERED WITH ID OF: " + SGame.RegisterModItem(so)); - - //StardewModdingAPI.Log.Async("REGISTERING SECOND CUSTOM ITEM"); - //SObject so2 = new SObject(); - //so2.Name = "Mario Painting"; - //so2.CategoryName = "SMAPI Test Mod"; - //so2.Description = "It's a painting of a creature from Mario!\nLoaded in realtime by SMAPI."; - //so2.Texture = Texture2D.FromStream(Game1.graphics.GraphicsDevice, new FileStream(_modContentPaths[0] + "\\PaintingTest.png", FileMode.Open)); - //so2.IsPassable = true; - //so2.IsPlaceable = true; - //StardewModdingAPI.Log.Async("REGISTERED WITH ID OF: " + SGame.RegisterModItem(so2)); - - Command.CallCommand("load"); -#endif } private static void Events_KeyPressed(object o, EventArgsKeyPressed e) { } - private static void Events_MenuChanged(IClickableMenu newMenu) - { - Log.AsyncY("NEW MENU: " + newMenu.GetType()); - if (newMenu is GameMenu) - { - Game1.activeClickableMenu = SGameMenu.ConstructFromBaseClass(Game1.activeClickableMenu as GameMenu); - } - } - - private static void Events_LocationsChanged(List newLocations) - { -#if DEBUG - SGame.ModLocations = SGameLocation.ConstructFromBaseClasses(Game1.locations); -#endif - } - - private static void Events_CurrentLocationChanged(GameLocation newLocation) - { - //SGame.CurrentLocation = null; - //System.Threading.Thread.Sleep(10); -#if DEBUG - Console.WriteLine(newLocation.name); - SGame.CurrentLocation = SGame.LoadOrCreateSGameLocationFromName(newLocation.name); -#endif - //Game1.currentLocation = SGame.CurrentLocation; - //Log.LogComment(((SGameLocation) newLocation).name); - //Log.LogComment("LOC CHANGED: " + SGame.currentLocation.name); - } - public static void StardewInvoke(Action a) { StardewForm.Invoke(a); diff --git a/src/StardewModdingAPI/StardewModdingAPI.csproj b/src/StardewModdingAPI/StardewModdingAPI.csproj index ab62bd87..7c555fd8 100644 --- a/src/StardewModdingAPI/StardewModdingAPI.csproj +++ b/src/StardewModdingAPI/StardewModdingAPI.csproj @@ -55,7 +55,7 @@ x86 bin\Debug\ false - TRACE + DEBUG;TRACE true true bin\Debug\StardewModdingAPI.XML @@ -82,10 +82,8 @@ $(HOME)/GOG Games/Stardew Valley/game $(HOME)/.local/share/Steam/steamapps/common/Stardew Valley - $(HOME)/Library/Application Support/Steam/steamapps/common/Stardew Valley/Contents/MacOS - C:\Program Files (x86)\GalaxyClient\Games\Stardew Valley C:\Program Files (x86)\Steam\steamapps\common\Stardew Valley @@ -226,4 +224,4 @@ - + \ No newline at end of file diff --git a/src/TrainerMod/TrainerMod.cs b/src/TrainerMod/TrainerMod.cs index da5365cb..92de9796 100644 --- a/src/TrainerMod/TrainerMod.cs +++ b/src/TrainerMod/TrainerMod.cs @@ -14,28 +14,6 @@ namespace TrainerMod { public class TrainerMod : Mod { - /* - public override string Name - { - get { return "Trainer Mod"; } - } - - public override string Authour - { - get { return "Zoryn Aaron"; } - } - - public override string Version - { - get { return "1.0"; } - } - - public override string Description - { - get { return "Registers several commands to use. Most commands are trainer-like in that they offer forms of cheating."; } - } - */ - public static int frozenTime; public static bool infHealth, infStamina, infMoney, freezeTime; @@ -758,11 +736,6 @@ namespace TrainerMod private static void RegisterNewItem(object sender, EventArgsCommand e) { -#if DEBUG - SObject s = SGame.PullModItemFromDict(0, true); - s.Stack = 999; - Game1.player.addItemToInventory(s); -#endif } } } \ No newline at end of file diff --git a/src/TrainerMod/TrainerMod.csproj b/src/TrainerMod/TrainerMod.csproj index 77d1c9ef..6844f1c1 100644 --- a/src/TrainerMod/TrainerMod.csproj +++ b/src/TrainerMod/TrainerMod.csproj @@ -20,7 +20,7 @@ full true ..\StardewModdingAPI\bin\Debug\Mods\TrainerMod\ - TRACE + DEBUG;TRACE prompt 4 x86 @@ -44,10 +44,8 @@ $(HOME)/GOG Games/Stardew Valley/game $(HOME)/.local/share/Steam/steamapps/common/Stardew Valley - $(HOME)/Library/Application Support/Steam/steamapps/common/Stardew Valley/Contents/MacOS - C:\Program Files (x86)\GalaxyClient\Games\Stardew Valley C:\Program Files (x86)\Steam\steamapps\common\Stardew Valley -- cgit From 4e17de2f2c33a6ddda4952265f7866d407965653 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 26 Oct 2016 23:43:32 -0400 Subject: use simpler crossplatform window management (#126) --- src/StardewModdingAPI/Program.cs | 35 ++++------------------------------- src/TrainerMod/FodyWeavers.xml | 5 ----- src/TrainerMod/TrainerMod.cs | 13 ------------- src/TrainerMod/TrainerMod.csproj | 5 ----- 4 files changed, 4 insertions(+), 54 deletions(-) delete mode 100644 src/TrainerMod/FodyWeavers.xml (limited to 'src') diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index f37f573d..f6c63851 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.Globalization; using System.IO; using System.Linq; @@ -11,9 +10,7 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using StardewModdingAPI.Events; using StardewModdingAPI.Inheritance; -using StardewModdingAPI.Inheritance.Menus; using StardewValley; -using StardewValley.Menus; namespace StardewModdingAPI { @@ -32,7 +29,6 @@ namespace StardewModdingAPI public static Assembly StardewAssembly; public static Type StardewProgramType; public static FieldInfo StardewGameInfo; - public static Form StardewForm; public static Thread gameThread; public static Thread consoleInputThread; @@ -154,12 +150,9 @@ namespace StardewModdingAPI GameEvents.LoadContent += Events_LoadContent; Log.AsyncY("Applying Final SDV Tweaks..."); - StardewInvoke(() => - { - gamePtr.IsMouseVisible = false; - gamePtr.Window.Title = "Stardew Valley - Version " + Game1.version; - StardewForm.Resize += GraphicsEvents.InvokeResize; - }); + gamePtr.IsMouseVisible = false; + gamePtr.Window.Title = "Stardew Valley - Version " + Game1.version; + gamePtr.Window.ClientSizeChanged += GraphicsEvents.InvokeResize; } /// @@ -226,10 +219,8 @@ namespace StardewModdingAPI Game1.graphics.GraphicsProfile = GraphicsProfile.HiDef; LoadMods(); - StardewForm = Control.FromHandle(gamePtr.Window.Handle).FindForm(); - if (StardewForm != null) StardewForm.Closing += StardewForm_Closing; - ready = true; + gamePtr.Exiting += (sender, e) => ready = false; StardewGameInfo.SetValue(StardewProgramType, gamePtr); gamePtr.Run(); @@ -240,19 +231,6 @@ namespace StardewModdingAPI } } - private static void StardewForm_Closing(object sender, CancelEventArgs e) - { - e.Cancel = true; - - if (true || MessageBox.Show("Are you sure you would like to quit Stardew Valley?\nUnsaved progress will be lost!", "Confirm Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) - { - gamePtr.Exit(); - gamePtr.Dispose(); - StardewForm.Hide(); - ready = false; - } - } - public static void LoadMods() { Log.AsyncY("LOADING MODS"); @@ -374,11 +352,6 @@ namespace StardewModdingAPI { } - public static void StardewInvoke(Action a) - { - StardewForm.Invoke(a); - } - private static void help_CommandFired(object o, EventArgsCommand e) { if (e.Command.CalledArgs.Length > 0) diff --git a/src/TrainerMod/FodyWeavers.xml b/src/TrainerMod/FodyWeavers.xml deleted file mode 100644 index dc708fcb..00000000 --- a/src/TrainerMod/FodyWeavers.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/TrainerMod/TrainerMod.cs b/src/TrainerMod/TrainerMod.cs index 92de9796..94fd823b 100644 --- a/src/TrainerMod/TrainerMod.cs +++ b/src/TrainerMod/TrainerMod.cs @@ -50,9 +50,6 @@ namespace TrainerMod { Command.RegisterCommand("types", "Lists all value types | types").CommandFired += types_CommandFired; - Command.RegisterCommand("hide", "Hides the game form | hide").CommandFired += hide_CommandFired; - Command.RegisterCommand("show", "Shows the game form | show").CommandFired += show_CommandFired; - Command.RegisterCommand("save", "Saves the game? Doesn't seem to work. | save").CommandFired += save_CommandFired; Command.RegisterCommand("load", "Shows the load screen | load").CommandFired += load_CommandFired; @@ -94,16 +91,6 @@ namespace TrainerMod Log.AsyncY($"[Int32: {int.MinValue} - {int.MaxValue}], [Int64: {long.MinValue} - {long.MaxValue}], [String: \"raw text\"], [Colour: r,g,b (EG: 128, 32, 255)]"); } - private static void hide_CommandFired(object sender, EventArgsCommand e) - { - Program.StardewInvoke(() => { Program.StardewForm.Hide(); }); - } - - private static void show_CommandFired(object sender, EventArgsCommand e) - { - Program.StardewInvoke(() => { Program.StardewForm.Show(); }); - } - private static void save_CommandFired(object sender, EventArgsCommand e) { SaveGame.Save(); diff --git a/src/TrainerMod/TrainerMod.csproj b/src/TrainerMod/TrainerMod.csproj index 6844f1c1..e5002ba4 100644 --- a/src/TrainerMod/TrainerMod.csproj +++ b/src/TrainerMod/TrainerMod.csproj @@ -95,9 +95,7 @@ - - @@ -119,9 +117,6 @@ - - - -- cgit From e643a38b7826ba45218936a5120eda1be13fa331 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 27 Oct 2016 00:40:48 -0400 Subject: only use assembly merging on Windows (#126) Costura doesn't work on Linux and Mac, but we can just add a separate DLL for Json.NET on those platforms. --- src/StardewModdingAPI/StardewModdingAPI.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/StardewModdingAPI/StardewModdingAPI.csproj b/src/StardewModdingAPI/StardewModdingAPI.csproj index 7c555fd8..af35fbac 100644 --- a/src/StardewModdingAPI/StardewModdingAPI.csproj +++ b/src/StardewModdingAPI/StardewModdingAPI.csproj @@ -213,7 +213,7 @@ - + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. -- cgit From 8eb0a94472f092fe37b48460269de988aff8562c Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 27 Oct 2016 01:19:21 -0400 Subject: add launcher for Linux and Mac (#126) --- src/StardewModdingAPI/StardewModdingAPI.csproj | 3 ++ src/StardewModdingAPI/StardewValley | 42 ++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/StardewModdingAPI/StardewValley (limited to 'src') diff --git a/src/StardewModdingAPI/StardewModdingAPI.csproj b/src/StardewModdingAPI/StardewModdingAPI.csproj index af35fbac..6c68308d 100644 --- a/src/StardewModdingAPI/StardewModdingAPI.csproj +++ b/src/StardewModdingAPI/StardewModdingAPI.csproj @@ -190,6 +190,9 @@ Designer + + Always + diff --git a/src/StardewModdingAPI/StardewValley b/src/StardewModdingAPI/StardewValley new file mode 100644 index 00000000..0bfe0d5c --- /dev/null +++ b/src/StardewModdingAPI/StardewValley @@ -0,0 +1,42 @@ +#!/bin/bash +# MonoKickstart Shell Script +# Written by Ethan "flibitijibibo" Lee +# Modified for StardewModdingAPI by Viz + +# Move to script's directory +cd "`dirname "$0"`" + +# Get the system architecture +UNAME=`uname` +ARCH=`uname -m` + +# MonoKickstart picks the right libfolder, so just execute the right binary. +if [ "$UNAME" == "Darwin" ]; then + # ... Except on OSX. + export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:./osx/ + + # El Capitan is a total idiot and wipes this variable out, making the + # Steam overlay disappear. This sidesteps "System Integrity Protection" + # and resets the variable with Valve's own variable (they provided this + # fix by the way, thanks Valve!). Note that you will need to update your + # launch configuration to the script location, NOT just the app location + # (i.e. Kick.app/Contents/MacOS/Kick, not just Kick.app). + # -flibit + if [ "$STEAM_DYLD_INSERT_LIBRARIES" != "" ] && [ "$DYLD_INSERT_LIBRARIES" == "" ]; then + export DYLD_INSERT_LIBRARIES="$STEAM_DYLD_INSERT_LIBRARIES" + fi + + ln -sf mcs.bin.osx mcs + cp StardewValley.bin.osx StardewModdingAPI.bin.osx + ./StardewModdingAPI.bin.osx $@ +else + if [ "$ARCH" == "x86_64" ]; then + ln -sf mcs.bin.x86_64 mcs + cp StardewValley.bin.x86_64 StardewModdingAPI.bin.x86_64 + ./StardewModdingAPI.bin.x86_64 $@ + else + ln -sf mcs.bin.x86 mcs + cp StardewValley.bin.x86 StardewModdingAPI.bin.x86 + ./StardewModdingAPI.bin.x86 $@ + fi +fi -- cgit From 80b2b3dddaaae07194f245567c6337c9613cb9ad Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 27 Oct 2016 02:03:29 -0400 Subject: rename Unix launcher for consistency with Windows install process (#126) --- src/StardewModdingAPI/StardewModdingAPI | 42 ++++++++++++++++++++++++++ src/StardewModdingAPI/StardewModdingAPI.csproj | 2 +- src/StardewModdingAPI/StardewValley | 42 -------------------------- 3 files changed, 43 insertions(+), 43 deletions(-) create mode 100644 src/StardewModdingAPI/StardewModdingAPI delete mode 100644 src/StardewModdingAPI/StardewValley (limited to 'src') diff --git a/src/StardewModdingAPI/StardewModdingAPI b/src/StardewModdingAPI/StardewModdingAPI new file mode 100644 index 00000000..0bfe0d5c --- /dev/null +++ b/src/StardewModdingAPI/StardewModdingAPI @@ -0,0 +1,42 @@ +#!/bin/bash +# MonoKickstart Shell Script +# Written by Ethan "flibitijibibo" Lee +# Modified for StardewModdingAPI by Viz + +# Move to script's directory +cd "`dirname "$0"`" + +# Get the system architecture +UNAME=`uname` +ARCH=`uname -m` + +# MonoKickstart picks the right libfolder, so just execute the right binary. +if [ "$UNAME" == "Darwin" ]; then + # ... Except on OSX. + export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:./osx/ + + # El Capitan is a total idiot and wipes this variable out, making the + # Steam overlay disappear. This sidesteps "System Integrity Protection" + # and resets the variable with Valve's own variable (they provided this + # fix by the way, thanks Valve!). Note that you will need to update your + # launch configuration to the script location, NOT just the app location + # (i.e. Kick.app/Contents/MacOS/Kick, not just Kick.app). + # -flibit + if [ "$STEAM_DYLD_INSERT_LIBRARIES" != "" ] && [ "$DYLD_INSERT_LIBRARIES" == "" ]; then + export DYLD_INSERT_LIBRARIES="$STEAM_DYLD_INSERT_LIBRARIES" + fi + + ln -sf mcs.bin.osx mcs + cp StardewValley.bin.osx StardewModdingAPI.bin.osx + ./StardewModdingAPI.bin.osx $@ +else + if [ "$ARCH" == "x86_64" ]; then + ln -sf mcs.bin.x86_64 mcs + cp StardewValley.bin.x86_64 StardewModdingAPI.bin.x86_64 + ./StardewModdingAPI.bin.x86_64 $@ + else + ln -sf mcs.bin.x86 mcs + cp StardewValley.bin.x86 StardewModdingAPI.bin.x86 + ./StardewModdingAPI.bin.x86 $@ + fi +fi diff --git a/src/StardewModdingAPI/StardewModdingAPI.csproj b/src/StardewModdingAPI/StardewModdingAPI.csproj index 6c68308d..c269ee39 100644 --- a/src/StardewModdingAPI/StardewModdingAPI.csproj +++ b/src/StardewModdingAPI/StardewModdingAPI.csproj @@ -190,7 +190,7 @@ Designer - + Always diff --git a/src/StardewModdingAPI/StardewValley b/src/StardewModdingAPI/StardewValley deleted file mode 100644 index 0bfe0d5c..00000000 --- a/src/StardewModdingAPI/StardewValley +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash -# MonoKickstart Shell Script -# Written by Ethan "flibitijibibo" Lee -# Modified for StardewModdingAPI by Viz - -# Move to script's directory -cd "`dirname "$0"`" - -# Get the system architecture -UNAME=`uname` -ARCH=`uname -m` - -# MonoKickstart picks the right libfolder, so just execute the right binary. -if [ "$UNAME" == "Darwin" ]; then - # ... Except on OSX. - export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:./osx/ - - # El Capitan is a total idiot and wipes this variable out, making the - # Steam overlay disappear. This sidesteps "System Integrity Protection" - # and resets the variable with Valve's own variable (they provided this - # fix by the way, thanks Valve!). Note that you will need to update your - # launch configuration to the script location, NOT just the app location - # (i.e. Kick.app/Contents/MacOS/Kick, not just Kick.app). - # -flibit - if [ "$STEAM_DYLD_INSERT_LIBRARIES" != "" ] && [ "$DYLD_INSERT_LIBRARIES" == "" ]; then - export DYLD_INSERT_LIBRARIES="$STEAM_DYLD_INSERT_LIBRARIES" - fi - - ln -sf mcs.bin.osx mcs - cp StardewValley.bin.osx StardewModdingAPI.bin.osx - ./StardewModdingAPI.bin.osx $@ -else - if [ "$ARCH" == "x86_64" ]; then - ln -sf mcs.bin.x86_64 mcs - cp StardewValley.bin.x86_64 StardewModdingAPI.bin.x86_64 - ./StardewModdingAPI.bin.x86_64 $@ - else - ln -sf mcs.bin.x86 mcs - cp StardewValley.bin.x86 StardewModdingAPI.bin.x86 - ./StardewModdingAPI.bin.x86 $@ - fi -fi -- cgit From 2ea2068486b5b2bff844aa5e57c11de0434c6ada Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 27 Oct 2016 12:23:00 -0400 Subject: include pdb for release build --- src/StardewModdingAPI/StardewModdingAPI.csproj | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/StardewModdingAPI/StardewModdingAPI.csproj b/src/StardewModdingAPI/StardewModdingAPI.csproj index c269ee39..b2fbfb31 100644 --- a/src/StardewModdingAPI/StardewModdingAPI.csproj +++ b/src/StardewModdingAPI/StardewModdingAPI.csproj @@ -71,6 +71,8 @@ true true 6 + pdbonly + true icon.ico -- cgit From f44eb6d66f547f15d87e273c2cb1f4597eee532a Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 27 Oct 2016 13:40:42 -0400 Subject: only hook into WinForms on Windows for Mac compatibility (#126) --- src/StardewModdingAPI/Program.cs | 4 ++++ src/StardewModdingAPI/StardewModdingAPI.csproj | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index f6c63851..b8a8b856 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -5,7 +5,9 @@ using System.IO; using System.Linq; using System.Reflection; using System.Threading; +#if SMAPI_FOR_WINDOWS using System.Windows.Forms; +#endif using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using StardewModdingAPI.Events; @@ -208,8 +210,10 @@ namespace StardewModdingAPI public static void RunGame() { +#if SMAPI_FOR_WINDOWS Application.ThreadException += Log.Application_ThreadException; Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); +#endif AppDomain.CurrentDomain.UnhandledException += Log.CurrentDomain_UnhandledException; try diff --git a/src/StardewModdingAPI/StardewModdingAPI.csproj b/src/StardewModdingAPI/StardewModdingAPI.csproj index b2fbfb31..4294c561 100644 --- a/src/StardewModdingAPI/StardewModdingAPI.csproj +++ b/src/StardewModdingAPI/StardewModdingAPI.csproj @@ -92,6 +92,9 @@ + + $(DefineConstants);SMAPI_FOR_WINDOWS + False @@ -117,6 +120,9 @@ + + $(DefineConstants);SMAPI_FOR_UNIX + $(GamePath)\MonoGame.Framework.dll @@ -142,7 +148,7 @@ - + -- cgit From 58c026285ad7f0aa013b74813a7f8aa9c5da954b Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 27 Oct 2016 14:32:28 -0400 Subject: add System.Numerics to mod package for Mac (#126) --- src/StardewModdingAPI/StardewModdingAPI.csproj | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/StardewModdingAPI/StardewModdingAPI.csproj b/src/StardewModdingAPI/StardewModdingAPI.csproj index 4294c561..3b952496 100644 --- a/src/StardewModdingAPI/StardewModdingAPI.csproj +++ b/src/StardewModdingAPI/StardewModdingAPI.csproj @@ -148,6 +148,9 @@ + + True + -- cgit From 6cc8c6d7c19e849aeac10e6399c4a48a5d954755 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 27 Oct 2016 15:17:17 -0400 Subject: run game on main thread for Mac compatibility (#126) --- src/StardewModdingAPI/Program.cs | 113 +++++++++++++++++---------------------- 1 file changed, 49 insertions(+), 64 deletions(-) (limited to 'src') diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index b8a8b856..ef273763 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -57,9 +57,7 @@ namespace StardewModdingAPI Log.AsyncY("SMAPI Version: " + Constants.Version.VersionString); ConfigureUI(); ConfigurePaths(); - ConfigureSDV(); - - GameRunInvoker(); + StartGame(); } catch (Exception e) { @@ -112,13 +110,12 @@ namespace StardewModdingAPI } /// - /// Load Stardev Valley and control features + /// Load Stardev Valley and control features, and launch the game. /// - private static void ConfigureSDV() + private static void StartGame() { - Log.AsyncY("Initializing SDV Assembly..."); - // Load in the assembly - ignores security + Log.AsyncY("Initializing SDV Assembly..."); StardewAssembly = Assembly.UnsafeLoadFrom(GameExecutablePath); StardewProgramType = StardewAssembly.GetType("StardewValley.Program", true); StardewGameInfo = StardewProgramType.GetField("gamePtr"); @@ -127,64 +124,52 @@ namespace StardewModdingAPI Log.AsyncY("Injecting New SDV Version..."); Game1.version += $"-Z_MODDED | SMAPI {Constants.Version.VersionString}"; - // Create the thread for the game to run in. - gameThread = new Thread(RunGame); - Log.AsyncY("Starting SDV..."); - gameThread.Start(); - - // Wait for the game to load up - while (!ready) + // initialise after game launches + new Thread(() => { - } - - //SDV is running - Log.AsyncY("SDV Loaded Into Memory"); - - //Create definition to listen for input - Log.AsyncY("Initializing Console Input Thread..."); - consoleInputThread = new Thread(ConsoleInputThread); - - // The only command in the API (at least it should be, for now) - Command.RegisterCommand("help", "Lists all commands | 'help ' returns command description").CommandFired += help_CommandFired; - - //Subscribe to events - ControlEvents.KeyPressed += Events_KeyPressed; - GameEvents.LoadContent += Events_LoadContent; - - Log.AsyncY("Applying Final SDV Tweaks..."); - gamePtr.IsMouseVisible = false; - gamePtr.Window.Title = "Stardew Valley - Version " + Game1.version; - gamePtr.Window.ClientSizeChanged += GraphicsEvents.InvokeResize; - } - - /// - /// Wrap the 'RunGame' method for console output - /// - private static void GameRunInvoker() - { - //Game's in memory now, send the event - Log.AsyncY("Game Loaded"); - GameEvents.InvokeGameLoaded(); - - Log.AsyncY("Type 'help' for help, or 'help ' for a command's usage"); - //Begin listening to input - consoleInputThread.Start(); - - - while (ready) - { - //Check if the game is still running 10 times a second - Thread.Sleep(1000 / 10); - } - - //abort the thread, we're closing - if (consoleInputThread != null && consoleInputThread.ThreadState == ThreadState.Running) - consoleInputThread.Abort(); - - Log.AsyncY("Game Execution Finished"); - Log.AsyncY("Shutting Down..."); - Thread.Sleep(100); - Environment.Exit(0); + // Wait for the game to load up + while (!ready) Thread.Sleep(1000); + + // Apply final tweaks + Log.AsyncY("Applying Final SDV Tweaks..."); + gamePtr.IsMouseVisible = false; + gamePtr.Window.Title = "Stardew Valley - Version " + Game1.version; + gamePtr.Window.ClientSizeChanged += GraphicsEvents.InvokeResize; + + // Create definition to listen for input + Log.AsyncY("Initializing Console Input Thread..."); + consoleInputThread = new Thread(ConsoleInputThread); + + // The only command in the API (at least it should be, for now) + Command.RegisterCommand("help", "Lists all commands | 'help ' returns command description").CommandFired += help_CommandFired; + + // Subscribe to events + ControlEvents.KeyPressed += Events_KeyPressed; + GameEvents.LoadContent += Events_LoadContent; + + // Game's in memory now, send the event + Log.AsyncY("Game Loaded"); + GameEvents.InvokeGameLoaded(); + + // Listen for command line input + Log.AsyncY("Type 'help' for help, or 'help ' for a command's usage"); + consoleInputThread.Start(); + while (ready) + Thread.Sleep(1000 / 10); // Check if the game is still running 10 times a second + + // Abort the thread, we're closing + if (consoleInputThread != null && consoleInputThread.ThreadState == ThreadState.Running) + consoleInputThread.Abort(); + + Log.AsyncY("Game Execution Finished"); + Log.AsyncY("Shutting Down..."); + Thread.Sleep(100); + Environment.Exit(0); + }).Start(); + + // Start game loop + Log.AsyncY("Starting SDV..."); + RunGame(); } /// -- cgit From a68f41c39603c29abf9a67e5ba8e655e50330a0c Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 27 Oct 2016 17:10:43 -0400 Subject: fix crossthread access violation when debugger is attached (#126) --- src/StardewModdingAPI/Program.cs | 82 +++++++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index ef273763..cd062f8b 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -124,17 +124,47 @@ namespace StardewModdingAPI Log.AsyncY("Injecting New SDV Version..."); Game1.version += $"-Z_MODDED | SMAPI {Constants.Version.VersionString}"; - // initialise after game launches - new Thread(() => + // add error interceptors +#if SMAPI_FOR_WINDOWS + Application.ThreadException += Log.Application_ThreadException; + Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); +#endif + AppDomain.CurrentDomain.UnhandledException += Log.CurrentDomain_UnhandledException; + + // initialise game + try { - // Wait for the game to load up - while (!ready) Thread.Sleep(1000); + Log.AsyncY("Initializing SDV..."); + gamePtr = new SGame(); + + // hook events + gamePtr.Exiting += (sender, e) => ready = false; + gamePtr.Window.ClientSizeChanged += GraphicsEvents.InvokeResize; + + // patch graphics + Log.AsyncY("Patching SDV Graphics Profile..."); + Game1.graphics.GraphicsProfile = GraphicsProfile.HiDef; + + // load mods + LoadMods(); - // Apply final tweaks + // initialise + StardewGameInfo.SetValue(StardewProgramType, gamePtr); Log.AsyncY("Applying Final SDV Tweaks..."); gamePtr.IsMouseVisible = false; gamePtr.Window.Title = "Stardew Valley - Version " + Game1.version; - gamePtr.Window.ClientSizeChanged += GraphicsEvents.InvokeResize; + } + catch (Exception ex) + { + Log.AsyncR("Game failed to initialise: " + ex); + return; + } + + // initialise after game launches + new Thread(() => + { + // Wait for the game to load up + while (!ready) Thread.Sleep(1000); // Create definition to listen for input Log.AsyncY("Initializing Console Input Thread..."); @@ -169,7 +199,16 @@ namespace StardewModdingAPI // Start game loop Log.AsyncY("Starting SDV..."); - RunGame(); + try + { + ready = true; + gamePtr.Run(); + } + catch (Exception ex) + { + ready = false; + Log.AsyncR("Game failed to start: " + ex); + } } /// @@ -193,33 +232,6 @@ namespace StardewModdingAPI ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - public static void RunGame() - { -#if SMAPI_FOR_WINDOWS - Application.ThreadException += Log.Application_ThreadException; - Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); -#endif - AppDomain.CurrentDomain.UnhandledException += Log.CurrentDomain_UnhandledException; - - try - { - gamePtr = new SGame(); - Log.AsyncY("Patching SDV Graphics Profile..."); - Game1.graphics.GraphicsProfile = GraphicsProfile.HiDef; - LoadMods(); - - ready = true; - gamePtr.Exiting += (sender, e) => ready = false; - - StardewGameInfo.SetValue(StardewProgramType, gamePtr); - gamePtr.Run(); - } - catch (Exception ex) - { - Log.AsyncR("Game failed to start: " + ex); - } - } - public static void LoadMods() { Log.AsyncY("LOADING MODS"); @@ -357,4 +369,4 @@ namespace StardewModdingAPI Log.AsyncY("Commands: " + Command.RegisteredCommands.Select(x => x.CommandName).ToSingular()); } } -} \ No newline at end of file +} -- cgit