From 126ce53618719f6734125669e1466f681be49a78 Mon Sep 17 00:00:00 2001 From: ClxS Date: Sun, 6 Mar 2016 18:01:52 +0000 Subject: Updated readme. Small change to prevent trainermod using copy-local --- README.md | 2 +- TrainerMod/TrainerMod.csproj | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 70e895c8..f8bdd12b 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,4 @@ See: https://github.com/Zoryn4163/SMAPI-Mods ##Latest Version: [0.37.0.1](https://github.com/ClxS/SMAPI/tree/0.37.1) -Mod developers! Work from the latest release tag. The master branch may contain updates which make it incompatable with the latest release binaries. \ No newline at end of file +Mod developers! You should develop from the release branch, which contains the code for the most recently released version. The master branch may contain updates which make it incompatable with the latest release binaries. \ No newline at end of file diff --git a/TrainerMod/TrainerMod.csproj b/TrainerMod/TrainerMod.csproj index c7dbe94f..8753bc1b 100644 --- a/TrainerMod/TrainerMod.csproj +++ b/TrainerMod/TrainerMod.csproj @@ -42,6 +42,7 @@ $(SteamInstallPath)\steamapps\common\Stardew Valley\Stardew Valley.exe + False @@ -53,6 +54,7 @@ $(SteamInstallPath)\steamapps\common\Stardew Valley\xTile.dll + False @@ -63,6 +65,7 @@ {f1a573b0-f436-472c-ae29-0b91ea6b9f8f} StardewModdingAPI + False -- cgit From bfe6537f84fe780197c4554f360f19c3f9f12371 Mon Sep 17 00:00:00 2001 From: ClxS Date: Sun, 6 Mar 2016 19:46:47 +0000 Subject: Added KeyReleased event --- StardewModdingAPI/Events/Controls.cs | 6 ++++++ StardewModdingAPI/Inheritance/SGame.cs | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/StardewModdingAPI/Events/Controls.cs b/StardewModdingAPI/Events/Controls.cs index ace890ca..8cf0f431 100644 --- a/StardewModdingAPI/Events/Controls.cs +++ b/StardewModdingAPI/Events/Controls.cs @@ -11,6 +11,7 @@ namespace StardewModdingAPI.Events { public static event EventHandler KeyboardChanged = delegate { }; public static event EventHandler KeyPressed = delegate { }; + public static event EventHandler KeyReleased = delegate { }; public static event EventHandler MouseChanged = delegate { }; public static void InvokeKeyboardChanged(KeyboardState priorState, KeyboardState newState) @@ -27,5 +28,10 @@ namespace StardewModdingAPI.Events { KeyPressed.Invoke(null, new EventArgsKeyPressed(key)); } + + public static void InvokeKeyReleased(Keys key) + { + KeyReleased.Invoke(null, new EventArgsKeyPressed(key)); + } } } diff --git a/StardewModdingAPI/Inheritance/SGame.cs b/StardewModdingAPI/Inheritance/SGame.cs index c7b07c43..120f4a6e 100644 --- a/StardewModdingAPI/Inheritance/SGame.cs +++ b/StardewModdingAPI/Inheritance/SGame.cs @@ -43,6 +43,10 @@ namespace StardewModdingAPI.Inheritance { get { return CurrentlyPressedKeys.Where(x => !PreviouslyPressedKeys.Contains(x)).ToArray(); } } + public Keys[] FrameReleasedKeys + { + get { return PreviouslyPressedKeys.Where(x => !CurrentlyPressedKeys.Contains(x)).ToArray(); } + } public int PreviousGameLocations { get; private set; } public int PreviousLocationObjects { get; private set; } @@ -233,11 +237,15 @@ namespace StardewModdingAPI.Inheritance { KStateNow = Keyboard.GetState(); CurrentlyPressedKeys = KStateNow.GetPressedKeys(); + MStateNow = Mouse.GetState(); foreach (Keys k in FramePressedKeys) Events.ControlEvents.InvokeKeyPressed(k); - + + foreach (Keys k in FrameReleasedKeys) + Events.ControlEvents.InvokeKeyReleased(k); + if (KStateNow != KStatePrior) { Events.ControlEvents.InvokeKeyboardChanged(KStatePrior, KStateNow); -- cgit From 65c7c9b733bf6c6122ea591bba789a914dbd404d Mon Sep 17 00:00:00 2001 From: James Finlay Date: Sun, 6 Mar 2016 12:19:59 -0800 Subject: Basic refactor of Main - Moved sections of Main out into: ConfigureUI, ConfigurePaths, ConfigureInjector, ConfigureSDV, GameRunInvoker --- StardewModdingAPI/Program.cs | 207 +++++++++++++++++++++++++------------------ 1 file changed, 120 insertions(+), 87 deletions(-) diff --git a/StardewModdingAPI/Program.cs b/StardewModdingAPI/Program.cs index 28073135..900c4889 100644 --- a/StardewModdingAPI/Program.cs +++ b/StardewModdingAPI/Program.cs @@ -18,10 +18,11 @@ namespace StardewModdingAPI { public class Program { + private static List _modPaths; + private static List _modContentPaths; + public static string ExecutionPath { get; private set; } - public static string DataPath = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley")); - public static List ModPaths = new List(); - public static List ModContentPaths = new List(); + public static string DataPath = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley")); public static string LogPath = Path.Combine(Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley")), "ErrorLogs"); public static Texture2D DebugPixel { get; private set; } @@ -37,86 +38,99 @@ namespace StardewModdingAPI public static Thread gameThread; public static Thread consoleInputThread; - public const string Version = "0.36 Alpha"; + private const string _version = "0.36 Alpha"; + private static string _consoleTitle = string.Format("Stardew Modding API Console - Version {0}", _version); public static bool StardewInjectorLoaded { get; private set; } public static Mod StardewInjectorMod { get; private set; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// + /// Main method holding the API execution + /// + /// private static void Main(string[] args) - { - Console.Title = "Stardew Modding API Console"; + { + try + { + ConfigureUI(); + ConfigurePaths(); + ConfigureInjector(); + ConfigureSDV(); + + GameRunInvoker(); + } + catch (Exception e) + { + // Catch and display all exceptions. + Log.Error("Critical error: " + e); + } + + Log.Comment("The API will now terminate. Press any key to continue..."); + Console.ReadKey(); + } - Console.Title += " - Version " + Version; + /// + /// Set up the console properties + /// + private static void ConfigureUI() + { + Console.Title = _consoleTitle; + #if DEBUG Console.Title += " - DEBUG IS NOT FALSE, AUTHOUR NEEDS TO REUPLOAD THIS VERSION"; -#endif +#endif + } + + /// + /// Setup the required paths and logging + /// + private static void ConfigurePaths() + { + Log.Info("Validating api paths..."); + + _modPaths = new List(); + _modContentPaths = new List(); //TODO: Have an app.config and put the paths inside it so users can define locations to load mods from ExecutionPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); - ModPaths.Add(Path.Combine(Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley")), "Mods")); - ModPaths.Add(Path.Combine(ExecutionPath, "Mods")); - ModPaths.Add(Path.Combine(Path.Combine(ExecutionPath, "Mods"), "Content")); - ModContentPaths.Add(Path.Combine(Path.Combine(Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley")), "Mods"), "Content")); + _modPaths.Add(Path.Combine(Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley")), "Mods")); + _modPaths.Add(Path.Combine(ExecutionPath, "Mods")); + _modPaths.Add(Path.Combine(Path.Combine(ExecutionPath, "Mods"), "Content")); + _modContentPaths.Add(Path.Combine(Path.Combine(Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley")), "Mods"), "Content")); //Checks that all defined modpaths exist as directories - foreach (string ModPath in ModPaths) - { - try - { - if (File.Exists(ModPath)) - File.Delete(ModPath); - if (!Directory.Exists(ModPath)) - Directory.CreateDirectory(ModPath); - } - catch (Exception ex) - { - Log.Error("Could not create a missing ModPath: " + ModPath + "\n\n" + ex); - } - } - //Same for content - foreach (string ModContentPath in ModContentPaths) - { - try - { - if (!Directory.Exists(ModContentPath)) - Directory.CreateDirectory(ModContentPath); - } - catch (Exception ex) - { - Log.Error("Could not create a missing ModContentPath: " + ModContentPath + "\n\n" + ex); - } - } - //And then make sure we have an errorlog dir - try - { - if (!Directory.Exists(LogPath)) - Directory.CreateDirectory(LogPath); - } - catch (Exception ex) - { - Log.Error("Could not create the missing ErrorLogs path: " + LogPath + "\n\n" + ex); - } + _modPaths.ForEach(path => VerifyPath(path)); + _modContentPaths.ForEach(path => VerifyPath(path)); + VerifyPath(LogPath); - Log.Info("Initializing SDV Assembly..."); - if (!File.Exists(ExecutionPath + "\\Stardew Valley.exe")) - { - //If the api isn't next to SDV.exe then terminate. Though it'll crash before we even get here w/o sdv.exe. Perplexing. - Log.Error("Could not find: " + ExecutionPath + "\\Stardew Valley.exe"); - Log.Error("The API will now terminate."); - Console.ReadKey(); - Environment.Exit(-4); + Log.Initialize(LogPath); + + Log.Verbose(LogPath); + + if (!File.Exists(ExecutionPath + "\\Stardew Valley.exe")) + { + throw new FileNotFoundException(string.Format("Could not found: {0}\\Stardew Valley.exe", ExecutionPath)); } - - //Load in that assembly. Also, ignore security :D - StardewAssembly = Assembly.UnsafeLoadFrom(ExecutionPath + "\\Stardew Valley.exe"); - - //This will load the injector before anything else if it sees it - //It doesn't matter though - //I'll leave it as a feature in case anyone in the community wants to tinker with it - //All you need is a DLL that inherits from mod and is called StardewInjector.dll with an Entry() method - foreach (string ModPath in ModPaths) + } + + /// + /// Load the injector. + /// + /// + /// This will load the injector before anything else if it sees it + /// It doesn't matter though + /// I'll leave it as a feature in case anyone in the community wants to tinker with it + /// All you need is a DLL that inherits from mod and is called StardewInjector.dll with an Entry() method + /// + private static void ConfigureInjector() + { + //This will load the injector before anything else if it sees it + //It doesn't matter though + //I'll leave it as a feature in case anyone in the community wants to tinker with it + //All you need is a DLL that inherits from mod and is called StardewInjector.dll with an Entry() method + foreach (string ModPath in _modPaths) { foreach (String s in Directory.GetFiles(ModPath, "StardewInjector.dll")) { @@ -145,7 +159,18 @@ namespace StardewModdingAPI Log.Error("Failed to load mod '{0}'. Exception details:\n" + ex, s); } } - } + } + } + + /// + /// Load Stardev Valley and control features + /// + private static void ConfigureSDV() + { + Log.Info("Initializing SDV Assembly..."); + + // Load in that assembly. Also, ignore security :D + StardewAssembly = Assembly.UnsafeLoadFrom(ExecutionPath + "\\Stardew Valley.exe"); StardewProgramType = StardewAssembly.GetType("StardewValley.Program", true); StardewGameInfo = StardewProgramType.GetField("gamePtr"); @@ -189,7 +214,7 @@ namespace StardewModdingAPI //Change the game's version Log.Info("Injecting New SDV Version..."); - Game1.version += "-Z_MODDED | SMAPI " + Version; + Game1.version += "-Z_MODDED | SMAPI " + _version; //Create the thread for the game to run in. gameThread = new Thread(RunGame); @@ -234,13 +259,19 @@ namespace StardewModdingAPI gamePtr.IsMouseVisible = false; gamePtr.Window.Title = "Stardew Valley - Version " + Game1.version; StardewForm.Resize += Events.GraphicsEvents.InvokeResize; - }); + }); + } + /// + /// Wrap the 'RunGame' method for console output + /// + private static void GameRunInvoker() + { //Game's in memory now, send the event Log.Verbose("Game Loaded"); Events.GameEvents.InvokeGameLoaded(); - Log.Comment(ConsoleColor.Cyan, "Type 'help' for help, or 'help ' for a command's usage"); + Log.Comment("Type 'help' for help, or 'help ' for a command's usage"); //Begin listening to input consoleInputThread.Start(); @@ -258,25 +289,27 @@ namespace StardewModdingAPI Log.Verbose("Game Execution Finished"); Log.Verbose("Shutting Down..."); Thread.Sleep(100); - /* - int time = 0; - int step = 100; - int target = 1000; - while (true) - { - time += step; - Thread.Sleep(step); - - Console.Write("."); - - if (time >= target) - break; - } - */ Environment.Exit(0); } - + /// + /// Create the given directory path if it does not exist + /// + /// Desired directory path + private static void VerifyPath(string path) + { + try + { + if (!Directory.Exists(path)) + { + Directory.CreateDirectory(path); + } + } + catch (Exception ex) + { + Log.Error("Could not create a path: " + path + "\n\n" + ex); + } + } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -340,7 +373,7 @@ namespace StardewModdingAPI { Log.Verbose("LOADING MODS"); int loadedMods = 0; - foreach (string ModPath in ModPaths) + foreach (string ModPath in _modPaths) { foreach (String s in Directory.GetFiles(ModPath, "*.dll")) { -- cgit From 04abcec53c132e6871782d7d6b860a9679113275 Mon Sep 17 00:00:00 2001 From: James Finlay Date: Sun, 6 Mar 2016 12:51:22 -0800 Subject: Quick fixes --- StardewModdingAPI/Program.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/StardewModdingAPI/Program.cs b/StardewModdingAPI/Program.cs index 9767c1b4..af845440 100644 --- a/StardewModdingAPI/Program.cs +++ b/StardewModdingAPI/Program.cs @@ -77,7 +77,6 @@ namespace StardewModdingAPI { Console.Title = _consoleTitle; - Console.Title += " - Version " + Version.VersionString; #if DEBUG Console.Title += " - DEBUG IS NOT FALSE, AUTHOUR NEEDS TO REUPLOAD THIS VERSION"; #endif @@ -107,13 +106,11 @@ namespace StardewModdingAPI StardewModdingAPI.Log.Initialize(LogPath); - StardewModdingAPI.Log.Verbose(LogPath); - if (!File.Exists(ExecutionPath + "\\Stardew Valley.exe")) { throw new FileNotFoundException(string.Format("Could not found: {0}\\Stardew Valley.exe", ExecutionPath)); - } } + } /// /// Load the injector. @@ -271,7 +268,7 @@ namespace StardewModdingAPI StardewModdingAPI.Log.Verbose("Game Loaded"); Events.GameEvents.InvokeGameLoaded(); - StardewModdingAPI.Log.Comment(ConsoleColor.Cyan, "Type 'help' for help, or 'help ' for a command's usage"); + StardewModdingAPI.Log.Comment("Type 'help' for help, or 'help ' for a command's usage"); //Begin listening to input consoleInputThread.Start(); -- cgit From 93112cbb3245409554878b835812048954314d2b Mon Sep 17 00:00:00 2001 From: James Finlay Date: Sun, 6 Mar 2016 13:58:40 -0800 Subject: Additional cleanup - Moved Version & static strings to 'Constants' class - Cleaned out unused code that is not being used --- StardewModdingAPI/Constants.cs | 44 ++++++++++++ StardewModdingAPI/Program.cs | 104 ++++++----------------------- StardewModdingAPI/StardewModdingAPI.csproj | 2 +- StardewModdingAPI/Version.cs | 23 ------- 4 files changed, 66 insertions(+), 107 deletions(-) create mode 100644 StardewModdingAPI/Constants.cs delete mode 100644 StardewModdingAPI/Version.cs diff --git a/StardewModdingAPI/Constants.cs b/StardewModdingAPI/Constants.cs new file mode 100644 index 00000000..fb35feb9 --- /dev/null +++ b/StardewModdingAPI/Constants.cs @@ -0,0 +1,44 @@ +using System; +using System.IO; +using System.Reflection; + +namespace StardewModdingAPI +{ + /// + /// Static class containing readonly values. + /// + public static class Constants + { + /// + /// Stardew Valley's local app data location. + /// %LocalAppData%//StardewValley + /// + public static string DataPath => Path.Combine(Environment.SpecialFolder.ApplicationData.ToString(), "StardewValley"); + + /// + /// Execution path to execute the code. + /// + public static string ExecutionPath => Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + + /// + /// Title for the API console + /// + public static string ConsoleTitle => string.Format("Stardew Modding API Console - Version {0}", VersionString); + + /// + /// Path for log files to be output to. + /// %LocalAppData%//StardewValley//ErrorLogs + /// + public static string LogPath => Path.Combine(Environment.SpecialFolder.ApplicationData.ToString(), "StardewValley", "ErrorLogs"); + + public const int MajorVersion = 0; + + public const int MinorVersion = 37; + + public const int PatchVersion = 1; + + public const string Build = "Alpha"; + + public static string VersionString => string.Format("{0}.{1}.{2} {3}", MajorVersion, MinorVersion, PatchVersion, Build); + } +} diff --git a/StardewModdingAPI/Program.cs b/StardewModdingAPI/Program.cs index af845440..f1ccd936 100644 --- a/StardewModdingAPI/Program.cs +++ b/StardewModdingAPI/Program.cs @@ -21,12 +21,6 @@ namespace StardewModdingAPI private static List _modPaths; private static List _modContentPaths; - private static string _consoleTitle = string.Format("Stardew Modding API Console - Version {0}", Version.VersionString); - - public static string ExecutionPath { get; private set; } - public static string DataPath = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley")); - public static string LogPath = Path.Combine(Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley")), "ErrorLogs"); - public static Texture2D DebugPixel { get; private set; } public static SGame gamePtr; @@ -75,7 +69,7 @@ namespace StardewModdingAPI /// private static void ConfigureUI() { - Console.Title = _consoleTitle; + Console.Title = Constants.ConsoleTitle; #if DEBUG Console.Title += " - DEBUG IS NOT FALSE, AUTHOUR NEEDS TO REUPLOAD THIS VERSION"; @@ -93,22 +87,21 @@ namespace StardewModdingAPI _modContentPaths = new List(); //TODO: Have an app.config and put the paths inside it so users can define locations to load mods from - ExecutionPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); - _modPaths.Add(Path.Combine(Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley")), "Mods")); - _modPaths.Add(Path.Combine(ExecutionPath, "Mods")); - _modPaths.Add(Path.Combine(Path.Combine(ExecutionPath, "Mods"), "Content")); - _modContentPaths.Add(Path.Combine(Path.Combine(Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley")), "Mods"), "Content")); + _modPaths.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley", "Mods")); + _modPaths.Add(Path.Combine(Constants.ExecutionPath, "Mods")); + _modPaths.Add(Path.Combine(Constants.ExecutionPath, "Mods", "Content")); + _modContentPaths.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley", "Mods", "Content")); //Checks that all defined modpaths exist as directories _modPaths.ForEach(path => VerifyPath(path)); _modContentPaths.ForEach(path => VerifyPath(path)); - VerifyPath(LogPath); + VerifyPath(Constants.LogPath); - StardewModdingAPI.Log.Initialize(LogPath); + StardewModdingAPI.Log.Initialize(Constants.LogPath); - if (!File.Exists(ExecutionPath + "\\Stardew Valley.exe")) + if (!File.Exists(Constants.ExecutionPath + "\\Stardew Valley.exe")) { - throw new FileNotFoundException(string.Format("Could not found: {0}\\Stardew Valley.exe", ExecutionPath)); + throw new FileNotFoundException(string.Format("Could not found: {0}\\Stardew Valley.exe", Constants.ExecutionPath)); } } @@ -122,11 +115,7 @@ namespace StardewModdingAPI /// All you need is a DLL that inherits from mod and is called StardewInjector.dll with an Entry() method /// private static void ConfigureInjector() - { - //This will load the injector before anything else if it sees it - //It doesn't matter though - //I'll leave it as a feature in case anyone in the community wants to tinker with it - //All you need is a DLL that inherits from mod and is called StardewInjector.dll with an Entry() method + { foreach (string ModPath in _modPaths) { foreach (String s in Directory.GetFiles(ModPath, "StardewInjector.dll")) @@ -166,65 +155,22 @@ namespace StardewModdingAPI { StardewModdingAPI.Log.Info("Initializing SDV Assembly..."); - // Load in that assembly. Also, ignore security :D - StardewAssembly = Assembly.UnsafeLoadFrom(ExecutionPath + "\\Stardew Valley.exe"); - + // Load in the assembly - ignores security + StardewAssembly = Assembly.UnsafeLoadFrom(Constants.ExecutionPath + "\\Stardew Valley.exe"); StardewProgramType = StardewAssembly.GetType("StardewValley.Program", true); StardewGameInfo = StardewProgramType.GetField("gamePtr"); - #region deprecated - /* - * Lol no. I tried though. - if (File.Exists(ExecutionPath + "\\Stardew_Injector.exe")) - { - //Stardew_Injector Mode - StardewInjectorLoaded = true; - Program.Log.LogInfo("STARDEW_INJECTOR DETECTED, LAUNCHING USING INJECTOR CALLS"); - Assembly inj = Assembly.UnsafeLoadFrom(ExecutionPath + "\\Stardew_Injector.exe"); - Type prog = inj.GetType("Stardew_Injector.Program", true); - FieldInfo hooker = prog.GetField("hooker", BindingFlags.NonPublic | BindingFlags.Static); - - //hook.GetMethod("Initialize").Invoke(hooker.GetValue(null), null); - //customize the initialize method for SGame instead of Game - Assembly cecil = Assembly.UnsafeLoadFrom(ExecutionPath + "\\Mono.Cecil.dll"); - Type assDef = cecil.GetType("Mono.Cecil.AssemblyDefinition"); - var aDefs = assDef.GetMethods(BindingFlags.Public | BindingFlags.Static); - var aDef = aDefs.First(x => x.ToString().Contains("ReadAssembly(System.String)")); - var theAssDef = aDef.Invoke(null, new object[] { Assembly.GetExecutingAssembly().Location }); - var modDef = assDef.GetProperty("MainModule", BindingFlags.Public | BindingFlags.Instance); - var theModDef = modDef.GetValue(theAssDef); - Console.WriteLine("MODDEF: " + theModDef); - Type hook = inj.GetType("Stardew_Injector.Stardew_Hooker", true); - hook.GetField("m_vAsmDefinition", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(hooker.GetValue(null), theAssDef); - hook.GetField("m_vModDefinition", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(hooker.GetValue(null), theModDef); - - //hook.GetMethod("Initialize").Invoke(hooker.GetValue(null), null); - hook.GetMethod("ApplyHooks").Invoke(hooker.GetValue(null), null); - //hook.GetMethod("Finalize").Invoke(hooker.GetValue(null), null); - //hook.GetMethod("Run").Invoke(hooker.GetValue(null), null); - - Console.ReadKey(); - //Now go back and load Stardew through SMAPI - } - */ - #endregion - - //Change the game's version - StardewModdingAPI.Log.Info("Injecting New SDV Version..."); - Game1.version += "-Z_MODDED | SMAPI " + Version.VersionString; + // Change the game's version + StardewModdingAPI.Log.Verbose("Injecting New SDV Version..."); + Game1.version += string.Format("-Z_MODDED | SMAPI {0}", Constants.VersionString); - //Create the thread for the game to run in. + // Create the thread for the game to run in. gameThread = new Thread(RunGame); StardewModdingAPI.Log.Info("Starting SDV..."); - gameThread.Start(); - - //I forget. - SGame.GetStaticFields(); + gameThread.Start(); - while (!ready) - { - //Wait for the game to load up - } + // Wait for the game to load up + while (!ready) ; //SDV is running StardewModdingAPI.Log.Comment("SDV Loaded Into Memory"); @@ -233,23 +179,15 @@ namespace StardewModdingAPI StardewModdingAPI.Log.Verbose("Initializing Console Input Thread..."); consoleInputThread = new Thread(ConsoleInputThread); - //The only command in the API (at least it should be, for now)\ - + // 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 Events.ControlEvents.KeyPressed += Events_KeyPressed; Events.GameEvents.LoadContent += Events_LoadContent; - //Events.MenuChanged += Events_MenuChanged; //Idk right now - -#if DEBUG - //Experimental - //Events.LocationsChanged += Events_LocationsChanged; - //Events.CurrentLocationChanged += Events_CurrentLocationChanged; -#endif + //Events.MenuChanged += Events_MenuChanged; //Idk right now - //Do tweaks using winforms invoke because I'm lazy StardewModdingAPI.Log.Verbose("Applying Final SDV Tweaks..."); StardewInvoke(() => { diff --git a/StardewModdingAPI/StardewModdingAPI.csproj b/StardewModdingAPI/StardewModdingAPI.csproj index 8d9dc4ba..6d70b1c5 100644 --- a/StardewModdingAPI/StardewModdingAPI.csproj +++ b/StardewModdingAPI/StardewModdingAPI.csproj @@ -98,6 +98,7 @@ + @@ -121,7 +122,6 @@ - diff --git a/StardewModdingAPI/Version.cs b/StardewModdingAPI/Version.cs deleted file mode 100644 index baccd53b..00000000 --- a/StardewModdingAPI/Version.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace StardewModdingAPI -{ - public static class Version - { - public const int MajorVersion = 0; - public const int MinorVersion = 37; - public const int PatchVersion = 1; - public const string Build = "Alpha"; - - public static string VersionString { - get - { - return string.Format("{0}.{1}.{2} {3}", MajorVersion, MinorVersion, PatchVersion, Build); - } - } - } -} -- cgit From bfd8d047666737443c8cf99bd4764d7bf03ee91b Mon Sep 17 00:00:00 2001 From: James Finlay Date: Sun, 6 Mar 2016 14:04:22 -0800 Subject: Reverting GetFolderPath change --- StardewModdingAPI/Constants.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/StardewModdingAPI/Constants.cs b/StardewModdingAPI/Constants.cs index fb35feb9..f8b913f7 100644 --- a/StardewModdingAPI/Constants.cs +++ b/StardewModdingAPI/Constants.cs @@ -13,7 +13,7 @@ namespace StardewModdingAPI /// Stardew Valley's local app data location. /// %LocalAppData%//StardewValley /// - public static string DataPath => Path.Combine(Environment.SpecialFolder.ApplicationData.ToString(), "StardewValley"); + public static string DataPath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley"); /// /// Execution path to execute the code. @@ -29,7 +29,7 @@ namespace StardewModdingAPI /// Path for log files to be output to. /// %LocalAppData%//StardewValley//ErrorLogs /// - public static string LogPath => Path.Combine(Environment.SpecialFolder.ApplicationData.ToString(), "StardewValley", "ErrorLogs"); + public static string LogPath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley", "ErrorLogs"); public const int MajorVersion = 0; -- cgit From 49090c98fcdc11ca536de42875f50b763e83ce63 Mon Sep 17 00:00:00 2001 From: ClxS Date: Sun, 6 Mar 2016 23:28:32 +0000 Subject: Fixed mod content path not being set correctly. Fixed object draw code. Custom objects can now be placed and show up correctly. --- StardewModdingAPI/Entities/SCharacter.cs | 12 ++++++++++ StardewModdingAPI/Entities/SFarm.cs | 12 ++++++++++ StardewModdingAPI/Entities/SFarmAnimal.cs | 12 ++++++++++ StardewModdingAPI/Entities/SNpc.cs | 12 ++++++++++ StardewModdingAPI/Entities/SPlayer.cs | 37 ++++++++++++++++++++++++++++++ StardewModdingAPI/Inheritance/SObject.cs | 13 ++++++----- StardewModdingAPI/Program.cs | 28 +++++++++++----------- StardewModdingAPI/StardewModdingAPI.csproj | 8 +++++++ TrainerMod/TrainerMod.cs | 4 +--- TrainerMod/TrainerMod.csproj | 6 ++--- 10 files changed, 118 insertions(+), 26 deletions(-) create mode 100644 StardewModdingAPI/Entities/SCharacter.cs create mode 100644 StardewModdingAPI/Entities/SFarm.cs create mode 100644 StardewModdingAPI/Entities/SFarmAnimal.cs create mode 100644 StardewModdingAPI/Entities/SNpc.cs create mode 100644 StardewModdingAPI/Entities/SPlayer.cs diff --git a/StardewModdingAPI/Entities/SCharacter.cs b/StardewModdingAPI/Entities/SCharacter.cs new file mode 100644 index 00000000..740a6d7f --- /dev/null +++ b/StardewModdingAPI/Entities/SCharacter.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StardewModdingAPI.Entities +{ + class SCharacter + { + } +} diff --git a/StardewModdingAPI/Entities/SFarm.cs b/StardewModdingAPI/Entities/SFarm.cs new file mode 100644 index 00000000..5d1647a8 --- /dev/null +++ b/StardewModdingAPI/Entities/SFarm.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StardewModdingAPI.Entities +{ + class SFarm + { + } +} diff --git a/StardewModdingAPI/Entities/SFarmAnimal.cs b/StardewModdingAPI/Entities/SFarmAnimal.cs new file mode 100644 index 00000000..0f768f6a --- /dev/null +++ b/StardewModdingAPI/Entities/SFarmAnimal.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StardewModdingAPI.Entities +{ + class SFarmAnimal + { + } +} diff --git a/StardewModdingAPI/Entities/SNpc.cs b/StardewModdingAPI/Entities/SNpc.cs new file mode 100644 index 00000000..02242d20 --- /dev/null +++ b/StardewModdingAPI/Entities/SNpc.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StardewModdingAPI.Entities +{ + class SNpc + { + } +} diff --git a/StardewModdingAPI/Entities/SPlayer.cs b/StardewModdingAPI/Entities/SPlayer.cs new file mode 100644 index 00000000..ae4e9472 --- /dev/null +++ b/StardewModdingAPI/Entities/SPlayer.cs @@ -0,0 +1,37 @@ +using StardewModdingAPI.Inheritance; +using StardewValley; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StardewModdingAPI.Entities +{ + public static class SPlayer + { + public static List AllFarmers + { + get + { + return SGame.getAllFarmers(); + } + } + + public static Farmer CurrentFarmer + { + get + { + return SGame.player; + } + } + + public static GameLocation CurrentFarmerLocation + { + get + { + return SGame.player.currentLocation; + } + } + } +} diff --git a/StardewModdingAPI/Inheritance/SObject.cs b/StardewModdingAPI/Inheritance/SObject.cs index 28254c24..3dcddb9e 100644 --- a/StardewModdingAPI/Inheritance/SObject.cs +++ b/StardewModdingAPI/Inheritance/SObject.cs @@ -65,17 +65,18 @@ namespace StardewModdingAPI.Inheritance } public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1) - { + { if (Texture != null) { - int targSize = Game1.tileSize; - - Vector2 local = Game1.GlobalToLocal(Game1.viewport, new Vector2(x,y)); - Rectangle targ = new Rectangle((int)local.X, (int)local.Y, targSize, targSize); - spriteBatch.Draw(Texture, targ, null, new Color(255, 255, 255, 255f * alpha)); + spriteBatch.Draw(Texture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(((x * Game1.tileSize) + (Game1.tileSize / 2)) + ((this.shakeTimer > 0) ? Game1.random.Next(-1, 2) : 0)), (float)(((y * Game1.tileSize) + (Game1.tileSize / 2)) + ((this.shakeTimer > 0) ? Game1.random.Next(-1, 2) : 0)))), new Rectangle?(Game1.currentLocation.getSourceRectForObject(this.ParentSheetIndex)), (Color)(Color.White * alpha), 0f, new Vector2(8f, 8f), (this.scale.Y > 1f) ? this.getScale().Y : ((float)Game1.pixelZoom), this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (this.isPassable() ? ((float)this.getBoundingBox(new Vector2((float)x, (float)y)).Top) : ((float)this.getBoundingBox(new Vector2((float)x, (float)y)).Bottom)) / 10000f); } } + public void drawAsProp(SpriteBatch b) + { + + } + public override void draw(SpriteBatch spriteBatch, int xNonTile, int yNonTile, float layerDepth, float alpha = 1) { Log.Debug("THIS DRAW FUNCTION IS NOT IMPLEMENTED I WANT TO KNOW WHERE IT IS CALLED"); diff --git a/StardewModdingAPI/Program.cs b/StardewModdingAPI/Program.cs index f1ccd936..61770f8e 100644 --- a/StardewModdingAPI/Program.cs +++ b/StardewModdingAPI/Program.cs @@ -89,7 +89,7 @@ namespace StardewModdingAPI //TODO: Have an app.config and put the paths inside it so users can define locations to load mods from _modPaths.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley", "Mods")); _modPaths.Add(Path.Combine(Constants.ExecutionPath, "Mods")); - _modPaths.Add(Path.Combine(Constants.ExecutionPath, "Mods", "Content")); + _modContentPaths.Add(Path.Combine(Constants.ExecutionPath, "Mods", "Content")); _modContentPaths.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley", "Mods", "Content")); //Checks that all defined modpaths exist as directories @@ -359,25 +359,25 @@ namespace StardewModdingAPI DebugPixel.SetData(new Color[] { Color.White }); #if DEBUG - Log.Verbose("REGISTERING BASE CUSTOM ITEM"); + StardewModdingAPI.Log.Verbose("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.Texture = Texture2D.FromStream(Game1.graphics.GraphicsDevice, new FileStream(_modContentPaths[0] + "\\Test.png", FileMode.Open)); so.IsPassable = true; so.IsPlaceable = true; - Log.Verbose("REGISTERED WITH ID OF: " + SGame.RegisterModItem(so)); - - Log.Verbose("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; - Log.Verbose("REGISTERED WITH ID OF: " + SGame.RegisterModItem(so2)); + StardewModdingAPI.Log.Verbose("REGISTERED WITH ID OF: " + SGame.RegisterModItem(so)); + + //StardewModdingAPI.Log.Verbose("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.Verbose("REGISTERED WITH ID OF: " + SGame.RegisterModItem(so2)); Command.CallCommand("load"); #endif diff --git a/StardewModdingAPI/StardewModdingAPI.csproj b/StardewModdingAPI/StardewModdingAPI.csproj index 6d70b1c5..5b962d44 100644 --- a/StardewModdingAPI/StardewModdingAPI.csproj +++ b/StardewModdingAPI/StardewModdingAPI.csproj @@ -61,6 +61,9 @@ x86 bin\x86\Debug\ false + + + true x86 @@ -99,6 +102,11 @@ + + + + + diff --git a/TrainerMod/TrainerMod.cs b/TrainerMod/TrainerMod.cs index 9f918ce4..e2482c5d 100644 --- a/TrainerMod/TrainerMod.cs +++ b/TrainerMod/TrainerMod.cs @@ -762,12 +762,10 @@ namespace TrainerMod static void RegisterNewItem(object sender, EventArgsCommand e) { #if DEBUG - Log.Error("Experimental code cannot be run in user mode."); - return; -#endif SObject s = SGame.PullModItemFromDict(0, true); s.Stack = 999; Game1.player.addItemToInventory(s); +#endif } } } diff --git a/TrainerMod/TrainerMod.csproj b/TrainerMod/TrainerMod.csproj index 8753bc1b..3cd42786 100644 --- a/TrainerMod/TrainerMod.csproj +++ b/TrainerMod/TrainerMod.csproj @@ -17,7 +17,7 @@ true full false - bin\Debug\ + ..\StardewModdingAPI\bin\x86\Debug\Mods\ DEBUG;TRACE prompt 4 @@ -41,7 +41,7 @@ False - $(SteamInstallPath)\steamapps\common\Stardew Valley\Stardew Valley.exe + ..\..\..\..\Games\SteamLibrary\steamapps\common\Stardew Valley\Stardew Valley.exe False @@ -53,7 +53,7 @@ - $(SteamInstallPath)\steamapps\common\Stardew Valley\xTile.dll + ..\..\..\..\Games\SteamLibrary\steamapps\common\Stardew Valley\xTile.dll False -- cgit From 71bcfc11dea8c189152a9aa2534c87e1b1486018 Mon Sep 17 00:00:00 2001 From: ClxS Date: Mon, 7 Mar 2016 13:49:45 +0000 Subject: Partially completed events for gamepad input --- StardewModdingAPI/Events/Controls.cs | 15 ++++++++- StardewModdingAPI/Events/EventArgs.cs | 24 +++++++++++++- StardewModdingAPI/Inheritance/SGame.cs | 52 ++++++++++++++++++++++++++++++ StardewModdingAPI/StardewModdingAPI.csproj | 13 +++----- 4 files changed, 93 insertions(+), 11 deletions(-) diff --git a/StardewModdingAPI/Events/Controls.cs b/StardewModdingAPI/Events/Controls.cs index 8cf0f431..fa344bab 100644 --- a/StardewModdingAPI/Events/Controls.cs +++ b/StardewModdingAPI/Events/Controls.cs @@ -1,4 +1,5 @@ -using Microsoft.Xna.Framework.Input; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Input; using System; using System.Collections.Generic; using System.Linq; @@ -13,6 +14,8 @@ namespace StardewModdingAPI.Events public static event EventHandler KeyPressed = delegate { }; public static event EventHandler KeyReleased = delegate { }; public static event EventHandler MouseChanged = delegate { }; + public static event EventHandler ControllerButtonPressed = delegate { }; + public static event EventHandler ControllerButtonReleased = delegate { }; public static void InvokeKeyboardChanged(KeyboardState priorState, KeyboardState newState) { @@ -33,5 +36,15 @@ namespace StardewModdingAPI.Events { KeyReleased.Invoke(null, new EventArgsKeyPressed(key)); } + + public static void InvokeButtonPressed(PlayerIndex playerIndex, Buttons buttons) + { + ControllerButtonPressed.Invoke(null, new EventArgsControllerButtonPressed(playerIndex, buttons)); + } + + public static void InvokeButtonReleased(PlayerIndex playerIndex, Buttons buttons) + { + ControllerButtonReleased.Invoke(null, new EventArgsControllerButtonReleased(playerIndex, buttons)); + } } } diff --git a/StardewModdingAPI/Events/EventArgs.cs b/StardewModdingAPI/Events/EventArgs.cs index 66d057a7..6c5e1401 100644 --- a/StardewModdingAPI/Events/EventArgs.cs +++ b/StardewModdingAPI/Events/EventArgs.cs @@ -30,7 +30,29 @@ namespace StardewModdingAPI.Events } public Keys KeyPressed { get; private set; } } - + + public class EventArgsControllerButtonPressed : EventArgs + { + public EventArgsControllerButtonPressed(PlayerIndex playerIndex, Buttons buttonPressed) + { + PlayerIndex = playerIndex; + ButtonPressed = buttonPressed; + } + public PlayerIndex PlayerIndex; + public Buttons ButtonPressed { get; private set; } + } + + public class EventArgsControllerButtonReleased : EventArgs + { + public EventArgsControllerButtonReleased(PlayerIndex playerIndex, Buttons buttonReleased) + { + PlayerIndex = playerIndex; + ButtonReleased = buttonReleased; + } + public PlayerIndex PlayerIndex; + public Buttons ButtonReleased { get; private set; } + } + public class EventArgsMouseStateChanged : EventArgs { public EventArgsMouseStateChanged(MouseState priorState, MouseState newState) diff --git a/StardewModdingAPI/Inheritance/SGame.cs b/StardewModdingAPI/Inheritance/SGame.cs index 120f4a6e..8da7c412 100644 --- a/StardewModdingAPI/Inheritance/SGame.cs +++ b/StardewModdingAPI/Inheritance/SGame.cs @@ -48,6 +48,40 @@ namespace StardewModdingAPI.Inheritance get { return PreviouslyPressedKeys.Where(x => !CurrentlyPressedKeys.Contains(x)).ToArray(); } } + public Buttons[][] CurrentlyPressedButtons; + public Buttons[][] PreviouslyPressedButtons; + + private bool WasButtonJustPressed(Buttons button, ButtonState buttonState, PlayerIndex stateIndex) + { + return buttonState == ButtonState.Pressed && !PreviouslyPressedButtons[(int)stateIndex].Contains(button); + } + + public Buttons[] GetFramePressedButtons(PlayerIndex index) + { + GamePadState state = GamePad.GetState((PlayerIndex)index); + List buttons = new List(); + if (state.IsConnected) + { + if (WasButtonJustPressed(Buttons.A, state.Buttons.A, index)) buttons.Add(Buttons.A); + if (WasButtonJustPressed(Buttons.B, state.Buttons.B, index)) buttons.Add(Buttons.B); + if (WasButtonJustPressed(Buttons.Back, state.Buttons.Back, index)) buttons.Add(Buttons.Back); + if (WasButtonJustPressed(Buttons.BigButton, state.Buttons.BigButton, index)) buttons.Add(Buttons.BigButton); + if (WasButtonJustPressed(Buttons.LeftShoulder, state.Buttons.LeftShoulder, index)) buttons.Add(Buttons.LeftShoulder); + if (WasButtonJustPressed(Buttons.LeftStick, state.Buttons.LeftStick, index)) buttons.Add(Buttons.LeftStick); + if (WasButtonJustPressed(Buttons.RightShoulder, state.Buttons.RightShoulder, index)) buttons.Add(Buttons.RightShoulder); + if (WasButtonJustPressed(Buttons.RightStick, state.Buttons.RightStick, index)) buttons.Add(Buttons.RightStick); + if (WasButtonJustPressed(Buttons.Start, state.Buttons.Start, index)) buttons.Add(Buttons.Start); + if (WasButtonJustPressed(Buttons.X, state.Buttons.X, index)) buttons.Add(Buttons.X); + if (WasButtonJustPressed(Buttons.Y, state.Buttons.Y, index)) buttons.Add(Buttons.Y); + if (WasButtonJustPressed(Buttons.DPadUp, state.DPad.Up, index)) buttons.Add(Buttons.DPadUp); + if (WasButtonJustPressed(Buttons.DPadDown, state.DPad.Down, index)) buttons.Add(Buttons.DPadDown); + if (WasButtonJustPressed(Buttons.DPadLeft, state.DPad.Left, index)) buttons.Add(Buttons.DPadLeft); + if (WasButtonJustPressed(Buttons.DPadRight, state.DPad.Right, index)) buttons.Add(Buttons.DPadRight); + + } + return buttons.ToArray(); + } + public int PreviousGameLocations { get; private set; } public int PreviousLocationObjects { get; private set; } public int PreviousItems_ { get; private set; } @@ -246,6 +280,24 @@ namespace StardewModdingAPI.Inheritance foreach (Keys k in FrameReleasedKeys) Events.ControlEvents.InvokeKeyReleased(k); + for (PlayerIndex i = PlayerIndex.One; i <= PlayerIndex.Four; i++) + { + foreach(Buttons b in GetFramePressedButtons(i)) + { + Events.ControlEvents.InvokeButtonPressed(i, b); + } + } + + for (PlayerIndex i = PlayerIndex.One; i <= PlayerIndex.Four; i++) + { + GamePadState state = GamePad.GetState(i); + if (state.IsConnected) + { + // TODO: Process state + } + } + + if (KStateNow != KStatePrior) { Events.ControlEvents.InvokeKeyboardChanged(KStatePrior, KStateNow); diff --git a/StardewModdingAPI/StardewModdingAPI.csproj b/StardewModdingAPI/StardewModdingAPI.csproj index 5b962d44..c563174a 100644 --- a/StardewModdingAPI/StardewModdingAPI.csproj +++ b/StardewModdingAPI/StardewModdingAPI.csproj @@ -78,11 +78,8 @@ - - False - $(SteamInstallPath)\steamapps\common\Stardew Valley\Stardew Valley.exe - False - True + + D:\Games\steamapps\common\Stardew Valley\Stardew Valley.exe @@ -93,10 +90,8 @@ - - False - $(SteamInstallPath)\steamapps\common\Stardew Valley\xTile.dll - True + + D:\Games\steamapps\common\Stardew Valley\xTile.dll -- cgit From dcda664c8314b26c3da5a65801dec5ce1ebb2e29 Mon Sep 17 00:00:00 2001 From: ClxS Date: Mon, 7 Mar 2016 14:35:24 +0000 Subject: Updated readme --- README.md | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index f8bdd12b..15748e10 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,33 @@ -# SMAPI -A Modding API For Stardew Valley -See: https://github.com/Zoryn4163/SMAPI-Mods - ## NOTICE: THIS PROJECT IS STILL IN ALPHA +# What is SMAPI + +SMAPI (Stardew Mapping Application Programming Interface) is a tool to help modders make changes to Stardew. It is a standalone executable which goes alongside your Stardew.exe. + +# Latest Version: 0.37.1 +- Minor update to avoid confusion by me forgetting to update the version information. Altered how version info is stored. +- Logging is now in it's own contained class and no longer part of the main program. Deprecated functions still exist to keep a bit of backwards compatibility but will eventually be removed. +- For Modders: Logging has changed, other than that nothing you need to worry about from 0.37.0 +Tested and works with current versions of: SmartMod, StardewCJB , FreezeInside + +Download: https://github.com/ClxS/SMAPI/releases/tag/0.37.1 + +# Installation + +To install SMAPI: +- Firstly, make sure you have .NET 4.5. You can get it here: https://www.microsoft.com/en-gb/download/details.aspx?id=30653 +- Download the the latest release binary here: https://github.com/ClxS/SMAPI/releases/latest +- Extract the zip file alongside your Stardew.exe, for example, if using Steam this would be somewhere like C:/ProgramFiles/Steam/steamapps/common/StardewValley +- To launch SMAPI, launch StardewValleyModdingAPI.exe + +To install mods: +- To install mods just download the mod's .DLL file, and place it in %appdata%\StardewValley\Mods\. SMAPI will take care of the rest! + +# Future Plans +- Content only mods +- Support for a wide range of events +- Enable the addition of new custom content such as locations, NPCs, and items. + +# Mod Developers! -##Latest Version: [0.37.0.1](https://github.com/ClxS/SMAPI/tree/0.37.1) -Mod developers! You should develop from the release branch, which contains the code for the most recently released version. The master branch may contain updates which make it incompatable with the latest release binaries. \ No newline at end of file +Mod developers would work off the release branch. The master branch will contain mid-version updates which could make your mods incompatable with both the current release and the upcoming releases. \ No newline at end of file -- cgit From ba6420efac4a3cb158ea343b926ba5cfeaf783a8 Mon Sep 17 00:00:00 2001 From: ClxS Date: Mon, 7 Mar 2016 14:36:11 +0000 Subject: Updated readme to be a little less shouty --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 15748e10..0672586b 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ SMAPI (Stardew Mapping Application Programming Interface) is a tool to help modders make changes to Stardew. It is a standalone executable which goes alongside your Stardew.exe. -# Latest Version: 0.37.1 +## Latest Version: 0.37.1 - Minor update to avoid confusion by me forgetting to update the version information. Altered how version info is stored. - Logging is now in it's own contained class and no longer part of the main program. Deprecated functions still exist to keep a bit of backwards compatibility but will eventually be removed. - For Modders: Logging has changed, other than that nothing you need to worry about from 0.37.0 @@ -12,7 +12,7 @@ Tested and works with current versions of: SmartMod, StardewCJB , FreezeInside Download: https://github.com/ClxS/SMAPI/releases/tag/0.37.1 -# Installation +## Installation To install SMAPI: - Firstly, make sure you have .NET 4.5. You can get it here: https://www.microsoft.com/en-gb/download/details.aspx?id=30653 @@ -23,11 +23,11 @@ To install SMAPI: To install mods: - To install mods just download the mod's .DLL file, and place it in %appdata%\StardewValley\Mods\. SMAPI will take care of the rest! -# Future Plans +## Future Plans - Content only mods - Support for a wide range of events - Enable the addition of new custom content such as locations, NPCs, and items. -# Mod Developers! +## Mod Developers! Mod developers would work off the release branch. The master branch will contain mid-version updates which could make your mods incompatable with both the current release and the upcoming releases. \ No newline at end of file -- cgit From 0462c9de79a2f1a02e720ac24400d1bf00f74680 Mon Sep 17 00:00:00 2001 From: ClxS Date: Mon, 7 Mar 2016 17:25:51 +0000 Subject: Finished gamepad input events --- StardewModdingAPI/Events/Controls.cs | 12 ++++ StardewModdingAPI/Events/EventArgs.cs | 30 +++++++- StardewModdingAPI/Inheritance/SGame.cs | 108 ++++++++++++++++++++++++++--- StardewModdingAPI/StardewModdingAPI.csproj | 10 +-- 4 files changed, 145 insertions(+), 15 deletions(-) diff --git a/StardewModdingAPI/Events/Controls.cs b/StardewModdingAPI/Events/Controls.cs index fa344bab..c79c28f6 100644 --- a/StardewModdingAPI/Events/Controls.cs +++ b/StardewModdingAPI/Events/Controls.cs @@ -16,6 +16,8 @@ namespace StardewModdingAPI.Events public static event EventHandler MouseChanged = delegate { }; public static event EventHandler ControllerButtonPressed = delegate { }; public static event EventHandler ControllerButtonReleased = delegate { }; + public static event EventHandler ControllerTriggerPressed = delegate { }; + public static event EventHandler ControllerTriggerReleased = delegate { }; public static void InvokeKeyboardChanged(KeyboardState priorState, KeyboardState newState) { @@ -46,5 +48,15 @@ namespace StardewModdingAPI.Events { ControllerButtonReleased.Invoke(null, new EventArgsControllerButtonReleased(playerIndex, buttons)); } + + public static void InvokeTriggerPressed(PlayerIndex playerIndex, Buttons buttons, float value) + { + ControllerTriggerPressed.Invoke(null, new EventArgsControllerTriggerPressed(playerIndex, buttons, value)); + } + + public static void InvokeTriggerReleased(PlayerIndex playerIndex, Buttons buttons, float value) + { + ControllerTriggerReleased.Invoke(null, new EventArgsControllerTriggerReleased(playerIndex, buttons, value)); + } } } diff --git a/StardewModdingAPI/Events/EventArgs.cs b/StardewModdingAPI/Events/EventArgs.cs index 6c5e1401..ee30b406 100644 --- a/StardewModdingAPI/Events/EventArgs.cs +++ b/StardewModdingAPI/Events/EventArgs.cs @@ -38,7 +38,7 @@ namespace StardewModdingAPI.Events PlayerIndex = playerIndex; ButtonPressed = buttonPressed; } - public PlayerIndex PlayerIndex; + public PlayerIndex PlayerIndex { get; private set; } public Buttons ButtonPressed { get; private set; } } @@ -49,10 +49,36 @@ namespace StardewModdingAPI.Events PlayerIndex = playerIndex; ButtonReleased = buttonReleased; } - public PlayerIndex PlayerIndex; + public PlayerIndex PlayerIndex { get; private set; } public Buttons ButtonReleased { get; private set; } } + public class EventArgsControllerTriggerPressed : EventArgs + { + public EventArgsControllerTriggerPressed(PlayerIndex playerIndex, Buttons buttonPressed, float value) + { + PlayerIndex = playerIndex; + ButtonPressed = buttonPressed; + Value = value; + } + public PlayerIndex PlayerIndex { get; private set; } + public Buttons ButtonPressed { get; private set; } + public float Value { get; private set; } + } + + public class EventArgsControllerTriggerReleased : EventArgs + { + public EventArgsControllerTriggerReleased(PlayerIndex playerIndex, Buttons buttonReleased, float value) + { + PlayerIndex = playerIndex; + ButtonReleased = buttonReleased; + Value = value; + } + public PlayerIndex PlayerIndex { get; private set; } + public Buttons ButtonReleased { get; private set; } + public float Value { get; private set; } + } + public class EventArgsMouseStateChanged : EventArgs { public EventArgsMouseStateChanged(MouseState priorState, MouseState newState) diff --git a/StardewModdingAPI/Inheritance/SGame.cs b/StardewModdingAPI/Inheritance/SGame.cs index 8da7c412..cccdff23 100644 --- a/S