diff options
Diffstat (limited to 'StardewModdingAPI')
| -rw-r--r-- | StardewModdingAPI/Config.cs | 124 | ||||
| -rw-r--r-- | StardewModdingAPI/Constants.cs | 4 | ||||
| -rw-r--r-- | StardewModdingAPI/Events/Game.cs | 63 | ||||
| -rw-r--r-- | StardewModdingAPI/Extensions.cs | 39 | ||||
| -rw-r--r-- | StardewModdingAPI/FodyWeavers.xml | 5 | ||||
| -rw-r--r-- | StardewModdingAPI/Inheritance/SGame.cs | 39 | ||||
| -rw-r--r-- | StardewModdingAPI/Log.cs | 23 | ||||
| -rw-r--r-- | StardewModdingAPI/Manifest.cs | 33 | ||||
| -rw-r--r-- | StardewModdingAPI/Mod.cs | 27 | ||||
| -rw-r--r-- | StardewModdingAPI/Program.cs | 838 | ||||
| -rw-r--r-- | StardewModdingAPI/StardewModdingAPI.csproj | 41 | ||||
| -rw-r--r-- | StardewModdingAPI/packages.config | 6 |
12 files changed, 821 insertions, 421 deletions
diff --git a/StardewModdingAPI/Config.cs b/StardewModdingAPI/Config.cs new file mode 100644 index 00000000..67c13a14 --- /dev/null +++ b/StardewModdingAPI/Config.cs @@ -0,0 +1,124 @@ +/* + Copyright 2016 Zoey (Zoryn) +*/ + +using System; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +namespace StardewModdingAPI +{ + public class Config + { + [JsonIgnore] + public virtual JObject JObject { get; protected set; } + + [JsonIgnore] + public virtual string ConfigLocation { get; protected set; } + + public static Config Instance + { + get { return new Config(); } + } + + public static Config InitializeConfig(string configLocation, Config baseConfig) + { + if (baseConfig == null) + { + Console.WriteLine("A config must be instantiated before being passed to Initialize.\n\t" + configLocation); + return null; + } + + baseConfig.ConfigLocation = configLocation; + return baseConfig.LoadConfig(baseConfig); + } + + public virtual Config GenerateBaseConfig(Config baseConfig) + { + //Must be implemented in sub-class + return null; + } + + public virtual Config LoadConfig(Config baseConfig) + { + if (!File.Exists(baseConfig.ConfigLocation)) + { + var v = (Config)baseConfig.GetType().GetMethod("GenerateBaseConfig", BindingFlags.Public | BindingFlags.Instance).Invoke(baseConfig, new object[] { baseConfig }); + v.WriteConfig(); + } + else + { + var p = baseConfig.ConfigLocation; + + try + { + var j = JObject.Parse(Encoding.UTF8.GetString(File.ReadAllBytes(baseConfig.ConfigLocation))); + baseConfig = (Config)j.ToObject(baseConfig.GetType()); + baseConfig.ConfigLocation = p; + baseConfig.JObject = j; + + baseConfig = UpdateConfig(baseConfig); + baseConfig.ConfigLocation = p; + baseConfig.JObject = j; + + baseConfig.WriteConfig(); + } + catch + { + Console.WriteLine("Invalid JSON Renamed: " + p); + if (File.Exists(p)) + File.Move(p, Path.Combine(Path.GetDirectoryName(p), Path.GetFileNameWithoutExtension(p) + "." + Guid.NewGuid() + ".json")); //Get it out of the way for a new one + var v = (Config)baseConfig.GetType().GetMethod("GenerateBaseConfig", BindingFlags.Public | BindingFlags.Instance).Invoke(baseConfig, new object[] { baseConfig }); + v.WriteConfig(); + } + } + + return baseConfig; + } + + public virtual Config UpdateConfig(Config baseConfig) + { + try + { + //default config with all standard values + var b = JObject.FromObject(baseConfig.GetType().GetMethod("GenerateBaseConfig", BindingFlags.Public | BindingFlags.Instance).Invoke(baseConfig, new object[] { baseConfig })); + //user config with their values + var u = baseConfig.JObject; + + b.Merge(u); + + return (Config)b.ToObject(baseConfig.GetType()); + } + catch (Exception ex) + { + Console.WriteLine(ex.ToString()); + } + return baseConfig; + } + + public static string GetBasePath(Mod theMod) + { + return theMod.PathOnDisk + "\\config.json"; + } + } + + public static class ConfigExtensions + { + public static void WriteConfig(this Config baseConfig) + { + var toWrite = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(baseConfig, baseConfig.GetType(), Formatting.Indented, new JsonSerializerSettings())); + if (!File.Exists(baseConfig.ConfigLocation) || !File.ReadAllBytes(baseConfig.ConfigLocation).SequenceEqual(toWrite)) + File.WriteAllBytes(baseConfig.ConfigLocation, toWrite); + toWrite = null; + } + + public static Config ReloadConfig(this Config baseConfig) + { + return baseConfig.UpdateConfig(baseConfig); + } + } +}
\ No newline at end of file diff --git a/StardewModdingAPI/Constants.cs b/StardewModdingAPI/Constants.cs index b8fe3389..fa117ece 100644 --- a/StardewModdingAPI/Constants.cs +++ b/StardewModdingAPI/Constants.cs @@ -33,9 +33,9 @@ namespace StardewModdingAPI public const int MajorVersion = 0; - public const int MinorVersion = 37; + public const int MinorVersion = 38; - public const int PatchVersion = 2; + public const int PatchVersion = 4; public const string Build = "Alpha"; diff --git a/StardewModdingAPI/Events/Game.cs b/StardewModdingAPI/Events/Game.cs index 6290d2c7..ac630ba9 100644 --- a/StardewModdingAPI/Events/Game.cs +++ b/StardewModdingAPI/Events/Game.cs @@ -11,7 +11,35 @@ namespace StardewModdingAPI.Events public static event EventHandler GameLoaded = delegate { };
public static event EventHandler Initialize = delegate { };
public static event EventHandler LoadContent = delegate { };
+ public static event EventHandler FirstUpdateTick = delegate { };
+ /// <summary>
+ /// Fires every update (1/60 of a second)
+ /// </summary>
public static event EventHandler UpdateTick = delegate { };
+ /// <summary>
+ /// Fires every other update (1/30 of a second)
+ /// </summary>
+ public static event EventHandler SecondUpdateTick = delegate { };
+ /// <summary>
+ /// Fires every fourth update (1/15 of a second)
+ /// </summary>
+ public static event EventHandler FourthUpdateTick = delegate { };
+ /// <summary>
+ /// Fires every eighth update (roughly 1/8 of a second)
+ /// </summary>
+ public static event EventHandler EighthUpdateTick = delegate { };
+ /// <summary>
+ /// Fires every fifthteenth update (1/4 of a second)
+ /// </summary>
+ public static event EventHandler QuarterSecondTick = delegate { };
+ /// <summary>
+ /// Fires every thirtieth update (1/2 of a second)
+ /// </summary>
+ public static event EventHandler HalfSecondTick = delegate { };
+ /// <summary>
+ /// Fires every sixtieth update (a second)
+ /// </summary>
+ public static event EventHandler OneSecondTick = delegate { };
public static void InvokeGameLoaded()
{
@@ -53,5 +81,40 @@ namespace StardewModdingAPI.Events Log.Error("An exception occured in XNA UpdateTick: " + ex.ToString());
}
}
+
+ public static void InvokeSecondUpdateTick()
+ {
+ SecondUpdateTick.Invoke(null, EventArgs.Empty);
+ }
+
+ public static void InvokeFourthUpdateTick()
+ {
+ FourthUpdateTick.Invoke(null, EventArgs.Empty);
+ }
+
+ public static void InvokeEighthUpdateTick()
+ {
+ EighthUpdateTick.Invoke(null, EventArgs.Empty);
+ }
+
+ public static void InvokeQuarterSecondTick()
+ {
+ QuarterSecondTick.Invoke(null, EventArgs.Empty);
+ }
+
+ public static void InvokeHalfSecondTick()
+ {
+ HalfSecondTick.Invoke(null, EventArgs.Empty);
+ }
+
+ public static void InvokeOneSecondTick()
+ {
+ OneSecondTick.Invoke(null, EventArgs.Empty);
+ }
+
+ public static void InvokeFirstUpdateTick()
+ {
+ FirstUpdateTick.Invoke(null, EventArgs.Empty);
+ }
}
}
diff --git a/StardewModdingAPI/Extensions.cs b/StardewModdingAPI/Extensions.cs index c504f470..d4b582b7 100644 --- a/StardewModdingAPI/Extensions.cs +++ b/StardewModdingAPI/Extensions.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; using Microsoft.Xna.Framework; @@ -59,6 +60,42 @@ namespace StardewModdingAPI hash ^= v.GetHashCode(); } return hash; - } + } + + public static T Cast<T>(this object o) where T : class + { + return o as T; + } + + public static FieldInfo[] GetPrivateFields(this object o) + { + return o.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic); + } + + public static FieldInfo GetBaseFieldInfo(this Type t, string name) + { + return t.GetField(name, BindingFlags.Instance | BindingFlags.NonPublic); + } + + public static T GetBaseFieldValue<T>(this Type t, object o, string name) where T : class + { + return t.GetBaseFieldInfo(name).GetValue(o) as T; + } + + /* + public static T GetBaseFieldValue<T>(this object o, string name) where T : class + { + return o.GetType().GetBaseFieldInfo(name).GetValue(o) as T; + }*/ + + public static object GetBaseFieldValue(this object o, string name) + { + return o.GetType().GetBaseFieldInfo(name).GetValue(o); + } + + public static void SetBaseFieldValue (this object o, string name, object newValue) + { + o.GetType().GetBaseFieldInfo(name).SetValue(o, newValue); + } } }
\ No newline at end of file diff --git a/StardewModdingAPI/FodyWeavers.xml b/StardewModdingAPI/FodyWeavers.xml new file mode 100644 index 00000000..2e6d4a7a --- /dev/null +++ b/StardewModdingAPI/FodyWeavers.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="utf-8"?> +<Weavers> + <Costura/> + +</Weavers>
\ No newline at end of file diff --git a/StardewModdingAPI/Inheritance/SGame.cs b/StardewModdingAPI/Inheritance/SGame.cs index 735cd58a..53d9df59 100644 --- a/StardewModdingAPI/Inheritance/SGame.cs +++ b/StardewModdingAPI/Inheritance/SGame.cs @@ -173,6 +173,15 @@ namespace StardewModdingAPI.Inheritance public Farmer PreviousFarmer { get; private set; }
+ public Int32 CurrentUpdateTick { get; private set; }
+ public bool FirstUpdate { get; private set; }
+
+ public RenderTarget2D Screen
+ {
+ get { return typeof (Game1).GetBaseFieldValue<RenderTarget2D>(Program.gamePtr, "screen"); }
+ set { typeof (Game1).SetBaseFieldValue("screen", value); }
+ }
+
private static SGame instance;
public static SGame Instance { get { return instance; } }
@@ -181,7 +190,9 @@ namespace StardewModdingAPI.Inheritance public SGame()
{
instance = this;
+ FirstUpdate = true;
+ /*
#if DEBUG
SaveGame.serializer = new XmlSerializer(typeof (SaveGame), new Type[28]
{
@@ -215,6 +226,7 @@ namespace StardewModdingAPI.Inheritance typeof (SObject)
});
#endif
+ */
}
protected override void Initialize()
@@ -251,6 +263,33 @@ namespace StardewModdingAPI.Inheritance }
Events.GameEvents.InvokeUpdateTick();
+ if (FirstUpdate)
+ {
+ GameEvents.InvokeFirstUpdateTick();
+ FirstUpdate = false;
+ }
+
+ if (CurrentUpdateTick % 2 == 0)
+ Events.GameEvents.InvokeSecondUpdateTick();
+
+ if (CurrentUpdateTick % 4 == 0)
+ Events.GameEvents.InvokeFourthUpdateTick();
+
+ if (CurrentUpdateTick % 8 == 0)
+ Events.GameEvents.InvokeEighthUpdateTick();
+
+ if (CurrentUpdateTick % 15 == 0)
+ Events.GameEvents.InvokeQuarterSecondTick();
+
+ if (CurrentUpdateTick % 30 == 0)
+ Events.GameEvents.InvokeHalfSecondTick();
+
+ if (CurrentUpdateTick % 60 == 0)
+ Events.GameEvents.InvokeOneSecondTick();
+
+ CurrentUpdateTick += 1;
+ if (CurrentUpdateTick >= 60)
+ CurrentUpdateTick = 0;
PreviouslyPressedKeys = CurrentlyPressedKeys;
for(PlayerIndex i = PlayerIndex.One; i <= PlayerIndex.Four; i++)
diff --git a/StardewModdingAPI/Log.cs b/StardewModdingAPI/Log.cs index 2784b709..04b05b55 100644 --- a/StardewModdingAPI/Log.cs +++ b/StardewModdingAPI/Log.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; using System.IO; using System.Threading; @@ -28,7 +29,7 @@ namespace StardewModdingAPI catch (Exception) { // TODO: not use general exception - Log.Error("Could not initialize LogStream - Logging is disabled"); + Error("Could not initialize LogStream - Logging is disabled"); } } @@ -36,11 +37,11 @@ namespace StardewModdingAPI /// Print provided parameters to the console/file as applicable /// </summary> /// <param name="message">Desired message</param> - /// <param name="suppressMessage">When true, writes to ONLY console and not the log file.</param> + /// <param name="disableLogging">When true, writes to ONLY console and not the log file.</param> /// <param name="values">Additional params to be added to the message</param> private static void PrintLog(object message, bool disableLogging, params object[] values) { - string logOutput = string.Format("[{0}] {1}", System.DateTime.Now.ToLongTimeString(), String.Format(message.ToString(), values)); + string logOutput = $"[{DateTime.Now.ToLongTimeString()}] {string.Format(message.ToString(), values)}"; Console.WriteLine(logOutput); if (_logStream != null && !disableLogging) @@ -58,7 +59,7 @@ namespace StardewModdingAPI public static void Success(object message, params object[] values) { Console.ForegroundColor = ConsoleColor.Green; - Log.PrintLog(message?.ToString(), false, values); + PrintLog(message?.ToString(), false, values); Console.ForegroundColor = ConsoleColor.Gray; } @@ -69,7 +70,9 @@ namespace StardewModdingAPI /// <param name="values"></param> public static void Verbose(object message, params object[] values) { - Log.PrintLog(message?.ToString(), false, values); + Console.ForegroundColor = ConsoleColor.Gray; + PrintLog(message?.ToString(), false, values); + Console.ForegroundColor = ConsoleColor.Gray; } /// <summary> @@ -80,7 +83,7 @@ namespace StardewModdingAPI public static void Comment(object message, params object[] values) { Console.ForegroundColor = ConsoleColor.Yellow; - Log.PrintLog(message?.ToString(), false, values); + PrintLog(message?.ToString(), false, values); Console.ForegroundColor = ConsoleColor.Gray; } @@ -91,7 +94,9 @@ namespace StardewModdingAPI /// <param name="values"></param> public static void Info(object message, params object[] values) { - Log.PrintLog(message.ToString(), true, values); + Console.ForegroundColor = ConsoleColor.Gray; + PrintLog(message?.ToString(), true, values); + Console.ForegroundColor = ConsoleColor.Gray; } /// <summary> @@ -102,7 +107,7 @@ namespace StardewModdingAPI public static void Error(object message, params object[] values) { Console.ForegroundColor = ConsoleColor.Red; - Log.PrintLog(message.ToString(), false, values); + PrintLog(message?.ToString(), false, values); Console.ForegroundColor = ConsoleColor.Gray; } @@ -127,7 +132,7 @@ namespace StardewModdingAPI public static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { Console.WriteLine("An exception has been caught"); - File.WriteAllText(_logPath + "\\MODDED_ErrorLog.Log_" + Extensions.Random.Next(100000000, 999999999) + ".txt", e.ExceptionObject.ToString()); + File.WriteAllText(_logPath + "\\MODDED_ErrorLog.Log_" + DateTime.UtcNow.Ticks + ".txt", e.ExceptionObject.ToString()); } /// <summary> diff --git a/StardewModdingAPI/Manifest.cs b/StardewModdingAPI/Manifest.cs new file mode 100644 index 00000000..4fc1ed3c --- /dev/null +++ b/StardewModdingAPI/Manifest.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StardewModdingAPI +{ + public class Manifest + { + /// <summary> + /// The name of your mod. + /// </summary> + public virtual string Name { get; set; } + + /// <summary> + /// The name of the mod's authour. + /// </summary> + public virtual string Authour { get; set; } + + /// <summary> + /// The version of the mod. + /// </summary> + public virtual string Version { get; set; } + + /// <summary> + /// A description of the mod. + /// </summary> + public virtual string Description { get; set; } + + public string EntryDll { get; set; } + } +} diff --git a/StardewModdingAPI/Mod.cs b/StardewModdingAPI/Mod.cs index eabdc539..fc86409b 100644 --- a/StardewModdingAPI/Mod.cs +++ b/StardewModdingAPI/Mod.cs @@ -10,23 +10,42 @@ namespace StardewModdingAPI { /// <summary> /// The name of your mod. + /// NOTE: THIS IS DEPRECATED AND WILL BE REMOVED IN THE NEXT VERSION OF SMAPI /// </summary> - public virtual string Name { get; protected set; } + [Obsolete] + public virtual string Name { get; set; } /// <summary> /// The name of the mod's authour. + /// NOTE: THIS IS DEPRECATED AND WILL BE REMOVED IN THE NEXT VERSION OF SMAPI /// </summary> - public virtual string Authour { get; protected set; } + [Obsolete] + public virtual string Authour { get; set; } /// <summary> /// The version of the mod. + /// NOTE: THIS IS DEPRECATED AND WILL BE REMOVED IN THE NEXT VERSION OF SMAPI /// </summary> - public virtual string Version { get; protected set; } + [Obsolete] + public virtual string Version { get; set; } /// <summary> /// A description of the mod. + /// NOTE: THIS IS DEPRECATED AND WILL BE REMOVED IN THE NEXT VERSION OF SMAPI /// </summary> - public virtual string Description { get; protected set; } + [Obsolete] + public virtual string Description { get; set; } + + + /// <summary> + /// The mod's manifest + /// </summary> + public Manifest Manifest { get; internal set; } + + /// <summary> + /// Where the mod is located on the disk. + /// </summary> + public string PathOnDisk { get; internal set; } /// <summary> /// A basic method that is the entry-point of your mod. It will always be called once when the mod loads. diff --git a/StardewModdingAPI/Program.cs b/StardewModdingAPI/Program.cs index 61770f8e..e4cbe609 100644 --- a/StardewModdingAPI/Program.cs +++ b/StardewModdingAPI/Program.cs @@ -1,55 +1,58 @@ -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
using StardewModdingAPI.Events;
-using StardewModdingAPI.Inheritance; -using StardewModdingAPI.Inheritance.Menus; -using StardewValley; -using StardewValley.Menus; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Threading; -using System.Windows.Forms; -
-namespace StardewModdingAPI -{ - public class Program - { - private static List<string> _modPaths; - private static List<string> _modContentPaths; - - 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 static bool StardewInjectorLoaded { get; private set; } - public static Mod StardewInjectorMod { get; private set; } - - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - +using StardewModdingAPI.Inheritance;
+using StardewModdingAPI.Inheritance.Menus;
+using StardewValley;
+using StardewValley.Menus;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Globalization;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+using System.Threading;
+using System.Windows.Forms;
+using Newtonsoft.Json;
+
+namespace StardewModdingAPI
+{
+ public class Program
+ {
+ private static List<string> _modPaths;
+ //private static List<string> _modContentPaths;
+
+ 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 static bool StardewInjectorLoaded { get; private set; }
+ public static Mod StardewInjectorMod { get; private set; }
+
+ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
/// <summary>
/// Main method holding the API execution
/// </summary>
- /// <param name="args"></param> - private static void Main(string[] args) - { + /// <param name="args"></param>
+ private static void Main(string[] args)
+ {
+ Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB");
+
try
{
ConfigureUI();
ConfigurePaths();
- ConfigureInjector();
ConfigureSDV();
GameRunInvoker();
@@ -62,16 +65,16 @@ namespace StardewModdingAPI StardewModdingAPI.Log.Comment("The API will now terminate. Press any key to continue...");
Console.ReadKey();
- } - + }
+
/// <summary>
/// Set up the console properties
- /// </summary> + /// </summary>
private static void ConfigureUI()
- { + {
Console.Title = Constants.ConsoleTitle;
- -#if DEBUG +
+#if DEBUG
Console.Title += " - DEBUG IS NOT FALSE, AUTHOUR NEEDS TO REUPLOAD THIS VERSION";
#endif
}
@@ -81,150 +84,109 @@ namespace StardewModdingAPI /// </summary>
private static void ConfigurePaths()
{
- StardewModdingAPI.Log.Info("Validating api paths..."); + StardewModdingAPI.Log.Info("Validating api paths...");
_modPaths = new List<string>();
- _modContentPaths = new List<string>();
+ //_modContentPaths = new List<string>();
//TODO: Have an app.config and put the paths inside it so users can define locations to load mods from
- _modPaths.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley", "Mods")); - _modPaths.Add(Path.Combine(Constants.ExecutionPath, "Mods")); - _modContentPaths.Add(Path.Combine(Constants.ExecutionPath, "Mods", "Content")); - _modContentPaths.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley", "Mods", "Content")); - - //Checks that all defined modpaths exist as directories - _modPaths.ForEach(path => VerifyPath(path)); - _modContentPaths.ForEach(path => VerifyPath(path)); - VerifyPath(Constants.LogPath); - + _modPaths.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley", "Mods"));
+ _modPaths.Add(Path.Combine(Constants.ExecutionPath, "Mods"));
+
+ //Mods need to make their own content paths, since we're doing a different, manifest-driven, approach.
+ //_modContentPaths.Add(Path.Combine(Constants.ExecutionPath, "Mods", "Content"));
+ //_modContentPaths.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley", "Mods", "Content"));
+
+ //Checks that all defined modpaths exist as directories
+ _modPaths.ForEach(path => VerifyPath(path));
+ //_modContentPaths.ForEach(path => VerifyPath(path));
+ VerifyPath(Constants.LogPath);
+
StardewModdingAPI.Log.Initialize(Constants.LogPath);
if (!File.Exists(Constants.ExecutionPath + "\\Stardew Valley.exe"))
- { + {
throw new FileNotFoundException(string.Format("Could not found: {0}\\Stardew Valley.exe", Constants.ExecutionPath));
- } - } - - /// <summary>
- /// Load the injector.
- /// </summary> - /// <remarks> - /// This will load the injector before anything else if it sees it
- /// It doesn't matter though
- /// I'll leave it as a feature in case anyone in the community wants to tinker with it
- /// All you need is a DLL that inherits from mod and is called StardewInjector.dll with an Entry() method
- /// </remarks> - private static void ConfigureInjector()
- { - foreach (string ModPath in _modPaths) - { - foreach (String s in Directory.GetFiles(ModPath, "StardewInjector.dll")) - { - StardewModdingAPI.Log.Success(ConsoleColor.Green, "Found Stardew Injector DLL: " + s); - try - { - Assembly mod = Assembly.UnsafeLoadFrom(s); //to combat internet-downloaded DLLs - - if (mod.DefinedTypes.Count(x => x.BaseType == typeof(Mod)) > 0) - { - StardewModdingAPI.Log.Success("Loading Injector DLL..."); - TypeInfo tar = mod.DefinedTypes.First(x => x.BaseType == typeof(Mod)); - Mod m = (Mod)mod.CreateInstance(tar.ToString()); - Console.WriteLine("LOADED: {0} by {1} - Version {2} | Description: {3}", m.Name, m.Authour, m.Version, m.Description); - m.Entry(false); - StardewInjectorLoaded = true; - StardewInjectorMod = m; - } - else - { - StardewModdingAPI.Log.Error("Invalid Mod DLL"); - } - } - catch (Exception ex) - { - StardewModdingAPI.Log.Error("Failed to load mod '{0}'. Exception details:\n" + ex, s); - } - } - } - } - + }
+ }
+
/// <summary>
/// Load Stardev Valley and control features
- /// </summary> + /// </summary>
private static void ConfigureSDV()
- { - StardewModdingAPI.Log.Info("Initializing SDV Assembly..."); - - // Load in the assembly - ignores security - StardewAssembly = Assembly.UnsafeLoadFrom(Constants.ExecutionPath + "\\Stardew Valley.exe"); - StardewProgramType = StardewAssembly.GetType("StardewValley.Program", true); - StardewGameInfo = StardewProgramType.GetField("gamePtr"); - - // Change the game's version - StardewModdingAPI.Log.Verbose("Injecting New SDV Version..."); + {
+ StardewModdingAPI.Log.Info("Initializing SDV Assembly...");
+
+ // Load in the assembly - ignores security
+ StardewAssembly = Assembly.UnsafeLoadFrom(Constants.ExecutionPath + "\\Stardew Valley.exe");
+ StardewProgramType = StardewAssembly.GetType("StardewValley.Program", true);
+ StardewGameInfo = StardewProgramType.GetField("gamePtr");
+
+ // Change the game's version
+ StardewModdingAPI.Log.Verbose("Injecting New SDV Version...");
Game1.version += string.Format("-Z_MODDED | SMAPI {0}", Constants.VersionString);
- - // Create the thread for the game to run in. - gameThread = new Thread(RunGame); - StardewModdingAPI.Log.Info("Starting SDV..."); +
+ // Create the thread for the game to run in.
+ gameThread = new Thread(RunGame);
+ StardewModdingAPI.Log.Info("Starting SDV...");
gameThread.Start();
// Wait for the game to load up
- while (!ready) ; - - //SDV is running - StardewModdingAPI.Log.Comment("SDV Loaded Into Memory"); - - //Create definition to listen for input - StardewModdingAPI.Log.Verbose("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.ControlEvents.KeyPressed += Events_KeyPressed; + while (!ready) ;
+
+ //SDV is running
+ StardewModdingAPI.Log.Comment("SDV Loaded Into Memory");
+
+ //Create definition to listen for input
+ StardewModdingAPI.Log.Verbose("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.ControlEvents.KeyPressed += Events_KeyPressed;
Events.GameEvents.LoadContent += Events_LoadContent;
- //Events.MenuChanged += Events_MenuChanged; //Idk right now - - StardewModdingAPI.Log.Verbose("Applying Final SDV Tweaks..."); - StardewInvoke(() => + //Events.MenuChanged += Events_MenuChanged; //Idk right now
+
+ StardewModdingAPI.Log.Verbose("Applying Final SDV Tweaks...");
+ StardewInvoke(() =>
{
gamePtr.IsMouseVisible = false;
gamePtr.Window.Title = "Stardew Valley - Version " + Game1.version;
- StardewForm.Resize += Events.GraphicsEvents.InvokeResize; - }); - } - + StardewForm.Resize += Events.GraphicsEvents.InvokeResize;
+ });
+ }
+
/// <summary>
/// Wrap the 'RunGame' method for console output
- /// </summary> + /// </summary>
private static void GameRunInvoker()
- { - //Game's in memory now, send the event - StardewModdingAPI.Log.Verbose("Game Loaded"); - Events.GameEvents.InvokeGameLoaded(); - + {
+ //Game's in memory now, send the event
+ StardewModdingAPI.Log.Verbose("Game Loaded");
+ Events.GameEvents.InvokeGameLoaded();
+
StardewModdingAPI.Log.Comment("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(); - - StardewModdingAPI.Log.Verbose("Game Execution Finished"); - StardewModdingAPI.Log.Verbose("Shutting Down..."); - Thread.Sleep(100); - Environment.Exit(0); + //Begin listening to input
+ consoleInputThread.Start();
+
+
+ while (ready)
+ {
+ //Check if the game is still running 10 times a second
+ Thread.Sleep(1000 / 10);
+ }
+
|
