From 55b5770718eb4b04e8507957088946d2732d2276 Mon Sep 17 00:00:00 2001 From: ClxS Date: Sun, 6 Mar 2016 15:54:09 +0000 Subject: [PATCH 1/5] Readded Program.cs Logging commands but with Obsolete attribute --- StardewModdingAPI/Program.cs | 132 +++++++++++++++++++++++++---------- 1 file changed, 97 insertions(+), 35 deletions(-) diff --git a/StardewModdingAPI/Program.cs b/StardewModdingAPI/Program.cs index 28073135..da7df466 100644 --- a/StardewModdingAPI/Program.cs +++ b/StardewModdingAPI/Program.cs @@ -72,7 +72,7 @@ namespace StardewModdingAPI } catch (Exception ex) { - Log.Error("Could not create a missing ModPath: " + ModPath + "\n\n" + ex); + StardewModdingAPI.Log.Error("Could not create a missing ModPath: " + ModPath + "\n\n" + ex); } } //Same for content @@ -85,7 +85,7 @@ namespace StardewModdingAPI } catch (Exception ex) { - Log.Error("Could not create a missing ModContentPath: " + ModContentPath + "\n\n" + ex); + StardewModdingAPI.Log.Error("Could not create a missing ModContentPath: " + ModContentPath + "\n\n" + ex); } } //And then make sure we have an errorlog dir @@ -96,15 +96,15 @@ namespace StardewModdingAPI } catch (Exception ex) { - Log.Error("Could not create the missing ErrorLogs path: " + LogPath + "\n\n" + ex); + StardewModdingAPI.Log.Error("Could not create the missing ErrorLogs path: " + LogPath + "\n\n" + ex); } - Log.Info("Initializing SDV Assembly..."); + StardewModdingAPI.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."); + StardewModdingAPI.Log.Error("Could not find: " + ExecutionPath + "\\Stardew Valley.exe"); + StardewModdingAPI.Log.Error("The API will now terminate."); Console.ReadKey(); Environment.Exit(-4); } @@ -120,14 +120,14 @@ namespace StardewModdingAPI { foreach (String s in Directory.GetFiles(ModPath, "StardewInjector.dll")) { - Log.Success(ConsoleColor.Green, "Found Stardew Injector DLL: " + s); + StardewModdingAPI.Log.Success(ConsoleColor.Green, "Found Stardew Injector DLL: " + s); try { Assembly mod = Assembly.UnsafeLoadFrom(s); //to combat internet-downloaded DLLs if (mod.DefinedTypes.Count(x => x.BaseType == typeof(Mod)) > 0) { - Log.Success("Loading Injector DLL..."); + StardewModdingAPI.Log.Success("Loading Injector DLL..."); TypeInfo tar = mod.DefinedTypes.First(x => x.BaseType == typeof(Mod)); Mod m = (Mod)mod.CreateInstance(tar.ToString()); Console.WriteLine("LOADED: {0} by {1} - Version {2} | Description: {3}", m.Name, m.Authour, m.Version, m.Description); @@ -137,12 +137,12 @@ namespace StardewModdingAPI } else { - Log.Error("Invalid Mod DLL"); + StardewModdingAPI.Log.Error("Invalid Mod DLL"); } } catch (Exception ex) { - Log.Error("Failed to load mod '{0}'. Exception details:\n" + ex, s); + StardewModdingAPI.Log.Error("Failed to load mod '{0}'. Exception details:\n" + ex, s); } } } @@ -188,12 +188,12 @@ namespace StardewModdingAPI #endregion //Change the game's version - Log.Info("Injecting New SDV Version..."); + StardewModdingAPI.Log.Info("Injecting New SDV Version..."); Game1.version += "-Z_MODDED | SMAPI " + Version; //Create the thread for the game to run in. gameThread = new Thread(RunGame); - Log.Info("Starting SDV..."); + StardewModdingAPI.Log.Info("Starting SDV..."); gameThread.Start(); //I forget. @@ -205,10 +205,10 @@ namespace StardewModdingAPI } //SDV is running - Log.Comment("SDV Loaded Into Memory"); + StardewModdingAPI.Log.Comment("SDV Loaded Into Memory"); //Create definition to listen for input - Log.Verbose("Initializing Console Input Thread..."); + StardewModdingAPI.Log.Verbose("Initializing Console Input Thread..."); consoleInputThread = new Thread(ConsoleInputThread); //The only command in the API (at least it should be, for now)\ @@ -228,7 +228,7 @@ namespace StardewModdingAPI #endif //Do tweaks using winforms invoke because I'm lazy - Log.Verbose("Applying Final SDV Tweaks..."); + StardewModdingAPI.Log.Verbose("Applying Final SDV Tweaks..."); StardewInvoke(() => { gamePtr.IsMouseVisible = false; @@ -237,10 +237,10 @@ namespace StardewModdingAPI }); //Game's in memory now, send the event - Log.Verbose("Game Loaded"); + StardewModdingAPI.Log.Verbose("Game Loaded"); Events.GameEvents.InvokeGameLoaded(); - Log.Comment(ConsoleColor.Cyan, "Type 'help' for help, or 'help ' for a command's usage"); + StardewModdingAPI.Log.Comment(ConsoleColor.Cyan, "Type 'help' for help, or 'help ' for a command's usage"); //Begin listening to input consoleInputThread.Start(); @@ -255,8 +255,8 @@ namespace StardewModdingAPI if (consoleInputThread != null && consoleInputThread.ThreadState == ThreadState.Running) consoleInputThread.Abort(); - Log.Verbose("Game Execution Finished"); - Log.Verbose("Shutting Down..."); + StardewModdingAPI.Log.Verbose("Game Execution Finished"); + StardewModdingAPI.Log.Verbose("Shutting Down..."); Thread.Sleep(100); /* int time = 0; @@ -282,14 +282,14 @@ namespace StardewModdingAPI public static void RunGame() { - Application.ThreadException += Log.Application_ThreadException; + Application.ThreadException += StardewModdingAPI.Log.Application_ThreadException; Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); - AppDomain.CurrentDomain.UnhandledException += Log.CurrentDomain_UnhandledException; + AppDomain.CurrentDomain.UnhandledException += StardewModdingAPI.Log.CurrentDomain_UnhandledException; try { gamePtr = new SGame(); - Log.Verbose("Patching SDV Graphics Profile..."); + StardewModdingAPI.Log.Verbose("Patching SDV Graphics Profile..."); Game1.graphics.GraphicsProfile = GraphicsProfile.HiDef; LoadMods(); @@ -319,7 +319,7 @@ namespace StardewModdingAPI } catch (Exception ex) { - Log.Error("Game failed to start: " + ex); + StardewModdingAPI.Log.Error("Game failed to start: " + ex); } } @@ -338,7 +338,7 @@ namespace StardewModdingAPI public static void LoadMods() { - Log.Verbose("LOADING MODS"); + StardewModdingAPI.Log.Verbose("LOADING MODS"); int loadedMods = 0; foreach (string ModPath in ModPaths) { @@ -346,14 +346,14 @@ namespace StardewModdingAPI { if (s.Contains("StardewInjector")) continue; - Log.Success("Found DLL: " + s); + StardewModdingAPI.Log.Success("Found DLL: " + s); try { Assembly mod = Assembly.UnsafeLoadFrom(s); //to combat internet-downloaded DLLs if (mod.DefinedTypes.Count(x => x.BaseType == typeof(Mod)) > 0) { - Log.Verbose("Loading Mod DLL..."); + StardewModdingAPI.Log.Verbose("Loading Mod DLL..."); TypeInfo tar = mod.DefinedTypes.First(x => x.BaseType == typeof(Mod)); Mod m = (Mod)mod.CreateInstance(tar.ToString()); Console.WriteLine("LOADED MOD: {0} by {1} - Version {2} | Description: {3}", m.Name, m.Authour, m.Version, m.Description); @@ -362,16 +362,16 @@ namespace StardewModdingAPI } else { - Log.Error("Invalid Mod DLL"); + StardewModdingAPI.Log.Error("Invalid Mod DLL"); } } catch (Exception ex) { - Log.Error("Failed to load mod '{0}'. Exception details:\n" + ex, s); + StardewModdingAPI.Log.Error("Failed to load mod '{0}'. Exception details:\n" + ex, s); } } } - Log.Success("LOADED {0} MODS", loadedMods); + StardewModdingAPI.Log.Success("LOADED {0} MODS", loadedMods); } public static void ConsoleInputThread() @@ -386,7 +386,7 @@ namespace StardewModdingAPI static void Events_LoadContent(object o, EventArgs e) { - Log.Info("Initializing Debug Assets..."); + StardewModdingAPI.Log.Info("Initializing Debug Assets..."); DebugPixel = new Texture2D(Game1.graphics.GraphicsDevice, 1, 1); DebugPixel.SetData(new Color[] { Color.White }); @@ -422,7 +422,7 @@ namespace StardewModdingAPI static void Events_MenuChanged(IClickableMenu newMenu) { - Log.Verbose("NEW MENU: " + newMenu.GetType()); + StardewModdingAPI.Log.Verbose("NEW MENU: " + newMenu.GetType()); if (newMenu is GameMenu) { Game1.activeClickableMenu = SGameMenu.ConstructFromBaseClass(Game1.activeClickableMenu as GameMenu); @@ -461,17 +461,79 @@ namespace StardewModdingAPI { Command fnd = Command.FindCommand(e.Command.CalledArgs[0]); if (fnd == null) - Log.Error("The command specified could not be found"); + StardewModdingAPI.Log.Error("The command specified could not be found"); else { if (fnd.CommandArgs.Length > 0) - Log.Info("{0}: {1} - {2}", fnd.CommandName, fnd.CommandDesc, fnd.CommandArgs.ToSingular()); + StardewModdingAPI.Log.Info("{0}: {1} - {2}", fnd.CommandName, fnd.CommandDesc, fnd.CommandArgs.ToSingular()); else - Log.Info("{0}: {1}", fnd.CommandName, fnd.CommandDesc); + StardewModdingAPI.Log.Info("{0}: {1}", fnd.CommandName, fnd.CommandDesc); } } else - Log.Info("Commands: " + Command.RegisteredCommands.Select(x => x.CommandName).ToSingular()); + StardewModdingAPI.Log.Info("Commands: " + Command.RegisteredCommands.Select(x => x.CommandName).ToSingular()); } + + #region Logging + [Obsolete("This method is obsolete and will be removed in v0.39, please use the appropriate methods in the Log class")] + public static void Log(object o, params object[] format) + { + StardewModdingAPI.Log.Info(o, format); + } + + [Obsolete("This method is obsolete and will be removed in v0.39, please use the appropriate methods in the Log class")] + public static void LogColour(ConsoleColor c, object o, params object[] format) + { + StardewModdingAPI.Log.Info(o, format); + } + + [Obsolete("This method is obsolete and will be removed in v0.39, please use the appropriate methods in the Log class")] + public static void LogInfo(object o, params object[] format) + { + StardewModdingAPI.Log.Info(o, format); + } + + [Obsolete("This method is obsolete and will be removed in v0.39, please use the appropriate methods in the Log class")] + public static void LogError(object o, params object[] format) + { + StardewModdingAPI.Log.Error(o, format); + } + + [Obsolete("This method is obsolete and will be removed in v0.39, please use the appropriate methods in the Log class")] + public static void LogDebug(object o, params object[] format) + { + StardewModdingAPI.Log.Debug(o, format); + } + + [Obsolete("This method is obsolete and will be removed in v0.39, please use the appropriate methods in the Log class")] + public static void LogValueNotSpecified() + { + StardewModdingAPI.Log.Error(" must be specified"); + } + + [Obsolete("This method is obsolete and will be removed in v0.39, please use the appropriate methods in the Log class")] + public static void LogObjectValueNotSpecified() + { + StardewModdingAPI.Log.Error(" and must be specified"); + } + + [Obsolete("This method is obsolete and will be removed in v0.39, please use the appropriate methods in the Log class")] + public static void LogValueInvalid() + { + StardewModdingAPI.Log.Error(" is invalid"); + } + + [Obsolete("This method is obsolete and will be removed in v0.39, please use the appropriate methods in the Log class")] + public static void LogObjectInvalid() + { + StardewModdingAPI.Log.Error(" is invalid"); + } + + [Obsolete("This method is obsolete and will be removed in v0.39, please use the appropriate methods in the Log class")] + public static void LogValueNotInt32() + { + StardewModdingAPI.Log.Error(" must be a whole number (Int32)"); + } + #endregion } } \ No newline at end of file From 1fbbd653a251c2a5c6bdeff7397b09ee27dadcc2 Mon Sep 17 00:00:00 2001 From: ClxS Date: Sun, 6 Mar 2016 16:48:43 +0000 Subject: [PATCH 2/5] Added version.cs --- StardewModdingAPI/Program.cs | 8 +++----- StardewModdingAPI/StardewModdingAPI.csproj | 1 + StardewModdingAPI/Version.cs | 23 ++++++++++++++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 StardewModdingAPI/Version.cs diff --git a/StardewModdingAPI/Program.cs b/StardewModdingAPI/Program.cs index da7df466..161ae9b2 100644 --- a/StardewModdingAPI/Program.cs +++ b/StardewModdingAPI/Program.cs @@ -36,9 +36,7 @@ namespace StardewModdingAPI public static Thread gameThread; public static Thread consoleInputThread; - - public const string Version = "0.36 Alpha"; - + public static bool StardewInjectorLoaded { get; private set; } public static Mod StardewInjectorMod { get; private set; } @@ -48,7 +46,7 @@ namespace StardewModdingAPI { Console.Title = "Stardew Modding API Console"; - Console.Title += " - Version " + Version; + Console.Title += " - Version " + Version.VersionString; #if DEBUG Console.Title += " - DEBUG IS NOT FALSE, AUTHOUR NEEDS TO REUPLOAD THIS VERSION"; #endif @@ -189,7 +187,7 @@ namespace StardewModdingAPI //Change the game's version StardewModdingAPI.Log.Info("Injecting New SDV Version..."); - Game1.version += "-Z_MODDED | SMAPI " + Version; + Game1.version += "-Z_MODDED | SMAPI " + Version.VersionString; //Create the thread for the game to run in. gameThread = new Thread(RunGame); diff --git a/StardewModdingAPI/StardewModdingAPI.csproj b/StardewModdingAPI/StardewModdingAPI.csproj index dde32d41..8d9dc4ba 100644 --- a/StardewModdingAPI/StardewModdingAPI.csproj +++ b/StardewModdingAPI/StardewModdingAPI.csproj @@ -121,6 +121,7 @@ + diff --git a/StardewModdingAPI/Version.cs b/StardewModdingAPI/Version.cs new file mode 100644 index 00000000..10c541ab --- /dev/null +++ b/StardewModdingAPI/Version.cs @@ -0,0 +1,23 @@ +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); + } + } + } +} From bc84a66a6fd2dd3b334eaf8405ef8b4fc6b4acc0 Mon Sep 17 00:00:00 2001 From: ClxS Date: Sun, 6 Mar 2016 17:53:37 +0000 Subject: [PATCH 3/5] Updated readme --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 286bd089..70e895c8 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,7 @@ A Modding API For Stardew Valley See: https://github.com/Zoryn4163/SMAPI-Mods ## NOTICE: THIS PROJECT IS STILL IN ALPHA + + +##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 From 126ce53618719f6734125669e1466f681be49a78 Mon Sep 17 00:00:00 2001 From: ClxS Date: Sun, 6 Mar 2016 18:01:52 +0000 Subject: [PATCH 4/5] 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 From bfe6537f84fe780197c4554f360f19c3f9f12371 Mon Sep 17 00:00:00 2001 From: ClxS Date: Sun, 6 Mar 2016 19:46:47 +0000 Subject: [PATCH 5/5] 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);