diff options
Diffstat (limited to 'StardewModdingAPI/Program.cs')
-rw-r--r-- | StardewModdingAPI/Program.cs | 149 |
1 files changed, 75 insertions, 74 deletions
diff --git a/StardewModdingAPI/Program.cs b/StardewModdingAPI/Program.cs index 05da664c..e6ba103b 100644 --- a/StardewModdingAPI/Program.cs +++ b/StardewModdingAPI/Program.cs @@ -20,9 +20,6 @@ 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;
@@ -34,6 +31,9 @@ namespace StardewModdingAPI public static Thread gameThread;
public static Thread consoleInputThread;
+ //private static List<string> _modContentPaths;
+
+ public static Texture2D DebugPixel { get; private set; }
public static bool StardewInjectorLoaded { get; private set; }
public static Mod StardewInjectorMod { get; private set; }
@@ -41,7 +41,7 @@ namespace StardewModdingAPI /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
- /// Main method holding the API execution
+ /// Main method holding the API execution
/// </summary>
/// <param name="args"></param>
private static void Main(string[] args)
@@ -61,15 +61,15 @@ namespace StardewModdingAPI // Catch and display all exceptions.
Console.WriteLine(e);
Console.ReadKey();
- Log.Error("Critical error: " + e);
+ Log.AsyncR("Critical error: " + e);
}
- Log.Comment("The API will now terminate. Press any key to continue...");
+ Log.AsyncY("The API will now terminate. Press any key to continue...");
Console.ReadKey();
}
/// <summary>
- /// Set up the console properties
+ /// Set up the console properties
/// </summary>
private static void ConfigureUI()
{
@@ -81,11 +81,11 @@ namespace StardewModdingAPI }
/// <summary>
- /// Setup the required paths and logging
+ /// Setup the required paths and logging
/// </summary>
private static void ConfigurePaths()
{
- Log.Info("Validating api paths...");
+ Log.AsyncY("Validating api paths...");
_modPaths = new List<string>();
//_modContentPaths = new List<string>();
@@ -110,11 +110,11 @@ namespace StardewModdingAPI }
/// <summary>
- /// Load Stardev Valley and control features
+ /// Load Stardev Valley and control features
/// </summary>
private static void ConfigureSDV()
{
- Log.Info("Initializing SDV Assembly...");
+ Log.AsyncY("Initializing SDV Assembly...");
// Load in the assembly - ignores security
StardewAssembly = Assembly.UnsafeLoadFrom(Constants.ExecutionPath + "\\Stardew Valley.exe");
@@ -122,22 +122,24 @@ namespace StardewModdingAPI StardewGameInfo = StardewProgramType.GetField("gamePtr");
// Change the game's version
- Log.Verbose("Injecting New SDV Version...");
- Game1.version += string.Format("-Z_MODDED | SMAPI {0}", Constants.Version.VersionString);
+ Log.AsyncY("Injecting New SDV Version...");
+ Game1.version += $"-Z_MODDED | SMAPI {Constants.Version.VersionString}";
// Create the thread for the game to run in.
gameThread = new Thread(RunGame);
- Log.Info("Starting SDV...");
+ Log.AsyncY("Starting SDV...");
gameThread.Start();
// Wait for the game to load up
- while (!ready) ;
+ while (!ready)
+ {
+ }
//SDV is running
- Log.Comment("SDV Loaded Into Memory");
+ Log.AsyncY("SDV Loaded Into Memory");
//Create definition to listen for input
- Log.Verbose("Initializing Console Input Thread...");
+ Log.AsyncY("Initializing Console Input Thread...");
consoleInputThread = new Thread(ConsoleInputThread);
// The only command in the API (at least it should be, for now)
@@ -149,7 +151,7 @@ namespace StardewModdingAPI GameEvents.LoadContent += Events_LoadContent;
//Events.MenuChanged += Events_MenuChanged; //Idk right now
- Log.Verbose("Applying Final SDV Tweaks...");
+ Log.AsyncY("Applying Final SDV Tweaks...");
StardewInvoke(() =>
{
gamePtr.IsMouseVisible = false;
@@ -159,15 +161,15 @@ namespace StardewModdingAPI }
/// <summary>
- /// Wrap the 'RunGame' method for console output
+ /// Wrap the 'RunGame' method for console output
/// </summary>
private static void GameRunInvoker()
{
//Game's in memory now, send the event
- Log.Verbose("Game Loaded");
+ Log.AsyncY("Game Loaded");
GameEvents.InvokeGameLoaded();
- Log.Comment("Type 'help' for help, or 'help <cmd>' for a command's usage");
+ Log.AsyncY("Type 'help' for help, or 'help <cmd>' for a command's usage");
//Begin listening to input
consoleInputThread.Start();
@@ -182,14 +184,14 @@ namespace StardewModdingAPI if (consoleInputThread != null && consoleInputThread.ThreadState == ThreadState.Running)
consoleInputThread.Abort();
- Log.Verbose("Game Execution Finished");
- Log.Verbose("Shutting Down...");
+ Log.AsyncY("Game Execution Finished");
+ Log.AsyncY("Shutting Down...");
Thread.Sleep(100);
Environment.Exit(0);
}
/// <summary>
- /// Create the given directory path if it does not exist
+ /// Create the given directory path if it does not exist
/// </summary>
/// <param name="path">Desired directory path</param>
private static void VerifyPath(string path)
@@ -203,7 +205,7 @@ namespace StardewModdingAPI }
catch (Exception ex)
{
- Log.Error("Could not create a path: " + path + "\n\n" + ex);
+ Log.AsyncR("Could not create a path: " + path + "\n\n" + ex);
}
}
@@ -218,7 +220,7 @@ namespace StardewModdingAPI try
{
gamePtr = new SGame();
- Log.Verbose("Patching SDV Graphics Profile...");
+ Log.AsyncY("Patching SDV Graphics Profile...");
Game1.graphics.GraphicsProfile = GraphicsProfile.HiDef;
LoadMods();
@@ -232,11 +234,11 @@ namespace StardewModdingAPI }
catch (Exception ex)
{
- Log.Error("Game failed to start: " + ex);
+ Log.AsyncR("Game failed to start: " + ex);
}
}
- static void StardewForm_Closing(object sender, CancelEventArgs e)
+ private static void StardewForm_Closing(object sender, CancelEventArgs e)
{
e.Cancel = true;
@@ -251,23 +253,23 @@ namespace StardewModdingAPI public static void LoadMods()
{
- Log.Verbose("LOADING MODS");
- foreach (string ModPath in _modPaths)
+ Log.AsyncY("LOADING MODS");
+ foreach (var ModPath in _modPaths)
{
- foreach (string d in Directory.GetDirectories(ModPath))
+ foreach (var d in Directory.GetDirectories(ModPath))
{
- foreach (string s in Directory.GetFiles(d, "manifest.json"))
+ foreach (var s in Directory.GetFiles(d, "manifest.json"))
{
if (s.Contains("StardewInjector"))
continue;
- Log.Success("Found Manifest: " + s);
- Manifest manifest = new Manifest();
+ Log.AsyncG("Found Manifest: " + s);
+ var manifest = new Manifest();
try
{
- string t = File.ReadAllText(s);
+ var t = File.ReadAllText(s);
if (string.IsNullOrEmpty(t))
{
- Log.Error($"Failed to read mod manifest '{s}'. Manifest is empty!");
+ Log.AsyncR($"Failed to read mod manifest '{s}'. Manifest is empty!");
continue;
}
@@ -275,18 +277,18 @@ namespace StardewModdingAPI if (string.IsNullOrEmpty(manifest.EntryDll))
{
- Log.Error($"Failed to read mod manifest '{s}'. EntryDll is empty!");
+ Log.AsyncR($"Failed to read mod manifest '{s}'. EntryDll is empty!");
continue;
}
}
catch (Exception ex)
{
- Log.Error($"Failed to read mod manifest '{s}'. Exception details:\n" + ex);
+ Log.AsyncR($"Failed to read mod manifest '{s}'. Exception details:\n" + ex);
continue;
}
- string targDir = Path.GetDirectoryName(s);
- string psDir = Path.Combine(targDir, "psconfigs");
- Log.Info($"Created psconfigs directory @{psDir}");
+ var targDir = Path.GetDirectoryName(s);
+ var psDir = Path.Combine(targDir, "psconfigs");
+ Log.AsyncY($"Created psconfigs directory @{psDir}");
try
{
if (manifest.PerSaveConfigs)
@@ -294,63 +296,63 @@ namespace StardewModdingAPI if (!Directory.Exists(psDir))
{
Directory.CreateDirectory(psDir);
- Log.Info($"Created psconfigs directory @{psDir}");
+ Log.AsyncY($"Created psconfigs directory @{psDir}");
}
if (!Directory.Exists(psDir))
{
- Log.Error($"Failed to create psconfigs directory '{psDir}'. No exception occured.");
+ Log.AsyncR($"Failed to create psconfigs directory '{psDir}'. No exception occured.");
continue;
}
}
}
catch (Exception ex)
{
- Log.Error($"Failed to create psconfigs directory '{targDir}'. Exception details:\n" + ex);
+ Log.AsyncR($"Failed to create psconfigs directory '{targDir}'. Exception details:\n" + ex);
continue;
}
- string targDll = string.Empty;
+ var targDll = string.Empty;
try
{
targDll = Path.Combine(targDir, manifest.EntryDll);
if (!File.Exists(targDll))
{
- Log.Error($"Failed to load mod '{manifest.EntryDll}'. File {targDll} does not exist!");
+ Log.AsyncR($"Failed to load mod '{manifest.EntryDll}'. File {targDll} does not exist!");
continue;
}
- Assembly mod = Assembly.UnsafeLoadFrom(targDll);
+ var mod = Assembly.UnsafeLoadFrom(targDll);
if (mod.DefinedTypes.Count(x => x.BaseType == typeof (Mod)) > 0)
{
- Log.Verbose("Loading Mod DLL...");
- TypeInfo tar = mod.DefinedTypes.First(x => x.BaseType == typeof (Mod));
- Mod m = (Mod) mod.CreateInstance(tar.ToString());
+ Log.AsyncY("Loading Mod DLL...");
+ var tar = mod.DefinedTypes.First(x => x.BaseType == typeof (Mod));
+ var m = (Mod) mod.CreateInstance(tar.ToString());
m.PathOnDisk = targDir;
m.Manifest = manifest;
- Log.Success($"LOADED MOD: {m.Manifest.Name} by {m.Manifest.Authour} - Version {m.Manifest.Version} | Description: {m.Manifest.Description} (@ {targDll})");
+ Log.AsyncG($"LOADED MOD: {m.Manifest.Name} by {m.Manifest.Authour} - Version {m.Manifest.Version} | Description: {m.Manifest.Description} (@ {targDll})");
Constants.ModsLoaded += 1;
m.Entry();
}
else
{
- Log.Error("Invalid Mod DLL");
+ Log.AsyncR("Invalid Mod DLL");
}
}
catch (Exception ex)
{
- Log.Error($"Failed to load mod '{targDll}'. Exception details:\n" + ex);
+ Log.AsyncR($"Failed to load mod '{targDll}'. Exception details:\n" + ex);
}
}
}
}
- Log.Success($"LOADED {Constants.ModsLoaded} MODS");
+ Log.AsyncG($"LOADED {Constants.ModsLoaded} MODS");
Console.Title = Constants.ConsoleTitle;
}
public static void ConsoleInputThread()
{
- string input = string.Empty;
+ var input = string.Empty;
while (true)
{
@@ -358,14 +360,14 @@ namespace StardewModdingAPI }
}
- static void Events_LoadContent(object o, EventArgs e)
+ private static void Events_LoadContent(object o, EventArgs e)
{
- Log.Info("Initializing Debug Assets...");
+ Log.AsyncY("Initializing Debug Assets...");
DebugPixel = new Texture2D(Game1.graphics.GraphicsDevice, 1, 1);
- DebugPixel.SetData(new[] { Color.White });
+ DebugPixel.SetData(new[] {Color.White});
#if DEBUG
- StardewModdingAPI.Log.Verbose("REGISTERING BASE CUSTOM ITEM");
+ StardewModdingAPI.Log.Async("REGISTERING BASE CUSTOM ITEM");
SObject so = new SObject();
so.Name = "Mario Block";
so.CategoryName = "SMAPI Test Mod";
@@ -373,9 +375,9 @@ namespace StardewModdingAPI so.Texture = Texture2D.FromStream(Game1.graphics.GraphicsDevice, new FileStream(_modContentPaths[0] + "\\Test.png", FileMode.Open));
so.IsPassable = true;
so.IsPlaceable = true;
- StardewModdingAPI.Log.Verbose("REGISTERED WITH ID OF: " + SGame.RegisterModItem(so));
+ StardewModdingAPI.Log.Async("REGISTERED WITH ID OF: " + SGame.RegisterModItem(so));
- //StardewModdingAPI.Log.Verbose("REGISTERING SECOND CUSTOM ITEM");
+ //StardewModdingAPI.Log.Async("REGISTERING SECOND CUSTOM ITEM");
//SObject so2 = new SObject();
//so2.Name = "Mario Painting";
//so2.CategoryName = "SMAPI Test Mod";
@@ -383,34 +385,33 @@ namespace StardewModdingAPI //so2.Texture = Texture2D.FromStream(Game1.graphics.GraphicsDevice, new FileStream(_modContentPaths[0] + "\\PaintingTest.png", FileMode.Open));
//so2.IsPassable = true;
//so2.IsPlaceable = true;
- //StardewModdingAPI.Log.Verbose("REGISTERED WITH ID OF: " + SGame.RegisterModItem(so2));
+ //StardewModdingAPI.Log.Async("REGISTERED WITH ID OF: " + SGame.RegisterModItem(so2));
Command.CallCommand("load");
#endif
}
- static void Events_KeyPressed(object o, EventArgsKeyPressed e)
+ private static void Events_KeyPressed(object o, EventArgsKeyPressed e)
{
-
}
- static void Events_MenuChanged(IClickableMenu newMenu)
+ private static void Events_MenuChanged(IClickableMenu newMenu)
{
- Log.Verbose("NEW MENU: " + newMenu.GetType());
+ Log.AsyncY("NEW MENU: " + newMenu.GetType());
if (newMenu is GameMenu)
{
Game1.activeClickableMenu = SGameMenu.ConstructFromBaseClass(Game1.activeClickableMenu as GameMenu);
}
}
- static void Events_LocationsChanged(List<GameLocation> newLocations)
+ private static void Events_LocationsChanged(List<GameLocation> newLocations)
{
#if DEBUG
SGame.ModLocations = SGameLocation.ConstructFromBaseClasses(Game1.locations);
#endif
}
- static void Events_CurrentLocationChanged(GameLocation newLocation)
+ private static void Events_CurrentLocationChanged(GameLocation newLocation)
{
//SGame.CurrentLocation = null;
//System.Threading.Thread.Sleep(10);
@@ -428,23 +429,23 @@ namespace StardewModdingAPI StardewForm.Invoke(a);
}
- static void help_CommandFired(object o, EventArgsCommand e)
+ private static void help_CommandFired(object o, EventArgsCommand e)
{
if (e.Command.CalledArgs.Length > 0)
{
- Command fnd = Command.FindCommand(e.Command.CalledArgs[0]);
+ var fnd = Command.FindCommand(e.Command.CalledArgs[0]);
if (fnd == null)
- Log.Error("The command specified could not be found");
+ Log.AsyncR("The command specified could not be found");
else
{
if (fnd.CommandArgs.Length > 0)
- Log.Info("{0}: {1} - {2}", fnd.CommandName, fnd.CommandDesc, fnd.CommandArgs.ToSingular());
+ Log.AsyncY($"{fnd.CommandName}: {fnd.CommandDesc} - {fnd.CommandArgs.ToSingular()}");
else
- Log.Info("{0}: {1}", fnd.CommandName, fnd.CommandDesc);
+ Log.AsyncY($"{fnd.CommandName}: {fnd.CommandDesc}");
}
}
else
- Log.Info("Commands: " + Command.RegisteredCommands.Select(x => x.CommandName).ToSingular());
+ Log.AsyncY("Commands: " + Command.RegisteredCommands.Select(x => x.CommandName).ToSingular());
}
}
}
\ No newline at end of file |