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 ++++++++++++++++++++++---------------------- 2 files changed, 71 insertions(+), 46 deletions(-) (limited to 'StardewModdingAPI') 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; -- cgit From b47f3a7e23d77a2fc8280f653caf51cc7951cee0 Mon Sep 17 00:00:00 2001 From: Zoryn Aaron Date: Sun, 20 Mar 2016 17:51:49 -0400 Subject: Content paths removed. Mods need to define their own. --- StardewModdingAPI/Program.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'StardewModdingAPI') diff --git a/StardewModdingAPI/Program.cs b/StardewModdingAPI/Program.cs index 92c6c079..bb863ca4 100644 --- a/StardewModdingAPI/Program.cs +++ b/StardewModdingAPI/Program.cs @@ -20,7 +20,7 @@ namespace StardewModdingAPI public class Program { private static List _modPaths; - private static List _modContentPaths; + //private static List _modContentPaths; public static Texture2D DebugPixel { get; private set; } @@ -84,17 +84,19 @@ namespace StardewModdingAPI StardewModdingAPI.Log.Info("Validating api paths..."); _modPaths = new List(); - _modContentPaths = new List(); + //_modContentPaths = new List(); //TODO: Have an app.config and put the paths inside it so users can define locations to load mods from _modPaths.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley", "Mods")); _modPaths.Add(Path.Combine(Constants.ExecutionPath, "Mods")); - _modContentPaths.Add(Path.Combine(Constants.ExecutionPath, "Mods", "Content")); - _modContentPaths.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley", "Mods", "Content")); + + //Mods need to make their own content paths, since we're doing a different, manifest-driven, approach. + //_modContentPaths.Add(Path.Combine(Constants.ExecutionPath, "Mods", "Content")); + //_modContentPaths.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley", "Mods", "Content")); //Checks that all defined modpaths exist as directories _modPaths.ForEach(path => VerifyPath(path)); - _modContentPaths.ForEach(path => VerifyPath(path)); + //_modContentPaths.ForEach(path => VerifyPath(path)); VerifyPath(Constants.LogPath); StardewModdingAPI.Log.Initialize(Constants.LogPath); -- 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 'StardewModdingAPI') 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}. + + +