diff options
| -rw-r--r-- | StardewInjector/StardewHooker.cs | 190 | ||||
| -rw-r--r-- | StardewInjector/StardewInjector.cs | 55 | ||||
| -rw-r--r-- | StardewModdingAPI/Command.cs | 11 | ||||
| -rw-r--r-- | StardewModdingAPI/Events/Game.cs | 6 | ||||
| -rw-r--r-- | StardewModdingAPI/Events/Graphics.cs | 2 | ||||
| -rw-r--r-- | StardewModdingAPI/Inheritance/Menus/SGameMenu.cs | 2 | ||||
| -rw-r--r-- | StardewModdingAPI/Inheritance/SGame.cs | 25 | ||||
| -rw-r--r-- | StardewModdingAPI/Inheritance/SGameLocation.cs | 4 | ||||
| -rw-r--r-- | StardewModdingAPI/Inheritance/SObject.cs | 6 | ||||
| -rw-r--r-- | StardewModdingAPI/Log.cs | 172 | ||||
| -rw-r--r-- | StardewModdingAPI/Program.cs | 399 | ||||
| -rw-r--r-- | StardewModdingAPI/StardewModdingAPI.csproj | 1 | ||||
| -rw-r--r-- | TrainerMod/TrainerMod.cs | 123 |
13 files changed, 638 insertions, 358 deletions
diff --git a/StardewInjector/StardewHooker.cs b/StardewInjector/StardewHooker.cs new file mode 100644 index 00000000..dbf1c5ef --- /dev/null +++ b/StardewInjector/StardewHooker.cs @@ -0,0 +1,190 @@ +using Microsoft.Xna.Framework; +using Mono.Cecil; +using Mono.Cecil.Cil; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using StardewModdingAPI; + +namespace StardewInjector +{ + public class Stardew_Hooker + { + private AssemblyDefinition m_vAsmDefinition = null; + private ModuleDefinition m_vModDefinition = null; + private Assembly m_vAssembly = null; + + public bool Initialize() + { + Console.WriteLine("Initiating StarDew_Injector...."); + try + { + this.m_vAsmDefinition = AssemblyDefinition.ReadAssembly(@"Stardew Valley.exe"); + this.m_vModDefinition = this.m_vAsmDefinition.MainModule; + return true; + } + catch (Exception ex) + { + Log.Error(ex); + return false; + } + } + + public bool Finalize() + { + Console.WriteLine("Finalizing StarDew_Injector...."); + try + { + if (this.m_vAsmDefinition == null) + return false; + + using (MemoryStream mStream = new MemoryStream()) + { + // Write the edited data to the memory stream.. + this.m_vAsmDefinition.Write(mStream); + + // Load the new assembly from the memory stream buffer.. + this.m_vAssembly = Assembly.Load(mStream.GetBuffer()); + + Program.StardewAssembly = m_vAssembly; + + return true; + } + } + catch (Exception ex) + { + Log.Error(ex); + return false; + } + } + + public bool Run() + { + if (this.m_vAssembly == null) + return false; + + Console.WriteLine("Starting Stardew Valley..."); + + m_vAssembly.EntryPoint.Invoke(null, new object[] {new string[0]}); + + return true; + } + + public void ApplyHooks() + { + Console.WriteLine("Applying StarDew_Injector...."); + try + { + InjectMovementSpeed(); + + if (Config.SecondsPerTenMinutes != 7) + InjectClockScale(); + + if (Config.EnableEasyFishing) + InjectEasyFishing(); + + if (Config.EnableAlwaysSpawnFishingBubble) + InjectMoreBubbles(); + + /* + if (Config.EnableDebugMode) + InjectDebugMode(); + */ + } + catch (Exception ex) + { + Log.Error(ex); + } + + } + + private void InjectDebugMode() + { + this.m_vModDefinition.FindMethod("StardewValley.Program::.cctor") + .FindSetField("releaseBuild").Previous() + .ReplaceCreate(OpCodes.Ldc_I4_0); + + Console.WriteLine("Enabled debug mode."); + } + + private void InjectMoreBubbles() + { + this.m_vModDefinition.FindMethod("StardewValley.GameLocation::performTenMinuteUpdate") + .FindLoadField("currentLocation").Next(i => i.ToString().Contains("NextDouble")).Next() + .ReplaceCreate(OpCodes.Ldc_R8, 1.1); + + Console.WriteLine("Forced each area to always spawn a fishing bubble."); + } + + private void InjectEasyFishing() + { + this.m_vModDefinition.FindMethod("StardewValley.Menus.BobberBar::update") + .FindLoadConstant(694) + .Next(i => i.OpCode == OpCodes.Ldc_R4) + .ReplaceCreate(OpCodes.Ldc_R4, 0.001f) + .Next(i => i.OpCode == OpCodes.Ldc_R4) + .ReplaceCreate(OpCodes.Ldc_R4, 0.001f); + + Console.WriteLine("Replaced fish escape constants for all bobbers & bobber id 694 with 0.001, slowing it down."); + } + + private void InjectClockScale() + { + int timeScale = Config.SecondsPerTenMinutes; + timeScale *= 1000; + + this.m_vModDefinition.FindMethod("StardewValley.Game1::UpdateGameClock") + .FindLoadConstant(7000f) + .ReplaceCreate(OpCodes.Ldc_R4, timeScale*1.0f) + .Next(i => i.OpCode == OpCodes.Ldc_R4 && (float) i.Operand == 7000f) + .ReplaceCreate(OpCodes.Ldc_R4, timeScale*1.0f) + .Next(i => i.OpCode == OpCodes.Ldc_I4 && (int) i.Operand == 7000) + .ReplaceCreate(OpCodes.Ldc_I4, timeScale); + + Console.WriteLine("Updated lighting for new timescale ({0}).", timeScale); + } + + private void InjectMovementSpeed() + { + + + if (Config.EnableTweakedDiagonalMovement) + { + this.m_vModDefinition.FindMethod("StardewValley.Farmer::getMovementSpeed") + .FindLoadField("movementDirections").Next(i => i.OpCode == OpCodes.Ldc_I4_1) + .ReplaceCreate(OpCodes.Ldc_I4_4); + + Console.WriteLine("Removed diagonal movement check."); + } + + if (Config.RunSpeed > 0) + { + this.m_vModDefinition.FindMethod("StardewValley.Farmer::getMovementSpeed") + .FindLoadField("movementDirections").Last().CreateBefore(OpCodes.Ldc_R4, (float) Config.RunSpeed).CreateAfter(OpCodes.Add); + + Console.WriteLine("Added run speed: " + Config.RunSpeed); + } + + + } + + + + private void DumpInstructionsToFile(MethodDefinition methodDefinition) + { + var fileName = string.Format("{0}.{1}.txt", methodDefinition.DeclaringType.Name, methodDefinition.Name); + + using (var stream = File.OpenWrite(Path.Combine(".", fileName))) + using (var writer = new StreamWriter(stream)) + { + var ilProcessor = methodDefinition.Body.GetILProcessor(); + for (int i = 0; i < ilProcessor.Body.Instructions.Count; i++) + writer.WriteLine((i) + ":" + ilProcessor.Body.Instructions[i]); + } + } + } +}
\ No newline at end of file diff --git a/StardewInjector/StardewInjector.cs b/StardewInjector/StardewInjector.cs new file mode 100644 index 00000000..b67a8bc9 --- /dev/null +++ b/StardewInjector/StardewInjector.cs @@ -0,0 +1,55 @@ +using StardewModdingAPI; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StardewInjector +{ + public class StardewInjector : Mod + { + public override string Name + { + get { return "Stardew Injector"; } + } + + public override string Authour + { + get { return "Zoryn Aaron"; } + } + + public override string Version + { + get { return "1.0"; } + } + + public override string Description + { + get { return "Pulled from https://github.com/kevinmurphy678/Stardew_Injector and converted to a mod."; } + } + + public static Stardew_Hooker hooker { get; set; } + public override void Entry(params object[] objects) + { + if (objects.Length <= 0 || (objects.Length > 0 && objects[0].AsBool() == false)) + { + hooker = new Stardew_Hooker(); + hooker.Initialize(); + hooker.ApplyHooks(); + hooker.Finalize(); + + Log.Verbose("INJECTOR ENTERED"); + } + else if (objects.Length > 0 && objects[0].AsBool() == true) + { + Log.Verbose("INJECTOR LAUNCHING"); + hooker.Run(); + } + else + { + Log.Verbose("INVALID PARAMETERS FOR INJECTOR"); + } + } + } +} diff --git a/StardewModdingAPI/Command.cs b/StardewModdingAPI/Command.cs index 4bfc7564..71a2483b 100644 --- a/StardewModdingAPI/Command.cs +++ b/StardewModdingAPI/Command.cs @@ -1,9 +1,6 @@ using StardewModdingAPI.Events;
using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace StardewModdingAPI { @@ -44,7 +41,7 @@ namespace StardewModdingAPI } else { - Program.LogError("Unknown Command"); + Log.Error("Unknown Command"); } } @@ -60,12 +57,12 @@ namespace StardewModdingAPI Command c = new Command(command, cdesc, args); if (RegisteredCommands.Contains(c)) { - Program.LogError("Command already registered! [{0}]", c.CommandName); + Log.Error("Command already registered! [{0}]", c.CommandName); return RegisteredCommands.Find(x => x.Equals(c)); } RegisteredCommands.Add(c); - Program.LogColour(ConsoleColor.Cyan, "Registered command: " + command); + Log.Verbose(ConsoleColor.Cyan, "Registered command: " + command); return c; } @@ -102,7 +99,7 @@ namespace StardewModdingAPI { if (CommandFired == null) { - Program.LogError("Command failed to fire because it's fire event is null: " + CommandName); + Log.Error("Command failed to fire because it's fire event is null: " + CommandName); return; } CommandFired.Invoke(this, new EventArgsCommand(this)); diff --git a/StardewModdingAPI/Events/Game.cs b/StardewModdingAPI/Events/Game.cs index d155ba2e..6290d2c7 100644 --- a/StardewModdingAPI/Events/Game.cs +++ b/StardewModdingAPI/Events/Game.cs @@ -26,7 +26,7 @@ namespace StardewModdingAPI.Events }
catch (Exception ex)
{
- Program.LogError("An exception occured in XNA Initialize: " + ex.ToString());
+ Log.Error("An exception occured in XNA Initialize: " + ex.ToString());
}
}
@@ -38,7 +38,7 @@ namespace StardewModdingAPI.Events }
catch (Exception ex)
{
- Program.LogError("An exception occured in XNA LoadContent: " + ex.ToString());
+ Log.Error("An exception occured in XNA LoadContent: " + ex.ToString());
}
}
@@ -50,7 +50,7 @@ namespace StardewModdingAPI.Events }
catch (Exception ex)
{
- Program.LogError("An exception occured in XNA UpdateTick: " + ex.ToString());
+ Log.Error("An exception occured in XNA UpdateTick: " + ex.ToString());
}
}
}
diff --git a/StardewModdingAPI/Events/Graphics.cs b/StardewModdingAPI/Events/Graphics.cs index 62bffe82..60ee7a74 100644 --- a/StardewModdingAPI/Events/Graphics.cs +++ b/StardewModdingAPI/Events/Graphics.cs @@ -19,7 +19,7 @@ namespace StardewModdingAPI.Events }
catch (Exception ex)
{
- Program.LogError("An exception occured in XNA DrawTick: " + ex.ToString());
+ Log.Error("An exception occured in XNA DrawTick: " + ex.ToString());
}
}
diff --git a/StardewModdingAPI/Inheritance/Menus/SGameMenu.cs b/StardewModdingAPI/Inheritance/Menus/SGameMenu.cs index 8b883fb6..721e04d8 100644 --- a/StardewModdingAPI/Inheritance/Menus/SGameMenu.cs +++ b/StardewModdingAPI/Inheritance/Menus/SGameMenu.cs @@ -39,7 +39,7 @@ namespace StardewModdingAPI.Inheritance.Menus { if (pages[currentTab] is InventoryPage) { - Program.LogInfo("INV SCREEN"); + Log.Verbose("INV SCREEN"); } else { diff --git a/StardewModdingAPI/Inheritance/SGame.cs b/StardewModdingAPI/Inheritance/SGame.cs index 69439209..c7b07c43 100644 --- a/StardewModdingAPI/Inheritance/SGame.cs +++ b/StardewModdingAPI/Inheritance/SGame.cs @@ -75,9 +75,8 @@ namespace StardewModdingAPI.Inheritance {
instance = this;
- if (Program.debug)
- {
- SaveGame.serializer = new XmlSerializer(typeof (SaveGame), new Type[28]
+#if DEBUG
+ SaveGame.serializer = new XmlSerializer(typeof (SaveGame), new Type[28]
{
typeof (Tool),
typeof (GameLocation),
@@ -108,12 +107,12 @@ namespace StardewModdingAPI.Inheritance typeof (TerrainFeature),
typeof (SObject)
});
- }
+#endif
}
protected override void Initialize()
{
- Program.Log("XNA Initialize");
+ Log.Verbose("XNA Initialize");
ModItems = new Dictionary<Int32, SObject>();
PreviouslyPressedKeys = new Keys[0];
base.Initialize();
@@ -122,7 +121,7 @@ namespace StardewModdingAPI.Inheritance protected override void LoadContent()
{
- Program.Log("XNA LoadContent");
+ Log.Verbose("XNA LoadContent");
base.LoadContent();
Events.GameEvents.InvokeLoadContent();
}
@@ -137,7 +136,7 @@ namespace StardewModdingAPI.Inheritance }
catch (Exception ex)
{
- Program.LogError("An error occured in the base update loop: " + ex);
+ Log.Error("An error occured in the base update loop: " + ex);
Console.ReadKey();
}
@@ -169,7 +168,7 @@ namespace StardewModdingAPI.Inheritance {
if (modItem.HasBeenRegistered)
{
- Program.LogError("The item {0} has already been registered with ID {1}", modItem.Name, modItem.RegisteredId);
+ Log.Error("The item {0} has already been registered with ID {1}", modItem.Name, modItem.RegisteredId);
return modItem.RegisteredId;
}
Int32 newId = LowestModItemID;
@@ -189,14 +188,14 @@ namespace StardewModdingAPI.Inheritance {
return ModItems.ElementAt(id).Value.Clone();
}
- Program.LogError("ModItem Dictionary does not contain index: " + id.ToString());
+ Log.Error("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.ToString());
+ Log.Error("ModItem Dictionary does not contain ID: " + id.ToString());
return null;
}
@@ -212,7 +211,7 @@ namespace StardewModdingAPI.Inheritance GameLocation gl = locations.FirstOrDefault(x => x.name == name);
if (gl != null)
{
- Program.LogDebug("A custom location was created for the new name: " + name);
+ Log.Debug("A custom location was created for the new name: " + name);
SGameLocation s = SGameLocation.ConstructFromBaseClass(gl);
ModLocations.Add(s);
return s;
@@ -220,13 +219,13 @@ namespace StardewModdingAPI.Inheritance if (currentLocation != null && currentLocation.name == name)
{
gl = currentLocation;
- Program.LogDebug("A custom location was created from the current location for the new name: " + name);
+ Log.Debug("A custom location was created from the current location for the new name: " + name);
SGameLocation s = SGameLocation.ConstructFromBaseClass(gl);
ModLocations.Add(s);
return s;
}
- Program.LogDebug("A custom location could not be created for: " + name);
+ Log.Debug("A custom location could not be created for: " + name);
return null;
}
diff --git a/StardewModdingAPI/Inheritance/SGameLocation.cs b/StardewModdingAPI/Inheritance/SGameLocation.cs index 0787c0e1..437b0bfa 100644 --- a/StardewModdingAPI/Inheritance/SGameLocation.cs +++ b/StardewModdingAPI/Inheritance/SGameLocation.cs @@ -25,7 +25,7 @@ namespace StardewModdingAPI.Inheritance s.BaseGameLocation = baseClass; s.name = baseClass.name; - Program.LogDebug("CONSTRUCTED: " + s.name); + Log.Debug("CONSTRUCTED: " + s.name); if (copyAllData) { @@ -42,7 +42,7 @@ namespace StardewModdingAPI.Inheritance } catch (Exception ex) { - Program.LogError(ex); + Log.Error(ex); } } } diff --git a/StardewModdingAPI/Inheritance/SObject.cs b/StardewModdingAPI/Inheritance/SObject.cs index 25cdb26e..28254c24 100644 --- a/StardewModdingAPI/Inheritance/SObject.cs +++ b/StardewModdingAPI/Inheritance/SObject.cs @@ -78,7 +78,7 @@ namespace StardewModdingAPI.Inheritance public override void draw(SpriteBatch spriteBatch, int xNonTile, int yNonTile, float layerDepth, float alpha = 1) { - Program.LogInfo("THIS DRAW FUNCTION IS NOT IMPLEMENTED I WANT TO KNOW WHERE IT IS CALLED"); + Log.Debug("THIS DRAW FUNCTION IS NOT IMPLEMENTED I WANT TO KNOW WHERE IT IS CALLED"); return; try { @@ -105,7 +105,7 @@ namespace StardewModdingAPI.Inheritance } catch (Exception ex) { - Program.LogError(ex.ToString()); + Log.Error(ex.ToString()); Console.ReadKey(); } } @@ -249,7 +249,7 @@ namespace StardewModdingAPI.Inheritance s.boundingBox = new Rectangle(x / Game1.tileSize * Game1.tileSize, y / Game1.tileSize * Game1.tileSize, this.boundingBox.Width, this.boundingBox.Height); location.objects.Add(key, s); - Program.LogInfo("{0} - {1}", this.GetHashCode(), s.GetHashCode()); + Log.Verbose("{0} - {1}", this.GetHashCode(), s.GetHashCode()); return true; } diff --git a/StardewModdingAPI/Log.cs b/StardewModdingAPI/Log.cs new file mode 100644 index 00000000..2784b709 --- /dev/null +++ b/StardewModdingAPI/Log.cs @@ -0,0 +1,172 @@ +using System; +using System.IO; +using System.Threading; + +namespace StardewModdingAPI +{ + + /// <summary> + /// Class to organize logging calls. + /// </summary> + public class Log + { + private static StreamWriter _logStream; + private static string _logPath; + + /// <summary> + /// Set up the logging stream + /// </summary> + /// <param name="logPath"></param> + public static void Initialize(string logPath) + { + _logPath = logPath; + var logFile = string.Format("{0}\\MODDED_ProgramLog.Log_LATEST.txt", logPath); + try + { + _logStream = new StreamWriter(logFile, false); + } + catch (Exception) + { + // TODO: not use general exception + Log.Error("Could not initialize LogStream - Logging is disabled"); + } + } + + /// <summary> + /// 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="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)); + Console.WriteLine(logOutput); + + if (_logStream != null && !disableLogging) + { + _logStream.WriteLine(logOutput); + _logStream.Flush(); + } + } + + /// <summary> + /// Successful message to display to console and logging. + /// </summary> + /// <param name="message"></param> + /// <param name="values"></param> + public static void Success(object message, params object[] values) + { + Console.ForegroundColor = ConsoleColor.Green; + Log.PrintLog(message?.ToString(), false, values); + Console.ForegroundColor = ConsoleColor.Gray; + } + + /// <summary> + /// Generic comment to display to console and logging. + /// </summary> + /// <param name="message"></param> + /// <param name="values"></param> + public static void Verbose(object message, params object[] values) + { + Log.PrintLog(message?.ToString(), false, values); + } + + /// <summary> + /// Additional comment to display to console and logging. + /// </summary> + /// <param name="message"></param> + /// <param name="values"></param> + public static void Comment(object message, params object[] values) + { + Console.ForegroundColor = ConsoleColor.Yellow; + Log.PrintLog(message?.ToString(), false, values); + Console.ForegroundColor = ConsoleColor.Gray; + } + + /// <summary> + /// Message for only console. Does not appear in logging. + /// </summary> + /// <param name="message"></param> + /// <param name="values"></param> + public static void Info(object message, params object[] values) + { + Log.PrintLog(message.ToString(), true, values); + } + + /// <summary> + /// Important message indicating an error. + /// </summary> + /// <param name="message"></param> + /// <param name="values"></param> + public static void Error(object message, params object[] values) + { + Console.ForegroundColor = ConsoleColor.Red; + Log.PrintLog(message.ToString(), false, values); + Console.ForegroundColor = ConsoleColor.Gray; + } + + /// <summary> + /// A message displayed only while in DEBUG mode + /// </summary> + /// <param name="message"></param> + /// <param name="values"></param> + public static void Debug(object message, params object[] values) + { +#if DEBUG + Console.ForegroundColor = ConsoleColor.Yellow; + Log.PrintLog(message.ToString(), false, values); + Console.ForegroundColor = ConsoleColor.Gray; +#endif + } + + /// <summary> + /// Catch unhandled exception from the application + /// </summary> + /// <remarks>Should be moved out of here if we do more than just log the exception.</remarks> + 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()); + } + + /// <summary> + /// Catch thread exception from the application + /// </summary> + /// <remarks>Should be moved out of here if we do more than just log the exception.</remarks> + public static void Application_ThreadException(object sender, ThreadExceptionEventArgs e) + { + Console.WriteLine("A thread exception has been caught"); + File.WriteAllText(_logPath + "\\MODDED_ErrorLog.Log_" + Extensions.Random.Next(100000000, 999999999) + ".txt", e.Exception.ToString()); + } + + // I'm including the following for now because they have a lot of references with different uses. + // They should be removed since they do not provide any insight into actual problems, and other log methods should be used. + + public static void LogValueNotSpecified() + { + Error("<value> must be specified"); + } + + public static void LogObjectValueNotSpecified() + { + Error("<object> and <value> must be specified"); + } + + public static void LogValueInvalid() + { + Error("<value> is invalid"); + } + + public static void LogObjectInvalid() + { + Error("<object> is invalid"); + } + + public static void LogValueNotInt32() + { + Error("<value> must be a whole number (Int32)"); + } + + } +} diff --git a/StardewModdingAPI/Program.cs b/StardewModdingAPI/Program.cs index 000ddab0..3e267af5 100644 --- a/StardewModdingAPI/Program.cs +++ b/StardewModdingAPI/Program.cs @@ -1,29 +1,18 @@ -using System; -using System.CodeDom.Compiler; +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.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; -using StardewModdingAPI.Events;
namespace StardewModdingAPI { @@ -32,7 +21,7 @@ namespace StardewModdingAPI 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 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; } @@ -51,25 +40,22 @@ namespace StardewModdingAPI public static Thread consoleInputThread; public const string Version = "0.36 Alpha"; - public const bool debug = false; - public static bool disableLogging { get; private set; } public static bool StardewInjectorLoaded { get; private set; } public static Mod StardewInjectorMod { 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 + Console.Title += " - Version " + Version;
+#if DEBUG + Console.Title += " - DEBUG IS NOT FALSE, AUTHOUR NEEDS TO REUPLOAD THIS VERSION";
+#endif
+
+ //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")); @@ -88,7 +74,7 @@ namespace StardewModdingAPI } catch (Exception ex) { - LogError("Could not create a missing ModPath: " + ModPath + "\n\n" + ex); + Log.Error("Could not create a missing ModPath: " + ModPath + "\n\n" + ex); } } //Same for content @@ -101,7 +87,7 @@ namespace StardewModdingAPI } catch (Exception ex) { - LogError("Could not create a missing ModContentPath: " + ModContentPath + "\n\n" + ex); + Log.Error("Could not create a missing ModContentPath: " + ModContentPath + "\n\n" + ex); } } //And then make sure we have an errorlog dir @@ -112,32 +98,15 @@ namespace StardewModdingAPI } 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"); + Log.Error("Could not create the missing ErrorLogs path: " + LogPath + "\n\n" + ex); } - - LogInfo("Initializing SDV Assembly..."); + Log.Info("Initializing SDV Assembly..."); if (!File.Exists(ExecutionPath + "\\Stardew Valley.exe")) { //If the api isn't next to SDV.exe then terminate. Though it'll crash before we even get here w/o sdv.exe. Perplexing. - LogError("Could not find: " + ExecutionPath + "\\Stardew Valley.exe"); - LogError("The API will now terminate."); + Log.Error("Could not find: " + ExecutionPath + "\\Stardew Valley.exe"); + Log.Error("The API will now terminate."); Console.ReadKey(); Environment.Exit(-4); } @@ -153,16 +122,16 @@ namespace StardewModdingAPI { foreach (String s in Directory.GetFiles(ModPath, "StardewInjector.dll")) { - LogColour(ConsoleColor.Green, "Found Stardew Injector DLL: " + s); + 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) + if (mod.DefinedTypes.Count(x => x.BaseType == typeof(Mod)) > 0) { - LogColour(ConsoleColor.Green, "Loading Injector DLL..."); - TypeInfo tar = mod.DefinedTypes.First(x => x.BaseType == typeof (Mod)); - Mod m = (Mod) mod.CreateInstance(tar.ToString()); + 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; @@ -170,12 +139,12 @@ namespace StardewModdingAPI } else { - LogError("Invalid Mod DLL"); + Log.Error("Invalid Mod DLL"); } } catch (Exception ex) { - LogError("Failed to load mod '{0}'. Exception details:\n" + ex, s); |
