From d12677b49c31e27d779bdfa0f1811a9eb2413ffd Mon Sep 17 00:00:00 2001 From: Zoryn Aaron Date: Tue, 1 Mar 2016 23:12:19 -0500 Subject: attempt to fix a few things --- Release/Mods/TrainerMod.dll | Bin 22528 -> 23040 bytes Release/SMAPI_0.31A.zip | Bin 0 -> 29642 bytes Release/SMAPI_0.3A.zip | Bin 29822 -> 0 bytes Release/StardewModdingAPI.exe | Bin 57344 -> 58368 bytes StardewModdingAPI/Program.cs | 72 ++++++++++++++++++++++++++---------- TrainerMod/TrainerMod.cs | 47 ++++++++++++++++++++++- TrainerMod/bin/Debug/TrainerMod.dll | Bin 22528 -> 23040 bytes TrainerMod/obj/Debug/TrainerMod.dll | Bin 22528 -> 23040 bytes 8 files changed, 98 insertions(+), 21 deletions(-) create mode 100644 Release/SMAPI_0.31A.zip delete mode 100644 Release/SMAPI_0.3A.zip diff --git a/Release/Mods/TrainerMod.dll b/Release/Mods/TrainerMod.dll index 8c80a376..d30355e9 100644 Binary files a/Release/Mods/TrainerMod.dll and b/Release/Mods/TrainerMod.dll differ diff --git a/Release/SMAPI_0.31A.zip b/Release/SMAPI_0.31A.zip new file mode 100644 index 00000000..70c538f2 Binary files /dev/null and b/Release/SMAPI_0.31A.zip differ diff --git a/Release/SMAPI_0.3A.zip b/Release/SMAPI_0.3A.zip deleted file mode 100644 index a20c66e7..00000000 Binary files a/Release/SMAPI_0.3A.zip and /dev/null differ diff --git a/Release/StardewModdingAPI.exe b/Release/StardewModdingAPI.exe index fc4e475c..6761f582 100644 Binary files a/Release/StardewModdingAPI.exe and b/Release/StardewModdingAPI.exe differ diff --git a/StardewModdingAPI/Program.cs b/StardewModdingAPI/Program.cs index c2bb1836..af765f97 100644 --- a/StardewModdingAPI/Program.cs +++ b/StardewModdingAPI/Program.cs @@ -49,7 +49,7 @@ namespace StardewModdingAPI public static Thread gameThread; public static Thread consoleInputThread; - public const string Version = "0.31 Alpha"; + public const string Version = "0.3x Alpha"; public const bool debug = false; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -60,7 +60,7 @@ namespace StardewModdingAPI Console.Title += " - Version " + Version; if (debug) - Console.Title += " - DEBUG IS NOT FALSE, AUTHOUR FORGET TO INCREMENT VERSION VARS"; + Console.Title += " - DEBUG IS NOT FALSE, AUTHOUR FORGOT TO INCREMENT VERSION VARS"; Application.ThreadException += Application_ThreadException; Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); @@ -69,19 +69,44 @@ namespace StardewModdingAPI ExecutionPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); ModPaths.Add(Path.Combine(Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley")), "Mods")); ModPaths.Add(Path.Combine(ExecutionPath, "Mods")); + ModPaths.Add(Path.Combine(Path.Combine(ExecutionPath, "Mods"), "Content")); ModContentPaths.Add(Path.Combine(Path.Combine(Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley")), "Mods"), "Content")); foreach (string ModPath in ModPaths) { - if (File.Exists(ModPath)) - File.Delete(ModPath); - if (!Directory.Exists(ModPath)) - Directory.CreateDirectory(ModPath); + try + { + if (File.Exists(ModPath)) + File.Delete(ModPath); + if (!Directory.Exists(ModPath)) + Directory.CreateDirectory(ModPath); + } + catch (Exception ex) + { + LogError("Could not create a missing ModPath: " + ModPath + "\n\n" + ex); + } } foreach (string ModContentPath in ModContentPaths) { - if (!Directory.Exists(ModContentPath)) - Directory.CreateDirectory(ModContentPath); + try + { + if (!Directory.Exists(ModContentPath)) + Directory.CreateDirectory(ModContentPath); + } + catch (Exception ex) + { + LogError("Could not create a missing ModContentPath: " + ModContentPath + "\n\n" + ex); + } + } + + try + { + if (Directory.Exists(LogPath)) + Directory.CreateDirectory(LogPath); + } + catch (Exception ex) + { + LogError("Could not create the missing ErrorLogs path: " + LogPath + "\n\n" + ex); } CurrentLog = LogPath + "\\MODDED_ProgramLog_" + System.DateTime.Now.Ticks + ".txt"; @@ -106,7 +131,7 @@ namespace StardewModdingAPI LogInfo("Injecting New SDV Version..."); - Game1.version += "-Z_MODDED"; + Game1.version += "-Z_MODDED | SMAPI " + Version; gameThread = new Thread(RunGame); LogInfo("Starting SDV..."); @@ -221,20 +246,27 @@ namespace StardewModdingAPI foreach (String s in Directory.GetFiles(ModPath, "*.dll")) { LogColour(ConsoleColor.Green, "Found DLL: " + s); - Assembly mod = Assembly.LoadFile(s); - - if (mod.DefinedTypes.Count(x => x.BaseType == typeof (Mod)) > 0) + try { - LogColour(ConsoleColor.Green, "Loading Mod DLL..."); - TypeInfo tar = mod.DefinedTypes.First(x => x.BaseType == typeof (Mod)); - 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); - loadedMods += 1; - m.Entry(); + Assembly mod = Assembly.UnsafeLoadFrom(s); //to combat internet-downloaded DLLs + + if (mod.DefinedTypes.Count(x => x.BaseType == typeof (Mod)) > 0) + { + LogColour(ConsoleColor.Green, "Loading Mod DLL..."); + TypeInfo tar = mod.DefinedTypes.First(x => x.BaseType == typeof (Mod)); + 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); + loadedMods += 1; + m.Entry(); + } + else + { + LogError("Invalid Mod DLL"); + } } - else + catch (Exception ex) { - LogError("Invalid Mod DLL"); + LogError("Failed to load mod '{0}'. Exception details:\n" + ex, s); } } } diff --git a/TrainerMod/TrainerMod.cs b/TrainerMod/TrainerMod.cs index d0a36fed..6e1b4b17 100644 --- a/TrainerMod/TrainerMod.cs +++ b/TrainerMod/TrainerMod.cs @@ -9,6 +9,7 @@ using StardewModdingAPI.Inheritance; using StardewValley; using StardewValley.Tools; using Microsoft.Xna.Framework; +using StardewValley.Objects; namespace TrainerMod { @@ -91,9 +92,11 @@ namespace TrainerMod Command.RegisterCommand("player_additem", "Gives the player an item | player_additem ", new[] { "? (Int32)" }).CommandFired += player_addItem; Command.RegisterCommand("player_addmelee", "Gives the player a melee item | player_addmelee ", new[] { "?" }).CommandFired += player_addMelee; + Command.RegisterCommand("player_addring", "Gives the player a ring | player_addring ", new[] { "?" }).CommandFired += player_addRing; Command.RegisterCommand("out_items", "Outputs a list of items | out_items", new[] { "" }).CommandFired += out_items; Command.RegisterCommand("out_melee", "Outputs a list of melee weapons | out_melee", new[] { "" }).CommandFired += out_melee; + Command.RegisterCommand("out_rings", "Outputs a list of rings | out_rings", new[] { "" }).CommandFired += out_rings; Command.RegisterCommand("newitem", "Outputs a list of melee weapons | out_melee", new[] { "" }).CommandFired += RegisterNewItem; Command.RegisterCommand("world_settime", "Sets the time to the specified value | world_settime ", new[] { "(Int32) The target time [06:00 AM is 600]" }).CommandFired += world_setTime; @@ -605,7 +608,9 @@ namespace TrainerMod return; } } - Game1.player.addItemByMenuIfNecessary((Item)new StardewValley.Object(cmd.CalledArgs[0].AsInt32(), count)); + Item i = (Item) new StardewValley.Object(cmd.CalledArgs[0].AsInt32(), count); + + Game1.player.addItemByMenuIfNecessary(i); } else { @@ -624,6 +629,7 @@ namespace TrainerMod { if (cmd.CalledArgs[0].IsInt32()) { + MeleeWeapon toAdd = new MeleeWeapon(cmd.CalledArgs[0].AsInt32()); Game1.player.addItemByMenuIfNecessary(toAdd); Program.LogInfo("Given {0} to {1}", toAdd.Name, Game1.player.Name); @@ -639,6 +645,28 @@ namespace TrainerMod } } + static void player_addRing(Command cmd) + { + if (cmd.CalledArgs.Length > 0) + { + if (cmd.CalledArgs[0].IsInt32()) + { + + Ring toAdd = new Ring(cmd.CalledArgs[0].AsInt32()); + Game1.player.addItemByMenuIfNecessary(toAdd); + Program.LogInfo("Given {0} to {1}", toAdd.Name, Game1.player.Name); + } + else + { + Program.LogError(" is invalid"); + } + } + else + { + Program.LogObjectValueNotSpecified(); + } + } + static void out_items(Command cmd) { for (int i = 0; i < 1000; i++) @@ -666,6 +694,23 @@ namespace TrainerMod } } + static void out_rings(Command cmd) + { + for (int i = 0; i < 100; i++) + { + try + { + Item it = new Ring(i); + if (it.Name != "Error Item") + Console.WriteLine(i + "| " + it.Name); + } + catch + { + + } + } + } + static void world_downMineLevel(Command cmd) { Game1.nextMineLevel(); diff --git a/TrainerMod/bin/Debug/TrainerMod.dll b/TrainerMod/bin/Debug/TrainerMod.dll index 8c80a376..d30355e9 100644 Binary files a/TrainerMod/bin/Debug/TrainerMod.dll and b/TrainerMod/bin/Debug/TrainerMod.dll differ diff --git a/TrainerMod/obj/Debug/TrainerMod.dll b/TrainerMod/obj/Debug/TrainerMod.dll index 8c80a376..d30355e9 100644 Binary files a/TrainerMod/obj/Debug/TrainerMod.dll and b/TrainerMod/obj/Debug/TrainerMod.dll differ -- cgit