From c50891a09367169f47c80d11ae5b5bcb0d3c50a2 Mon Sep 17 00:00:00 2001 From: Zoryn Aaron Date: Sun, 20 Mar 2016 15:43:31 -0400 Subject: Zoryn returns. Added JSON. Added Config.cs. --- TrainerMod/TrainerMod.csproj | 25 ++++++++++++++++--------- TrainerMod/packages.config | 4 ++++ 2 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 TrainerMod/packages.config (limited to 'TrainerMod') diff --git a/TrainerMod/TrainerMod.csproj b/TrainerMod/TrainerMod.csproj index ddf1b317..2baa6a26 100644 --- a/TrainerMod/TrainerMod.csproj +++ b/TrainerMod/TrainerMod.csproj @@ -34,16 +34,16 @@ false - - - $(SteamInstallPath) + + + $(SteamInstallPath) - - - - ..\..\..\..\Games\SteamLibrary - - + + + + ..\ + + @@ -52,6 +52,10 @@ False + + ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll + True + $(SteamPath)\steamapps\common\Stardew Valley\Stardew Valley.exe False @@ -80,6 +84,9 @@ False + + + diff --git a/TrainerMod/packages.config b/TrainerMod/packages.config new file mode 100644 index 00000000..583acbdf --- /dev/null +++ b/TrainerMod/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file -- cgit From f0cb2c0e63c9e00a7a902a7729c862a569d21061 Mon Sep 17 00:00:00 2001 From: Zoryn Aaron Date: Sun, 20 Mar 2016 17:19:02 -0400 Subject: converted mod loading to a manifest structure. mods now go in ./Mods// - in there you need a 'manifest.json' and your dll. See trainermod for example. --- StardewModdingAPI/Manifest.cs | 33 +++++++++++++ StardewModdingAPI/Mod.cs | 19 +------ StardewModdingAPI/Program.cs | 79 +++++++++++++++++++++--------- StardewModdingAPI/StardewModdingAPI.csproj | 1 + TrainerMod/TrainerMod.cs | 2 + TrainerMod/TrainerMod.csproj | 1 + TrainerMod/manifest.json | 7 +++ 7 files changed, 102 insertions(+), 40 deletions(-) create mode 100644 StardewModdingAPI/Manifest.cs create mode 100644 TrainerMod/manifest.json (limited to 'TrainerMod') diff --git a/StardewModdingAPI/Manifest.cs b/StardewModdingAPI/Manifest.cs new file mode 100644 index 00000000..4fc1ed3c --- /dev/null +++ b/StardewModdingAPI/Manifest.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StardewModdingAPI +{ + public class Manifest + { + /// + /// The name of your mod. + /// + public virtual string Name { get; set; } + + /// + /// The name of the mod's authour. + /// + public virtual string Authour { get; set; } + + /// + /// The version of the mod. + /// + public virtual string Version { get; set; } + + /// + /// A description of the mod. + /// + public virtual string Description { get; set; } + + public string EntryDll { get; set; } + } +} diff --git a/StardewModdingAPI/Mod.cs b/StardewModdingAPI/Mod.cs index a196c3a2..4b923fd7 100644 --- a/StardewModdingAPI/Mod.cs +++ b/StardewModdingAPI/Mod.cs @@ -9,24 +9,9 @@ namespace StardewModdingAPI public class Mod { /// - /// The name of your mod. + /// The mod's manifest /// - public virtual string Name { get; protected set; } - - /// - /// The name of the mod's authour. - /// - public virtual string Authour { get; protected set; } - - /// - /// The version of the mod. - /// - public virtual string Version { get; protected set; } - - /// - /// A description of the mod. - /// - public virtual string Description { get; protected set; } + public Manifest Manifest { get; internal set; } /// /// Where the mod is located on the disk. diff --git a/StardewModdingAPI/Program.cs b/StardewModdingAPI/Program.cs index 5ed2d644..6d137a68 100644 --- a/StardewModdingAPI/Program.cs +++ b/StardewModdingAPI/Program.cs @@ -13,6 +13,7 @@ using System.Linq; using System.Reflection; using System.Threading; using System.Windows.Forms; +using Newtonsoft.Json; namespace StardewModdingAPI { @@ -131,7 +132,7 @@ namespace StardewModdingAPI StardewModdingAPI.Log.Success("Loading Injector DLL..."); TypeInfo tar = mod.DefinedTypes.First(x => x.BaseType == typeof(Mod)); Mod m = (Mod)mod.CreateInstance(tar.ToString()); - Console.WriteLine("LOADED: {0} by {1} - Version {2} | Description: {3} (@:{4})", m.Name, m.Authour, m.Version, m.Description, s); + Console.WriteLine("LOADED: {0} by {1} - Version {2} | Description: {3} (@:{4})", m.Manifest.Name, m.Manifest.Authour, m.Manifest.Version, m.Manifest.Description, s); m.PathOnDisk = Path.GetDirectoryName(s); m.Entry(false); StardewInjectorLoaded = true; @@ -312,33 +313,66 @@ namespace StardewModdingAPI int loadedMods = 0; foreach (string ModPath in _modPaths) { - foreach (String s in Directory.GetFiles(ModPath, "*.dll")) + foreach (String d in Directory.GetDirectories(ModPath)) { - if (s.Contains("StardewInjector")) - continue; - StardewModdingAPI.Log.Success("Found DLL: " + s); - try + foreach (String s in Directory.GetFiles(d, "manifest.json")) { - Assembly mod = Assembly.UnsafeLoadFrom(s); //to combat internet-downloaded DLLs - - if (mod.DefinedTypes.Count(x => x.BaseType == typeof(Mod)) > 0) + if (s.Contains("StardewInjector")) + continue; + StardewModdingAPI.Log.Success("Found Manifest: " + s); + Manifest manifest = new Manifest(); + try { - StardewModdingAPI.Log.Verbose("Loading Mod DLL..."); - TypeInfo tar = mod.DefinedTypes.First(x => x.BaseType == typeof(Mod)); - Mod m = (Mod)mod.CreateInstance(tar.ToString()); - m.PathOnDisk = Path.GetDirectoryName(s); - Console.WriteLine("LOADED MOD: {0} by {1} - Version {2} | Description: {3} (@{4})", m.Name, m.Authour, m.Version, m.Description, m.PathOnDisk); - loadedMods += 1; - m.Entry(); + string t = File.ReadAllText(s); + if (string.IsNullOrEmpty(t)) + { + StardewModdingAPI.Log.Error("Failed to read mod manifest '{0}'. Manifest is empty!", s); + continue; + } + manifest = JsonConvert.DeserializeObject(t); + if (string.IsNullOrEmpty(manifest.EntryDll)) + { + StardewModdingAPI.Log.Error("Failed to read mod manifest '{0}'. EntryDll is empty!", s); + continue; + } } - else + catch (Exception ex) { - StardewModdingAPI.Log.Error("Invalid Mod DLL"); + StardewModdingAPI.Log.Error("Failed to read mod manifest '{0}'. Exception details:\n" + ex, s); + continue; + } + try + { + string targDll = Path.Combine(Path.GetDirectoryName(s), manifest.EntryDll); + if (!File.Exists(targDll)) + { + StardewModdingAPI.Log.Error("Failed to load mod '{0}'. File {1} does not exist!", s, targDll); + continue; + } + + Assembly mod = Assembly.UnsafeLoadFrom(targDll); + + if (mod.DefinedTypes.Count(x => x.BaseType == typeof (Mod)) > 0) + { + StardewModdingAPI.Log.Verbose("Loading Mod DLL..."); + TypeInfo tar = mod.DefinedTypes.First(x => x.BaseType == typeof (Mod)); + Mod m = (Mod) mod.CreateInstance(tar.ToString()); + m.PathOnDisk = Path.GetDirectoryName(s); + m.Manifest = manifest; + StardewModdingAPI.Log.Success("LOADED MOD: {0} by {1} - Version {2} | Description: {3} (@ {4})", m.Manifest.Name, m.Manifest.Authour, m.Manifest.Version, m.Manifest.Description, targDll); + loadedMods += 1; + m.Entry(); + } + else + { + StardewModdingAPI.Log.Error("Invalid Mod DLL"); + } + } + catch (Exception ex) + { + StardewModdingAPI.Log.Error("Failed to load mod '{0}'. Exception details:\n" + ex, s); + continue; } - } - catch (Exception ex) - { - StardewModdingAPI.Log.Error("Failed to load mod '{0}'. Exception details:\n" + ex, s); } } } @@ -400,7 +434,6 @@ namespace StardewModdingAPI } } - static void Events_LocationsChanged(List newLocations) { #if DEBUG diff --git a/StardewModdingAPI/StardewModdingAPI.csproj b/StardewModdingAPI/StardewModdingAPI.csproj index b4494faf..c2f286ce 100644 --- a/StardewModdingAPI/StardewModdingAPI.csproj +++ b/StardewModdingAPI/StardewModdingAPI.csproj @@ -150,6 +150,7 @@ + diff --git a/TrainerMod/TrainerMod.cs b/TrainerMod/TrainerMod.cs index e2482c5d..bed66b21 100644 --- a/TrainerMod/TrainerMod.cs +++ b/TrainerMod/TrainerMod.cs @@ -16,6 +16,7 @@ namespace TrainerMod { public class TrainerMod : Mod { + /* public override string Name { get { return "Trainer Mod"; } @@ -35,6 +36,7 @@ namespace TrainerMod { get { return "Registers several commands to use. Most commands are trainer-like in that they offer forms of cheating."; } } + */ public static int frozenTime; public static bool infHealth, infStamina, infMoney, freezeTime; diff --git a/TrainerMod/TrainerMod.csproj b/TrainerMod/TrainerMod.csproj index 2baa6a26..6424ecdb 100644 --- a/TrainerMod/TrainerMod.csproj +++ b/TrainerMod/TrainerMod.csproj @@ -85,6 +85,7 @@ + diff --git a/TrainerMod/manifest.json b/TrainerMod/manifest.json new file mode 100644 index 00000000..a85f8dc3 --- /dev/null +++ b/TrainerMod/manifest.json @@ -0,0 +1,7 @@ +{ + "Name": "Trainer Mod", + "Authour": "Zoryn", + "Version": "1.0", + "Description": "Registers several commands to use. Most commands are trainer-like in that they offer forms of cheating.", + "EntryDll": "TrainerMod.dll" +} \ No newline at end of file -- cgit From cb9cdad62d4f457ab3081854e5aa363d03630bb8 Mon Sep 17 00:00:00 2001 From: Zoryn Aaron Date: Sun, 20 Mar 2016 17:45:45 -0400 Subject: adds support for old-style mods that don't use manifest. It will be removed in future version --- StardewModdingAPI/Mod.cs | 25 ++++++++++++ StardewModdingAPI/Program.cs | 92 ++++++++++++++++++++++---------------------- TrainerMod/TrainerMod.csproj | 6 ++- 3 files changed, 75 insertions(+), 48 deletions(-) (limited to 'TrainerMod') diff --git a/StardewModdingAPI/Mod.cs b/StardewModdingAPI/Mod.cs index 4b923fd7..b323b6ec 100644 --- a/StardewModdingAPI/Mod.cs +++ b/StardewModdingAPI/Mod.cs @@ -8,6 +8,31 @@ namespace StardewModdingAPI { public class Mod { + /// + /// The name of your mod. + /// NOTE: THIS IS DEPRECATED AND WILL BE REMOVED IN THE NEXT VERSION OF SMAPI + /// + public virtual string Name { get; set; } + + /// + /// The name of the mod's authour. + /// NOTE: THIS IS DEPRECATED AND WILL BE REMOVED IN THE NEXT VERSION OF SMAPI + /// + public virtual string Authour { get; set; } + + /// + /// The version of the mod. + /// NOTE: THIS IS DEPRECATED AND WILL BE REMOVED IN THE NEXT VERSION OF SMAPI + /// + public virtual string Version { get; set; } + + /// + /// A description of the mod. + /// NOTE: THIS IS DEPRECATED AND WILL BE REMOVED IN THE NEXT VERSION OF SMAPI + /// + public virtual string Description { get; set; } + + /// /// The mod's manifest /// diff --git a/StardewModdingAPI/Program.cs b/StardewModdingAPI/Program.cs index 6d137a68..92c6c079 100644 --- a/StardewModdingAPI/Program.cs +++ b/StardewModdingAPI/Program.cs @@ -50,7 +50,6 @@ namespace StardewModdingAPI { ConfigureUI(); ConfigurePaths(); - ConfigureInjector(); ConfigureSDV(); GameRunInvoker(); @@ -106,51 +105,6 @@ namespace StardewModdingAPI } } - /// - /// Load the injector. - /// Is this deprecated? Why is there a LoadMods? - /// - /// - /// This will load the injector before anything else if it sees it - /// It doesn't matter though - /// I'll leave it as a feature in case anyone in the community wants to tinker with it - /// All you need is a DLL that inherits from mod and is called StardewInjector.dll with an Entry() method - /// - private static void ConfigureInjector() - { - foreach (string ModPath in _modPaths) - { - foreach (String s in Directory.GetFiles(ModPath, "StardewInjector.dll")) - { - StardewModdingAPI.Log.Success(ConsoleColor.Green, "Found Stardew Injector DLL: " + s); - try - { - Assembly mod = Assembly.UnsafeLoadFrom(s); //to combat internet-downloaded DLLs - - if (mod.DefinedTypes.Count(x => x.BaseType == typeof(Mod)) > 0) - { - StardewModdingAPI.Log.Success("Loading Injector DLL..."); - TypeInfo tar = mod.DefinedTypes.First(x => x.BaseType == typeof(Mod)); - Mod m = (Mod)mod.CreateInstance(tar.ToString()); - Console.WriteLine("LOADED: {0} by {1} - Version {2} | Description: {3} (@:{4})", m.Manifest.Name, m.Manifest.Authour, m.Manifest.Version, m.Manifest.Description, s); - m.PathOnDisk = Path.GetDirectoryName(s); - m.Entry(false); - StardewInjectorLoaded = true; - StardewInjectorMod = m; - } - else - { - StardewModdingAPI.Log.Error("Invalid Mod DLL"); - } - } - catch (Exception ex) - { - StardewModdingAPI.Log.Error("Failed to load mod '{0}'. Exception details:\n" + ex, s); - } - } - } - } - /// /// Load Stardev Valley and control features /// @@ -263,6 +217,8 @@ namespace StardewModdingAPI StardewModdingAPI.Log.Verbose("Patching SDV Graphics Profile..."); Game1.graphics.GraphicsProfile = GraphicsProfile.HiDef; LoadMods(); + //DEPRECATED WAY + LoadMods_OldWay(); StardewForm = Control.FromHandle(Program.gamePtr.Window.Handle).FindForm(); StardewForm.Closing += StardewForm_Closing; @@ -379,6 +335,50 @@ namespace StardewModdingAPI StardewModdingAPI.Log.Success("LOADED {0} MODS", loadedMods); } + /// + /// DEPRECATED. REMOVE + /// + public static void LoadMods_OldWay() + { + StardewModdingAPI.Log.Verbose("LOADING MODS (OLD WAY - DEPRECATED. ANY MODS LOADED THIS WAY NEED TO UPDATE)"); + int loadedMods = 0; + foreach (string ModPath in _modPaths) + { + foreach (String s in Directory.GetFiles(ModPath, "*.dll")) + { + if (s.Contains("StardewInjector")) + continue; + StardewModdingAPI.Log.Success("Found DLL: " + s); + try + { + Assembly mod = Assembly.UnsafeLoadFrom(s); //to combat internet-downloaded DLLs + + if (mod.DefinedTypes.Count(x => x.BaseType == typeof(Mod)) > 0) + { + StardewModdingAPI.Log.Verbose("Loading Mod DLL..."); + TypeInfo tar = mod.DefinedTypes.First(x => x.BaseType == typeof(Mod)); + Mod m = (Mod)mod.CreateInstance(tar.ToString()); + m.Manifest = null; + m.PathOnDisk = Path.GetDirectoryName(s); + Console.WriteLine("LOADED MOD: {0} by {1} - Version {2} | Description: {3}", m.Name, m.Authour, m.Version, m.Description); + loadedMods += 1; + m.Entry(); + } + else + { + StardewModdingAPI.Log.Error("Invalid Mod DLL"); + } + } + catch (Exception ex) + { + StardewModdingAPI.Log.Error("Failed to load mod '{0}'. Exception details:\n" + ex, s); + } + } + } + StardewModdingAPI.Log.Success("LOADED {0} MODS THAT NEED TO UPDATE", loadedMods); + } + + public static void ConsoleInputThread() { string input = string.Empty; diff --git a/TrainerMod/TrainerMod.csproj b/TrainerMod/TrainerMod.csproj index 6424ecdb..8f1a494f 100644 --- a/TrainerMod/TrainerMod.csproj +++ b/TrainerMod/TrainerMod.csproj @@ -54,7 +54,7 @@ ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll - True + False $(SteamPath)\steamapps\common\Stardew Valley\Stardew Valley.exe @@ -85,7 +85,9 @@ - + + PreserveNewest + -- cgit From 17021ae35162cfa4a6dad2c0457d4981f38878bc Mon Sep 17 00:00:00 2001 From: Zoryn Aaron Date: Sun, 20 Mar 2016 18:50:31 -0400 Subject: commit things --- StardewModdingAPI/Constants.cs | 2 +- StardewModdingAPI/FodyWeavers.xml | 5 +++ StardewModdingAPI/Program.cs | 66 +++++++++++++++--------------- StardewModdingAPI/StardewModdingAPI.csproj | 14 ++++++- StardewModdingAPI/packages.config | 2 + TrainerMod/FodyWeavers.xml | 4 ++ TrainerMod/TrainerMod.csproj | 11 ++--- 7 files changed, 63 insertions(+), 41 deletions(-) create mode 100644 StardewModdingAPI/FodyWeavers.xml create mode 100644 TrainerMod/FodyWeavers.xml (limited to 'TrainerMod') diff --git a/StardewModdingAPI/Constants.cs b/StardewModdingAPI/Constants.cs index 6812fbee..071f0435 100644 --- a/StardewModdingAPI/Constants.cs +++ b/StardewModdingAPI/Constants.cs @@ -35,7 +35,7 @@ namespace StardewModdingAPI public const int MinorVersion = 38; - public const int PatchVersion = 0; + public const int PatchVersion = 1; public const string Build = "Alpha"; diff --git a/StardewModdingAPI/FodyWeavers.xml b/StardewModdingAPI/FodyWeavers.xml new file mode 100644 index 00000000..2e6d4a7a --- /dev/null +++ b/StardewModdingAPI/FodyWeavers.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/StardewModdingAPI/Program.cs b/StardewModdingAPI/Program.cs index bb863ca4..cde2dfbc 100644 --- a/StardewModdingAPI/Program.cs +++ b/StardewModdingAPI/Program.cs @@ -342,41 +342,41 @@ namespace StardewModdingAPI /// public static void LoadMods_OldWay() { - StardewModdingAPI.Log.Verbose("LOADING MODS (OLD WAY - DEPRECATED. ANY MODS LOADED THIS WAY NEED TO UPDATE)"); - int loadedMods = 0; - foreach (string ModPath in _modPaths) - { - foreach (String s in Directory.GetFiles(ModPath, "*.dll")) - { - if (s.Contains("StardewInjector")) - continue; - StardewModdingAPI.Log.Success("Found DLL: " + s); - try - { - Assembly mod = Assembly.UnsafeLoadFrom(s); //to combat internet-downloaded DLLs - - if (mod.DefinedTypes.Count(x => x.BaseType == typeof(Mod)) > 0) - { - StardewModdingAPI.Log.Verbose("Loading Mod DLL..."); - TypeInfo tar = mod.DefinedTypes.First(x => x.BaseType == typeof(Mod)); + StardewModdingAPI.Log.Verbose("LOADING MODS (OLD WAY - DEPRECATED. ANY MODS LOADED THIS WAY NEED TO UPDATE)"); + int loadedMods = 0; + foreach (string ModPath in _modPaths) + { + foreach (String s in Directory.GetFiles(ModPath, "*.dll")) + { + if (s.Contains("StardewInjector")) + continue; + StardewModdingAPI.Log.Success("Found DLL: " + s); + try + { + Assembly mod = Assembly.UnsafeLoadFrom(s); //to combat internet-downloaded DLLs + + if (mod.DefinedTypes.Count(x => x.BaseType == typeof(Mod)) > 0) + { + StardewModdingAPI.Log.Verbose("Loading Mod DLL..."); + TypeInfo tar = mod.DefinedTypes.First(x => x.BaseType == typeof(Mod)); Mod m = (Mod)mod.CreateInstance(tar.ToString()); m.Manifest = null; - m.PathOnDisk = Path.GetDirectoryName(s); - Console.WriteLine("LOADED MOD: {0} by {1} - Version {2} | Description: {3}", m.Name, m.Authour, m.Version, m.Description); - loadedMods += 1; - m.Entry(); - } - else - { - StardewModdingAPI.Log.Error("Invalid Mod DLL"); - } - } - catch (Exception ex) - { - StardewModdingAPI.Log.Error("Failed to load mod '{0}'. Exception details:\n" + ex, s); - } - } - } + m.PathOnDisk = Path.GetDirectoryName(s); + Console.WriteLine("LOADED MOD: {0} by {1} - Version {2} | Description: {3}", m.Name, m.Authour, m.Version, m.Description); + loadedMods += 1; + m.Entry(); + } + else + { + StardewModdingAPI.Log.Error("Invalid Mod DLL"); + } + } + catch (Exception ex) + { + StardewModdingAPI.Log.Error("Failed to load mod '{0}'. Exception details:\n" + ex, s); + } + } + } StardewModdingAPI.Log.Success("LOADED {0} MODS THAT NEED TO UPDATE", loadedMods); } diff --git a/StardewModdingAPI/StardewModdingAPI.csproj b/StardewModdingAPI/StardewModdingAPI.csproj index c2f286ce..2f217795 100644 --- a/StardewModdingAPI/StardewModdingAPI.csproj +++ b/StardewModdingAPI/StardewModdingAPI.csproj @@ -19,6 +19,8 @@ + false + publish\ true Disk @@ -31,10 +33,10 @@ true 0 1.0.0.%2a - false false true - + + @@ -162,6 +164,7 @@ + @@ -182,6 +185,13 @@ + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + +