From 441ded8c9a9e3dea39cb180df429d3fcc5f3cc96 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 9 Dec 2018 18:52:21 -0500 Subject: fix error when a mod makes invalid changes to an NPC schedule --- src/SMAPI/Framework/ContentCoordinator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/ContentCoordinator.cs b/src/SMAPI/Framework/ContentCoordinator.cs index 08a32a9b..7e256939 100644 --- a/src/SMAPI/Framework/ContentCoordinator.cs +++ b/src/SMAPI/Framework/ContentCoordinator.cs @@ -81,7 +81,7 @@ namespace StardewModdingAPI.Framework this.ContentManagers.Add( this.MainContentManager = new GameContentManager("Game1.content", serviceProvider, rootDirectory, currentCulture, this, monitor, reflection, this.OnDisposing) ); - this.CoreAssets = new CoreAssetPropagator(this.MainContentManager.AssertAndNormaliseAssetName, reflection); + this.CoreAssets = new CoreAssetPropagator(this.MainContentManager.AssertAndNormaliseAssetName, reflection, monitor); } /// Get a new content manager which handles reading files from the game content folder with support for interception. -- cgit From 3fef9bb2a5cc39fc6ba15199b0889fae5533c5f0 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 9 Dec 2018 19:35:38 -0500 Subject: fix 'begin must be called' sprite batch errors when using Display.RenderedWorld event --- src/SMAPI/Framework/SGame.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs index 7b3335b7..4d790d9f 100644 --- a/src/SMAPI/Framework/SGame.cs +++ b/src/SMAPI/Framework/SGame.cs @@ -1422,8 +1422,8 @@ namespace StardewModdingAPI.Framework } Game1.spriteBatch.End(); } - this.Events.RenderedWorld.RaiseEmpty(); Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null); + this.Events.RenderedWorld.RaiseEmpty(); if (Game1.drawGrid) { int num1 = -Game1.viewport.X % 64; -- cgit From e447ce225f46f60131519a1ff77dfddf520696bb Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 13 Dec 2018 01:16:38 -0500 Subject: add content pack API --- src/SMAPI/Framework/ModHelpers/CommandHelper.cs | 2 +- .../Framework/ModHelpers/ContentPackHelper.cs | 82 ++++++++++++++++++++++ src/SMAPI/Framework/ModHelpers/ModHelper.cs | 59 +++------------- src/SMAPI/Framework/SCore.cs | 5 +- 4 files changed, 97 insertions(+), 51 deletions(-) create mode 100644 src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/ModHelpers/CommandHelper.cs b/src/SMAPI/Framework/ModHelpers/CommandHelper.cs index 5a3304f3..a4fd21c1 100644 --- a/src/SMAPI/Framework/ModHelpers/CommandHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/CommandHelper.cs @@ -6,7 +6,7 @@ namespace StardewModdingAPI.Framework.ModHelpers internal class CommandHelper : BaseHelper, ICommandHelper { /********* - ** Accessors + ** Properties *********/ /// The mod using this instance. private readonly IModMetadata Mod; diff --git a/src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs b/src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs new file mode 100644 index 00000000..c4b86cda --- /dev/null +++ b/src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.IO; +using StardewModdingAPI.Toolkit.Serialisation.Models; + +namespace StardewModdingAPI.Framework.ModHelpers +{ + /// Provides an API for managing content packs. + internal class ContentPackHelper : BaseHelper, IContentPackHelper + { + /********* + ** Properties + *********/ + /// The content packs loaded for this mod. + private readonly Lazy ContentPacks; + + /// Create a temporary content pack. + private readonly Func CreateContentPack; + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The unique ID of the relevant mod. + /// The content packs loaded for this mod. + /// Create a temporary content pack. + public ContentPackHelper(string modID, Lazy contentPacks, Func createContentPack) + : base(modID) + { + this.ContentPacks = contentPacks; + this.CreateContentPack = createContentPack; + } + + /// Get all content packs loaded for this mod. + public IEnumerable GetOwned() + { + return this.ContentPacks.Value; + } + + /// Create a temporary content pack to read files from a directory. This will generate fake manifest data; any manifest.json in the directory will be ignored. Temporary content packs will not appear in the SMAPI log and update checks will not be performed. + /// The absolute directory path containing the content pack files. + public IContentPack CreateFake(string directoryPath) + { + string id = Guid.NewGuid().ToString("N"); + return this.CreateFake(directoryPath, id, id, id, id, new SemanticVersion(1, 0, 0)); + } + + /// Create a temporary content pack to read files from a directory. Temporary content packs will not appear in the SMAPI log and update checks will not be performed. + /// The absolute directory path containing the content pack files. + /// The content pack's unique ID. + /// The content pack name. + /// The content pack description. + /// The content pack author's name. + /// The content pack version. + public IContentPack CreateFake(string directoryPath, string id, string name, string description, string author, ISemanticVersion version) + { + // validate + if (string.IsNullOrWhiteSpace(directoryPath)) + throw new ArgumentNullException(nameof(directoryPath)); + if (string.IsNullOrWhiteSpace(id)) + throw new ArgumentNullException(nameof(id)); + if (string.IsNullOrWhiteSpace(name)) + throw new ArgumentNullException(nameof(name)); + if (!Directory.Exists(directoryPath)) + throw new ArgumentException($"Can't create content pack for directory path '{directoryPath}' because no such directory exists."); + + // create manifest + IManifest manifest = new Manifest( + uniqueID: id, + name: name, + author: author, + description: description, + version: version, + contentPackFor: this.ModID + ); + + // create content pack + return this.CreateContentPack(directoryPath, manifest); + } + } +} diff --git a/src/SMAPI/Framework/ModHelpers/ModHelper.cs b/src/SMAPI/Framework/ModHelpers/ModHelper.cs index 070d9c65..87d405e9 100644 --- a/src/SMAPI/Framework/ModHelpers/ModHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/ModHelper.cs @@ -15,12 +15,6 @@ namespace StardewModdingAPI.Framework.ModHelpers /********* ** Properties *********/ - /// The content packs loaded for this mod. - private readonly Lazy ContentPacks; - - /// Create a transitional content pack. - private readonly Func CreateContentPack; - #if !SMAPI_3_0_STRICT /// Manages deprecation warnings. private readonly DeprecationManager DeprecationManager; @@ -44,6 +38,9 @@ namespace StardewModdingAPI.Framework.ModHelpers /// An API for loading content assets. public IContentHelper Content { get; } + /// An API for managing content packs. + public IContentPackHelper ContentPacks { get; } + /// An API for reading and writing persistent mod data. public IDataHelper Data { get; } @@ -76,18 +73,17 @@ namespace StardewModdingAPI.Framework.ModHelpers /// Manages the game's input state. /// Manages access to events raised by SMAPI. /// An API for loading content assets. + /// An API for managing content packs. /// An API for managing console commands. /// An API for reading and writing persistent mod data. /// an API for fetching metadata about loaded mods. /// An API for accessing private game code. /// Provides multiplayer utilities. /// An API for reading translations stored in the mod's i18n folder. - /// The content packs loaded for this mod. - /// Create a transitional content pack. /// Manages deprecation warnings. /// An argument is null or empty. /// The path does not exist on disk. - public ModHelper(string modID, string modDirectory, JsonHelper jsonHelper, SInputState inputState, IModEvents events, IContentHelper contentHelper, ICommandHelper commandHelper, IDataHelper dataHelper, IModRegistry modRegistry, IReflectionHelper reflectionHelper, IMultiplayerHelper multiplayer, ITranslationHelper translationHelper, Func contentPacks, Func createContentPack, DeprecationManager deprecationManager) + public ModHelper(string modID, string modDirectory, JsonHelper jsonHelper, SInputState inputState, IModEvents events, IContentHelper contentHelper, IContentPackHelper contentPackHelper, ICommandHelper commandHelper, IDataHelper dataHelper, IModRegistry modRegistry, IReflectionHelper reflectionHelper, IMultiplayerHelper multiplayer, ITranslationHelper translationHelper, DeprecationManager deprecationManager) : base(modID) { // validate directory @@ -99,6 +95,7 @@ namespace StardewModdingAPI.Framework.ModHelpers // initialise this.DirectoryPath = modDirectory; this.Content = contentHelper ?? throw new ArgumentNullException(nameof(contentHelper)); + this.ContentPacks = contentPackHelper ?? throw new ArgumentNullException(nameof(contentPackHelper)); this.Data = dataHelper ?? throw new ArgumentNullException(nameof(dataHelper)); this.Input = new InputHelper(modID, inputState); this.ModRegistry = modRegistry ?? throw new ArgumentNullException(nameof(modRegistry)); @@ -106,8 +103,6 @@ namespace StardewModdingAPI.Framework.ModHelpers this.Reflection = reflectionHelper ?? throw new ArgumentNullException(nameof(reflectionHelper)); this.Multiplayer = multiplayer ?? throw new ArgumentNullException(nameof(multiplayer)); this.Translation = translationHelper ?? throw new ArgumentNullException(nameof(translationHelper)); - this.ContentPacks = new Lazy(contentPacks); - this.CreateContentPack = createContentPack; this.Events = events; #if !SMAPI_3_0_STRICT this.JsonHelper = jsonHelper ?? throw new ArgumentNullException(nameof(jsonHelper)); @@ -171,39 +166,6 @@ namespace StardewModdingAPI.Framework.ModHelpers /**** ** Content packs ****/ - /// Create a temporary content pack to read files from a directory. Temporary content packs will not appear in the SMAPI log and update checks will not be performed. - /// The absolute directory path containing the content pack files. - /// The content pack's unique ID. - /// The content pack name. - /// The content pack description. - /// The content pack author's name. - /// The content pack version. - public IContentPack CreateTemporaryContentPack(string directoryPath, string id, string name, string description, string author, ISemanticVersion version) - { - // validate - if (string.IsNullOrWhiteSpace(directoryPath)) - throw new ArgumentNullException(nameof(directoryPath)); - if (string.IsNullOrWhiteSpace(id)) - throw new ArgumentNullException(nameof(id)); - if (string.IsNullOrWhiteSpace(name)) - throw new ArgumentNullException(nameof(name)); - if (!Directory.Exists(directoryPath)) - throw new ArgumentException($"Can't create content pack for directory path '{directoryPath}' because no such directory exists."); - - // create manifest - IManifest manifest = new Manifest( - uniqueID: id, - name: name, - author: author, - description: description, - version: version, - contentPackFor: this.ModID - ); - - // create content pack - return this.CreateContentPack(directoryPath, manifest); - } - #if !SMAPI_3_0_STRICT /// Manually create a transitional content pack to support pre-SMAPI content packs. This provides a way to access legacy content packs using the SMAPI content pack APIs, but the content pack will not be visible in the log or validated by SMAPI. /// The absolute directory path containing the content pack files. @@ -212,19 +174,20 @@ namespace StardewModdingAPI.Framework.ModHelpers /// The content pack description. /// The content pack author's name. /// The content pack version. - [Obsolete("Use " + nameof(IModHelper) + "." + nameof(IModHelper.CreateTemporaryContentPack) + " instead")] + [Obsolete("Use " + nameof(IModHelper) + "." + nameof(IModHelper.ContentPacks) + "." + nameof(IContentPackHelper.CreateFake) + " instead")] public IContentPack CreateTransitionalContentPack(string directoryPath, string id, string name, string description, string author, ISemanticVersion version) { this.DeprecationManager.Warn($"{nameof(IModHelper)}.{nameof(IModHelper.CreateTransitionalContentPack)}", "2.5", DeprecationLevel.Notice); - return this.CreateTemporaryContentPack(directoryPath, id, name, description, author, version); + return this.ContentPacks.CreateFake(directoryPath, id, name, description, author, version); } -#endif /// Get all content packs loaded for this mod. + [Obsolete("Use " + nameof(IModHelper) + "." + nameof(IModHelper.ContentPacks) + "." + nameof(IContentPackHelper.GetOwned) + " instead")] public IEnumerable GetContentPacks() { - return this.ContentPacks.Value; + return this.ContentPacks.GetOwned(); } +#endif /**** ** Disposal diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 800b9c09..76b091d0 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -1014,20 +1014,21 @@ namespace StardewModdingAPI.Framework IModEvents events = new ModEvents(mod, this.EventManager); ICommandHelper commandHelper = new CommandHelper(mod, this.GameInstance.CommandManager); IContentHelper contentHelper = new ContentHelper(contentCore, mod.DirectoryPath, manifest.UniqueID, mod.DisplayName, monitor); + IContentPackHelper contentPackHelper = new ContentPackHelper(manifest.UniqueID, new Lazy(GetContentPacks), CreateFakeContentPack); IDataHelper dataHelper = new DataHelper(manifest.UniqueID, mod.DirectoryPath, jsonHelper); IReflectionHelper reflectionHelper = new ReflectionHelper(manifest.UniqueID, mod.DisplayName, this.Reflection, this.DeprecationManager); IModRegistry modRegistryHelper = new ModRegistryHelper(manifest.UniqueID, this.ModRegistry, proxyFactory, monitor); IMultiplayerHelper multiplayerHelper = new MultiplayerHelper(manifest.UniqueID, this.GameInstance.Multiplayer); ITranslationHelper translationHelper = new TranslationHelper(manifest.UniqueID, manifest.Name, contentCore.GetLocale(), contentCore.Language); - IContentPack CreateTransitionalContentPack(string packDirPath, IManifest packManifest) + IContentPack CreateFakeContentPack(string packDirPath, IManifest packManifest) { IMonitor packMonitor = this.GetSecondaryMonitor(packManifest.Name); IContentHelper packContentHelper = new ContentHelper(contentCore, packDirPath, packManifest.UniqueID, packManifest.Name, packMonitor); return new ContentPack(packDirPath, packManifest, packContentHelper, this.Toolkit.JsonHelper); } - modHelper = new ModHelper(manifest.UniqueID, mod.DirectoryPath, this.Toolkit.JsonHelper, this.GameInstance.Input, events, contentHelper, commandHelper, dataHelper, modRegistryHelper, reflectionHelper, multiplayerHelper, translationHelper, GetContentPacks, CreateTransitionalContentPack, this.DeprecationManager); + modHelper = new ModHelper(manifest.UniqueID, mod.DirectoryPath, this.Toolkit.JsonHelper, this.GameInstance.Input, events, contentHelper, contentPackHelper, commandHelper, dataHelper, modRegistryHelper, reflectionHelper, multiplayerHelper, translationHelper, this.DeprecationManager); } // init mod -- cgit From 11787f9fea35ee8597c8a4c028b9c3be42751463 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 13 Dec 2018 01:26:54 -0500 Subject: tweak new API method name --- src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs | 4 ++-- src/SMAPI/Framework/ModHelpers/ModHelper.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs b/src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs index c4b86cda..4bd28b36 100644 --- a/src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs @@ -43,7 +43,7 @@ namespace StardewModdingAPI.Framework.ModHelpers public IContentPack CreateFake(string directoryPath) { string id = Guid.NewGuid().ToString("N"); - return this.CreateFake(directoryPath, id, id, id, id, new SemanticVersion(1, 0, 0)); + return this.CreateTemporary(directoryPath, id, id, id, id, new SemanticVersion(1, 0, 0)); } /// Create a temporary content pack to read files from a directory. Temporary content packs will not appear in the SMAPI log and update checks will not be performed. @@ -53,7 +53,7 @@ namespace StardewModdingAPI.Framework.ModHelpers /// The content pack description. /// The content pack author's name. /// The content pack version. - public IContentPack CreateFake(string directoryPath, string id, string name, string description, string author, ISemanticVersion version) + public IContentPack CreateTemporary(string directoryPath, string id, string name, string description, string author, ISemanticVersion version) { // validate if (string.IsNullOrWhiteSpace(directoryPath)) diff --git a/src/SMAPI/Framework/ModHelpers/ModHelper.cs b/src/SMAPI/Framework/ModHelpers/ModHelper.cs index 87d405e9..0dbc5fd7 100644 --- a/src/SMAPI/Framework/ModHelpers/ModHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/ModHelper.cs @@ -174,7 +174,7 @@ namespace StardewModdingAPI.Framework.ModHelpers /// The content pack description. /// The content pack author's name. /// The content pack version. - [Obsolete("Use " + nameof(IModHelper) + "." + nameof(IModHelper.ContentPacks) + "." + nameof(IContentPackHelper.CreateFake) + " instead")] + [Obsolete("Use " + nameof(IModHelper) + "." + nameof(IModHelper.ContentPacks) + "." + nameof(IContentPackHelper.CreateTemporary) + " instead")] public IContentPack CreateTransitionalContentPack(string directoryPath, string id, string name, string description, string author, ISemanticVersion version) { this.DeprecationManager.Warn($"{nameof(IModHelper)}.{nameof(IModHelper.CreateTransitionalContentPack)}", "2.5", DeprecationLevel.Notice); -- cgit From 6045351395f6b74846a2b18b131f662b88641569 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 13 Dec 2018 02:00:30 -0500 Subject: simplify access to deprecation manager for deprecation warnings --- src/SMAPI/Framework/ModHelpers/ModHelper.cs | 17 ++------ src/SMAPI/Framework/ModHelpers/ReflectionHelper.cs | 7 +-- src/SMAPI/Framework/SCore.cs | 51 +++++++++++----------- 3 files changed, 30 insertions(+), 45 deletions(-) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/ModHelpers/ModHelper.cs b/src/SMAPI/Framework/ModHelpers/ModHelper.cs index 0dbc5fd7..ca872e32 100644 --- a/src/SMAPI/Framework/ModHelpers/ModHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/ModHelper.cs @@ -12,15 +12,6 @@ namespace StardewModdingAPI.Framework.ModHelpers /// Provides simplified APIs for writing mods. internal class ModHelper : BaseHelper, IModHelper, IDisposable { - /********* - ** Properties - *********/ -#if !SMAPI_3_0_STRICT - /// Manages deprecation warnings. - private readonly DeprecationManager DeprecationManager; -#endif - - /********* ** Accessors *********/ @@ -80,10 +71,9 @@ namespace StardewModdingAPI.Framework.ModHelpers /// An API for accessing private game code. /// Provides multiplayer utilities. /// An API for reading translations stored in the mod's i18n folder. - /// Manages deprecation warnings. /// An argument is null or empty. /// The path does not exist on disk. - public ModHelper(string modID, string modDirectory, JsonHelper jsonHelper, SInputState inputState, IModEvents events, IContentHelper contentHelper, IContentPackHelper contentPackHelper, ICommandHelper commandHelper, IDataHelper dataHelper, IModRegistry modRegistry, IReflectionHelper reflectionHelper, IMultiplayerHelper multiplayer, ITranslationHelper translationHelper, DeprecationManager deprecationManager) + public ModHelper(string modID, string modDirectory, JsonHelper jsonHelper, SInputState inputState, IModEvents events, IContentHelper contentHelper, IContentPackHelper contentPackHelper, ICommandHelper commandHelper, IDataHelper dataHelper, IModRegistry modRegistry, IReflectionHelper reflectionHelper, IMultiplayerHelper multiplayer, ITranslationHelper translationHelper) : base(modID) { // validate directory @@ -106,7 +96,6 @@ namespace StardewModdingAPI.Framework.ModHelpers this.Events = events; #if !SMAPI_3_0_STRICT this.JsonHelper = jsonHelper ?? throw new ArgumentNullException(nameof(jsonHelper)); - this.DeprecationManager = deprecationManager; #endif } @@ -177,8 +166,8 @@ namespace StardewModdingAPI.Framework.ModHelpers [Obsolete("Use " + nameof(IModHelper) + "." + nameof(IModHelper.ContentPacks) + "." + nameof(IContentPackHelper.CreateTemporary) + " instead")] public IContentPack CreateTransitionalContentPack(string directoryPath, string id, string name, string description, string author, ISemanticVersion version) { - this.DeprecationManager.Warn($"{nameof(IModHelper)}.{nameof(IModHelper.CreateTransitionalContentPack)}", "2.5", DeprecationLevel.Notice); - return this.ContentPacks.CreateFake(directoryPath, id, name, description, author, version); + SCore.DeprecationManager.Warn($"{nameof(IModHelper)}.{nameof(IModHelper.CreateTransitionalContentPack)}", "2.5", DeprecationLevel.Notice); + return this.ContentPacks.CreateTemporary(directoryPath, id, name, description, author, version); } /// Get all content packs loaded for this mod. diff --git a/src/SMAPI/Framework/ModHelpers/ReflectionHelper.cs b/src/SMAPI/Framework/ModHelpers/ReflectionHelper.cs index 648d6742..cfe2ddbe 100644 --- a/src/SMAPI/Framework/ModHelpers/ReflectionHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/ReflectionHelper.cs @@ -17,9 +17,6 @@ namespace StardewModdingAPI.Framework.ModHelpers /// The mod name for error messages. private readonly string ModName; - /// Manages deprecation warnings. - private readonly DeprecationManager DeprecationManager; - /********* ** Public methods @@ -28,13 +25,11 @@ namespace StardewModdingAPI.Framework.ModHelpers /// The unique ID of the relevant mod. /// The mod name for error messages. /// The underlying reflection helper. - /// Manages deprecation warnings. - public ReflectionHelper(string modID, string modName, Reflector reflector, DeprecationManager deprecationManager) + public ReflectionHelper(string modID, string modName, Reflector reflector) : base(modID) { this.ModName = modName; this.Reflector = reflector; - this.DeprecationManager = deprecationManager; } /// Get an instance field. diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 76b091d0..3749bab4 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -75,10 +75,6 @@ namespace StardewModdingAPI.Framework /// This is initialised after the game starts. private readonly ModRegistry ModRegistry = new ModRegistry(); - /// Manages deprecation warnings. - /// This is initialised after the game starts. - private readonly DeprecationManager DeprecationManager; - /// Manages SMAPI events for mods. private readonly EventManager EventManager; @@ -120,6 +116,14 @@ namespace StardewModdingAPI.Framework private string ModsPath => Constants.ModsPath; + /********* + ** Accessors + *********/ + /// Manages deprecation warnings. + /// This is initialised after the game starts. This is accessed directly because it's not part of the normal class model. + internal static DeprecationManager DeprecationManager { get; private set; } + + /********* ** Public methods *********/ @@ -148,15 +152,12 @@ namespace StardewModdingAPI.Framework }; this.MonitorForGame = this.GetSecondaryMonitor("game"); this.EventManager = new EventManager(this.Monitor, this.ModRegistry); - this.DeprecationManager = new DeprecationManager(this.Monitor, this.ModRegistry); + SCore.DeprecationManager = new DeprecationManager(this.Monitor, this.ModRegistry); // redirect direct console output if (this.MonitorForGame.WriteToConsole) this.ConsoleManager.OnMessageIntercepted += message => this.HandleConsoleMessage(this.MonitorForGame, message); - // inject deprecation managers - SemanticVersion.DeprecationManager = this.DeprecationManager; - // init logging this.Monitor.Log($"SMAPI {Constants.ApiVersion} with Stardew Valley {Constants.GameVersion} on {EnvironmentUtility.GetFriendlyPlatformName(Constants.Platform)}", LogLevel.Info); this.Monitor.Log($"Mods go here: {modsPath}"); @@ -196,19 +197,19 @@ namespace StardewModdingAPI.Framework { #if !SMAPI_3_0_STRICT // hook up events - ContentEvents.Init(this.EventManager, this.DeprecationManager); - ControlEvents.Init(this.EventManager, this.DeprecationManager); - GameEvents.Init(this.EventManager, this.DeprecationManager); - GraphicsEvents.Init(this.EventManager, this.DeprecationManager); - InputEvents.Init(this.EventManager, this.DeprecationManager); - LocationEvents.Init(this.EventManager, this.DeprecationManager); - MenuEvents.Init(this.EventManager, this.DeprecationManager); - MineEvents.Init(this.EventManager, this.DeprecationManager); - MultiplayerEvents.Init(this.EventManager, this.DeprecationManager); - PlayerEvents.Init(this.EventManager, this.DeprecationManager); - SaveEvents.Init(this.EventManager, this.DeprecationManager); - SpecialisedEvents.Init(this.EventManager, this.DeprecationManager); - TimeEvents.Init(this.EventManager, this.DeprecationManager); + ContentEvents.Init(this.EventManager); + ControlEvents.Init(this.EventManager); + GameEvents.Init(this.EventManager); + GraphicsEvents.Init(this.EventManager); + InputEvents.Init(this.EventManager); + LocationEvents.Init(this.EventManager); + MenuEvents.Init(this.EventManager); + MineEvents.Init(this.EventManager); + MultiplayerEvents.Init(this.EventManager); + PlayerEvents.Init(this.EventManager); + SaveEvents.Init(this.EventManager); + SpecialisedEvents.Init(this.EventManager); + TimeEvents.Init(this.EventManager); #endif // init JSON parser @@ -232,7 +233,7 @@ namespace StardewModdingAPI.Framework // override game SGame.ConstructorHack = new SGameConstructorHack(this.Monitor, this.Reflection, this.Toolkit.JsonHelper); - this.GameInstance = new SGame(this.Monitor, this.MonitorForGame, this.Reflection, this.EventManager, this.Toolkit.JsonHelper, this.ModRegistry, this.DeprecationManager, this.OnLocaleChanged, this.InitialiseAfterGameStart, this.Dispose); + this.GameInstance = new SGame(this.Monitor, this.MonitorForGame, this.Reflection, this.EventManager, this.Toolkit.JsonHelper, this.ModRegistry, SCore.DeprecationManager, this.OnLocaleChanged, this.InitialiseAfterGameStart, this.Dispose); StardewValley.Program.gamePtr = this.GameInstance; // add exit handler @@ -920,7 +921,7 @@ namespace StardewModdingAPI.Framework // add deprecation warning for old version format { if (mod.Manifest?.Version is Toolkit.SemanticVersion version && version.IsLegacyFormat) - this.DeprecationManager.Warn(mod.DisplayName, "non-string manifest version", "2.8", DeprecationLevel.Notice); + SCore.DeprecationManager.Warn(mod.DisplayName, "non-string manifest version", "2.8", DeprecationLevel.Notice); } #endif @@ -1016,7 +1017,7 @@ namespace StardewModdingAPI.Framework IContentHelper contentHelper = new ContentHelper(contentCore, mod.DirectoryPath, manifest.UniqueID, mod.DisplayName, monitor); IContentPackHelper contentPackHelper = new ContentPackHelper(manifest.UniqueID, new Lazy(GetContentPacks), CreateFakeContentPack); IDataHelper dataHelper = new DataHelper(manifest.UniqueID, mod.DirectoryPath, jsonHelper); - IReflectionHelper reflectionHelper = new ReflectionHelper(manifest.UniqueID, mod.DisplayName, this.Reflection, this.DeprecationManager); + IReflectionHelper reflectionHelper = new ReflectionHelper(manifest.UniqueID, mod.DisplayName, this.Reflection); IModRegistry modRegistryHelper = new ModRegistryHelper(manifest.UniqueID, this.ModRegistry, proxyFactory, monitor); IMultiplayerHelper multiplayerHelper = new MultiplayerHelper(manifest.UniqueID, this.GameInstance.Multiplayer); ITranslationHelper translationHelper = new TranslationHelper(manifest.UniqueID, manifest.Name, contentCore.GetLocale(), contentCore.Language); @@ -1028,7 +1029,7 @@ namespace StardewModdingAPI.Framework return new ContentPack(packDirPath, packManifest, packContentHelper, this.Toolkit.JsonHelper); } - modHelper = new ModHelper(manifest.UniqueID, mod.DirectoryPath, this.Toolkit.JsonHelper, this.GameInstance.Input, events, contentHelper, contentPackHelper, commandHelper, dataHelper, modRegistryHelper, reflectionHelper, multiplayerHelper, translationHelper, this.DeprecationManager); + modHelper = new ModHelper(manifest.UniqueID, mod.DirectoryPath, this.Toolkit.JsonHelper, this.GameInstance.Input, events, contentHelper, contentPackHelper, commandHelper, dataHelper, modRegistryHelper, reflectionHelper, multiplayerHelper, translationHelper); } // init mod -- cgit From fd47e992dbdbf4298fd9130b8ef9bfcf52fcab19 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 13 Dec 2018 02:01:23 -0500 Subject: deprecate assetData.AsDictionary().Set --- src/SMAPI/Framework/Content/AssetDataForDictionary.cs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/Content/AssetDataForDictionary.cs b/src/SMAPI/Framework/Content/AssetDataForDictionary.cs index 7b80875f..9bd70711 100644 --- a/src/SMAPI/Framework/Content/AssetDataForDictionary.cs +++ b/src/SMAPI/Framework/Content/AssetDataForDictionary.cs @@ -19,28 +19,36 @@ namespace StardewModdingAPI.Framework.Content public AssetDataForDictionary(string locale, string assetName, IDictionary data, Func getNormalisedPath, Action> onDataReplaced) : base(locale, assetName, data, getNormalisedPath, onDataReplaced) { } +#if !SMAPI_3_0_STRICT /// Add or replace an entry in the dictionary. /// The entry key. /// The entry value. + [Obsolete("Access " + nameof(AssetData>.Data) + "field directly.")] public void Set(TKey key, TValue value) { + SCore.DeprecationManager.Warn($"AssetDataForDictionary.{nameof(Set)}", "2.10", DeprecationLevel.Notice); this.Data[key] = value; } /// Add or replace an entry in the dictionary. /// The entry key. /// A callback which accepts the current value and returns the new value. + [Obsolete("Access " + nameof(AssetData>.Data) + "field directly.")] public void Set(TKey key, Func value) { + SCore.DeprecationManager.Warn($"AssetDataForDictionary.{nameof(Set)}", "2.10", DeprecationLevel.Notice); this.Data[key] = value(this.Data[key]); } /// Dynamically replace values in the dictionary. /// A lambda which takes the current key and value for an entry, and returns the new value. + [Obsolete("Access " + nameof(AssetData>.Data) + "field directly.")] public void Set(Func replacer) { + SCore.DeprecationManager.Warn($"AssetDataForDictionary.{nameof(Set)}", "2.10", DeprecationLevel.Notice); foreach (var pair in this.Data.ToArray()) this.Data[pair.Key] = replacer(pair.Key, pair.Value); } +#endif } } -- cgit From 95b1dedb667d1fe2fd9ee89ece342bacbdd3be48 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 13 Dec 2018 02:11:06 -0500 Subject: clarify docblock --- src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs b/src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs index 4bd28b36..26c4648c 100644 --- a/src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs @@ -38,7 +38,7 @@ namespace StardewModdingAPI.Framework.ModHelpers return this.ContentPacks.Value; } - /// Create a temporary content pack to read files from a directory. This will generate fake manifest data; any manifest.json in the directory will be ignored. Temporary content packs will not appear in the SMAPI log and update checks will not be performed. + /// Create a temporary content pack to read files from a directory, using randomised manifest fields. This will generate fake manifest data; any manifest.json in the directory will be ignored. Temporary content packs will not appear in the SMAPI log and update checks will not be performed. /// The absolute directory path containing the content pack files. public IContentPack CreateFake(string directoryPath) { -- cgit From 8eee91c67db0f09e9c604c7b4a2809e5bc937258 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 14 Dec 2018 00:23:48 -0500 Subject: fix game launch error logged as 'SMAPI' --- src/SMAPI/Framework/SCore.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 3749bab4..e43d3f8b 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -315,7 +315,7 @@ namespace StardewModdingAPI.Framework } catch (Exception ex) { - this.Monitor.Log($"The game failed unexpectedly: {ex.GetLogSummary()}", LogLevel.Error); + this.MonitorForGame.Log($"The game failed to launch: {ex.GetLogSummary()}", LogLevel.Error); this.PressAnyKeyToExit(); } finally -- cgit From 0d26285da12156c6304c1ff4458bd0b62e6e8dca Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 14 Dec 2018 00:42:00 -0500 Subject: add friendly error when the game can't find its Content\XACT folder --- src/SMAPI/Framework/SCore.cs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index e43d3f8b..3bc0aca4 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -313,6 +313,12 @@ namespace StardewModdingAPI.Framework this.Monitor.Log($"Technical details: {ex.GetLogSummary()}", LogLevel.Trace); this.PressAnyKeyToExit(); } + catch (FileNotFoundException ex) when (ex.Message == "Could not find file 'C:\\Program Files (x86)\\Steam\\SteamApps\\common\\Stardew Valley\\Content\\XACT\\FarmerSounds.xgs'.") // path in error is hardcoded regardless of install path + { + this.Monitor.Log("The game can't find its Content\\XACT\\FarmerSounds.xgs file. You can usually fix this by resetting your content files (see https://smapi.io/troubleshoot#reset-content ), or by uninstalling and reinstalling the game.", LogLevel.Error); + this.Monitor.Log($"Technical details: {ex.GetLogSummary()}", LogLevel.Trace); + this.PressAnyKeyToExit(); + } catch (Exception ex) { this.MonitorForGame.Log($"The game failed to launch: {ex.GetLogSummary()}", LogLevel.Error); -- cgit From c6135e0759fc0f50c873b0278f006aeb7e67e712 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 14 Dec 2018 18:58:06 -0500 Subject: clarify trace message --- src/SMAPI/Framework/ContentManagers/GameContentManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/ContentManagers/GameContentManager.cs b/src/SMAPI/Framework/ContentManagers/GameContentManager.cs index 4f3b6fbc..81732d3f 100644 --- a/src/SMAPI/Framework/ContentManagers/GameContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/GameContentManager.cs @@ -238,7 +238,7 @@ namespace StardewModdingAPI.Framework.ContentManagers try { editor.Edit(asset); - this.Monitor.Log($"{mod.DisplayName} intercepted {info.AssetName}.", LogLevel.Trace); + this.Monitor.Log($"{mod.DisplayName} edited {info.AssetName}.", LogLevel.Trace); } catch (Exception ex) { -- cgit From 39341d772e99492f239ad8aff09cca8760ff5b83 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 15 Dec 2018 13:33:22 -0500 Subject: prevent invalid items from crashing the game --- src/SMAPI/Framework/SCore.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 3bc0aca4..679838ba 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -184,7 +184,8 @@ namespace StardewModdingAPI.Framework // apply game patches new GamePatcher(this.Monitor).Apply( - new DialogueErrorPatch(this.MonitorForGame, this.Reflection) + new DialogueErrorPatch(this.MonitorForGame, this.Reflection), + new ObjectErrorPatch() ); } -- cgit From 803f9f439ca7547a5de100ee6564d295fa44cbf3 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 16 Dec 2018 02:55:41 -0500 Subject: fix messages not sent correctly to farmhands connected via Steam friends --- src/SMAPI/Framework/Networking/SGalaxyNetServer.cs | 24 ++++++++++++++++------ src/SMAPI/Framework/SMultiplayer.cs | 2 ++ 2 files changed, 20 insertions(+), 6 deletions(-) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/Networking/SGalaxyNetServer.cs b/src/SMAPI/Framework/Networking/SGalaxyNetServer.cs index 2fc92737..82d11938 100644 --- a/src/SMAPI/Framework/Networking/SGalaxyNetServer.cs +++ b/src/SMAPI/Framework/Networking/SGalaxyNetServer.cs @@ -34,9 +34,14 @@ namespace StardewModdingAPI.Framework.Networking this.OnProcessingMessage = onProcessingMessage; } + + /********* + ** Protected methods + *********/ /// Read and process a message from the client. /// The Galaxy peer ID. /// The data to process. + /// This reimplements , but adds a callback to . [SuppressMessage("ReSharper", "AccessToDisposedClosure", Justification = "The callback is invoked synchronously.")] protected override void onReceiveMessage(GalaxyID peer, Stream messageStream) { @@ -44,20 +49,27 @@ namespace StardewModdingAPI.Framework.Networking using (BinaryReader reader = new BinaryReader(messageStream)) { message.Read(reader); - this.OnProcessingMessage(message, outgoing => this.sendMessage(peer, outgoing), () => + ulong peerID = peer.ToUint64(); // note: GalaxyID instances get reused, so need to store the underlying ID instead + this.OnProcessingMessage(message, outgoing => this.SendMessageToPeerID(peerID, outgoing), () => { - if (this.peers.ContainsLeft(message.FarmerID) && (long)this.peers[message.FarmerID] == (long)peer.ToUint64()) - { + if (this.peers.ContainsLeft(message.FarmerID) && (long)this.peers[message.FarmerID] == (long)peerID) this.gameServer.processIncomingMessage(message); - } else if (message.MessageType == StardewValley.Multiplayer.playerIntroduction) { NetFarmerRoot farmer = this.Multiplayer.readFarmer(message.Reader); - GalaxyID capturedPeer = new GalaxyID(peer.ToUint64()); - this.gameServer.checkFarmhandRequest(Convert.ToString(peer.ToUint64()), farmer, msg => this.sendMessage(capturedPeer, msg), () => this.peers[farmer.Value.UniqueMultiplayerID] = capturedPeer.ToUint64()); + GalaxyID capturedPeer = new GalaxyID(peerID); + this.gameServer.checkFarmhandRequest(Convert.ToString(peerID), farmer, msg => this.sendMessage(capturedPeer, msg), () => this.peers[farmer.Value.UniqueMultiplayerID] = capturedPeer.ToUint64()); } }); } } + + /// Send a message to a remote peer. + /// The unique Galaxy ID, derived from . + /// The message to send. + private void SendMessageToPeerID(ulong peerID, OutgoingMessage message) + { + this.sendMessage(new GalaxyID(peerID), message); + } } } diff --git a/src/SMAPI/Framework/SMultiplayer.cs b/src/SMAPI/Framework/SMultiplayer.cs index 12cd2d46..784edae3 100644 --- a/src/SMAPI/Framework/SMultiplayer.cs +++ b/src/SMAPI/Framework/SMultiplayer.cs @@ -119,6 +119,7 @@ namespace StardewModdingAPI.Framework } default: + this.Monitor.Log($"Unknown multiplayer client type: {client.GetType().AssemblyQualifiedName}", LogLevel.Trace); return client; } } @@ -142,6 +143,7 @@ namespace StardewModdingAPI.Framework } default: + this.Monitor.Log($"Unknown multiplayer server type: {server.GetType().AssemblyQualifiedName}", LogLevel.Trace); return server; } } -- cgit