Merge pull request #4 from Jtfinlay/release

Logging refactor
This commit is contained in:
ClxS 2016-03-06 15:26:04 +00:00
commit ff96bba617
12 changed files with 401 additions and 368 deletions

View File

@ -1,9 +1,6 @@
using StardewModdingAPI.Events; using StardewModdingAPI.Events;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StardewModdingAPI namespace StardewModdingAPI
{ {
@ -44,7 +41,7 @@ namespace StardewModdingAPI
} }
else else
{ {
Program.LogError("Unknown Command"); Log.Error("Unknown Command");
} }
} }
@ -60,12 +57,12 @@ namespace StardewModdingAPI
Command c = new Command(command, cdesc, args); Command c = new Command(command, cdesc, args);
if (RegisteredCommands.Contains(c)) 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)); return RegisteredCommands.Find(x => x.Equals(c));
} }
RegisteredCommands.Add(c); RegisteredCommands.Add(c);
Program.LogColour(ConsoleColor.Cyan, "Registered command: " + command); Log.Verbose(ConsoleColor.Cyan, "Registered command: " + command);
return c; return c;
} }
@ -102,7 +99,7 @@ namespace StardewModdingAPI
{ {
if (CommandFired == null) 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; return;
} }
CommandFired.Invoke(this, new EventArgsCommand(this)); CommandFired.Invoke(this, new EventArgsCommand(this));

View File

@ -26,7 +26,7 @@ namespace StardewModdingAPI.Events
} }
catch (Exception ex) 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) 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) catch (Exception ex)
{ {
Program.LogError("An exception occured in XNA UpdateTick: " + ex.ToString()); Log.Error("An exception occured in XNA UpdateTick: " + ex.ToString());
} }
} }
} }

View File

@ -19,7 +19,7 @@ namespace StardewModdingAPI.Events
} }
catch (Exception ex) catch (Exception ex)
{ {
Program.LogError("An exception occured in XNA DrawTick: " + ex.ToString()); Log.Error("An exception occured in XNA DrawTick: " + ex.ToString());
} }
} }

View File

@ -39,7 +39,7 @@ namespace StardewModdingAPI.Inheritance.Menus
{ {
if (pages[currentTab] is InventoryPage) if (pages[currentTab] is InventoryPage)
{ {
Program.LogInfo("INV SCREEN"); Log.Verbose("INV SCREEN");
} }
else else
{ {

View File

@ -75,8 +75,7 @@ namespace StardewModdingAPI.Inheritance
{ {
instance = this; instance = this;
if (Program.debug) #if DEBUG
{
SaveGame.serializer = new XmlSerializer(typeof (SaveGame), new Type[28] SaveGame.serializer = new XmlSerializer(typeof (SaveGame), new Type[28]
{ {
typeof (Tool), typeof (Tool),
@ -108,12 +107,12 @@ namespace StardewModdingAPI.Inheritance
typeof (TerrainFeature), typeof (TerrainFeature),
typeof (SObject) typeof (SObject)
}); });
} #endif
} }
protected override void Initialize() protected override void Initialize()
{ {
Program.Log("XNA Initialize"); Log.Verbose("XNA Initialize");
ModItems = new Dictionary<Int32, SObject>(); ModItems = new Dictionary<Int32, SObject>();
PreviouslyPressedKeys = new Keys[0]; PreviouslyPressedKeys = new Keys[0];
base.Initialize(); base.Initialize();
@ -122,7 +121,7 @@ namespace StardewModdingAPI.Inheritance
protected override void LoadContent() protected override void LoadContent()
{ {
Program.Log("XNA LoadContent"); Log.Verbose("XNA LoadContent");
base.LoadContent(); base.LoadContent();
Events.GameEvents.InvokeLoadContent(); Events.GameEvents.InvokeLoadContent();
} }
@ -137,7 +136,7 @@ namespace StardewModdingAPI.Inheritance
} }
catch (Exception ex) 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(); Console.ReadKey();
} }
@ -169,7 +168,7 @@ namespace StardewModdingAPI.Inheritance
{ {
if (modItem.HasBeenRegistered) 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; return modItem.RegisteredId;
} }
Int32 newId = LowestModItemID; Int32 newId = LowestModItemID;
@ -189,14 +188,14 @@ namespace StardewModdingAPI.Inheritance
{ {
return ModItems.ElementAt(id).Value.Clone(); 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; return null;
} }
if (ModItems.ContainsKey(id)) if (ModItems.ContainsKey(id))
{ {
return ModItems[id].Clone(); 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; return null;
} }
@ -212,7 +211,7 @@ namespace StardewModdingAPI.Inheritance
GameLocation gl = locations.FirstOrDefault(x => x.name == name); GameLocation gl = locations.FirstOrDefault(x => x.name == name);
if (gl != null) 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); SGameLocation s = SGameLocation.ConstructFromBaseClass(gl);
ModLocations.Add(s); ModLocations.Add(s);
return s; return s;
@ -220,13 +219,13 @@ namespace StardewModdingAPI.Inheritance
if (currentLocation != null && currentLocation.name == name) if (currentLocation != null && currentLocation.name == name)
{ {
gl = currentLocation; 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); SGameLocation s = SGameLocation.ConstructFromBaseClass(gl);
ModLocations.Add(s); ModLocations.Add(s);
return 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; return null;
} }

View File

@ -25,7 +25,7 @@ namespace StardewModdingAPI.Inheritance
s.BaseGameLocation = baseClass; s.BaseGameLocation = baseClass;
s.name = baseClass.name; s.name = baseClass.name;
Program.LogDebug("CONSTRUCTED: " + s.name); Log.Debug("CONSTRUCTED: " + s.name);
if (copyAllData) if (copyAllData)
{ {
@ -42,7 +42,7 @@ namespace StardewModdingAPI.Inheritance
} }
catch (Exception ex) catch (Exception ex)
{ {
Program.LogError(ex); Log.Error(ex);
} }
} }
} }

View File

@ -78,7 +78,7 @@ namespace StardewModdingAPI.Inheritance
public override void draw(SpriteBatch spriteBatch, int xNonTile, int yNonTile, float layerDepth, float alpha = 1) 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; return;
try try
{ {
@ -105,7 +105,7 @@ namespace StardewModdingAPI.Inheritance
} }
catch (Exception ex) catch (Exception ex)
{ {
Program.LogError(ex.ToString()); Log.Error(ex.ToString());
Console.ReadKey(); 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); 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); location.objects.Add(key, s);
Program.LogInfo("{0} - {1}", this.GetHashCode(), s.GetHashCode()); Log.Verbose("{0} - {1}", this.GetHashCode(), s.GetHashCode());
return true; return true;
} }

172
StardewModdingAPI/Log.cs Normal file
View File

@ -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)");
}
}
}

View File

@ -1,29 +1,18 @@
using System; using Microsoft.Xna.Framework;
using System.CodeDom.Compiler; 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.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms; 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 namespace StardewModdingAPI
{ {
@ -34,8 +23,6 @@ namespace StardewModdingAPI
public static List<string> ModPaths = new List<string>(); 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 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 Texture2D DebugPixel { get; private set; }
@ -51,23 +38,20 @@ namespace StardewModdingAPI
public static Thread consoleInputThread; public static Thread consoleInputThread;
public const string Version = "0.36 Alpha"; 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 bool StardewInjectorLoaded { get; private set; }
public static Mod StardewInjectorMod { get; private set; } public static Mod StardewInjectorMod { get; private set; }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private static void Main(string[] args) private static void Main(string[] args)
{ {
Console.Title = "Stardew Modding API Console"; Console.Title = "Stardew Modding API Console";
Console.Title += " - Version " + Version; Console.Title += " - Version " + Version;
if (debug) #if DEBUG
Console.Title += " - DEBUG IS NOT FALSE, AUTHOUR NEEDS TO REUPLOAD THIS VERSION"; 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 //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); ExecutionPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
@ -88,7 +72,7 @@ namespace StardewModdingAPI
} }
catch (Exception ex) 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 //Same for content
@ -101,7 +85,7 @@ namespace StardewModdingAPI
} }
catch (Exception ex) 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 //And then make sure we have an errorlog dir
@ -112,32 +96,15 @@ namespace StardewModdingAPI
} }
catch (Exception ex) catch (Exception ex)
{ {
LogError("Could not create the missing ErrorLogs path: " + LogPath + "\n\n" + ex); Log.Error("Could not create the missing ErrorLogs path: " + LogPath + "\n\n" + ex);
} }
//Define the path to the current log file Log.Info("Initializing SDV Assembly...");
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 (!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. //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"); Log.Error("Could not find: " + ExecutionPath + "\\Stardew Valley.exe");
LogError("The API will now terminate."); Log.Error("The API will now terminate.");
Console.ReadKey(); Console.ReadKey();
Environment.Exit(-4); Environment.Exit(-4);
} }
@ -153,14 +120,14 @@ namespace StardewModdingAPI
{ {
foreach (String s in Directory.GetFiles(ModPath, "StardewInjector.dll")) 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 try
{ {
Assembly mod = Assembly.UnsafeLoadFrom(s); //to combat internet-downloaded DLLs 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..."); Log.Success("Loading Injector DLL...");
TypeInfo tar = mod.DefinedTypes.First(x => x.BaseType == typeof(Mod)); TypeInfo tar = mod.DefinedTypes.First(x => x.BaseType == typeof(Mod));
Mod m = (Mod)mod.CreateInstance(tar.ToString()); 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); Console.WriteLine("LOADED: {0} by {1} - Version {2} | Description: {3}", m.Name, m.Authour, m.Version, m.Description);
@ -170,12 +137,12 @@ namespace StardewModdingAPI
} }
else else
{ {
LogError("Invalid Mod DLL"); Log.Error("Invalid Mod DLL");
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
LogError("Failed to load mod '{0}'. Exception details:\n" + ex, s); Log.Error("Failed to load mod '{0}'. Exception details:\n" + ex, s);
} }
} }
} }
@ -190,7 +157,7 @@ namespace StardewModdingAPI
{ {
//Stardew_Injector Mode //Stardew_Injector Mode
StardewInjectorLoaded = true; StardewInjectorLoaded = true;
Program.LogInfo("STARDEW_INJECTOR DETECTED, LAUNCHING USING INJECTOR CALLS"); Program.Log.LogInfo("STARDEW_INJECTOR DETECTED, LAUNCHING USING INJECTOR CALLS");
Assembly inj = Assembly.UnsafeLoadFrom(ExecutionPath + "\\Stardew_Injector.exe"); Assembly inj = Assembly.UnsafeLoadFrom(ExecutionPath + "\\Stardew_Injector.exe");
Type prog = inj.GetType("Stardew_Injector.Program", true); Type prog = inj.GetType("Stardew_Injector.Program", true);
FieldInfo hooker = prog.GetField("hooker", BindingFlags.NonPublic | BindingFlags.Static); FieldInfo hooker = prog.GetField("hooker", BindingFlags.NonPublic | BindingFlags.Static);
@ -221,12 +188,12 @@ namespace StardewModdingAPI
#endregion #endregion
//Change the game's version //Change the game's version
LogInfo("Injecting New SDV Version..."); Log.Info("Injecting New SDV Version...");
Game1.version += "-Z_MODDED | SMAPI " + Version; Game1.version += "-Z_MODDED | SMAPI " + Version;
//Create the thread for the game to run in. //Create the thread for the game to run in.
gameThread = new Thread(RunGame); gameThread = new Thread(RunGame);
LogInfo("Starting SDV..."); Log.Info("Starting SDV...");
gameThread.Start(); gameThread.Start();
//I forget. //I forget.
@ -238,10 +205,10 @@ namespace StardewModdingAPI
} }
//SDV is running //SDV is running
Log("SDV Loaded Into Memory"); Log.Comment("SDV Loaded Into Memory");
//Create definition to listen for input //Create definition to listen for input
LogInfo("Initializing Console Input Thread..."); Log.Verbose("Initializing Console Input Thread...");
consoleInputThread = new Thread(ConsoleInputThread); consoleInputThread = new Thread(ConsoleInputThread);
//The only command in the API (at least it should be, for now)\ //The only command in the API (at least it should be, for now)\
@ -253,15 +220,15 @@ namespace StardewModdingAPI
Events.ControlEvents.KeyPressed += Events_KeyPressed; Events.ControlEvents.KeyPressed += Events_KeyPressed;
Events.GameEvents.LoadContent += Events_LoadContent; Events.GameEvents.LoadContent += Events_LoadContent;
//Events.MenuChanged += Events_MenuChanged; //Idk right now //Events.MenuChanged += Events_MenuChanged; //Idk right now
if (debug)
{ #if DEBUG
//Experimental //Experimental
//Events.LocationsChanged += Events_LocationsChanged; //Events.LocationsChanged += Events_LocationsChanged;
//Events.CurrentLocationChanged += Events_CurrentLocationChanged; //Events.CurrentLocationChanged += Events_CurrentLocationChanged;
} #endif
//Do tweaks using winforms invoke because I'm lazy //Do tweaks using winforms invoke because I'm lazy
LogInfo("Applying Final SDV Tweaks..."); Log.Verbose("Applying Final SDV Tweaks...");
StardewInvoke(() => StardewInvoke(() =>
{ {
gamePtr.IsMouseVisible = false; gamePtr.IsMouseVisible = false;
@ -270,10 +237,10 @@ namespace StardewModdingAPI
}); });
//Game's in memory now, send the event //Game's in memory now, send the event
LogInfo("Game Loaded"); Log.Verbose("Game Loaded");
Events.GameEvents.InvokeGameLoaded(); Events.GameEvents.InvokeGameLoaded();
LogColour(ConsoleColor.Cyan, "Type 'help' for help, or 'help <cmd>' for a command's usage"); Log.Comment(ConsoleColor.Cyan, "Type 'help' for help, or 'help <cmd>' for a command's usage");
//Begin listening to input //Begin listening to input
consoleInputThread.Start(); consoleInputThread.Start();
@ -288,8 +255,8 @@ namespace StardewModdingAPI
if (consoleInputThread != null && consoleInputThread.ThreadState == ThreadState.Running) if (consoleInputThread != null && consoleInputThread.ThreadState == ThreadState.Running)
consoleInputThread.Abort(); consoleInputThread.Abort();
LogInfo("Game Execution Finished"); Log.Verbose("Game Execution Finished");
LogInfo("Shutting Down..."); Log.Verbose("Shutting Down...");
Thread.Sleep(100); Thread.Sleep(100);
/* /*
int time = 0; int time = 0;
@ -313,20 +280,16 @@ namespace StardewModdingAPI
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public static void RunGame() public static void RunGame()
{ {
//Does this even do anything??? Application.ThreadException += Log.Application_ThreadException;
Application.ThreadException += Application_ThreadException;
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; AppDomain.CurrentDomain.UnhandledException += Log.CurrentDomain_UnhandledException;
//I've yet to see it called :|
try try
{ {
gamePtr = new SGame(); gamePtr = new SGame();
LogInfo("Patching SDV Graphics Profile..."); Log.Verbose("Patching SDV Graphics Profile...");
Game1.graphics.GraphicsProfile = GraphicsProfile.HiDef; Game1.graphics.GraphicsProfile = GraphicsProfile.HiDef;
LoadMods(); LoadMods();
@ -356,7 +319,7 @@ namespace StardewModdingAPI
} }
catch (Exception ex) catch (Exception ex)
{ {
LogError("Game failed to start: " + ex); Log.Error("Game failed to start: " + ex);
} }
} }
@ -375,7 +338,7 @@ namespace StardewModdingAPI
public static void LoadMods() public static void LoadMods()
{ {
LogColour(ConsoleColor.Green, "LOADING MODS"); Log.Verbose("LOADING MODS");
int loadedMods = 0; int loadedMods = 0;
foreach (string ModPath in ModPaths) foreach (string ModPath in ModPaths)
{ {
@ -383,14 +346,14 @@ namespace StardewModdingAPI
{ {
if (s.Contains("StardewInjector")) if (s.Contains("StardewInjector"))
continue; continue;
LogColour(ConsoleColor.Green, "Found DLL: " + s); Log.Success("Found DLL: " + s);
try try
{ {
Assembly mod = Assembly.UnsafeLoadFrom(s); //to combat internet-downloaded DLLs 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 Mod DLL..."); Log.Verbose("Loading Mod DLL...");
TypeInfo tar = mod.DefinedTypes.First(x => x.BaseType == typeof(Mod)); TypeInfo tar = mod.DefinedTypes.First(x => x.BaseType == typeof(Mod));
Mod m = (Mod)mod.CreateInstance(tar.ToString()); 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); Console.WriteLine("LOADED MOD: {0} by {1} - Version {2} | Description: {3}", m.Name, m.Authour, m.Version, m.Description);
@ -399,16 +362,16 @@ namespace StardewModdingAPI
} }
else else
{ {
LogError("Invalid Mod DLL"); Log.Error("Invalid Mod DLL");
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
LogError("Failed to load mod '{0}'. Exception details:\n" + ex, s); Log.Error("Failed to load mod '{0}'. Exception details:\n" + ex, s);
} }
} }
} }
LogColour(ConsoleColor.Green, "LOADED {0} MODS", loadedMods); Log.Success("LOADED {0} MODS", loadedMods);
} }
public static void ConsoleInputThread() public static void ConsoleInputThread()
@ -423,13 +386,12 @@ namespace StardewModdingAPI
static void Events_LoadContent(object o, EventArgs e) static void Events_LoadContent(object o, EventArgs e)
{ {
LogInfo("Initializing Debug Assets..."); Log.Info("Initializing Debug Assets...");
DebugPixel = new Texture2D(Game1.graphics.GraphicsDevice, 1, 1); DebugPixel = new Texture2D(Game1.graphics.GraphicsDevice, 1, 1);
DebugPixel.SetData(new Color[] { Color.White }); DebugPixel.SetData(new Color[] { Color.White });
if (debug) #if DEBUG
{ Log.Verbose("REGISTERING BASE CUSTOM ITEM");
LogColour(ConsoleColor.Magenta, "REGISTERING BASE CUSTOM ITEM");
SObject so = new SObject(); SObject so = new SObject();
so.Name = "Mario Block"; so.Name = "Mario Block";
so.CategoryName = "SMAPI Test Mod"; so.CategoryName = "SMAPI Test Mod";
@ -437,9 +399,9 @@ namespace StardewModdingAPI
so.Texture = Texture2D.FromStream(Game1.graphics.GraphicsDevice, new FileStream(ModContentPaths[0] + "\\Test.png", FileMode.Open)); so.Texture = Texture2D.FromStream(Game1.graphics.GraphicsDevice, new FileStream(ModContentPaths[0] + "\\Test.png", FileMode.Open));
so.IsPassable = true; so.IsPassable = true;
so.IsPlaceable = true; so.IsPlaceable = true;
LogColour(ConsoleColor.Cyan, "REGISTERED WITH ID OF: " + SGame.RegisterModItem(so)); Log.Verbose("REGISTERED WITH ID OF: " + SGame.RegisterModItem(so));
LogColour(ConsoleColor.Magenta, "REGISTERING SECOND CUSTOM ITEM"); Log.Verbose("REGISTERING SECOND CUSTOM ITEM");
SObject so2 = new SObject(); SObject so2 = new SObject();
so2.Name = "Mario Painting"; so2.Name = "Mario Painting";
so2.CategoryName = "SMAPI Test Mod"; so2.CategoryName = "SMAPI Test Mod";
@ -447,11 +409,10 @@ namespace StardewModdingAPI
so2.Texture = Texture2D.FromStream(Game1.graphics.GraphicsDevice, new FileStream(ModContentPaths[0] + "\\PaintingTest.png", FileMode.Open)); so2.Texture = Texture2D.FromStream(Game1.graphics.GraphicsDevice, new FileStream(ModContentPaths[0] + "\\PaintingTest.png", FileMode.Open));
so2.IsPassable = true; so2.IsPassable = true;
so2.IsPlaceable = true; so2.IsPlaceable = true;
LogColour(ConsoleColor.Cyan, "REGISTERED WITH ID OF: " + SGame.RegisterModItem(so2)); Log.Verbose("REGISTERED WITH ID OF: " + SGame.RegisterModItem(so2));
}
if (debug)
Command.CallCommand("load"); Command.CallCommand("load");
#endif
} }
static void Events_KeyPressed(object o, EventArgsKeyPressed e) static void Events_KeyPressed(object o, EventArgsKeyPressed e)
@ -461,33 +422,32 @@ namespace StardewModdingAPI
static void Events_MenuChanged(IClickableMenu newMenu) static void Events_MenuChanged(IClickableMenu newMenu)
{ {
LogInfo("NEW MENU: " + newMenu.GetType()); Log.Verbose("NEW MENU: " + newMenu.GetType());
if (newMenu is GameMenu) if (newMenu is GameMenu)
{ {
Game1.activeClickableMenu = SGameMenu.ConstructFromBaseClass(Game1.activeClickableMenu as GameMenu); Game1.activeClickableMenu = SGameMenu.ConstructFromBaseClass(Game1.activeClickableMenu as GameMenu);
} }
} }
static void Events_LocationsChanged(List<GameLocation> newLocations) static void Events_LocationsChanged(List<GameLocation> newLocations)
{ {
if (debug) #if DEBUG
{
SGame.ModLocations = SGameLocation.ConstructFromBaseClasses(Game1.locations); SGame.ModLocations = SGameLocation.ConstructFromBaseClasses(Game1.locations);
} #endif
} }
static void Events_CurrentLocationChanged(GameLocation newLocation) static void Events_CurrentLocationChanged(GameLocation newLocation)
{ {
//SGame.CurrentLocation = null; //SGame.CurrentLocation = null;
//System.Threading.Thread.Sleep(10); //System.Threading.Thread.Sleep(10);
if (debug) #if DEBUG
{
Console.WriteLine(newLocation.name); Console.WriteLine(newLocation.name);
SGame.CurrentLocation = SGame.LoadOrCreateSGameLocationFromName(newLocation.name); SGame.CurrentLocation = SGame.LoadOrCreateSGameLocationFromName(newLocation.name);
} #endif
//Game1.currentLocation = SGame.CurrentLocation; //Game1.currentLocation = SGame.CurrentLocation;
//LogInfo(((SGameLocation) newLocation).name); //Log.LogComment(((SGameLocation) newLocation).name);
//LogInfo("LOC CHANGED: " + SGame.currentLocation.name); //Log.LogComment("LOC CHANGED: " + SGame.currentLocation.name);
} }
public static void StardewInvoke(Action a) public static void StardewInvoke(Action a)
@ -495,118 +455,23 @@ namespace StardewModdingAPI
StardewForm.Invoke(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 o, EventArgsCommand e) static void help_CommandFired(object o, EventArgsCommand e)
{ {
if (e.Command.CalledArgs.Length > 0) if (e.Command.CalledArgs.Length > 0)
{ {
Command fnd = Command.FindCommand(e.Command.CalledArgs[0]); Command fnd = Command.FindCommand(e.Command.CalledArgs[0]);
if (fnd == null) if (fnd == null)
LogError("The command specified could not be found"); Log.Error("The command specified could not be found");
else else
{ {
if (fnd.CommandArgs.Length > 0) if (fnd.CommandArgs.Length > 0)
LogInfo("{0}: {1} - {2}", fnd.CommandName, fnd.CommandDesc, fnd.CommandArgs.ToSingular()); Log.Info("{0}: {1} - {2}", fnd.CommandName, fnd.CommandDesc, fnd.CommandArgs.ToSingular());
else else
LogInfo("{0}: {1}", fnd.CommandName, fnd.CommandDesc); Log.Info("{0}: {1}", fnd.CommandName, fnd.CommandDesc);
} }
} }
else else
LogInfo("Commands: " + Command.RegisteredCommands.Select(x => x.CommandName).ToSingular()); Log.Info("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("<value> must be specified");
}
public static void LogObjectValueNotSpecified()
{
LogError("<object> and <value> must be specified");
}
public static void LogValueInvalid()
{
LogError("<value> is invalid");
}
public static void LogObjectInvalid()
{
LogError("<object> is invalid");
}
public static void LogValueNotInt32()
{
LogError("<value> must be a whole number (Int32)");
}
#endregion
}
}

View File

@ -77,7 +77,7 @@
<Reference Include="Microsoft.Xna.Framework.Xact, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" /> <Reference Include="Microsoft.Xna.Framework.Xact, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
<Reference Include="Stardew Valley, Version=1.0.5900.38427, Culture=neutral, processorArchitecture=x86"> <Reference Include="Stardew Valley, Version=1.0.5900.38427, Culture=neutral, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\Games\SteamLibrary\steamapps\common\Stardew Valley\Stardew Valley.exe</HintPath> <HintPath>$(SteamInstallPath)\steamapps\common\Stardew Valley\Stardew Valley.exe</HintPath>
<EmbedInteropTypes>False</EmbedInteropTypes> <EmbedInteropTypes>False</EmbedInteropTypes>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
@ -92,7 +92,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="xTile, Version=2.0.4.0, Culture=neutral, processorArchitecture=x86"> <Reference Include="xTile, Version=2.0.4.0, Culture=neutral, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\Games\SteamLibrary\steamapps\common\Stardew Valley\xTile.dll</HintPath> <HintPath>$(SteamInstallPath)\steamapps\common\Stardew Valley\xTile.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
</ItemGroup> </ItemGroup>
@ -115,6 +115,7 @@
<Compile Include="Inheritance\Minigames\SMinigameBase.cs" /> <Compile Include="Inheritance\Minigames\SMinigameBase.cs" />
<Compile Include="Inheritance\SGameLocation.cs" /> <Compile Include="Inheritance\SGameLocation.cs" />
<Compile Include="Inheritance\SObject.cs" /> <Compile Include="Inheritance\SObject.cs" />
<Compile Include="Log.cs" />
<Compile Include="Mod.cs" /> <Compile Include="Mod.cs" />
<Compile Include="ModItem.cs" /> <Compile Include="ModItem.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />

View File

@ -113,7 +113,7 @@ namespace TrainerMod
static void types_CommandFired(object sender, EventArgsCommand e) 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); Log.Verbose("[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) static void hide_CommandFired(object sender, EventArgsCommand e)
@ -156,7 +156,7 @@ namespace TrainerMod
Game1.player.Name = e.Command.CalledArgs[1]; Game1.player.Name = e.Command.CalledArgs[1];
break; break;
case "pet": case "pet":
Program.LogError("Pets cannot currently be renamed."); Log.Error("Pets cannot currently be renamed.");
break; break;
case "farm": case "farm":
Game1.player.farmName = e.Command.CalledArgs[1]; Game1.player.farmName = e.Command.CalledArgs[1];
@ -165,12 +165,12 @@ namespace TrainerMod
} }
else else
{ {
Program.LogObjectInvalid(); Log.LogObjectInvalid();
} }
} }
else else
{ {
Program.LogObjectValueNotSpecified(); Log.LogObjectValueNotSpecified();
} }
} }
@ -189,17 +189,17 @@ namespace TrainerMod
if (Int32.TryParse(e.Command.CalledArgs[0], out ou)) if (Int32.TryParse(e.Command.CalledArgs[0], out ou))
{ {
Game1.player.Money = ou; Game1.player.Money = ou;
Program.LogInfo("Set {0}'s money to {1}", Game1.player.Name, Game1.player.Money); Log.Verbose("Set {0}'s money to {1}", Game1.player.Name, Game1.player.Money);
} }
else else
{ {
Program.LogValueNotInt32(); Log.LogValueNotInt32();
} }
} }
} }
else else
{ {
Program.LogValueNotSpecified(); Log.LogValueNotSpecified();
} }
} }
@ -218,17 +218,17 @@ namespace TrainerMod
if (Int32.TryParse(e.Command.CalledArgs[0], out ou)) if (Int32.TryParse(e.Command.CalledArgs[0], out ou))
{ {
Game1.player.Stamina = ou; Game1.player.Stamina = ou;
Program.LogInfo("Set {0}'s stamina to {1}", Game1.player.Name, Game1.player.Stamina); Log.Verbose("Set {0}'s stamina to {1}", Game1.player.Name, Game1.player.Stamina);
} }
else else
{ {
Program.LogValueNotInt32(); Log.LogValueNotInt32();
} }
} }
} }
else else
{ {
Program.LogValueNotSpecified(); Log.LogValueNotSpecified();
} }
} }
@ -240,16 +240,16 @@ namespace TrainerMod
if (Int32.TryParse(e.Command.CalledArgs[0], out ou)) if (Int32.TryParse(e.Command.CalledArgs[0], out ou))
{ {
Game1.player.MaxStamina = ou; Game1.player.MaxStamina = ou;
Program.LogInfo("Set {0}'s max stamina to {1}", Game1.player.Name, Game1.player.MaxStamina); Log.Verbose("Set {0}'s max stamina to {1}", Game1.player.Name, Game1.player.MaxStamina);
} }
else else
{ {
Program.LogValueNotInt32(); Log.LogValueNotInt32();
} }
} }
else else
{ {
Program.LogValueNotSpecified(); Log.LogValueNotSpecified();
} }
} }
@ -288,17 +288,17 @@ namespace TrainerMod
} }
else else
{ {
Program.LogValueNotInt32(); Log.LogValueNotInt32();
} }
} }
else else
{ {
Program.LogError("<skill> is invalid"); Log.Error("<skill> is invalid");
} }
} }
else else
{ {
Program.LogError("<skill> and <value> must be specified"); Log.Error("<skill> and <value> must be specified");
} }
} }
@ -309,16 +309,16 @@ namespace TrainerMod
if (e.Command.CalledArgs[0].IsInt32()) if (e.Command.CalledArgs[0].IsInt32())
{ {
Game1.player.addedSpeed = e.Command.CalledArgs[0].AsInt32(); Game1.player.addedSpeed = e.Command.CalledArgs[0].AsInt32();
Program.LogInfo("Set {0}'s added speed to {1}", Game1.player.Name, Game1.player.addedSpeed); Log.Verbose("Set {0}'s added speed to {1}", Game1.player.Name, Game1.player.addedSpeed);
} }
else else
{ {
Program.LogValueNotInt32(); Log.LogValueNotInt32();
} }
} }
else else
{ {
Program.LogValueNotSpecified(); Log.LogValueNotSpecified();
} }
} }
@ -349,17 +349,17 @@ namespace TrainerMod
} }
else else
{ {
Program.LogError("<colour> is invalid"); Log.Error("<colour> is invalid");
} }
} }
else else
{ {
Program.LogObjectInvalid(); Log.LogObjectInvalid();
} }
} }
else else
{ {
Program.LogError("<object> and <colour> must be specified"); Log.Error("<object> and <colour> must be specified");
} }
} }
@ -397,7 +397,7 @@ namespace TrainerMod
else if (i == 1) else if (i == 1)
Game1.player.changeIntoSwimsuit(); Game1.player.changeIntoSwimsuit();
else else
Program.LogError("<value> must be 0 or 1 for this <object>"); Log.Error("<value> must be 0 or 1 for this <object>");
break; break;
case "gender": case "gender":
if (i == 0) if (i == 0)
@ -405,23 +405,23 @@ namespace TrainerMod
else if (i == 1) else if (i == 1)
Game1.player.changeGender(false); Game1.player.changeGender(false);
else else
Program.LogError("<value> must be 0 or 1 for this <object>"); Log.Error("<value> must be 0 or 1 for this <object>");
break; break;
} }
} }
else else
{ {
Program.LogValueInvalid(); Log.LogValueInvalid();
} }
} }
else else
{ {
Program.LogObjectInvalid(); Log.LogObjectInvalid();
} }
} }
else else
{ {
Program.LogObjectValueNotSpecified(); Log.LogObjectValueNotSpecified();
} }
} }
@ -435,21 +435,21 @@ namespace TrainerMod
{ {
freezeTime = e.Command.CalledArgs[0].AsInt32() == 1; freezeTime = e.Command.CalledArgs[0].AsInt32() == 1;
frozenTime = freezeTime ? Game1.timeOfDay : 0; frozenTime = freezeTime ? Game1.timeOfDay : 0;
Program.LogInfo("Time is now " + (freezeTime ? "frozen" : "thawed")); Log.Verbose("Time is now " + (freezeTime ? "frozen" : "thawed"));
} }
else else
{ {
Program.LogError("<value> should be 0 or 1"); Log.Error("<value> should be 0 or 1");
} }
} }
else else
{ {
Program.LogValueNotInt32(); Log.LogValueNotInt32();
} }
} }
else else
{ {
Program.LogValueNotSpecified(); Log.LogValueNotSpecified();
} }
} }
@ -463,21 +463,21 @@ namespace TrainerMod
{ {
Game1.timeOfDay = e.Command.CalledArgs[0].AsInt32(); Game1.timeOfDay = e.Command.CalledArgs[0].AsInt32();
frozenTime = freezeTime ? Game1.timeOfDay : 0; frozenTime = freezeTime ? Game1.timeOfDay : 0;
Program.LogInfo("Time set to: " + Game1.timeOfDay); Log.Verbose("Time set to: " + Game1.timeOfDay);
} }
else else
{ {
Program.LogError("<value> should be between 600 and 2600 (06:00 AM - 02:00 AM [NEXT DAY])"); Log.Error("<value> should be between 600 and 2600 (06:00 AM - 02:00 AM [NEXT DAY])");
} }
} }
else else
{ {
Program.LogValueNotInt32(); Log.LogValueNotInt32();
} }
} }
else else
{ {
Program.LogValueNotSpecified(); Log.LogValueNotSpecified();
} }
} }
@ -493,17 +493,17 @@ namespace TrainerMod
} }
else else
{ {
Program.LogError("<value> must be between 1 and 28"); Log.Verbose("<value> must be between 1 and 28");
} }
} }
else else
{ {
Program.LogValueNotInt32(); Log.LogValueNotInt32();
} }
} }
else else
{ {
Program.LogValueNotSpecified(); Log.LogValueNotSpecified();
} }
} }
@ -519,12 +519,12 @@ namespace TrainerMod
} }
else else
{ {
Program.LogValueInvalid(); Log.LogValueInvalid();
} }
} }
else else
{ {
Program.LogValueNotSpecified(); Log.LogValueNotSpecified();
} }
} }
@ -545,13 +545,13 @@ namespace TrainerMod
} }
else else
{ {
Program.LogValueNotInt32(); Log.LogValueNotInt32();
} }
} }
} }
else else
{ {
Program.LogValueNotSpecified(); Log.LogValueNotSpecified();
} }
} }
@ -565,12 +565,12 @@ namespace TrainerMod
} }
else else
{ {
Program.LogValueNotInt32(); Log.LogValueNotInt32();
} }
} }
else else
{ {
Program.LogValueNotSpecified(); Log.LogValueNotSpecified();
} }
} }
@ -584,12 +584,12 @@ namespace TrainerMod
} }
else else
{ {
Program.LogValueNotInt32(); Log.LogValueNotInt32();
} }
} }
else else
{ {
Program.LogValueNotSpecified(); Log.LogValueNotSpecified();
} }
} }
@ -610,7 +610,7 @@ namespace TrainerMod
} }
else else
{ {
Program.LogError("[count] is invalid"); Log.Error("[count] is invalid");
return; return;
} }
@ -622,7 +622,7 @@ namespace TrainerMod
} }
else else
{ {
Program.LogError("[quality] is invalid"); Log.Error("[quality] is invalid");
return; return;
} }
@ -636,12 +636,12 @@ namespace TrainerMod
} }
else else
{ {
Program.LogError("<item> is invalid"); Log.Error("<item> is invalid");
} }
} }
else else
{ {
Program.LogObjectValueNotSpecified(); Log.LogObjectValueNotSpecified();
} }
} }
@ -654,16 +654,16 @@ namespace TrainerMod
MeleeWeapon toAdd = new MeleeWeapon(e.Command.CalledArgs[0].AsInt32()); MeleeWeapon toAdd = new MeleeWeapon(e.Command.CalledArgs[0].AsInt32());
Game1.player.addItemByMenuIfNecessary(toAdd); Game1.player.addItemByMenuIfNecessary(toAdd);
Program.LogInfo("Given {0} to {1}", toAdd.Name, Game1.player.Name); Log.Verbose("Given {0} to {1}", toAdd.Name, Game1.player.Name);
} }
else else
{ {
Program.LogError("<item> is invalid"); Log.Error("<item> is invalid");
} }
} }
else else
{ {
Program.LogObjectValueNotSpecified(); Log.LogObjectValueNotSpecified();
} }
} }
@ -676,16 +676,16 @@ namespace TrainerMod
Ring toAdd = new Ring(e.Command.CalledArgs[0].AsInt32()); Ring toAdd = new Ring(e.Command.CalledArgs[0].AsInt32());
Game1.player.addItemByMenuIfNecessary(toAdd); Game1.player.addItemByMenuIfNecessary(toAdd);
Program.LogInfo("Given {0} to {1}", toAdd.Name, Game1.player.Name); Log.Verbose("Given {0} to {1}", toAdd.Name, Game1.player.Name);
} }
else else
{ {
Program.LogError("<item> is invalid"); Log.Error("<item> is invalid");
} }
} }
else else
{ {
Program.LogObjectValueNotSpecified(); Log.LogObjectValueNotSpecified();
} }
} }
@ -748,12 +748,12 @@ namespace TrainerMod
} }
else else
{ {
Program.LogValueNotInt32(); Log.LogValueNotInt32();
} }
} }
else else
{ {
Program.LogValueNotSpecified(); Log.LogValueNotSpecified();
} }
} }
@ -761,11 +761,10 @@ namespace TrainerMod
static void RegisterNewItem(object sender, EventArgsCommand e) static void RegisterNewItem(object sender, EventArgsCommand e)
{ {
if (!Program.debug) #if DEBUG
{ Log.Error("Experimental code cannot be run in user mode.");
Program.LogError("Experimental code cannot be run in user mode.");
return; return;
} #endif
SObject s = SGame.PullModItemFromDict(0, true); SObject s = SGame.PullModItemFromDict(0, true);
s.Stack = 999; s.Stack = 999;
Game1.player.addItemToInventory(s); Game1.player.addItemToInventory(s);

View File

@ -41,7 +41,7 @@
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="Stardew Valley"> <Reference Include="Stardew Valley">
<HintPath>..\..\..\..\Games\SteamLibrary\steamapps\common\Stardew Valley\Stardew Valley.exe</HintPath> <HintPath>$(SteamInstallPath)\steamapps\common\Stardew Valley\Stardew Valley.exe</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
@ -52,7 +52,7 @@
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="xTile"> <Reference Include="xTile">
<HintPath>..\..\..\..\Games\SteamLibrary\steamapps\common\Stardew Valley\xTile.dll</HintPath> <HintPath>$(SteamInstallPath)\steamapps\common\Stardew Valley\xTile.dll</HintPath>
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>