summaryrefslogtreecommitdiff
path: root/StardewModdingAPI
diff options
context:
space:
mode:
authorZoryn <zoryn4163@gmail.com>2016-03-03 14:04:29 -0500
committerZoryn <zoryn4163@gmail.com>2016-03-03 14:04:29 -0500
commitde3f161a49bf7486290f0e4b3531177f949bc3cd (patch)
tree2569382d6a7d2c67a58f9c8f7b4c9b11731f4b35 /StardewModdingAPI
parenteee4e9c0fe434e3c49d53b5b8dcca1836a08abf8 (diff)
parentd12c5babf6e3cb7d700be4f5eb29f5d34214d5f6 (diff)
downloadSMAPI-de3f161a49bf7486290f0e4b3531177f949bc3cd.tar.gz
SMAPI-de3f161a49bf7486290f0e4b3531177f949bc3cd.tar.bz2
SMAPI-de3f161a49bf7486290f0e4b3531177f949bc3cd.zip
Merge remote-tracking branch 'origin/master'
# Conflicts: # Release/StardewModdingAPI.exe # StardewModdingAPI/Program.cs # StardewModdingAPI/StardewModdingAPI.csproj # StardewModdingAPI/obj/x86/Debug/StardewModdingAPI.csproj.FileListAbsolute.txt # TrainerMod/bin/Debug/TrainerMod.dll # TrainerMod/obj/Debug/TrainerMod.dll
Diffstat (limited to 'StardewModdingAPI')
-rw-r--r--StardewModdingAPI/Command.cs5
-rw-r--r--StardewModdingAPI/EventArgs.cs116
-rw-r--r--StardewModdingAPI/Events.cs312
-rw-r--r--StardewModdingAPI/Extensions.cs2
-rw-r--r--StardewModdingAPI/Inheritance/SGame.cs42
-rw-r--r--StardewModdingAPI/Inheritance/SObject.cs2
-rw-r--r--StardewModdingAPI/Program.cs516
-rw-r--r--StardewModdingAPI/StardewModdingAPI.csproj110
-rw-r--r--StardewModdingAPI/obj/x86/Debug/StardewModdingAPI.csproj.FileListAbsolute.txt41
9 files changed, 954 insertions, 192 deletions
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<EventArgsCommand> CommandFired;
/// <summary>
/// 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<GameLocation> newLocations)
+ {
+ NewLocations = newLocations;
+ }
+ public List<GameLocation> 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..3ae861d9 100644
--- a/StardewModdingAPI/Events.cs
+++ b/StardewModdingAPI/Events.cs
@@ -1,166 +1,146 @@
-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<GameLocation> 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<GameLocation> 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 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<EventArgsKeyboardStateChanged> KeyboardChanged = delegate { };
+ public static event EventHandler<EventArgsKeyPressed> KeyPressed = delegate { };
+ public static event EventHandler<EventArgsMouseStateChanged> MouseChanged = delegate { };
+ public static event EventHandler<EventArgsClickableMenuChanged> MenuChanged = delegate { };
+ public static event EventHandler<EventArgsGameLocationsChanged> LocationsChanged = delegate { };
+ public static event EventHandler<EventArgsCurrentLocationChanged> CurrentLocationChanged = delegate { };
+ public static event EventHandler Resize = delegate { };
+ public static event EventHandler<EventArgsFarmerChanged> FarmerChanged = delegate { };
+ public static event EventHandler<EventArgsIntChanged> TimeOfDayChanged = delegate { };
+ public static event EventHandler<EventArgsIntChanged> DayOfMonthChanged = delegate { };
+ public static event EventHandler<EventArgsIntChanged> YearOfGameChanged = delegate { };
+ public static event EventHandler<EventArgsStringChanged> 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<GameLocation> 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 8fd34b6c..1bd589db 100644
--- a/StardewModdingAPI/Extensions.cs
+++ b/StardewModdingAPI/Extensions.cs
@@ -56,7 +56,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 a13f25a8..dccc9ef3 100644
--- a/StardewModdingAPI/Program.cs
+++ b/StardewModdingAPI/Program.cs
@@ -1,3 +1,4 @@
+<<<<<<< HEAD
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
@@ -587,3 +588,518 @@ namespace StardewModdingAPI
#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<string> ModPaths = new List<string>();
+ public static List<string> ModContentPaths = new List<string>();
+ 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 <cmd>' 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 <cmd>' 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)
+