From 4e26cb7abc6fb699f0df9ddf1d50bc3ef2fe01c6 Mon Sep 17 00:00:00 2001 From: ClxS Date: Thu, 3 Mar 2016 18:50:22 +0000 Subject: Resolved static analysis issues Standardised event handlers so there's less hassle with future changes --- Release/StardewModdingAPI.exe | Bin 67072 -> 71168 bytes StardewModdingAPI/Command.cs | 5 +- StardewModdingAPI/EventArgs.cs | 116 ++ StardewModdingAPI/Events.cs | 314 ++-- StardewModdingAPI/Extensions.cs | 2 +- StardewModdingAPI/Inheritance/SGame.cs | 42 +- StardewModdingAPI/Inheritance/SObject.cs | 2 +- StardewModdingAPI/Program.cs | 1026 ++++++------- StardewModdingAPI/StardewModdingAPI.csproj | 215 +-- .../StardewModdingAPI.csproj.FileListAbsolute.txt | 66 +- TrainerMod/TrainerMod.cs | 1546 ++++++++++---------- TrainerMod/bin/Debug/TrainerMod.dll | Bin 23552 -> 0 bytes 12 files changed, 1717 insertions(+), 1617 deletions(-) create mode 100644 StardewModdingAPI/EventArgs.cs delete mode 100644 TrainerMod/bin/Debug/TrainerMod.dll diff --git a/Release/StardewModdingAPI.exe b/Release/StardewModdingAPI.exe index 24cc0edd..06f57e1f 100644 Binary files a/Release/StardewModdingAPI.exe and b/Release/StardewModdingAPI.exe differ diff --git a/StardewModdingAPI/Command.cs b/StardewModdingAPI/Command.cs index c65e8122..f0162a4d 100644 --- a/StardewModdingAPI/Command.cs +++ b/StardewModdingAPI/Command.cs @@ -14,8 +14,7 @@ namespace StardewModdingAPI public String CommandDesc; public String[] CommandArgs; public String[] CalledArgs; - public delegate void CommandFireHandler(Command cmd); - public event CommandFireHandler CommandFired; + public event EventHandler CommandFired; /// /// Calls the specified command. (It runs the command) @@ -105,7 +104,7 @@ namespace StardewModdingAPI Program.LogError("Command failed to fire because it's fire event is null: " + CommandName); return; } - CommandFired.Invoke(this); + CommandFired.Invoke(this, null); } } } diff --git a/StardewModdingAPI/EventArgs.cs b/StardewModdingAPI/EventArgs.cs new file mode 100644 index 00000000..c8119bf8 --- /dev/null +++ b/StardewModdingAPI/EventArgs.cs @@ -0,0 +1,116 @@ +using Microsoft.Xna.Framework.Input; +using StardewValley; +using StardewValley.Menus; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StardewModdingAPI +{ + public class EventArgsKeyboardStateChanged : EventArgs + { + public EventArgsKeyboardStateChanged(KeyboardState priorState, KeyboardState newState) + { + NewState = newState; + NewState = newState; + } + public KeyboardState NewState { get; private set; } + public KeyboardState PriorState { get; private set; } + } + + public class EventArgsKeyPressed : EventArgs + { + public EventArgsKeyPressed(Keys keyPressed) + { + KeyPressed = keyPressed; + } + public Keys KeyPressed { get; private set; } + } + + public class EventArgsMouseStateChanged : EventArgs + { + public EventArgsMouseStateChanged(MouseState priorState, MouseState newState) + { + NewState = newState; + NewState = newState; + } + public MouseState NewState { get; private set; } + public MouseState PriorState { get; private set; } + } + + public class EventArgsClickableMenuChanged : EventArgs + { + public EventArgsClickableMenuChanged(IClickableMenu priorMenu, IClickableMenu newMenu) + { + NewMenu = newMenu; + PriorMenu = priorMenu; + } + public IClickableMenu NewMenu { get; private set; } + public IClickableMenu PriorMenu { get; private set; } + } + + public class EventArgsGameLocationsChanged : EventArgs + { + public EventArgsGameLocationsChanged(List newLocations) + { + NewLocations = newLocations; + } + public List NewLocations { get; private set; } + } + + public class EventArgsCurrentLocationChanged : EventArgs + { + public EventArgsCurrentLocationChanged(GameLocation priorLocation, GameLocation newLocation) + { + NewLocation = newLocation; + PriorLocation = priorLocation; + } + public GameLocation NewLocation { get; private set; } + public GameLocation PriorLocation { get; private set; } + } + + public class EventArgsFarmerChanged : EventArgs + { + public EventArgsFarmerChanged(Farmer priorFarmer, Farmer newFarmer) + { + NewFarmer = NewFarmer; + PriorFarmer = PriorFarmer; + } + public Farmer NewFarmer { get; private set; } + public Farmer PriorFarmer { get; private set; } + } + + public class EventArgsIntChanged : EventArgs + { + public EventArgsIntChanged(Int32 priorInt, Int32 newInt) + { + NewInt = NewInt; + PriorInt = PriorInt; + } + public Int32 NewInt { get; private set; } + public Int32 PriorInt { get; private set; } + } + + public class EventArgsStringChanged : EventArgs + { + public EventArgsStringChanged(String priorString, String newString) + { + NewString = newString; + PriorString = priorString; + } + public String NewString { get; private set; } + public String PriorString { get; private set; } + } + + public class EventArgsCommand : EventArgs + { + public EventArgsCommand(Command command) + { + Command = command; + } + public Command Command { get; private set; } + } +} + diff --git a/StardewModdingAPI/Events.cs b/StardewModdingAPI/Events.cs index 97e55d8d..e8e9727c 100644 --- a/StardewModdingAPI/Events.cs +++ b/StardewModdingAPI/Events.cs @@ -1,166 +1,148 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Microsoft.Xna.Framework.Input; -using StardewValley; -using StardewValley.Menus; - -namespace StardewModdingAPI -{ - public static class Events - { - public delegate void BlankEventHandler(); - - public static event BlankEventHandler GameLoaded = delegate { }; - public static event BlankEventHandler Initialize = delegate { }; - public static event BlankEventHandler LoadContent = delegate { }; - public static event BlankEventHandler UpdateTick = delegate { }; - public static event BlankEventHandler DrawTick = delegate { }; - - public delegate void KStateChanged(KeyboardState newState); - public static event KStateChanged KeyboardChanged = delegate { }; - - public delegate void KeyStateChanged(Keys key); - public static event KeyStateChanged KeyPressed = delegate { }; - - public delegate void MStateChanged(MouseState newState); - public static event MStateChanged MouseChanged = delegate { }; - - public delegate void ClickableMenuChanged(IClickableMenu newMenu); - public static event ClickableMenuChanged MenuChanged = delegate { }; - - public delegate void GameLocationsChanged(List newLocations); - public static event GameLocationsChanged LocationsChanged = delegate { }; - - public delegate void CurrentLocationsChanged(GameLocation newLocation); - public static event CurrentLocationsChanged CurrentLocationChanged = delegate { }; - - public static event EventHandler Resize = delegate { }; - - public delegate void FarmerChangedD(Farmer newFarmer); - public static event FarmerChangedD FarmerChanged = delegate { }; - - public delegate void IntChanged(Int32 newInt); - public static event IntChanged TimeOfDayChanged = delegate { }; - public static event IntChanged DayOfMonthChanged = delegate { }; - public static event IntChanged YearOfGameChanged = delegate { }; - - public delegate void StringChanged(String newString); - public static event StringChanged SeasonOfYearChanged = delegate { }; - - public static void InvokeGameLoaded() - { - GameLoaded.Invoke(); - } - - public static void InvokeInitialize() - { - try - { - Initialize.Invoke(); - } - catch (Exception ex) - { - Program.LogError("An exception occured in XNA Initialize: " + ex.ToString()); - } - } - - public static void InvokeLoadContent() - { - try - { - LoadContent.Invoke(); - } - catch (Exception ex) - { - Program.LogError("An exception occured in XNA LoadContent: " + ex.ToString()); - } - } - - public static void InvokeUpdateTick() - { - try - { - UpdateTick.Invoke(); - } - catch (Exception ex) - { - Program.LogError("An exception occured in XNA UpdateTick: " + ex.ToString()); - } - } - - public static void InvokeDrawTick() - { - try - { - DrawTick.Invoke(); - } - catch (Exception ex) - { - Program.LogError("An exception occured in XNA DrawTick: " + ex.ToString()); - } - } - - public static void InvokeKeyboardChanged(KeyboardState newState) - { - KeyboardChanged.Invoke(newState); - } - - public static void InvokeMouseChanged(MouseState newState) - { - MouseChanged.Invoke(newState); - } - - public static void InvokeKeyPressed(Keys key) - { - KeyPressed.Invoke(key); - } - - public static void InvokeMenuChanged(IClickableMenu newMenu) - { - MenuChanged.Invoke(newMenu); - } - - public static void InvokeLocationsChanged(List newLocations) - { - LocationsChanged.Invoke(newLocations); - } - - public static void InvokeCurrentLocationChanged(GameLocation newLocation) - { - CurrentLocationChanged.Invoke(newLocation); - } - - public static void InvokeResize(object sender, EventArgs e) - { - Resize.Invoke(sender, e); - } - - public static void InvokeFarmerChanged(Farmer newFarmer) - { - FarmerChanged.Invoke(newFarmer); - } - - public static void InvokeTimeOfDayChanged(Int32 newInt) - { - TimeOfDayChanged.Invoke(newInt); - } - - public static void InvokeDayOfMonthChanged(Int32 newInt) - { - DayOfMonthChanged.Invoke(newInt); - } - - public static void InvokeYearOfGameChanged(Int32 newInt) - { - YearOfGameChanged.Invoke(newInt); - } - - public static void InvokeSeasonOfYearChanged(String newString) - { - SeasonOfYearChanged.Invoke(newString); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework.Input; +using StardewValley; +using StardewValley.Menus; + +namespace StardewModdingAPI +{ + public static class Events + { + public delegate void BlankEventHandler(object sender, EventArgs e); + + public static event BlankEventHandler GameLoaded = delegate { }; + public static event BlankEventHandler Initialize = delegate { }; + public static event BlankEventHandler LoadContent = delegate { }; + public static event BlankEventHandler UpdateTick = delegate { }; + public static event BlankEventHandler DrawTick = delegate { }; + + public static event EventHandler KeyboardChanged = delegate { }; + public static event EventHandler KeyPressed = delegate { }; + public static event EventHandler MouseChanged = delegate { }; + public static event EventHandler MenuChanged = delegate { }; + public static event EventHandler LocationsChanged = delegate { }; + public static event EventHandler CurrentLocationChanged = delegate { }; + public static event EventHandler Resize = delegate { }; + public static event EventHandler FarmerChanged = delegate { }; + public static event EventHandler TimeOfDayChanged = delegate { }; + public static event EventHandler DayOfMonthChanged = delegate { }; + public static event EventHandler YearOfGameChanged = delegate { }; + public static event EventHandler SeasonOfYearChanged = delegate { }; + + public static void InvokeGameLoaded() + { + GameLoaded.Invoke(null, EventArgs.Empty); + } + + public static void InvokeInitialize() + { + try + { + Initialize.Invoke(null, EventArgs.Empty); + } + catch (Exception ex) + { + Program.LogError("An exception occured in XNA Initialize: " + ex.ToString()); + } + } + + public static void InvokeLoadContent() + { + try + { + LoadContent.Invoke(null, EventArgs.Empty); + } + catch (Exception ex) + { + Program.LogError("An exception occured in XNA LoadContent: " + ex.ToString()); + } + } + + public static void InvokeUpdateTick() + { + try + { + UpdateTick.Invoke(null, EventArgs.Empty); + } + catch (Exception ex) + { + Program.LogError("An exception occured in XNA UpdateTick: " + ex.ToString()); + } + } + + public static void InvokeDrawTick() + { + try + { + DrawTick.Invoke(null, EventArgs.Empty); + } + catch (Exception ex) + { + Program.LogError("An exception occured in XNA DrawTick: " + ex.ToString()); + } + } + + public static void InvokeKeyboardChanged(KeyboardState priorState, KeyboardState newState) + { + KeyboardChanged.Invoke(null, new EventArgsKeyboardStateChanged(priorState, newState)); + } + + public static void InvokeMouseChanged(MouseState priorState, MouseState newState) + { + MouseChanged.Invoke(null, new EventArgsMouseStateChanged(priorState, newState)); + } + + public static void InvokeKeyPressed(Keys key) + { + KeyPressed.Invoke(null, new EventArgsKeyPressed(key)); + } + + public static void InvokeMenuChanged(IClickableMenu priorMenu, IClickableMenu newMenu) + { + MenuChanged.Invoke(null, new EventArgsClickableMenuChanged(priorMenu, newMenu)); + } + + public static void InvokeLocationsChanged(List newLocations) + { + LocationsChanged.Invoke(null, new EventArgsGameLocationsChanged(newLocations)); + } + + public static void InvokeCurrentLocationChanged(GameLocation priorLocation, GameLocation newLocation) + { + CurrentLocationChanged.Invoke(null, new EventArgsCurrentLocationChanged(priorLocation, newLocation)); + } + + public static void InvokeResize(object sender, EventArgs e) + { + Resize.Invoke(sender, e); + } + + public static void InvokeFarmerChanged(Farmer priorFarmer, Farmer newFarmer) + { + FarmerChanged.Invoke(null, new EventArgsFarmerChanged(priorFarmer, newFarmer)); + } + + public static void InvokeTimeOfDayChanged(Int32 priorInt, Int32 newInt) + { + TimeOfDayChanged.Invoke(null, new EventArgsIntChanged(priorInt, newInt)); + } + + public static void InvokeDayOfMonthChanged(Int32 priorInt, Int32 newInt) + { + DayOfMonthChanged.Invoke(null, new EventArgsIntChanged(priorInt, newInt)); + } + + public static void InvokeYearOfGameChanged(Int32 priorInt, Int32 newInt) + { + YearOfGameChanged.Invoke(null, new EventArgsIntChanged(priorInt, newInt)); + } + + public static void InvokeSeasonOfYearChanged(String priorString, String newString) + { + SeasonOfYearChanged.Invoke(null, new EventArgsStringChanged(priorString, newString)); + } + } +} diff --git a/StardewModdingAPI/Extensions.cs b/StardewModdingAPI/Extensions.cs index 8b99be1c..d2d8dce8 100644 --- a/StardewModdingAPI/Extensions.cs +++ b/StardewModdingAPI/Extensions.cs @@ -45,7 +45,7 @@ namespace StardewModdingAPI string s = string.Empty; foreach (var v in enumerable) { - s += v.GetHashCode(); + s += v.GetHashCode().ToString(); } return s.GetHashCode(); } diff --git a/StardewModdingAPI/Inheritance/SGame.cs b/StardewModdingAPI/Inheritance/SGame.cs index bed57e34..21fbea70 100644 --- a/StardewModdingAPI/Inheritance/SGame.cs +++ b/StardewModdingAPI/Inheritance/SGame.cs @@ -170,14 +170,14 @@ namespace StardewModdingAPI.Inheritance { return ModItems.ElementAt(id).Value.Clone(); } - Program.LogError("ModItem Dictionary does not contain index: " + id); + Program.LogError("ModItem Dictionary does not contain index: " + id.ToString()); return null; } if (ModItems.ContainsKey(id)) { return ModItems[id].Clone(); } - Program.LogError("ModItem Dictionary does not contain ID: " + id); + Program.LogError("ModItem Dictionary does not contain ID: " + id.ToString()); return null; } @@ -226,62 +226,62 @@ namespace StardewModdingAPI.Inheritance Events.InvokeKeyPressed(k); if (KStateNow != KStatePrior) - { - Events.InvokeKeyboardChanged(KStateNow); + { + Events.InvokeKeyboardChanged(KStatePrior, KStateNow); KStatePrior = KStateNow; } if (MStateNow != MStatePrior) - { - Events.InvokeMouseChanged(MStateNow); + { + Events.InvokeMouseChanged(MStatePrior, MStateNow); MStatePrior = MStateNow; } if (activeClickableMenu != null && activeClickableMenu != PreviousActiveMenu) - { - Events.InvokeMenuChanged(activeClickableMenu); + { + Events.InvokeMenuChanged(PreviousActiveMenu, activeClickableMenu); PreviousActiveMenu = activeClickableMenu; } if (locations.GetHash() != PreviousGameLocations) - { + { Events.InvokeLocationsChanged(locations); PreviousGameLocations = locations.GetHash(); } if (currentLocation != PreviousGameLocation) - { - Events.InvokeCurrentLocationChanged(currentLocation); + { + Events.InvokeCurrentLocationChanged(PreviousGameLocation, currentLocation); PreviousGameLocation = currentLocation; } if (player != null && player != PreviousFarmer) - { - Events.InvokeFarmerChanged(player); + { + Events.InvokeFarmerChanged(PreviousFarmer, player); PreviousFarmer = player; } if (timeOfDay != PreviousTimeOfDay) - { - Events.InvokeTimeOfDayChanged(timeOfDay); + { + Events.InvokeTimeOfDayChanged(PreviousTimeOfDay, timeOfDay); PreviousTimeOfDay = timeOfDay; } if (dayOfMonth != PreviousDayOfMonth) - { - Events.InvokeDayOfMonthChanged(dayOfMonth); + { + Events.InvokeDayOfMonthChanged(PreviousDayOfMonth, dayOfMonth); PreviousDayOfMonth = dayOfMonth; } if (currentSeason != PreviousSeasonOfYear) - { - Events.InvokeSeasonOfYearChanged(currentSeason); + { + Events.InvokeSeasonOfYearChanged(PreviousSeasonOfYear, currentSeason); PreviousSeasonOfYear = currentSeason; } if (year != PreviousYearOfGame) - { - Events.InvokeYearOfGameChanged(year); + { + Events.InvokeYearOfGameChanged(PreviousYearOfGame, year); PreviousYearOfGame = year; } } diff --git a/StardewModdingAPI/Inheritance/SObject.cs b/StardewModdingAPI/Inheritance/SObject.cs index 023106b8..25cdb26e 100644 --- a/StardewModdingAPI/Inheritance/SObject.cs +++ b/StardewModdingAPI/Inheritance/SObject.cs @@ -132,7 +132,7 @@ namespace StardewModdingAPI.Inheritance if (drawStackNumber) { float scale = 0.5f + scaleSize; - Game1.drawWithBorder(string.Concat(this.stack), Color.Black, Color.White, location + new Vector2((float) Game1.tileSize - Game1.tinyFont.MeasureString(string.Concat(this.stack)).X * scale, (float) Game1.tileSize - (float) ((double) Game1.tinyFont.MeasureString(string.Concat(this.stack)).Y * 3.0f / 4.0f) * scale), 0.0f, scale, 1f, true); + Game1.drawWithBorder(string.Concat(this.stack.ToString()), Color.Black, Color.White, location + new Vector2((float) Game1.tileSize - Game1.tinyFont.MeasureString(string.Concat(this.stack.ToString())).X * scale, (float) Game1.tileSize - (float) ((double) Game1.tinyFont.MeasureString(string.Concat(this.stack.ToString())).Y * 3.0f / 4.0f) * scale), 0.0f, scale, 1f, true); } } diff --git a/StardewModdingAPI/Program.cs b/StardewModdingAPI/Program.cs index 313fcbe5..0903a9b9 100644 --- a/StardewModdingAPI/Program.cs +++ b/StardewModdingAPI/Program.cs @@ -1,513 +1,513 @@ -using System; -using System.CodeDom.Compiler; -using System.Collections.Generic; -using System.ComponentModel; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Reflection.Emit; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using System.Windows.Forms; -using Microsoft.CSharp; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using Microsoft.Xna.Framework.Input; -using StardewModdingAPI.Inheritance; -using StardewModdingAPI.Inheritance.Menus; -using StardewValley; -using StardewValley.Menus; -using StardewValley.Minigames; -using StardewValley.Network; -using StardewValley.Tools; -using Keys = Microsoft.Xna.Framework.Input.Keys; -using Object = StardewValley.Object; - -namespace StardewModdingAPI -{ - public class Program - { - 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 LogPath = Path.Combine(Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley")), "ErrorLogs"); - public static string CurrentLog { get; private set; } - public static StreamWriter LogStream { get; private set; } - - public static Texture2D DebugPixel { get; private set; } - - public static SGame gamePtr; - public static bool ready; - - public static Assembly StardewAssembly; - public static Type StardewProgramType; - public static FieldInfo StardewGameInfo; - public static Form StardewForm; - - public static Thread gameThread; - public static Thread consoleInputThread; - - public const string Version = "0.36 Alpha"; - public const bool debug = true; - public static bool disableLogging { get; private set; } - - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - - - private static void Main(string[] args) - { - Console.Title = "Stardew Modding API Console"; - - Console.Title += " - Version " + Version; - if (debug) - Console.Title += " - DEBUG IS NOT FALSE, AUTHOUR NEEDS TO REUPLOAD THIS VERSION"; - - //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")); - - //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) - { - - LogError("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) - { - LogError("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) - { - LogError("Could not create the missing ErrorLogs path: " + LogPath + "\n\n" + ex); - } - - //Define the path to the current log file - CurrentLog = LogPath + "\\MODDED_ProgramLog_LATEST"/* + System.DateTime.Now.Ticks + */ + ".txt"; - - Log(ExecutionPath, false); - - //Create a writer to the log file - try - { - LogStream = new StreamWriter(CurrentLog, false); - } - catch (Exception ex) - { - disableLogging = true; - LogError("Could not initialize LogStream - Logging is disabled"); - } - - - LogInfo("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. - LogError("Could not find: " + ExecutionPath + "\\Stardew Valley.exe"); - LogError("The API will now terminate."); - Console.ReadKey(); - Environment.Exit(-4); - } - - //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"); - - //Change the game's version - LogInfo("Injecting New SDV Version..."); - Game1.version += "-Z_MODDED | SMAPI " + Version; - - //Create the thread for the game to run in. - gameThread = new Thread(RunGame); - LogInfo("Starting SDV..."); - gameThread.Start(); - - //I forget. - SGame.GetStaticFields(); - - while (!ready) - { - //Wait for the game to load up - } - - //SDV is running - Log("SDV Loaded Into Memory"); - - //Create definition to listen for input - LogInfo("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; - //Command.RegisterCommand("crash", "crashes sdv").CommandFired += delegate { Game1.player.draw(null); }; - - //Subscribe to events - Events.KeyPressed += Events_KeyPressed; - Events.LoadContent += Events_LoadContent; - //Events.MenuChanged += Events_MenuChanged; //Idk right now - if (debug) - { - //Experimental - //Events.LocationsChanged += Events_LocationsChanged; - //Events.CurrentLocationChanged += Events_CurrentLocationChanged; - } - - //Do tweaks using winforms invoke because I'm lazy - LogInfo("Applying Final SDV Tweaks..."); - StardewInvoke(() => - { - gamePtr.IsMouseVisible = false; - gamePtr.Window.Title = "Stardew Valley - Version " + Game1.version; - StardewForm.Resize += Events.InvokeResize; - }); - - //Game's in memory now, send the event - LogInfo("Game Loaded"); - Events.InvokeGameLoaded(); - - LogColour(ConsoleColor.Cyan, "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(); - - LogInfo("Game Execution Finished"); - LogInfo("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); - } - - - - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - - - public static void RunGame() - { - //Does this even do anything??? - Application.ThreadException += Application_ThreadException; - Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); - AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; - //I've yet to see it called :| - - try - { - gamePtr = new SGame(); - LogInfo("Patching SDV Graphics Profile..."); - Game1.graphics.GraphicsProfile = GraphicsProfile.HiDef; - LoadMods(); - - StardewForm = Control.FromHandle(Program.gamePtr.Window.Handle).FindForm(); - StardewForm.Closing += StardewForm_Closing; - StardewGameInfo.SetValue(StardewProgramType, gamePtr); - - ready = true; - - gamePtr.Run(); - } - catch (Exception ex) - { - LogError("Game failed to start: " + ex); - } - } - - static void StardewForm_Closing(object sender, CancelEventArgs e) - { - e.Cancel = true; - gamePtr.Exit(); - gamePtr.Dispose(); - StardewForm.Hide(); - ready = false; - } - - public static void LoadMods() - { - LogColour(ConsoleColor.Green, "LOADING MODS"); - int loadedMods = 0; - foreach (string ModPath in ModPaths) - { - foreach (String s in Directory.GetFiles(ModPath, "*.dll")) - { - LogColour(ConsoleColor.Green, "Found DLL: " + s); - try - { - Assembly mod = Assembly.UnsafeLoadFrom(s); //to combat internet-downloaded DLLs - - if (mod.DefinedTypes.Count(x => x.BaseType == typeof (Mod)) > 0) - { - LogColour(ConsoleColor.Green, "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); - loadedMods += 1; - m.Entry(); - } - else - { - LogError("Invalid Mod DLL"); - } - } - catch (Exception ex) - { - LogError("Failed to load mod '{0}'. Exception details:\n" + ex, s); - } - } - } - LogColour(ConsoleColor.Green, "LOADED {0} MODS", loadedMods); - } - - public static void ConsoleInputThread() - { - string input = string.Empty; - - while (true) - { - Command.CallCommand(Console.ReadLine()); - } - } - - static void Events_LoadContent() - { - LogInfo("Initializing Debug Assets..."); - DebugPixel = new Texture2D(Game1.graphics.GraphicsDevice, 1, 1); - DebugPixel.SetData(new Color[] { Color.White }); - - if (debug) - { - LogColour(ConsoleColor.Magenta, "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; - LogColour(ConsoleColor.Cyan, "REGISTERED WITH ID OF: " + SGame.RegisterModItem(so)); - - LogColour(ConsoleColor.Magenta, "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; - LogColour(ConsoleColor.Cyan, "REGISTERED WITH ID OF: " + SGame.RegisterModItem(so2)); - } - - if (debug) - Command.CallCommand("load"); - } - - static void Events_KeyPressed(Keys key) - { - - } - - static void Events_MenuChanged(IClickableMenu newMenu) - { - LogInfo("NEW MENU: " + newMenu.GetType()); - if (newMenu is GameMenu) - { - Game1.activeClickableMenu = SGameMenu.ConstructFromBaseClass(Game1.activeClickableMenu as GameMenu); - } - } - - static void Events_LocationsChanged(List newLocations) - { - if (debug) - { - SGame.ModLocations = SGameLocation.ConstructFromBaseClasses(Game1.locations); - } - } - - 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); - } - //Game1.currentLocation = SGame.CurrentLocation; - //LogInfo(((SGameLocation) newLocation).name); - //LogInfo("LOC CHANGED: " + SGame.currentLocation.name); - } - - public static void StardewInvoke(Action a) - { - StardewForm.Invoke(a); - } - - static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) - { - Console.WriteLine("An exception has been caught"); - File.WriteAllText(Program.LogPath + "\\MODDED_ErrorLog_" + Extensions.Random.Next(100000000, 999999999) + ".txt", e.ExceptionObject.ToString()); - } - - static void Application_ThreadException(object sender, ThreadExceptionEventArgs e) - { - Console.WriteLine("A thread exception has been caught"); - File.WriteAllText(Program.LogPath + "\\MODDED_ErrorLog_" + Extensions.Random.Next(100000000, 999999999) + ".txt", e.Exception.ToString()); - } - - static void help_CommandFired(Command cmd) - { - if (cmd.CalledArgs.Length > 0) - { - Command fnd = Command.FindCommand(cmd.CalledArgs[0]); - if (fnd == null) - LogError("The command specified could not be found"); - else - { - if (fnd.CommandArgs.Length > 0) - LogInfo("{0}: {1} - {2}", fnd.CommandName, fnd.CommandDesc, fnd.CommandArgs.ToSingular()); - else - LogInfo("{0}: {1}", fnd.CommandName, fnd.CommandDesc); - } - } - else - LogInfo("Commands: " + Command.RegisteredCommands.Select(x => x.CommandName).ToSingular()); - } - - #region Logging - - public static void Log(object o, params object[] format) - { - if (format.Length > 0) - { - if (format[0] is bool) - { - if ((bool)format[0] == false) - { - //suppress logging to file - Console.WriteLine("[{0}] {1}", System.DateTime.Now.ToLongTimeString(), String.Format(o.ToString(), format)); - return; - } - } - } - string toLog = string.Format("[{0}] {1}", System.DateTime.Now.ToLongTimeString(), String.Format(o.ToString(), format)); - Console.WriteLine(toLog); - - if (!disableLogging) - { - LogStream.WriteLine(toLog); - LogStream.Flush(); - } - } - - public static void LogColour(ConsoleColor c, object o, params object[] format) - { - Console.ForegroundColor = c; - Log(o.ToString(), format); - Console.ForegroundColor = ConsoleColor.Gray; - } - - public static void LogInfo(object o, params object[] format) - { - Console.ForegroundColor = ConsoleColor.Yellow; - Log(o.ToString(), format); - Console.ForegroundColor = ConsoleColor.Gray; - } - - public static void LogError(object o, params object[] format) - { - Console.ForegroundColor = ConsoleColor.Red; - Log(o.ToString(), format); - Console.ForegroundColor = ConsoleColor.Gray; - } - - public static void LogDebug(object o, params object[] format) - { - if (!debug) - return; - Console.ForegroundColor = ConsoleColor.DarkYellow; - Log(o.ToString(), format); - Console.ForegroundColor = ConsoleColor.Gray; - } - - public static void LogValueNotSpecified() - { - LogError(" must be specified"); - } - - public static void LogObjectValueNotSpecified() - { - LogError(" and must be specified"); - } - - public static void LogValueInvalid() - { - LogError(" is invalid"); - } - - public static void LogObjectInvalid() - { - LogError(" is invalid"); - } - - public static void LogValueNotInt32() - { - LogError(" must be a whole number (Int32)"); - } - - #endregion - } -} +using System; +using System.CodeDom.Compiler; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Reflection.Emit; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Forms; +using Microsoft.CSharp; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; +using StardewModdingAPI.Inheritance; +using StardewModdingAPI.Inheritance.Menus; +using StardewValley; +using StardewValley.Menus; +using StardewValley.Minigames; +using StardewValley.Network; +using StardewValley.Tools; +using Keys = Microsoft.Xna.Framework.Input.Keys; +using Object = StardewValley.Object; + +namespace StardewModdingAPI +{ + public class Program + { + 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 LogPath = Path.Combine(Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley")), "ErrorLogs"); + public static string CurrentLog { get; private set; } + public static StreamWriter LogStream { get; private set; } + + public static Texture2D DebugPixel { get; private set; } + + public static SGame gamePtr; + public static bool ready; + + public static Assembly StardewAssembly; + public static Type StardewProgramType; + public static FieldInfo StardewGameInfo; + public static Form StardewForm; + + public static Thread gameThread; + public static Thread consoleInputThread; + + public const string Version = "0.36 Alpha"; + public const bool debug = true; + public static bool disableLogging { get; private set; } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + [STAThread] + private static void Main(string[] args) + { + Console.Title = "Stardew Modding API Console"; + + Console.Title += " - Version " + Version; + if (debug) + Console.Title += " - DEBUG IS NOT FALSE, AUTHOUR NEEDS TO REUPLOAD THIS VERSION"; + + //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")); + + //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) + { + + LogError("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) + { + LogError("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) + { + LogError("Could not create the missing ErrorLogs path: " + LogPath + "\n\n" + ex); + } + + //Define the path to the current log file + CurrentLog = LogPath + "\\MODDED_ProgramLog_LATEST"/* + System.DateTime.Now.Ticks + */ + ".txt"; + + Log(ExecutionPath, false); + + //Create a writer to the log file + try + { + LogStream = new StreamWriter(CurrentLog, false); + } + catch (Exception ex) + { + disableLogging = true; + LogError("Could not initialize LogStream - Logging is disabled"); + } + + + LogInfo("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. + LogError("Could not find: " + ExecutionPath + "\\Stardew Valley.exe"); + LogError("The API will now terminate."); + Console.ReadKey(); + Environment.Exit(-4); + } + + //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"); + + //Change the game's version + LogInfo("Injecting New SDV Version..."); + Game1.version += "-Z_MODDED | SMAPI " + Version; + + //Create the thread for the game to run in. + gameThread = new Thread(RunGame); + LogInfo("Starting SDV..."); + gameThread.Start(); + + //I forget. + SGame.GetStaticFields(); + + while (!ready) + { + //Wait for the game to load up + } + + //SDV is running + Log("SDV Loaded Into Memory"); + + //Create definition to listen for input + LogInfo("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; + //Command.RegisterCommand("crash", "crashes sdv").CommandFired += delegate { Game1.player.draw(null); }; + + //Subscribe to events + Events.KeyPressed += Events_KeyPressed; + Events.LoadContent += Events_LoadContent; + //Events.MenuChanged += Events_MenuChanged; //Idk right now + if (debug) + { + //Experimental + //Events.LocationsChanged += Events_LocationsChanged; + //Events.CurrentLocationChanged += Events_CurrentLocationChanged; + } + + //Do tweaks using winforms invoke because I'm lazy + LogInfo("Applying Final SDV Tweaks..."); + StardewInvoke(() => + { + gamePtr.IsMouseVisible = false; + gamePtr.Window.Title = "Stardew Valley - Version " + Game1.version; + StardewForm.Resize += Events.InvokeResize; + }); + + //Game's in memory now, send the event + LogInfo("Game Loaded"); + Events.InvokeGameLoaded(); + + LogColour(ConsoleColor.Cyan, "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(); + + LogInfo("Game Execution Finished"); + LogInfo("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); + } + + + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + + + public static void RunGame() + { + //Does this even do anything??? + Application.ThreadException += Application_ThreadException; + Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); + AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; + //I've yet to see it called :| + + try + { + gamePtr = new SGame(); + LogInfo("Patching SDV Graphics Profile..."); + Game1.graphics.GraphicsProfile = GraphicsProfile.HiDef; + LoadMods(); + + StardewForm = Control.FromHandle(Program.gamePtr.Window.Handle).FindForm(); + StardewForm.Closing += StardewForm_Closing; + StardewGameInfo.SetValue(StardewProgramType, gamePtr); + + ready = true; + + gamePtr.Run(); + } + catch (Exception ex) + { + LogError("Game failed to start: " + ex); + } + } + + static void StardewForm_Closing(object sender, CancelEventArgs e) + { + e.Cancel = true; + gamePtr.Exit(); + gamePtr.Dispose(); + StardewForm.Hide(); + ready = false; + } + + public static void LoadMods() + { + LogColour(ConsoleColor.Green, "LOADING MODS"); + int loadedMods = 0; + foreach (string ModPath in ModPaths) + { + foreach (String s in Directory.GetFiles(ModPath, "*.dll")) + { + LogColour(ConsoleColor.Green, "Found DLL: " + s); + try + { + Assembly mod = Assembly.UnsafeLoadFrom(s); //to combat internet-downloaded DLLs + + if (mod.DefinedTypes.Count(x => x.BaseType == typeof (Mod)) > 0) + { + LogColour(ConsoleColor.Green, "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); + loadedMods += 1; + m.Entry(); + } + else + { + LogError("Invalid Mod DLL"); + } + } + catch (Exception ex) + { + LogError("Failed to load mod '{0}'. Exception details:\n" + ex, s); + } + } + } + LogColour(ConsoleColor.Green, "LOADED {0} MODS", loadedMods); + } + + public static void ConsoleInputThread() + { + string input = string.Empty; + + while (true) + { + Command.CallCommand(Console.ReadLine()); + } + } + + static void Events_LoadContent(object sender, EventArgs e) + { + LogInfo("Initializing Debug Assets..."); + DebugPixel = new Texture2D(Game1.graphics.GraphicsDevice, 1, 1); + DebugPixel.SetData(new Color[] { Color.White }); + + if (debug) + { + LogColour(ConsoleColor.Magenta, "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; + LogColour(ConsoleColor.Cyan, "REGISTERED WITH ID OF: " + SGame.RegisterModItem(so)); + + LogColour(ConsoleColor.Magenta, "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; + LogColour(ConsoleColor.Cyan, "REGISTERED WITH ID OF: " + SGame.RegisterModItem(so2)); + } + + if (debug) + Command.CallCommand("load"); + } + + static void Events_KeyPressed(object key, EventArgs e) + { + + } + + static void Events_MenuChanged(IClickableMenu newMenu) + { + LogInfo("NEW MENU: " + newMenu.GetType()); + if (newMenu is GameMenu) + { + Game1.activeClickableMenu = SGameMenu.ConstructFromBaseClass(Game1.activeClickableMenu as GameMenu); + } + } + + static void Events_LocationsChanged(List newLocations) + { + if (debug) + { + SGame.ModLocations = SGameLocation.ConstructFromBaseClasses(Game1.locations); + } + } + + 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); + } + //Game1.currentLocation = SGame.CurrentLocation; + //LogInfo(((SGameLocation) newLocation).name); + //LogInfo("LOC CHANGED: " + SGame.currentLocation.name); + } + + public static void StardewInvoke(Action a) + { + StardewForm.Invoke(a); + } + + static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) + { + Console.WriteLine("An exception has been caught"); + File.WriteAllText(Program.LogPath + "\\MODDED_ErrorLog_" + Extensions.Random.Next(100000000, 999999999) + ".txt", e.ExceptionObject.ToString()); + } + + static void Application_ThreadException(object sender, ThreadExceptionEventArgs e) + { + Console.WriteLine("A thread exception has been caught"); + File.WriteAllText(Program.LogPath + "\\MODDED_ErrorLog_" + Extensions.Random.Next(100000000, 999999999) + ".txt", e.Exception.ToString()); + } + + static void help_CommandFired(object sender, EventArgs e) + { + Command cmd = sender as Command; + if (cmd.CalledArgs.Length > 0) + { + Command fnd = Command.FindCommand(cmd.CalledArgs[0]); + if (fnd == null) + LogError("The command specified could not be found"); + else + { + if (fnd.CommandArgs.Length > 0) + LogInfo("{0}: {1} - {2}", fnd.CommandName, fnd.CommandDesc, fnd.CommandArgs.ToSingular()); + else + LogInfo("{0}: {1}", fnd.CommandName, fnd.CommandDesc); + } + } + else + LogInfo("Commands: " + Command.RegisteredCommands.Select(x => x.CommandName).ToSingular()); + } + + #region Logging + + public static void Log(object o, params object[] format) + { + if (format.Length > 0) + { + if (format[0] is bool) + { + if ((bool)format[0] == false) + { + //suppress logging to file + Console.WriteLine("[{0}] {1}", System.DateTime.Now.ToLongTimeString(), String.Format(o.ToString(), format)); + return; + } + } + } + string toLog = string.Format("[{0}] {1}", System.DateTime.Now.ToLongTimeString(), String.Format(o.ToString(), format)); + Console.WriteLine(toLog); + + if (!disableLogging) + { + LogStream.WriteLine(toLog); + LogStream.Flush(); + } + } + + public static void LogColour(ConsoleColor c, object o, params object[] format) + { + Console.ForegroundColor = c; + Log(o.ToString(), format); + Console.ForegroundColor = ConsoleColor.Gray; + } + + public static void LogInfo(object o, params object[] format) + { + Console.ForegroundColor = ConsoleColor.Yellow; + Log(o.ToString(), format); + Console.ForegroundColor = ConsoleColor.Gray; + } + + public static void LogError(object o, params object[] format) + { + Console.ForegroundColor = ConsoleColor.Red; + Log(o.ToString(), format); + Console.ForegroundColor = ConsoleColor.Gray; + } + + public static void LogDebug(object o, params object[] format) + { + if (!debug) + return; + Console.ForegroundColor = ConsoleColor.DarkYellow; + Log(o.ToString(), format); + Console.ForegroundColor = ConsoleColor.Gray; + } + + public static void LogValueNotSpecified() + { + LogError(" must be specified"); + } + + public static void LogObjectValueNotSpecified() + { + LogError(" and must be specified"); + } + + public static void LogValueInvalid() + { + LogError(" is invalid"); + } + + public static void LogObjectInvalid() + { + LogError(" is invalid"); + } + + public static void LogValueNotInt32() + { + LogError(" must be a whole number (Int32)"); + } + + #endregion + } +} diff --git a/StardewModdingAPI/StardewModdingAPI.csproj b/StardewModdingAPI/StardewModdingAPI.csproj index 9ca0a64b..58ad0399 100644 --- a/StardewModdingAPI/StardewModdingAPI.csproj +++ b/StardewModdingAPI/StardewModdingAPI.csproj @@ -1,114 +1,115 @@ - - - - - Debug - AnyCPU - {F1A573B0-F436-472C-AE29-0B91EA6B9F8F} - Exe - Properties - StardewModdingAPI - StardewModdingAPI - v4.5 - 512 - SAK - SAK - SAK - SAK - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - x86 - bin\x86\Debug\ - - - x86 - bin\x86\Release\ - - - icon.ico - - - - False - - - - - - - False - ..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Stardew Valley\Stardew Valley.exe - False - False - - - - - - - - - - - - False - D:\#Network-Steam\SteamRepo\steamapps\common\Stardew Valley\xTile.dll - False - - - - - - - - - - - - - - - - - - - - - - - - - PreserveNewest - - - - - copy /y "$(SolutionDir)$(ProjectName)\$(OutDir)StardewModdingAPI.exe" "$(SolutionDir)Release\" - + + + + + Debug + AnyCPU + {F1A573B0-F436-472C-AE29-0B91EA6B9F8F} + Exe + Properties + StardewModdingAPI + StardewModdingAPI + v4.5 + 512 + SAK + SAK + SAK + SAK + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + x86 + bin\x86\Debug\ + + + x86 + bin\x86\Release\ + + + icon.ico + + + + False + + + + + + + False + ..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Stardew Valley\Stardew Valley.exe + False + False + + + + + + + + + + + + False + D:\#Network-Steam\SteamRepo\steamapps\common\Stardew Valley\xTile.dll + False + + + + + + + + + + + + + + + + + + + + + + + + + + PreserveNewest + + + + + copy /y "$(SolutionDir)$(ProjectName)\$(OutDir)StardewModdingAPI.exe" "$(SolutionDir)Release\" + + --> \ No newline at end of file diff --git a/StardewModdingAPI/obj/x86/Debug/StardewModdingAPI.csproj.FileListAbsolute.txt b/StardewModdingAPI/obj/x86/Debug/StardewModdingAPI.csproj.FileListAbsolute.txt index c86a6fc8..0d8f693b 100644 --- a/StardewModdingAPI/obj/x86/Debug/StardewModdingAPI.csproj.FileListAbsolute.txt +++ b/StardewModdingAPI/obj/x86/Debug/StardewModdingAPI.csproj.FileListAbsolute.txt @@ -1,32 +1,34 @@ -C:\Users\Zoryn\Documents\Visual Studio 2013\Projects\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\Stardew Valley.exe -C:\Users\Zoryn\Documents\Visual Studio 2013\Projects\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\xTile.dll -C:\Users\Zoryn\Documents\Visual Studio 2013\Projects\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\Lidgren.Network.dll -C:\Users\Zoryn\Documents\Visual Studio 2013\Projects\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\Steamworks.NET.dll -C:\Users\Zoryn\Documents\Visual Studio 2013\Projects\StardewModdingAPI\StardewModdingAPI\obj\x86\Debug\StardewModdingAPI.csprojResolveAssemblyReference.cache -C:\Users\Zoryn\Documents\Visual Studio 2013\Projects\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\WindowsGame1.exe -C:\Users\Zoryn\Documents\Visual Studio 2013\Projects\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\WindowsGame1.pdb -C:\Users\Zoryn\Documents\Visual Studio 2013\Projects\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\StardewModdingAPI.exe.config -C:\Users\Zoryn\Documents\Visual Studio 2013\Projects\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\StardewModdingAPI.exe -C:\Users\Zoryn\Documents\Visual Studio 2013\Projects\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\StardewModdingAPI.pdb -C:\Users\Zoryn\Documents\Visual Studio 2013\Projects\StardewModdingAPI\StardewModdingAPI\obj\x86\Debug\StardewModdingAPI.exe -C:\Users\Zoryn\Documents\Visual Studio 2013\Projects\StardewModdingAPI\StardewModdingAPI\obj\x86\Debug\StardewModdingAPI.pdb -C:\Users\Zoryn\Documents\Visual Studio 2013\Projects\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\Stardew Valley.pdb -C:\Users\zoryn\Desktop\SDV\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\StardewModdingAPI.exe.config -C:\Users\zoryn\Desktop\SDV\StardewModdingAPI\StardewModdingAPI\obj\x86\Debug\StardewModdingAPI.exe -C:\Users\zoryn\Desktop\SDV\StardewModdingAPI\StardewModdingAPI\obj\x86\Debug\StardewModdingAPI.pdb -C:\Users\zoryn\Desktop\SDV\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\StardewModdingAPI.exe -C:\Users\zoryn\Desktop\SDV\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\StardewModdingAPI.pdb -C:\Users\zoryn\Desktop\SDV\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\Stardew Valley.exe -C:\Users\zoryn\Desktop\SDV\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\WindowsGame1.exe -C:\Users\zoryn\Desktop\SDV\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\xTile.dll -C:\Users\zoryn\Desktop\SDV\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\Lidgren.Network.dll -C:\Users\zoryn\Desktop\SDV\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\Steamworks.NET.dll -C:\Users\zoryn\Desktop\SDV\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\WindowsGame1.pdb -C:\Users\zoryn\Desktop\SDV\StardewModdingAPI\StardewModdingAPI\obj\x86\Debug\StardewModdingAPI.csprojResolveAssemblyReference.cache -C:\TFSource\Master-Collection\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\steam_appid.txt -C:\TFSource\Master-Collection\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\StardewModdingAPI.exe.config -C:\TFSource\Master-Collection\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\StardewModdingAPI.exe -C:\TFSource\Master-Collection\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\StardewModdingAPI.pdb -C:\TFSource\Master-Collection\StardewModdingAPI\StardewModdingAPI\obj\x86\Debug\StardewModdingAPI.exe -C:\TFSource\Master-Collection\StardewModdingAPI\StardewModdingAPI\obj\x86\Debug\StardewModdingAPI.pdb -C:\TFSource\Master-Collection\StardewModdingAPI\StardewModdingAPI\obj\x86\Debug\StardewModdingAPI.csprojResolveAssemblyReference.cache +C:\Users\Zoryn\Documents\Visual Studio 2013\Projects\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\Stardew Valley.exe +C:\Users\Zoryn\Documents\Visual Studio 2013\Projects\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\xTile.dll +C:\Users\Zoryn\Documents\Visual Studio 2013\Projects\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\Lidgren.Network.dll +C:\Users\Zoryn\Documents\Visual Studio 2013\Projects\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\Steamworks.NET.dll +C:\Users\Zoryn\Documents\Visual Studio 2013\Projects\StardewModdingAPI\StardewModdingAPI\obj\x86\Debug\StardewModdingAPI.csprojResolveAssemblyReference.cache +C:\Users\Zoryn\Documents\Visual Studio 2013\Projects\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\WindowsGame1.exe +C:\Users\Zoryn\Documents\Visual Studio 2013\Projects\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\WindowsGame1.pdb +C:\Users\Zoryn\Documents\Visual Studio 2013\Projects\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\StardewModdingAPI.exe.config +C:\Users\Zoryn\Documents\Visual Studio 2013\Projects\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\StardewModdingAPI.exe +C:\Users\Zoryn\Documents\Visual Studio 2013\Projects\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\StardewModdingAPI.pdb +C:\Users\Zoryn\Documents\Visual Studio 2013\Projects\StardewModdingAPI\StardewModdingAPI\obj\x86\Debug\StardewModdingAPI.exe +C:\Users\Zoryn\Documents\Visual Studio 2013\Projects\StardewModdingAPI\StardewModdingAPI\obj\x86\Debug\StardewModdingAPI.pdb +C:\Users\Zoryn\Documents\Visual Studio 2013\Projects\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\Stardew Valley.pdb +C:\Users\zoryn\Desktop\SDV\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\StardewModdingAPI.exe.config +C:\Users\zoryn\Desktop\SDV\StardewModdingAPI\StardewModdingAPI\obj\x86\Debug\StardewModdingAPI.exe +C:\Users\zoryn\Desktop\SDV\StardewModdingAPI\StardewModdingAPI\obj\x86\Debug\StardewModdingAPI.pdb +C:\Users\zoryn\Desktop\SDV\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\StardewModdingAPI.exe +C:\Users\zoryn\Desktop\SDV\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\StardewModdingAPI.pdb +C:\Users\zoryn\Desktop\SDV\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\Stardew Valley.exe +C:\Users\zoryn\Desktop\SDV\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\WindowsGame1.exe +C:\Users\zoryn\Desktop\SDV\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\xTile.dll +C:\Users\zoryn\Desktop\SDV\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\Lidgren.Network.dll +C:\Users\zoryn\Desktop\SDV\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\Steamworks.NET.dll +C:\Users\zoryn\Desktop\SDV\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\WindowsGame1.pdb +C:\Users\zoryn\Desktop\SDV\StardewModdingAPI\StardewModdingAPI\obj\x86\Debug\StardewModdingAPI.csprojResolveAssemblyReference.cache +C:\TFSource\Master-Collection\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\steam_appid.txt +C:\TFSource\Master-Collection\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\StardewModdingAPI.exe.config +C:\TFSource\Master-Collection\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\StardewModdingAPI.exe +C:\TFSource\Master-Collection\StardewModdingAPI\StardewModdingAPI\bin\x86\Debug\StardewModdingAPI.pdb +C:\TFSource\Master-Collection\StardewModdingAPI\StardewModdingAPI\obj\x86\Debug\StardewModdingAPI.exe +C:\TFSource\Master-Collection\StardewModdingAPI\StardewModdingAPI\obj\x86\Debug\StardewModdingAPI.pdb +C:\TFSource\Master-Collection\StardewModdingAPI\StardewModdingAPI\obj\x86\Debug\StardewModdingAPI.csprojResolveAssemblyReference.cache +Z:\Projects\C#\SMAPI\StardewModdingAPI\obj\x86\Debug\StardewModdingAPI.exe +Z:\Projects\C#\SMAPI\StardewModdingAPI\obj\x86\Debug\StardewModdingAPI.pdb diff --git a/TrainerMod/TrainerMod.cs b/TrainerMod/TrainerMod.cs index 4aa2167f..aea740c4 100644 --- a/TrainerMod/TrainerMod.cs +++ b/TrainerMod/TrainerMod.cs @@ -1,773 +1,773 @@ -using StardewModdingAPI; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Mime; -using System.Text; -using System.Threading.Tasks; -using StardewModdingAPI.Inheritance; -using StardewValley; -using StardewValley.Tools; -using Microsoft.Xna.Framework; -using StardewValley.Objects; - -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; - - public override void Entry() - { - RegisterCommands(); - Events.UpdateTick += Events_UpdateTick; - } - - static void Events_UpdateTick() - { - if (Game1.player == null) - return; - - if (infHealth) - { - Game1.player.health = Game1.player.maxHealth; - } - if (infStamina) - { - Game1.player.stamina = Game1.player.MaxStamina; - } - if (infMoney) - { - Game1.player.money = 999999; - } - if (freezeTime) - { - Game1.timeOfDay = frozenTime; - } - } - - public static void RegisterCommands() - { - 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; - - Command.RegisterCommand("exit", "Closes the game | exit").CommandFired += exit_CommandFired; - Command.RegisterCommand("stop", "Closes the game | stop").CommandFired += exit_CommandFired; - - Command.RegisterCommand("player_setname", "Sets the player's name | player_setname ", new[] { "(player, pet, farm) (String) The target name" }).CommandFired += player_setName; - Command.RegisterCommand("player_setmoney", "Sets the player's money | player_setmoney |inf", new[] { "(Int32) The target money" }).CommandFired += player_setMoney; - Command.RegisterCommand("player_setstamina", "Sets the player's stamina | player_setstamina |inf", new[] { "(Int32) The target stamina" }).CommandFired += player_setStamina; - Command.RegisterCommand("player_setmaxstamina", "Sets the player's max stamina | player_setmaxstamina ", new[] { "(Int32) The target max stamina" }).CommandFired += player_setMaxStamina; - Command.RegisterCommand("player_sethealth", "Sets the player's health | player_sethealth |inf", new[] { "(Int32) The target health" }).CommandFired += player_setHealth; - Command.RegisterCommand("player_setmaxhealth", "Sets the player's max health | player_setmaxhealth ", new[] { "(Int32) The target max health" }).CommandFired += player_setMaxHealth; - Command.RegisterCommand("player_setimmunity", "Sets the player's immunity | player_setimmunity ", new[] { "(Int32) The target immunity" }).CommandFired += player_setImmunity; - - Command.RegisterCommand("player_setlevel", "Sets the player's specified skill to the specified value | player_setlevel ", new[] { "(luck, mining, combat, farming, fishing, foraging) (1-10) The target level" }).CommandFired += player_setLevel; - Command.RegisterCommand("player_setspeed", "Sets the player's speed to the specified value?", new[] { "(Int32) The target speed [0 is normal]" }).CommandFired += player_setSpeed; - Command.RegisterCommand("player_changecolour", "Sets the player's colour of the specified object | player_changecolor ", new[] { "(hair, eyes, pants) (r,g,b)" }).CommandFired += player_changeColour; - Command.RegisterCommand("player_changestyle", "Sets the player's style of the specified object | player_changecolor ", new[] { "(hair, shirt, skin, acc, shoe, swim, gender) (Int32)" }).CommandFired += player_changeStyle; - - Command.RegisterCommand("player_additem", "Gives the player an item | player_additem [count] [quality]", new[] { "(Int32) (Int32)[count] (Int32)[quality]" }).CommandFired += player_addItem; - Command.RegisterCommand("player_addmelee", "Gives the player a melee item | player_addmelee ", new[] { "?" }).CommandFired += player_addMelee; - Command.RegisterCommand("player_addring", "Gives the player a ring | player_addring ", new[] { "?" }).CommandFired += player_addRing; - - Command.RegisterCommand("out_items", "Outputs a list of items | out_items", new[] { "" }).CommandFired += out_items; - Command.RegisterCommand("out_melee", "Outputs a list of melee weapons | out_melee", new[] { "" }).CommandFired += out_melee; - Command.RegisterCommand("out_rings", "Outputs a list of rings | out_rings", new[] { "" }).CommandFired += out_rings; - Command.RegisterCommand("newitem", "Outputs a list of melee weapons | out_melee", new[] { "" }).CommandFired += RegisterNewItem; - - Command.RegisterCommand("world_settime", "Sets the time to the specified value | world_settime ", new[] { "(Int32) The target time [06:00 AM is 600]" }).CommandFired += world_setTime; - Command.RegisterCommand("world_freezetime", "Freezes or thaws time | world_freezetime ", new[] { "(0 - 1) Whether or not to freeze time. 0 is thawed, 1 is frozen" }).CommandFired += world_freezeTime; - Command.RegisterCommand("world_setday", "Sets the day to the specified value | world_setday ", new[] { "(Int32) The target day [1-28]" }).CommandFired += world_setDay; - Command.RegisterCommand("world_setseason", "Sets the season to the specified value | world_setseason ", new[] { "(winter, spring, summer, fall) The target season" }).CommandFired += world_setSeason; - Command.RegisterCommand("world_downminelevel", "Goes down one mine level? | world_downminelevel", new[] { "" }).CommandFired += world_downMineLevel; - Command.RegisterCommand("world_setminelevel", "Sets mine level? | world_setminelevel", new[] { "(Int32) The target level" }).CommandFired += world_setMineLevel; - } - - static void types_CommandFired(Command cmd) - { - Program.LogInfo("[Int32: {0} - {1}], [Int64: {2} - {3}], [String: \"raw text\"], [Colour: r,g,b (EG: 128, 32, 255)]", Int32.MinValue, Int32.MaxValue, Int64.MinValue, Int64.MaxValue); - } - - static void hide_CommandFired(Command cmd) - { - Program.StardewInvoke(() => { Program.StardewForm.Hide(); }); - } - - static void show_CommandFired(Command cmd) - { - Program.StardewInvoke(() => { Program.StardewForm.Show(); }); - } - - static void save_CommandFired(Command cmd) - { - StardewValley.SaveGame.Save(); - } - - static void load_CommandFired(Command cmd) - { - Game1.activeClickableMenu = new StardewValley.Menus.LoadGameMenu(); - } - - static void exit_CommandFired(Command cmd) - { - Program.gamePtr.Exit(); - Environment.Exit(0); - } - - static void player_setName(Command cmd) - { - if (cmd.CalledArgs.Length > 1) - { - string obj = cmd.CalledArgs[0]; - string[] objs = "player,pet,farm".Split(new[] { ',' }); - if (objs.Contains(obj)) - { - switch (obj) - { - case "player": - Game1.player.Name = cmd.CalledArgs[1]; - break; - case "pet": - Program.LogError("Pets cannot currently be renamed."); - break; - case "farm": - Game1.player.farmName = cmd.CalledArgs[1]; - break; - } - } - else - { - Program.LogObjectInvalid(); - } - } - else - { - Program.LogObjectValueNotSpecified(); - } - } - - static void player_setMoney(Command cmd) - { - if (cmd.CalledArgs.Length > 0) - { - if (cmd.CalledArgs[0] == "inf") - { - infMoney = true; - } - else - { - infMoney = false; - int ou = 0; - if (Int32.TryParse(cmd.CalledArgs[0], out ou)) - { - Game1.player.Money = ou; - Program.LogInfo("Set {0}'s money to {1}", Game1.player.Name, Game1.player.Money); - } - else - { - Program.LogValueNotInt32(); - } - } - } - else - { - Program.LogValueNotSpecified(); - } - } - - static void player_setStamina(Command cmd) - { - if (cmd.CalledArgs.Length > 0) - { - if (cmd.CalledArgs[0] == "inf") - { - infStamina = true; - } - else - { - infStamina = false; - int ou = 0; - if (Int32.TryParse(cmd.CalledArgs[0], out ou)) - { - Game1.player.Stamina = ou; - Program.LogInfo("Set {0}'s stamina to {1}", Game1.player.Name, Game1.player.Stamina); - } - else - { - Program.LogValueNotInt32(); - } - } - } - else - { - Program.LogValueNotSpecified(); - } - } - - static void player_setMaxStamina(Command cmd) - { - if (cmd.CalledArgs.Length > 0) - { - int ou = 0; - if (Int32.TryParse(cmd.CalledArgs[0], out ou)) - { - Game1.player.MaxStamina = ou; - Program.LogInfo("Set {0}'s max stamina to {1}", Game1.player.Name, Game1.player.MaxStamina); - } - else - { - Program.LogValueNotInt32(); - } - } - else - { - Program.LogValueNotSpecified(); - } - } - - static void player_setLevel(Command cmd) - { - if (cmd.CalledArgs.Length > 1) - { - string skill = cmd.CalledArgs[0]; - string[] skills = "luck,mining,combat,farming,fishing,foraging".Split(new[] { ',' }); - if (skills.Contains(skill)) - { - int ou = 0; - if (Int32.TryParse(cmd.CalledArgs[1], out ou)) - { - switch (skill) - { - case "luck": - Game1.player.LuckLevel = ou; - break; - case "mining": - Game1.player.MiningLevel = ou; - break; - case "combat": - Game1.player.CombatLevel = ou; - break; - case "farming": - Game1.player.FarmingLevel = ou; - break; - case "fishing": - Game1.player.FishingLevel = ou; - break; - case "foraging": - Game1.player.ForagingLevel = ou; - break; - } - } - else - { - Program.LogValueNotInt32(); - } - } - else - { - Program.LogError(" is invalid"); - } - } - else - { - Program.LogError(" and must be specified"); - } - } - - static void player_setSpeed(Command cmd) - { - if (cmd.CalledArgs.Length > 0) - { - if (cmd.CalledArgs[0].IsInt32()) - { - Game1.player.addedSpeed = cmd.CalledArgs[0].AsInt32(); - Program.LogInfo("Set {0}'s added speed to {1}", Game1.player.Name, Game1.player.addedSpeed); - } - else - { - Program.LogValueNotInt32(); - } - } - else - { - Program.LogValueNotSpecified(); - } - } - - static void player_changeColour(Command cmd) - { - if (cmd.CalledArgs.Length > 1) - { - string obj = cmd.CalledArgs[0]; - string[] objs = "hair,eyes,pants".Split(new[] { ',' }); - if (objs.Contains(obj)) - { - string[] cs = cmd.CalledArgs[1].Split(new[] { ',' }, 3); - if (cs[0].IsInt32() && cs[1].IsInt32() && cs[2].IsInt32()) - { - Color c = new Color(cs[0].AsInt32(), cs[1].AsInt32(), cs[2].AsInt32()); - switch (obj) - { - case "hair": - Game1.player.hairstyleColor = c; - break; - case "eyes": - Game1.player.changeEyeColor(c); - break; - case "pants": - Game1.player.pantsColor = c; - break; - } - } - else - { - Program.LogError(" is invalid"); - } - } - else - { - Program.LogObjectInvalid(); - } - } - else - { - Program.LogError(" and must be specified"); - } - } - - static void player_changeStyle(Command cmd) - { - if (cmd.CalledArgs.Length > 1) - { - string obj = cmd.CalledArgs[0]; - string[] objs = "hair,shirt,skin,acc,shoe,swim,gender".Split(new[] { ',' }); - if (objs.Contains(obj)) - { - if (cmd.CalledArgs[1].IsInt32()) - { - int i = cmd.CalledArgs[1].AsInt32(); - switch (obj) - { - case "hair": - Game1.player.changeHairStyle(i); - break; - case "shirt": - Game1.player.changeShirt(i); - break; - case "acc": - Game1.player.changeAccessory(i); - break; - case "skin": - Game1.player.changeSkinColor(i); - break; - case "shoe": - Game1.player.changeShoeColor(i); - break; - case "swim": - if (i == 0) - Game1.player.changeOutOfSwimSuit(); - else if (i == 1) - Game1.player.changeIntoSwimsuit(); - else - Program.LogError(" must be 0 or 1 for this "); - break; - case "gender": - if (i == 0) - Game1.player.changeGender(true); - else if (i == 1) - Game1.player.changeGender(false); - else - Program.LogError(" must be 0 or 1 for this "); - break; - } - } - else - { - Program.LogValueInvalid(); - } - } - else - { - Program.LogObjectInvalid(); - } - } - else - { - Program.LogObjectValueNotSpecified(); - } - } - - static void world_freezeTime(Command cmd) - { - if (cmd.CalledArgs.Length > 0) - { - if (cmd.CalledArgs[0].IsInt32()) - { - if (cmd.CalledArgs[0].AsInt32() == 0 || cmd.CalledArgs[0].AsInt32() == 1) - { - freezeTime = cmd.CalledArgs[0].AsInt32() == 1; - frozenTime = freezeTime ? Game1.timeOfDay : 0; - Program.LogInfo("Time is now " + (freezeTime ? "frozen" : "thawed")); - } - else - { - Program.LogError(" should be 0 or 1"); - } - } - else - { - Program.LogValueNotInt32(); - } - } - else - { - Program.LogValueNotSpecified(); - } - } - - static void world_setTime(Command cmd) - { - if (cmd.CalledArgs.Length > 0) - { - if (cmd.CalledArgs[0].IsInt32()) - { - if (cmd.CalledArgs[0].AsInt32() <= 2600 && cmd.CalledArgs[0].AsInt32() >= 600) - { - Game1.timeOfDay = cmd.CalledArgs[0].AsInt32(); - frozenTime = freezeTime ? Game1.timeOfDay : 0; - Program.LogInfo("Time set to: " + Game1.timeOfDay); - } - else - { - Program.LogError(" should be between 600 and 2600 (06:00 AM - 02:00 AM [NEXT DAY])"); - } - } - else - { - Program.LogValueNotInt32(); - } - } - else - { - Program.LogValueNotSpecified(); - } - } - - static void world_setDay(Command cmd) - { - if (cmd.CalledArgs.Length > 0) - { - if (cmd.CalledArgs[0].IsInt32()) - { - if (cmd.CalledArgs[0].AsInt32() <= 28 && cmd.CalledArgs[0].AsInt32() > 0) - { - Game1.dayOfMonth = cmd.CalledArgs[0].AsInt32(); - } - else - { - Program.LogError(" must be between 1 and 28"); - } - } - else - { - Program.LogValueNotInt32(); - } - } - else - { - Program.LogValueNotSpecified(); - } - } - - static void world_setSeason(Command cmd) - { - if (cmd.CalledArgs.Length > 0) - { - string obj = cmd.CalledArgs[0]; - string[] objs = "winter,spring,summer,fall".Split(new[] { ',' }); - if (objs.Contains(obj)) - { - Game1.currentSeason = obj; - } - else - { - Program.LogValueInvalid(); - } - } - else - { - Program.LogValueNotSpecified(); - } - } - - static void player_setHealth(Command cmd) - { - if (cmd.CalledArgs.Length > 0) - { - if (cmd.CalledArgs[0] == "inf") - { - infHealth = true; - } - else - { - infHealth = false; - if (cmd.CalledArgs[0].IsInt32()) - { - Game1.player.health = cmd.CalledArgs[0].AsInt32(); - } - else - { - Program.LogValueNotInt32(); - } - } - } - else - { - Program.LogValueNotSpecified(); - } - } - - static void player_setMaxHealth(Command cmd) - { - if (cmd.CalledArgs.Length > 0) - { - if (cmd.CalledArgs[0].IsInt32()) - { - Game1.player.maxHealth = cmd.CalledArgs[0].AsInt32(); - } - else - { - Program.LogValueNotInt32(); - } - } - else - { - Program.LogValueNotSpecified(); - } - } - - static void player_setImmunity(Command cmd) - { - if (cmd.CalledArgs.Length > 0) - { - if (cmd.CalledArgs[0].IsInt32()) - { - Game1.player.immunity = cmd.CalledArgs[0].AsInt32(); - } - else - { - Program.LogValueNotInt32(); - } - } - else - { - Program.LogValueNotSpecified(); - } - } - - static void player_addItem(Command cmd) - { - if (cmd.CalledArgs.Length > 0) - { - if (cmd.CalledArgs[0].IsInt32()) - { - int count = 1; - int quality = 0; - if (cmd.CalledArgs.Length > 1) - { - Console.WriteLine(cmd.CalledArgs[1]); - if (cmd.CalledArgs[1].IsInt32()) - { - count = cmd.CalledArgs[1].AsInt32(); - } - else - { - Program.LogError("[count] is invalid"); - return; - } - - if (cmd.CalledArgs.Length > 2) - { - if (cmd.CalledArgs[2].IsInt32()) - { - quality = cmd.CalledArgs[2].AsInt32(); - } - else - { - Program.LogError("[quality] is invalid"); - return; - } - - } - } - - StardewValley.Object o = new StardewValley.Object(cmd.CalledArgs[0].AsInt32(), count); - o.quality = quality; - - Game1.player.addItemByMenuIfNecessary((Item)o); - } - else - { - Program.LogError(" is invalid"); - } - } - else - { - Program.LogObjectValueNotSpecified(); - } - } - - static void player_addMelee(Command cmd) - { - if (cmd.CalledArgs.Length > 0) - { - if (cmd.CalledArgs[0].IsInt32()) - { - - MeleeWeapon toAdd = new MeleeWeapon(cmd.CalledArgs[0].AsInt32()); - Game1.player.addItemByMenuIfNecessary(toAdd); - Program.LogInfo("Given {0} to {1}", toAdd.Name, Game1.player.Name); - } - else - { - Program.LogError(" is invalid"); - } - } - else - { - Program.LogObjectValueNotSpecified(); - } - } - - static void player_addRing(Command cmd) - { - if (cmd.CalledArgs.Length > 0) - { - if (cmd.CalledArgs[0].IsInt32()) - { - - Ring toAdd = new Ring(cmd.CalledArgs[0].AsInt32()); - Game1.player.addItemByMenuIfNecessary(toAdd); - Program.LogInfo("Given {0} to {1}", toAdd.Name, Game1.player.Name); - } - else - { - Program.LogError(" is invalid"); - } - } - else - { - Program.LogObjectValueNotSpecified(); - } - } - - static void out_items(Command cmd) - { - for (int i = 0; i < 1000; i++) - { - try - { - Item it = new StardewValley.Object(i, 1); - if (it.Name != "Error Item") - Console.WriteLine(i + "| " + it.Name); - } - catch - { - - } - } - } - - static void out_melee(Command cmd) - { - Dictionary d = Game1.content.Load>("Data\\weapons"); - Console.Write("DATA\\WEAPONS: "); - foreach (var v in d) - { - Console.WriteLine(v.Key + " | " + v.Value); - } - } - - static void out_rings(Command cmd) - { - for (int i = 0; i < 100; i++) - { - try - { - Item it = new Ring(i); - if (it.Name != "Error Item") - Console.WriteLine(i + "| " + it.Name); - } - catch - { - - } - } - } - - static void world_downMineLevel(Command cmd) - { - Game1.nextMineLevel(); - } - - static void world_setMineLevel(Command cmd) - { - if (cmd.CalledArgs.Length > 0) - { - if (cmd.CalledArgs[0].IsInt32()) - { - Game1.enterMine(true, cmd.CalledArgs[0].AsInt32(), ""); - } - else - { - Program.LogValueNotInt32(); - } - } - else - { - Program.LogValueNotSpecified(); - } - } - - static void blank_command(Command cmd) { } - - static void RegisterNewItem(Command cmd) - { - if (!Program.debug) - { - Program.LogError("Experimental code cannot be run in user mode."); - return; - } - SObject s = SGame.PullModItemFromDict(0, true); - s.Stack = 999; - Game1.player.addItemToInventory(s); - } - } -} +using StardewModdingAPI; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Mime; +using System.Text; +using System.Threading.Tasks; +using StardewModdingAPI.Inheritance; +using StardewValley; +using StardewValley.Tools; +using Microsoft.Xna.Framework; +using StardewValley.Objects; + +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; + + public override void Entry() + { + RegisterCommands(); + Events.UpdateTick += Events_UpdateTick; + } + + static void Events_UpdateTick(object sender, EventArgs e) + { + if (Game1.player == null) + return; + + if (infHealth) + { + Game1.player.health = Game1.player.maxHealth; + } + if (infStamina) + { + Game1.player.stamina = Game1.player.MaxStamina; + } + if (infMoney) + { + Game1.player.money = 999999; + } + if (freezeTime) + { + Game1.timeOfDay = frozenTime; + } + } + + public static void RegisterCommands() + { + 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; + + Command.RegisterCommand("exit", "Closes the game | exit").CommandFired += exit_CommandFired; + Command.RegisterCommand("stop", "Closes the game | stop").CommandFired += exit_CommandFired; + + Command.RegisterCommand("player_setname", "Sets the player's name | player_setname ", new[] { "(player, pet, farm) (String) The target name" }).CommandFired += player_setName; + Command.RegisterCommand("player_setmoney", "Sets the player's money | player_setmoney |inf", new[] { "(Int32) The target money" }).CommandFired += player_setMoney; + Command.RegisterCommand("player_setstamina", "Sets the player's stamina | player_setstamina |inf", new[] { "(Int32) The target stamina" }).CommandFired += player_setStamina; + Command.RegisterCommand("player_setmaxstamina", "Sets the player's max stamina | player_setmaxstamina ", new[] { "(Int32) The target max stamina" }).CommandFired += player_setMaxStamina; + Command.RegisterCommand("player_sethealth", "Sets the player's health | player_sethealth |inf", new[] { "(Int32) The target health" }).CommandFired += player_setHealth; + Command.RegisterCommand("player_setmaxhealth", "Sets the player's max health | player_setmaxhealth ", new[] { "(Int32) The target max health" }).CommandFired += player_setMaxHealth; + Command.RegisterCommand("player_setimmunity", "Sets the player's immunity | player_setimmunity ", new[] { "(Int32) The target immunity" }).CommandFired += player_setImmunity; + + Command.RegisterCommand("player_setlevel", "Sets the player's specified skill to the specified value | player_setlevel ", new[] { "(luck, mining, combat, farming, fishing, foraging) (1-10) The target level" }).CommandFired += player_setLevel; + Command.RegisterCommand("player_setspeed", "Sets the player's speed to the specified value?", new[] { "(Int32) The target speed [0 is normal]" }).CommandFired += player_setSpeed; + Command.RegisterCommand("player_changecolour", "Sets the player's colour of the specified object | player_changecolor ", new[] { "(hair, eyes, pants) (r,g,b)" }).CommandFired += player_changeColour; + Command.RegisterCommand("player_changestyle", "Sets the player's style of the specified object | player_changecolor ", new[] { "(hair, shirt, skin, acc, shoe, swim, gender) (Int32)" }).CommandFired += player_changeStyle; + + Command.RegisterCommand("player_additem", "Gives the player an item | player_additem [count] [quality]", new[] { "(Int32) (Int32)[count] (Int32)[quality]" }).CommandFired += player_addItem; + Command.RegisterCommand("player_addmelee", "Gives the player a melee item | player_addmelee ", new[] { "?" }).CommandFired += player_addMelee; + Command.RegisterCommand("player_addring", "Gives the player a ring | player_addring ", new[] { "?" }).CommandFired += player_addRing; + + Command.RegisterCommand("out_items", "Outputs a list of items | out_items", new[] { "" }).CommandFired += out_items; + Command.RegisterCommand("out_melee", "Outputs a list of melee weapons | out_melee", new[] { "" }).CommandFired += out_melee; + Command.RegisterCommand("out_rings", "Outputs a list of rings | out_rings", new[] { "" }).CommandFired += out_rings; + Command.RegisterCommand("newitem", "Outputs a list of melee weapons | out_melee", new[] { "" }).CommandFired += RegisterNewItem; + + Command.RegisterCommand("world_settime", "Sets the time to the specified value | world_settime ", new[] { "(Int32) The target time [06:00 AM is 600]" }).CommandFired += world_setTime; + Command.RegisterCommand("world_freezetime", "Freezes or thaws time | world_freezetime ", new[] { "(0 - 1) Whether or not to freeze time. 0 is thawed, 1 is frozen" }).CommandFired += world_freezeTime; + Command.RegisterCommand("world_setday", "Sets the day to the specified value | world_setday ", new[] { "(Int32) The target day [1-28]" }).CommandFired += world_setDay; + Command.RegisterCommand("world_setseason", "Sets the season to the specified value | world_setseason ", new[] { "(winter, spring, summer, fall) The target season" }).CommandFired += world_setSeason; + Command.RegisterCommand("world_downminelevel", "Goes down one mine level? | world_downminelevel", new[] { "" }).CommandFired += world_downMineLevel; + Command.RegisterCommand("world_setminelevel", "Sets mine level? | world_setminelevel", new[] { "(Int32) The target level" }).CommandFired += world_setMineLevel; + } + + static void types_CommandFired(object sender, EventArgsCommand e) + { + Program.LogInfo("[Int32: {0} - {1}], [Int64: {2} - {3}], [String: \"raw text\"], [Colour: r,g,b (EG: 128, 32, 255)]", Int32.MinValue, Int32.MaxValue, Int64.MinValue, Int64.MaxValue); + } + + static void hide_CommandFired(object sender, EventArgsCommand e) + { + Program.StardewInvoke(() => { Program.StardewForm.Hide(); }); + } + + static void show_CommandFired(object sender, EventArgsCommand e) + { + Program.StardewInvoke(() => { Program.StardewForm.Show(); }); + } + + static void save_CommandFired(object sender, EventArgsCommand e) + { + StardewValley.SaveGame.Save(); + } + + static void load_CommandFired(object sender, EventArgsCommand e) + { + Game1.activeClickableMenu = new StardewValley.Menus.LoadGameMenu(); + } + + static void exit_CommandFired(object sender, EventArgsCommand e) + { + Program.gamePtr.Exit(); + Environment.Exit(0); + } + + static void player_setName(object sender, EventArgsCommand e) + { + if (e.Command.CalledArgs.Length > 1) + { + string obj = e.Command.CalledArgs[0]; + string[] objs = "player,pet,farm".Split(new[] { ',' }); + if (objs.Contains(obj)) + { + switch (obj) + { + case "player": + Game1.player.Name = e.Command.CalledArgs[1]; + break; + case "pet": + Program.LogError("Pets cannot currently be renamed."); + break; + case "farm": + Game1.player.farmName = e.Command.CalledArgs[1]; + break; + } + } + else + { + Program.LogObjectInvalid(); + } + } + else + { + Program.LogObjectValueNotSpecified(); + } + } + + static void player_setMoney(object sender, EventArgsCommand e) + { + if (e.Command.CalledArgs.Length > 0) + { + if (e.Command.CalledArgs[0] == "inf") + { + infMoney = true; + } + else + { + infMoney = false; + int ou = 0; + if (Int32.TryParse(e.Command.CalledArgs[0], out ou)) + { + Game1.player.Money = ou; + Program.LogInfo("Set {0}'s money to {1}", Game1.player.Name, Game1.player.Money); + } + else + { + Program.LogValueNotInt32(); + } + } + } + else + { + Program.LogValueNotSpecified(); + } + } + + static void player_setStamina(object sender, EventArgsCommand e) + { + if (e.Command.CalledArgs.Length > 0) + { + if (e.Command.CalledArgs[0] == "inf") + { + infStamina = true; + } + else + { + infStamina = false; + int ou = 0; + if (Int32.TryParse(e.Command.CalledArgs[0], out ou)) + { + Game1.player.Stamina = ou; + Program.LogInfo("Set {0}'s stamina to {1}", Game1.player.Name, Game1.player.Stamina); + } + else + { + Program.LogValueNotInt32(); + } + } + } + else + { + Program.LogValueNotSpecified(); + } + } + + static void player_setMaxStamina(object sender, EventArgsCommand e) + { + if (e.Command.CalledArgs.Length > 0) + { + int ou = 0; + if (Int32.TryParse(e.Command.CalledArgs[0], out ou)) + { + Game1.player.MaxStamina = ou; + Program.LogInfo("Set {0}'s max stamina to {1}", Game1.player.Name, Game1.player.MaxStamina); + } + else + { + Program.LogValueNotInt32(); + } + } + else + { + Program.LogValueNotSpecified(); + } + } + + static void player_setLevel(object sender, EventArgsCommand e) + { + if (e.Command.CalledArgs.Length > 1) + { + string skill = e.Command.CalledArgs[0]; + string[] skills = "luck,mining,combat,farming,fishing,foraging".Split(new[] { ',' }); + if (skills.Contains(skill)) + { + int ou = 0; + if (Int32.TryParse(e.Command.CalledArgs[1], out ou)) + { + switch (skill) + { + case "luck": + Game1.player.LuckLevel = ou; + break; + case "mining": + Game1.player.MiningLevel = ou; + break; + case "combat": + Game1.player.CombatLevel = ou; + break; + case "farming": + Game1.player.FarmingLevel = ou; + break; + case "fishing": + Game1.player.FishingLevel = ou; + break; + case "foraging": + Game1.player.ForagingLevel = ou; + break; + } + } + else + { + Program.LogValueNotInt32(); + } + } + else + { + Program.LogError(" is invalid"); + } + } + else + { + Program.LogError(" and must be specified"); + } + } + + static void player_setSpeed(object sender, EventArgsCommand e) + { + if (e.Command.CalledArgs.Length > 0) + { + if (e.Command.CalledArgs[0].IsInt32()) + { + Game1.player.addedSpeed = e.Command.CalledArgs[0].AsInt32(); + Program.LogInfo("Set {0}'s added speed to {1}", Game1.player.Name, Game1.player.addedSpeed); + } + else + { + Program.LogValueNotInt32(); + } + } + else + { + Program.LogValueNotSpecified(); + } + } + + static void player_changeColour(object sender, EventArgsCommand e) + { + if (e.Command.CalledArgs.Length > 1) + { + string obj = e.Command.CalledArgs[0]; + string[] objs = "hair,eyes,pants".Split(new[] { ',' }); + if (objs.Contains(obj)) + { + string[] cs = e.Command.CalledArgs[1].Split(new[] { ',' }, 3); + if (cs[0].IsInt32() && cs[1].IsInt32() && cs[2].IsInt32()) + { + Color c = new Color(cs[0].AsInt32(), cs[1].AsInt32(), cs[2].AsInt32()); + switch (obj) + { + case "hair": + Game1.player.hairstyleColor = c; + break; + case "eyes": + Game1.player.changeEyeColor(c); + break; + case "pants": + Game1.player.pantsColor = c; + break; + } + } + else + { + Program.LogError(" is invalid"); + } + } + else + { + Program.LogObjectInvalid(); + } + } + else + { + Program.LogError(" and must be specified"); + } + } + + static void player_changeStyle(object sender, EventArgsCommand e) + { + if (e.Command.CalledArgs.Length > 1) + { + string obj = e.Command.CalledArgs[0]; + string[] objs = "hair,shirt,skin,acc,shoe,swim,gender".Split(new[] { ',' }); + if (objs.Contains(obj)) + { + if (e.Command.CalledArgs[1].IsInt32()) + { + int i = e.Command.CalledArgs[1].AsInt32(); + switch (obj) + { + case "hair": + Game1.player.changeHairStyle(i); + break; + case "shirt": + Game1.player.changeShirt(i); + break; + case "acc": + Game1.player.changeAccessory(i); + break; + case "skin": + Game1.player.changeSkinColor(i); + break; + case "shoe": + Game1.player.changeShoeColor(i); + break; + case "swim": + if (i == 0) + Game1.player.changeOutOfSwimSuit(); + else if (i == 1) + Game1.player.changeIntoSwimsuit(); + else + Program.LogError(" must be 0 or 1 for this "); + break; + case "gender": + if (i == 0) + Game1.player.changeGender(true); + else if (i == 1) + Game1.player.changeGender(false); + else + Program.LogError(" must be 0 or 1 for this "); + break; + } + } + else + { + Program.LogValueInvalid(); + } + } + else + { + Program.LogObjectInvalid(); + } + } + else + { + Program.LogObjectValueNotSpecified(); + } + } + + static void world_freezeTime(object sender, EventArgsCommand e) + { + if (e.Command.CalledArgs.Length > 0) + { + if (e.Command.CalledArgs[0].IsInt32()) + { + if (e.Command.CalledArgs[0].AsInt32() == 0 || e.Command.CalledArgs[0].AsInt32() == 1) + { + freezeTime = e.Command.CalledArgs[0].AsInt32() == 1; + frozenTime = freezeTime ? Game1.timeOfDay : 0; + Program.LogInfo("Time is now " + (freezeTime ? "frozen" : "thawed")); + } + else + { + Program.LogError(" should be 0 or 1"); + } + } + else + { + Program.LogValueNotInt32(); + } + } + else + { + Program.LogValueNotSpecified(); + } + } + + static void world_setTime(object sender, EventArgsCommand e) + { + if (e.Command.CalledArgs.Length > 0) + { + if (e.Command.CalledArgs[0].IsInt32()) + { + if (e.Command.CalledArgs[0].AsInt32() <= 2600 && e.Command.CalledArgs[0].AsInt32() >= 600) + { + Game1.timeOfDay = e.Command.CalledArgs[0].AsInt32(); + frozenTime = freezeTime ? Game1.timeOfDay : 0; + Program.LogInfo("Time set to: " + Game1.timeOfDay); + } + else + { + Program.LogError(" should be between 600 and 2600 (06:00 AM - 02:00 AM [NEXT DAY])"); + } + } + else + { + Program.LogValueNotInt32(); + } + } + else + { + Program.LogValueNotSpecified(); + } + } + + static void world_setDay(object sender, EventArgsCommand e) + { + if (e.Command.CalledArgs.Length > 0) + { + if (e.Command.CalledArgs[0].IsInt32()) + { + if (e.Command.CalledArgs[0].AsInt32() <= 28 && e.Command.CalledArgs[0].AsInt32() > 0) + { + Game1.dayOfMonth = e.Command.CalledArgs[0].AsInt32(); + } + else + { + Program.LogError(" must be between 1 and 28"); + } + } + else + { + Program.LogValueNotInt32(); + } + } + else + { + Program.LogValueNotSpecified(); + } + } + + static void world_setSeason(object sender, EventArgsCommand e) + { + if (e.Command.CalledArgs.Length > 0) + { + string obj = e.Command.CalledArgs[0]; + string[] objs = "winter,spring,summer,fall".Split(new[] { ',' }); + if (objs.Contains(obj)) + { + Game1.currentSeason = obj; + } + else + { + Program.LogValueInvalid(); + } + } + else + { + Program.LogValueNotSpecified(); + } + } + + static void player_setHealth(object sender, EventArgsCommand e) + { + if (e.Command.CalledArgs.Length > 0) + { + if (e.Command.CalledArgs[0] == "inf") + { + infHealth = true; + } + else + { + infHealth = false; + if (e.Command.CalledArgs[0].IsInt32()) + { + Game1.player.health = e.Command.CalledArgs[0].AsInt32(); + } + else + { + Program.LogValueNotInt32(); + } + } + } + else + { + Program.LogValueNotSpecified(); + } + } + + static void player_setMaxHealth(object sender, EventArgsCommand e) + { + if (e.Command.CalledArgs.Length > 0) + { + if (e.Command.CalledArgs[0].IsInt32()) + { + Game1.player.maxHealth = e.Command.CalledArgs[0].AsInt32(); + } + else + { + Program.LogValueNotInt32(); + } + } + else + { + Program.LogValueNotSpecified(); + } + } + + static void player_setImmunity(object sender, EventArgsCommand e) + { + if (e.Command.CalledArgs.Length > 0) + { + if (e.Command.CalledArgs[0].IsInt32()) + { + Game1.player.immunity = e.Command.CalledArgs[0].AsInt32(); + } + else + { + Program.LogValueNotInt32(); + } + } + else + { + Program.LogValueNotSpecified(); + } + } + + static void player_addItem(object sender, EventArgsCommand e) + { + if (e.Command.CalledArgs.Length > 0) + { + if (e.Command.CalledArgs[0].IsInt32()) + { + int count = 1; + int quality = 0; + if (e.Command.CalledArgs.Length > 1) + { + Console.WriteLine(e.Command.CalledArgs[1]); + if (e.Command.CalledArgs[1].IsInt32()) + { + count = e.Command.CalledArgs[1].AsInt32(); + } + else + { + Program.LogError("[count] is invalid"); + return; + } + + if (e.Command.CalledArgs.Length > 2) + { + if (e.Command.CalledArgs[2].IsInt32()) + { + quality = e.Command.CalledArgs[2].AsInt32(); + } + else + { + Program.LogError("[quality] is invalid"); + return; + } + + } + } + + StardewValley.Object o = new StardewValley.Object(e.Command.CalledArgs[0].AsInt32(), count); + o.quality = quality; + + Game1.player.addItemByMenuIfNecessary((Item)o); + } + else + { + Program.LogError(" is invalid"); + } + } + else + { + Program.LogObjectValueNotSpecified(); + } + } + + static void player_addMelee(object sender, EventArgsCommand e) + { + if (e.Command.CalledArgs.Length > 0) + { + if (e.Command.CalledArgs[0].IsInt32()) + { + + MeleeWeapon toAdd = new MeleeWeapon(e.Command.CalledArgs[0].AsInt32()); + Game1.player.addItemByMenuIfNecessary(toAdd); + Program.LogInfo("Given {0} to {1}", toAdd.Name, Game1.player.Name); + } + else + { + Program.LogError(" is invalid"); + } + } + else + { + Program.LogObjectValueNotSpecified(); + } + } + + static void player_addRing(object sender, EventArgsCommand e) + { + if (e.Command.CalledArgs.Length > 0) + { + if (e.Command.CalledArgs[0].IsInt32()) + { + + Ring toAdd = new Ring(e.Command.CalledArgs[0].AsInt32()); + Game1.player.addItemByMenuIfNecessary(toAdd); + Program.LogInfo("Given {0} to {1}", toAdd.Name, Game1.player.Name); + } + else + { + Program.LogError(" is invalid"); + } + } + else + { + Program.LogObjectValueNotSpecified(); + } + } + + static void out_items(object sender, EventArgsCommand e) + { + for (int i = 0; i < 1000; i++) + { + try + { + Item it = new StardewValley.Object(i, 1); + if (it.Name != "Error Item") + Console.WriteLine(i + "| " + it.Name); + } + catch + { + + } + } + } + + static void out_melee(object sender, EventArgsCommand e) + { + Dictionary d = Game1.content.Load>("Data\\weapons"); + Console.Write("DATA\\WEAPONS: "); + foreach (var v in d) + { + Console.WriteLine(v.Key + " | " + v.Value); + } + } + + static void out_rings(object sender, EventArgsCommand e) + { + for (int i = 0; i < 100; i++) + { + try + { + Item it = new Ring(i); + if (it.Name != "Error Item") + Console.WriteLine(i + "| " + it.Name); + } + catch + { + + } + } + } + + static void world_downMineLevel(object sender, EventArgsCommand e) + { + Game1.nextMineLevel(); + } + + static void world_setMineLevel(object sender, EventArgsCommand e) + { + if (e.Command.CalledArgs.Length > 0) + { + if (e.Command.CalledArgs[0].IsInt32()) + { + Game1.enterMine(true, e.Command.CalledArgs[0].AsInt32(), ""); + } + else + { + Program.LogValueNotInt32(); + } + } + else + { + Program.LogValueNotSpecified(); + } + } + + static void blank_command(object sender, EventArgsCommand e) { } + + static void RegisterNewItem(object sender, EventArgsCommand e) + { + if (!Program.debug) + { + Program.LogError("Experimental code cannot be run in user mode."); + return; + } + SObject s = SGame.PullModItemFromDict(0, true); + s.Stack = 999; + Game1.player.addItemToInventory(s); + } + } +} diff --git a/TrainerMod/bin/Debug/TrainerMod.dll b/TrainerMod/bin/Debug/TrainerMod.dll deleted file mode 100644 index d6e49439..00000000 Binary files a/TrainerMod/bin/Debug/TrainerMod.dll and /dev/null differ -- cgit From de0cd2ac5095fb3db924317eb1628ec33fb4ffb7 Mon Sep 17 00:00:00 2001 From: ClxS Date: Thu, 3 Mar 2016 18:55:36 +0000 Subject: Forgot to remove unneeded BlankEventHandler --- Release/StardewModdingAPI.exe | Bin 71168 -> 70656 bytes StardewModdingAPI/Events.cs | 12 +++++------- .../StardewModdingAPI.csproj.FileListAbsolute.txt | 4 ++++ TrainerMod/obj/Debug/TrainerMod.dll | Bin 23552 -> 24064 bytes 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Release/StardewModdingAPI.exe b/Release/StardewModdingAPI.exe index 06f57e1f..3897c71f 100644 Binary files a/Release/StardewModdingAPI.exe and b/Release/StardewModdingAPI.exe differ diff --git a/StardewModdingAPI/Events.cs b/StardewModdingAPI/Events.cs index e8e9727c..3ae861d9 100644 --- a/StardewModdingAPI/Events.cs +++ b/StardewModdingAPI/Events.cs @@ -11,13 +11,11 @@ namespace StardewModdingAPI { public static class Events { - public delegate void BlankEventHandler(object sender, EventArgs e); - - public static event BlankEventHandler GameLoaded = delegate { }; - public static event BlankEventHandler Initialize = delegate { }; - public static event BlankEventHandler LoadContent = delegate { }; - public static event BlankEventHandler UpdateTick = delegate { }; - public static event BlankEventHandler DrawTick = delegate { }; + public static event EventHandler GameLoaded = delegate { }; + public static event EventHandler Initialize = delegate { }; + public static event EventHandler LoadContent = delegate { }; + public static event EventHandler UpdateTick = delegate { }; + public static event EventHandler DrawTick = delegate { }; public static event EventHandler KeyboardChanged = delegate { }; public static event EventHandler KeyPressed = delegate { }; diff --git a/StardewModdingAPI/obj/x86/Debug/StardewModdingAPI.csproj.FileListAbsolute.txt b/StardewModdingAPI/obj/x86/Debug/StardewModdingAPI.csproj.FileListAbsolute.txt index 0d8f693b..241cf998 100644 --- a/StardewModdingAPI/obj/x86/Debug/StardewModdingAPI.csproj.FileListAbsolute.txt +++ b/StardewModdingAPI/obj/x86/Debug/StardewModdingAPI.csproj.FileListAbsolute.txt @@ -32,3 +32,7 @@ C:\TFSource\Master-Collection\StardewModdingAPI\StardewModdingAPI\obj\x86\Debug\ C:\TFSource\Master-Collection\StardewModdingAPI\StardewModdingAPI\obj\x86\Debug\StardewModdingAPI.csprojResolveAssemblyReference.cache Z:\Projects\C#\SMAPI\StardewModdingAPI\obj\x86\Debug\StardewModdingAPI.exe Z:\Projects\C#\SMAPI\StardewModdingAPI\obj\x86\Debug\StardewModdingAPI.pdb +Z:\Projects\C#\SMAPI\StardewModdingAPI\bin\x86\Debug\steam_appid.txt +Z:\Projects\C#\SMAPI\StardewModdingAPI\bin\x86\Debug\StardewModdingAPI.exe.config +Z:\Projects\C#\SMAPI\StardewModdingAPI\bin\x86\Debug\StardewModdingAPI.exe +Z:\Projects\C#\SMAPI\StardewModdingAPI\bin\x86\Debug\StardewModdingAPI.pdb diff --git a/TrainerMod/obj/Debug/TrainerMod.dll b/TrainerMod/obj/Debug/TrainerMod.dll index d6e49439..eda3dfa9 100644 Binary files a/TrainerMod/obj/Debug/TrainerMod.dll and b/TrainerMod/obj/Debug/TrainerMod.dll differ -- cgit