commit
d3912b4305
|
@ -11,7 +11,7 @@ using Newtonsoft.Json.Linq;
|
|||
|
||||
namespace StardewModdingAPI
|
||||
{
|
||||
public partial class Config
|
||||
public class Config
|
||||
{
|
||||
[JsonIgnore]
|
||||
public virtual string ConfigLocation { get; protected internal set; }
|
||||
|
@ -47,7 +47,7 @@ namespace StardewModdingAPI
|
|||
if (!File.Exists(ConfigLocation))
|
||||
{
|
||||
//no config exists, generate default values
|
||||
var c = this.GenerateBaseConfig<T>();
|
||||
var c = this.GenerateDefaultConfig<T>();
|
||||
c.ConfigLocation = ConfigLocation;
|
||||
ret = c;
|
||||
}
|
||||
|
@ -67,8 +67,8 @@ namespace StardewModdingAPI
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("Invalid JSON Config: {0} \n{1}", ConfigLocation, ex);
|
||||
return GenerateBaseConfig<T>();
|
||||
Log.Error("Invalid JSON ({0}): {1} \n{2}", GetType().Name, ConfigLocation, ex);
|
||||
return GenerateDefaultConfig<T>();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,15 +84,6 @@ namespace StardewModdingAPI
|
|||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use the public GenerateDefaultConfig insteaad
|
||||
/// </summary>
|
||||
[Obsolete]
|
||||
protected virtual T GenerateBaseConfig<T>() where T : Config
|
||||
{
|
||||
return GenerateDefaultConfig<T>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Merges a default-value config with the user-config on disk.
|
||||
/// </summary>
|
||||
|
@ -103,7 +94,7 @@ namespace StardewModdingAPI
|
|||
try
|
||||
{
|
||||
//default config
|
||||
var b = JObject.FromObject(Instance<T>().GenerateBaseConfig<T>());
|
||||
var b = JObject.FromObject(Instance<T>().GenerateDefaultConfig<T>());
|
||||
|
||||
//user config
|
||||
var u = JObject.FromObject(this);
|
||||
|
@ -133,7 +124,12 @@ namespace StardewModdingAPI
|
|||
/// Initializes an instance of any class that inherits from Config.
|
||||
/// This method performs the loading, saving, and merging of the config on the disk and in memory at a default state.
|
||||
/// This method should not be used to re-load or to re-save a config.
|
||||
/// NOTE: You MUST set your config EQUAL to the return of this method!
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="baseConfig"></param>
|
||||
/// <param name="configLocation"></param>
|
||||
/// <returns></returns>
|
||||
public static T InitializeConfig<T>(this T baseConfig, string configLocation) where T : Config
|
||||
{
|
||||
if (baseConfig == null)
|
||||
|
@ -184,122 +180,5 @@ namespace StardewModdingAPI
|
|||
{
|
||||
return baseConfig.UpdateConfig<T>();
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public static void WriteConfig(this Config baseConfig)
|
||||
{
|
||||
Log.Error("A config has been written through an obsolete way.\n\tThis method of writing configs will not be supported in future versions.");
|
||||
WriteConfig<Config>(baseConfig);
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public static Config ReloadConfig(this Config baseConfig)
|
||||
{
|
||||
Log.Error("A config has been reloaded through an obsolete way.\n\tThis method of loading configs will not be supported in future versions.");
|
||||
return baseConfig.ReloadConfig<Config>();
|
||||
}
|
||||
}
|
||||
|
||||
public partial class Config
|
||||
{
|
||||
[Obsolete] public static int invalids = 0;
|
||||
|
||||
[JsonIgnore]
|
||||
[Obsolete]
|
||||
public virtual JObject JObject { get; protected set; }
|
||||
|
||||
[Obsolete]
|
||||
public static Config InitializeConfig(string configLocation, Config baseConfig)
|
||||
{
|
||||
invalids++;
|
||||
|
||||
if (string.IsNullOrEmpty(configLocation))
|
||||
{
|
||||
Log.Verbose("The location to save the config to must not be empty.");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (baseConfig == null)
|
||||
{
|
||||
Log.Verbose("A config must be instantiated before being passed to Initialize.\n\t" + configLocation);
|
||||
return null;
|
||||
}
|
||||
|
||||
baseConfig.ConfigLocation = configLocation;
|
||||
return baseConfig.LoadConfig(baseConfig);
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public virtual Config GenerateBaseConfig(Config baseConfig)
|
||||
{
|
||||
//Must be implemented in sub-class
|
||||
return null;
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public virtual Config LoadConfig(Config baseConfig)
|
||||
{
|
||||
if (!File.Exists(baseConfig.ConfigLocation))
|
||||
{
|
||||
var v = (Config) baseConfig.GetType().GetMethod("GenerateBaseConfig", BindingFlags.Public | BindingFlags.Instance).Invoke(baseConfig, new object[] {baseConfig});
|
||||
v.WriteConfig();
|
||||
}
|
||||
else
|
||||
{
|
||||
var p = baseConfig.ConfigLocation;
|
||||
|
||||
try
|
||||
{
|
||||
var j = JObject.Parse(File.ReadAllText(baseConfig.ConfigLocation));
|
||||
baseConfig = (Config) j.ToObject(baseConfig.GetType());
|
||||
baseConfig.ConfigLocation = p;
|
||||
baseConfig.JObject = j;
|
||||
|
||||
baseConfig = UpdateConfig(baseConfig);
|
||||
baseConfig.ConfigLocation = p;
|
||||
baseConfig.JObject = j;
|
||||
|
||||
baseConfig.WriteConfig();
|
||||
}
|
||||
catch
|
||||
{
|
||||
Log.Verbose("Invalid JSON: " + p);
|
||||
}
|
||||
}
|
||||
|
||||
return baseConfig;
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public virtual Config UpdateConfig(Config baseConfig)
|
||||
{
|
||||
try
|
||||
{
|
||||
//default config with all standard values
|
||||
var b = JObject.FromObject(baseConfig.GetType().GetMethod("GenerateBaseConfig", BindingFlags.Public | BindingFlags.Instance).Invoke(baseConfig, new object[] {baseConfig}));
|
||||
//user config with their values
|
||||
var u = baseConfig.JObject;
|
||||
|
||||
b.Merge(u, new JsonMergeSettings {MergeArrayHandling = MergeArrayHandling.Replace});
|
||||
|
||||
return (Config) b.ToObject(baseConfig.GetType());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex.ToString());
|
||||
}
|
||||
return baseConfig;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// NOTICE: THIS IS OBSOLETE AND WILL BE REMOVED IN THE FUTURE. 'BaseConfigPath' IS NOW A PROPERTY IN A MOD
|
||||
/// </summary>
|
||||
/// <param name="theMod"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete]
|
||||
public static string GetBasePath(Mod theMod)
|
||||
{
|
||||
return theMod.BaseConfigPath;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -36,7 +36,7 @@ namespace StardewModdingAPI
|
|||
/// <summary>
|
||||
/// Title for the API console
|
||||
/// </summary>
|
||||
public static string ConsoleTitle => string.Format("Stardew Modding API Console - Version {0} - Mods Loaded: {1}", VersionString, ModsLoaded);
|
||||
public static string ConsoleTitle => $"Stardew Modding API Console - Version {Version.VersionString} - Mods Loaded: {ModsLoaded}";
|
||||
|
||||
/// <summary>
|
||||
/// Path for log files to be output to.
|
||||
|
@ -44,15 +44,7 @@ namespace StardewModdingAPI
|
|||
/// </summary>
|
||||
public static string LogPath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley", "ErrorLogs");
|
||||
|
||||
public const int MajorVersion = 0;
|
||||
|
||||
public const int MinorVersion = 38;
|
||||
|
||||
public const int PatchVersion = 8;
|
||||
|
||||
public const string Build = "Alpha";
|
||||
|
||||
public static string VersionString => string.Format("{0}.{1}.{2} {3}", MajorVersion, MinorVersion, PatchVersion, Build);
|
||||
public static readonly Version Version = new Version(0, 39, 1, "Alpha");
|
||||
|
||||
/// <summary>
|
||||
/// Not quite "constant", but it makes more sense for it to be here, at least for now
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using StardewValley;
|
||||
|
||||
namespace StardewModdingAPI.Inheritance
|
||||
{
|
||||
[Obsolete]
|
||||
public class SGameLocation : GameLocation
|
||||
{
|
||||
public GameLocation BaseGameLocation { get; private set; }
|
||||
|
||||
public SerializableDictionary<Vector2, SObject> ModObjects { get; set; }
|
||||
|
||||
public static SGameLocation ConstructFromBaseClass(GameLocation baseClass, bool copyAllData = false)
|
||||
{
|
||||
SGameLocation s = new SGameLocation();
|
||||
s.BaseGameLocation = baseClass;
|
||||
s.name = baseClass.name;
|
||||
|
||||
Log.Debug("CONSTRUCTED: " + s.name);
|
||||
|
||||
if (copyAllData)
|
||||
{
|
||||
foreach (var v in baseClass.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
|
||||
{
|
||||
try
|
||||
{
|
||||
var fi = s.GetType().GetField(v.Name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
if (fi != null && !fi.IsStatic)
|
||||
{
|
||||
fi.SetValue(s, v.GetValue(baseClass));
|
||||
//Console.WriteLine("SET {0} ON {1} TO {2}", fi.Name, s.name, v.GetValue(baseClass));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
public static List<SGameLocation> ConstructFromBaseClasses(List<GameLocation> baseGameLocations, bool copyAllData = false)
|
||||
{
|
||||
return baseGameLocations.Select(gl => ConstructFromBaseClass(gl, copyAllData)).ToList();
|
||||
}
|
||||
|
||||
public virtual void update(GameTime gameTime)
|
||||
{
|
||||
}
|
||||
|
||||
public override void draw(SpriteBatch b)
|
||||
{
|
||||
foreach (var v in ModObjects)
|
||||
{
|
||||
v.Value.draw(b, (int)v.Key.X, (int)v.Key.Y, 0.999f, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public SGameLocation()
|
||||
{
|
||||
ModObjects = new SerializableDictionary<Vector2, SObject>();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@ namespace StardewModdingAPI
|
|||
/// <summary>
|
||||
/// The version of the mod.
|
||||
/// </summary>
|
||||
public virtual string Version { get; set; }
|
||||
public virtual Version Version { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A description of the mod.
|
||||
|
@ -39,11 +39,11 @@ namespace StardewModdingAPI
|
|||
/// </summary>
|
||||
public virtual string EntryDll { get; set; }
|
||||
|
||||
protected override T GenerateBaseConfig<T>()
|
||||
public override T GenerateDefaultConfig<T>()
|
||||
{
|
||||
Name = "";
|
||||
Authour = "";
|
||||
Version = "";
|
||||
Version = new Version(0, 0, 0, "");
|
||||
Description = "";
|
||||
UniqueID = Guid.NewGuid().ToString();
|
||||
PerSaveConfigs = false;
|
||||
|
|
|
@ -5,34 +5,6 @@ namespace StardewModdingAPI
|
|||
{
|
||||
public class Mod
|
||||
{
|
||||
/// <summary>
|
||||
/// The name of your mod.
|
||||
/// NOTE: THIS IS DEPRECATED AND WILL BE REMOVED IN THE NEXT VERSION OF SMAPI
|
||||
/// </summary>
|
||||
[Obsolete]
|
||||
public virtual string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of the mod's authour.
|
||||
/// NOTE: THIS IS DEPRECATED AND WILL BE REMOVED IN THE NEXT VERSION OF SMAPI
|
||||
/// </summary>
|
||||
[Obsolete]
|
||||
public virtual string Authour { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The version of the mod.
|
||||
/// NOTE: THIS IS DEPRECATED AND WILL BE REMOVED IN THE NEXT VERSION OF SMAPI
|
||||
/// </summary>
|
||||
[Obsolete]
|
||||
public virtual string Version { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A description of the mod.
|
||||
/// NOTE: THIS IS DEPRECATED AND WILL BE REMOVED IN THE NEXT VERSION OF SMAPI
|
||||
/// </summary>
|
||||
[Obsolete]
|
||||
public virtual string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The mod's manifest
|
||||
/// </summary>
|
||||
|
|
|
@ -9,7 +9,6 @@ using System.Threading;
|
|||
using System.Windows.Forms;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Newtonsoft.Json;
|
||||
using StardewModdingAPI.Events;
|
||||
using StardewModdingAPI.Inheritance;
|
||||
using StardewModdingAPI.Inheritance.Menus;
|
||||
|
@ -60,10 +59,10 @@ namespace StardewModdingAPI
|
|||
catch (Exception e)
|
||||
{
|
||||
// Catch and display all exceptions.
|
||||
StardewModdingAPI.Log.Error("Critical error: " + e);
|
||||
Log.Error("Critical error: " + e);
|
||||
}
|
||||
|
||||
StardewModdingAPI.Log.Comment("The API will now terminate. Press any key to continue...");
|
||||
Log.Comment("The API will now terminate. Press any key to continue...");
|
||||
Console.ReadKey();
|
||||
}
|
||||
|
||||
|
@ -84,7 +83,7 @@ namespace StardewModdingAPI
|
|||
/// </summary>
|
||||
private static void ConfigurePaths()
|
||||
{
|
||||
StardewModdingAPI.Log.Info("Validating api paths...");
|
||||
Log.Info("Validating api paths...");
|
||||
|
||||
_modPaths = new List<string>();
|
||||
//_modContentPaths = new List<string>();
|
||||
|
@ -102,7 +101,7 @@ namespace StardewModdingAPI
|
|||
//_modContentPaths.ForEach(path => VerifyPath(path));
|
||||
VerifyPath(Constants.LogPath);
|
||||
|
||||
StardewModdingAPI.Log.Initialize(Constants.LogPath);
|
||||
Log.Initialize(Constants.LogPath);
|
||||
|
||||
if (!File.Exists(Constants.ExecutionPath + "\\Stardew Valley.exe"))
|
||||
{
|
||||
|
@ -115,7 +114,7 @@ namespace StardewModdingAPI
|
|||
/// </summary>
|
||||
private static void ConfigureSDV()
|
||||
{
|
||||
StardewModdingAPI.Log.Info("Initializing SDV Assembly...");
|
||||
Log.Info("Initializing SDV Assembly...");
|
||||
|
||||
// Load in the assembly - ignores security
|
||||
StardewAssembly = Assembly.UnsafeLoadFrom(Constants.ExecutionPath + "\\Stardew Valley.exe");
|
||||
|
@ -123,22 +122,22 @@ namespace StardewModdingAPI
|
|||
StardewGameInfo = StardewProgramType.GetField("gamePtr");
|
||||
|
||||
// Change the game's version
|
||||
StardewModdingAPI.Log.Verbose("Injecting New SDV Version...");
|
||||
Game1.version += string.Format("-Z_MODDED | SMAPI {0}", Constants.VersionString);
|
||||
Log.Verbose("Injecting New SDV Version...");
|
||||
Game1.version += string.Format("-Z_MODDED | SMAPI {0}", Constants.Version.VersionString);
|
||||
|
||||
// Create the thread for the game to run in.
|
||||
gameThread = new Thread(RunGame);
|
||||
StardewModdingAPI.Log.Info("Starting SDV...");
|
||||
Log.Info("Starting SDV...");
|
||||
gameThread.Start();
|
||||
|
||||
// Wait for the game to load up
|
||||
while (!ready) ;
|
||||
|
||||
//SDV is running
|
||||
StardewModdingAPI.Log.Comment("SDV Loaded Into Memory");
|
||||
Log.Comment("SDV Loaded Into Memory");
|
||||
|
||||
//Create definition to listen for input
|
||||
StardewModdingAPI.Log.Verbose("Initializing Console Input Thread...");
|
||||
Log.Verbose("Initializing Console Input Thread...");
|
||||
consoleInputThread = new Thread(ConsoleInputThread);
|
||||
|
||||
// The only command in the API (at least it should be, for now)
|
||||
|
@ -150,7 +149,7 @@ namespace StardewModdingAPI
|
|||
GameEvents.LoadContent += Events_LoadContent;
|
||||
//Events.MenuChanged += Events_MenuChanged; //Idk right now
|
||||
|
||||
StardewModdingAPI.Log.Verbose("Applying Final SDV Tweaks...");
|
||||
Log.Verbose("Applying Final SDV Tweaks...");
|
||||
StardewInvoke(() =>
|
||||
{
|
||||
gamePtr.IsMouseVisible = false;
|
||||
|
@ -165,10 +164,10 @@ namespace StardewModdingAPI
|
|||
private static void GameRunInvoker()
|
||||
{
|
||||
//Game's in memory now, send the event
|
||||
StardewModdingAPI.Log.Verbose("Game Loaded");
|
||||
Log.Verbose("Game Loaded");
|
||||
GameEvents.InvokeGameLoaded();
|
||||
|
||||
StardewModdingAPI.Log.Comment("Type 'help' for help, or 'help <cmd>' for a command's usage");
|
||||
Log.Comment("Type 'help' for help, or 'help <cmd>' for a command's usage");
|
||||
//Begin listening to input
|
||||
consoleInputThread.Start();
|
||||
|
||||
|
@ -183,8 +182,8 @@ namespace StardewModdingAPI
|
|||
if (consoleInputThread != null && consoleInputThread.ThreadState == ThreadState.Running)
|
||||
consoleInputThread.Abort();
|
||||
|
||||
StardewModdingAPI.Log.Verbose("Game Execution Finished");
|
||||
StardewModdingAPI.Log.Verbose("Shutting Down...");
|
||||
Log.Verbose("Game Execution Finished");
|
||||
Log.Verbose("Shutting Down...");
|
||||
Thread.Sleep(100);
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
@ -204,7 +203,7 @@ namespace StardewModdingAPI
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
StardewModdingAPI.Log.Error("Could not create a path: " + path + "\n\n" + ex);
|
||||
Log.Error("Could not create a path: " + path + "\n\n" + ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -212,18 +211,16 @@ namespace StardewModdingAPI
|
|||
|
||||
public static void RunGame()
|
||||
{
|
||||
Application.ThreadException += StardewModdingAPI.Log.Application_ThreadException;
|
||||
Application.ThreadException += Log.Application_ThreadException;
|
||||
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
|
||||
AppDomain.CurrentDomain.UnhandledException += StardewModdingAPI.Log.CurrentDomain_UnhandledException;
|
||||
AppDomain.CurrentDomain.UnhandledException += Log.CurrentDomain_UnhandledException;
|
||||
|
||||
try
|
||||
{
|
||||
gamePtr = new SGame();
|
||||
StardewModdingAPI.Log.Verbose("Patching SDV Graphics Profile...");
|
||||
Log.Verbose("Patching SDV Graphics Profile...");
|
||||
Game1.graphics.GraphicsProfile = GraphicsProfile.HiDef;
|
||||
LoadMods();
|
||||
//DEPRECATED WAY
|
||||
LoadMods_OldWay();
|
||||
|
||||
StardewForm = Control.FromHandle(gamePtr.Window.Handle).FindForm();
|
||||
StardewForm.Closing += StardewForm_Closing;
|
||||
|
@ -232,26 +229,10 @@ namespace StardewModdingAPI
|
|||
|
||||
StardewGameInfo.SetValue(StardewProgramType, gamePtr);
|
||||
gamePtr.Run();
|
||||
|
||||
#region deprecated
|
||||
if (false)
|
||||
{
|
||||
//Nope, I can't get it to work. I depend on Game1 being an SGame, and can't cast a parent to a child
|
||||
//I'm leaving this here in case the community is interested
|
||||
//StardewInjectorMod.Entry(true);
|
||||
Type gt = StardewAssembly.GetType("StardewValley.Game1", true);
|
||||
gamePtr = (SGame)Activator.CreateInstance(gt);
|
||||
|
||||
ready = true;
|
||||
|
||||
StardewGameInfo.SetValue(StardewProgramType, gamePtr);
|
||||
gamePtr.Run();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
StardewModdingAPI.Log.Error("Game failed to start: " + ex);
|
||||
Log.Error("Game failed to start: " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -270,38 +251,37 @@ namespace StardewModdingAPI
|
|||
|
||||
public static void LoadMods()
|
||||
{
|
||||
StardewModdingAPI.Log.Verbose("LOADING MODS");
|
||||
Log.Verbose("LOADING MODS");
|
||||
foreach (string ModPath in _modPaths)
|
||||
{
|
||||
foreach (String d in Directory.GetDirectories(ModPath))
|
||||
foreach (string d in Directory.GetDirectories(ModPath))
|
||||
{
|
||||
foreach (String s in Directory.GetFiles(d, "manifest.json"))
|
||||
foreach (string s in Directory.GetFiles(d, "manifest.json"))
|
||||
{
|
||||
if (s.Contains("StardewInjector"))
|
||||
continue;
|
||||
StardewModdingAPI.Log.Success("Found Manifest: " + s);
|
||||
Log.Success("Found Manifest: " + s);
|
||||
Manifest manifest = new Manifest();
|
||||
try
|
||||
{
|
||||
string t = File.ReadAllText(s);
|
||||
if (string.IsNullOrEmpty(t))
|
||||
{
|
||||
StardewModdingAPI.Log.Error("Failed to read mod manifest '{0}'. Manifest is empty!", s);
|
||||
Log.Error("Failed to read mod manifest '{0}'. Manifest is empty!", s);
|
||||
continue;
|
||||
}
|
||||
|
||||
//manifest = (Manifest)Config.InitializeConfig(s, manifest);
|
||||
manifest = manifest.InitializeConfig(s);
|
||||
|
||||
if (string.IsNullOrEmpty(manifest.EntryDll))
|
||||
{
|
||||
StardewModdingAPI.Log.Error("Failed to read mod manifest '{0}'. EntryDll is empty!", s);
|
||||
Log.Error("Failed to read mod manifest '{0}'. EntryDll is empty!", s);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
StardewModdingAPI.Log.Error("Failed to read mod manifest '{0}'. Exception details:\n" + ex, s);
|
||||
Log.Error("Failed to read mod manifest '{0}'. Exception details:\n" + ex, s);
|
||||
continue;
|
||||
}
|
||||
try
|
||||
|
@ -313,14 +293,14 @@ namespace StardewModdingAPI
|
|||
|
||||
if (!Directory.Exists(Path.GetDirectoryName(s)))
|
||||
{
|
||||
StardewModdingAPI.Log.Error("Failed to create psconfigs directory '{0}'. No exception occured.", Path.GetDirectoryName(s));
|
||||
Log.Error("Failed to create psconfigs directory '{0}'. No exception occured.", Path.GetDirectoryName(s));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
StardewModdingAPI.Log.Error("Failed to create psconfigs directory '{0}'. Exception details:\n" + ex, Path.GetDirectoryName(s));
|
||||
Log.Error("Failed to create psconfigs directory '{0}'. Exception details:\n" + ex, Path.GetDirectoryName(s));
|
||||
continue;
|
||||
}
|
||||
try
|
||||
|
@ -328,7 +308,7 @@ namespace StardewModdingAPI
|
|||
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);
|
||||
Log.Error("Failed to load mod '{0}'. File {1} does not exist!", s, targDll);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -336,80 +316,31 @@ namespace StardewModdingAPI
|
|||
|
||||
if (mod.DefinedTypes.Count(x => x.BaseType == typeof (Mod)) > 0)
|
||||
{
|
||||
StardewModdingAPI.Log.Verbose("Loading Mod DLL...");
|
||||
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);
|
||||
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);
|
||||
Constants.ModsLoaded += 1;
|
||||
m.Entry();
|
||||
}
|
||||
else
|
||||
{
|
||||
StardewModdingAPI.Log.Error("Invalid Mod DLL");
|
||||
Log.Error("Invalid Mod DLL");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
StardewModdingAPI.Log.Error("Failed to load mod '{0}'. Exception details:\n" + ex, s);
|
||||
Log.Error("Failed to load mod '{0}'. Exception details:\n" + ex, s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
StardewModdingAPI.Log.Success("LOADED {0} MODS", Constants.ModsLoaded);
|
||||
if (Config.invalids > 0)
|
||||
{
|
||||
StardewModdingAPI.Log.Error("LOADED {0} MODS THAT HAVE INVALID CONFIG INIT CALLS\n\tTHESE MODS NEED TO UPDATE", Config.invalids);
|
||||
}
|
||||
Log.Success("LOADED {0} MODS", Constants.ModsLoaded);
|
||||
Console.Title = Constants.ConsoleTitle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// DEPRECATED. REMOVE
|
||||
/// </summary>
|
||||
[Obsolete]
|
||||
public static void LoadMods_OldWay()
|
||||
{
|
||||
StardewModdingAPI.Log.Error("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.Error("LOADED {0} MODS THAT NEED TO UPDATE", loadedMods);
|
||||
}
|
||||
|
||||
|
||||
public static void ConsoleInputThread()
|
||||
{
|
||||
string input = string.Empty;
|
||||
|
@ -422,7 +353,7 @@ namespace StardewModdingAPI
|
|||
|
||||
static void Events_LoadContent(object o, EventArgs e)
|
||||
{
|
||||
StardewModdingAPI.Log.Info("Initializing Debug Assets...");
|
||||
Log.Info("Initializing Debug Assets...");
|
||||
DebugPixel = new Texture2D(Game1.graphics.GraphicsDevice, 1, 1);
|
||||
DebugPixel.SetData(new[] { Color.White });
|
||||
|
||||
|
@ -458,7 +389,7 @@ namespace StardewModdingAPI
|
|||
|
||||
static void Events_MenuChanged(IClickableMenu newMenu)
|
||||
{
|
||||
StardewModdingAPI.Log.Verbose("NEW MENU: " + newMenu.GetType());
|
||||
Log.Verbose("NEW MENU: " + newMenu.GetType());
|
||||
if (newMenu is GameMenu)
|
||||
{
|
||||
Game1.activeClickableMenu = SGameMenu.ConstructFromBaseClass(Game1.activeClickableMenu as GameMenu);
|
||||
|
@ -496,79 +427,17 @@ namespace StardewModdingAPI
|
|||
{
|
||||
Command fnd = Command.FindCommand(e.Command.CalledArgs[0]);
|
||||
if (fnd == null)
|
||||
StardewModdingAPI.Log.Error("The command specified could not be found");
|
||||
Log.Error("The command specified could not be found");
|
||||
else
|
||||
{
|
||||
if (fnd.CommandArgs.Length > 0)
|
||||
StardewModdingAPI.Log.Info("{0}: {1} - {2}", fnd.CommandName, fnd.CommandDesc, fnd.CommandArgs.ToSingular());
|
||||
Log.Info("{0}: {1} - {2}", fnd.CommandName, fnd.CommandDesc, fnd.CommandArgs.ToSingular());
|
||||
else
|
||||
StardewModdingAPI.Log.Info("{0}: {1}", fnd.CommandName, fnd.CommandDesc);
|
||||
Log.Info("{0}: {1}", fnd.CommandName, fnd.CommandDesc);
|
||||
}
|
||||
}
|
||||
else
|
||||
StardewModdingAPI.Log.Info("Commands: " + Command.RegisteredCommands.Select(x => x.CommandName).ToSingular());
|
||||
}
|
||||
|
||||
#region Logging
|
||||
[Obsolete("This method is obsolete and will be removed in v0.39, please use the appropriate methods in the Log class")]
|
||||
public static void Log(object o, params object[] format)
|
||||
{
|
||||
StardewModdingAPI.Log.Info(o, format);
|
||||
}
|
||||
|
||||
[Obsolete("This method is obsolete and will be removed in v0.39, please use the appropriate methods in the Log class")]
|
||||
public static void LogColour(ConsoleColor c, object o, params object[] format)
|
||||
{
|
||||
StardewModdingAPI.Log.Info(o, format);
|
||||
}
|
||||
|
||||
[Obsolete("This method is obsolete and will be removed in v0.39, please use the appropriate methods in the Log class")]
|
||||
public static void LogInfo(object o, params object[] format)
|
||||
{
|
||||
StardewModdingAPI.Log.Info(o, format);
|
||||
}
|
||||
|
||||
[Obsolete("This method is obsolete and will be removed in v0.39, please use the appropriate methods in the Log class")]
|
||||
public static void LogError(object o, params object[] format)
|
||||
{
|
||||
StardewModdingAPI.Log.Error(o, format);
|
||||
}
|
||||
|
||||
[Obsolete("This method is obsolete and will be removed in v0.39, please use the appropriate methods in the Log class")]
|
||||
public static void LogDebug(object o, params object[] format)
|
||||
{
|
||||
StardewModdingAPI.Log.Debug(o, format);
|
||||
}
|
||||
|
||||
[Obsolete("This method is obsolete and will be removed in v0.39, please use the appropriate methods in the Log class")]
|
||||
public static void LogValueNotSpecified()
|
||||
{
|
||||
StardewModdingAPI.Log.Error("<value> must be specified");
|
||||
}
|
||||
|
||||
[Obsolete("This method is obsolete and will be removed in v0.39, please use the appropriate methods in the Log class")]
|
||||
public static void LogObjectValueNotSpecified()
|
||||
{
|
||||
StardewModdingAPI.Log.Error("<object> and <value> must be specified");
|
||||
}
|
||||
|
||||
[Obsolete("This method is obsolete and will be removed in v0.39, please use the appropriate methods in the Log class")]
|
||||
public static void LogValueInvalid()
|
||||
{
|
||||
StardewModdingAPI.Log.Error("<value> is invalid");
|
||||
}
|
||||
|
||||
[Obsolete("This method is obsolete and will be removed in v0.39, please use the appropriate methods in the Log class")]
|
||||
public static void LogObjectInvalid()
|
||||
{
|
||||
StardewModdingAPI.Log.Error("<object> is invalid");
|
||||
}
|
||||
|
||||
[Obsolete("This method is obsolete and will be removed in v0.39, please use the appropriate methods in the Log class")]
|
||||
public static void LogValueNotInt32()
|
||||
{
|
||||
StardewModdingAPI.Log.Error("<value> must be a whole number (Int32)");
|
||||
}
|
||||
#endregion
|
||||
Log.Info("Commands: " + Command.RegisteredCommands.Select(x => x.CommandName).ToSingular());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -149,7 +149,6 @@
|
|||
<Compile Include="Inheritance\Menus\SGameMenu.cs" />
|
||||
<Compile Include="Inheritance\Menus\SInventoryPage.cs" />
|
||||
<Compile Include="Inheritance\Minigames\SMinigameBase.cs" />
|
||||
<Compile Include="Inheritance\SGameLocation.cs" />
|
||||
<Compile Include="Inheritance\SObject.cs" />
|
||||
<Compile Include="Log.cs" />
|
||||
<Compile Include="Manifest.cs" />
|
||||
|
@ -158,6 +157,7 @@
|
|||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Inheritance\SGame.cs" />
|
||||
<Compile Include="Version.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace StardewModdingAPI
|
||||
{
|
||||
public struct Version
|
||||
{
|
||||
public int MajorVersion { get; set; }
|
||||
public int MinorVersion { get; set; }
|
||||
public int PatchVersion { get; set; }
|
||||
public string Build { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public string VersionString => $"{MajorVersion}.{MinorVersion}.{PatchVersion} {Build}";
|
||||
|
||||
public Version(int major, int minor, int patch, string build)
|
||||
{
|
||||
MajorVersion = major;
|
||||
MinorVersion = minor;
|
||||
PatchVersion = patch;
|
||||
Build = build;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
"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"
|
||||
}
|
Loading…
Reference in New Issue