diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2018-12-07 13:40:44 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2018-12-07 13:40:44 -0500 |
commit | a78b1935928919694dfe8de823a1accd6d222732 (patch) | |
tree | 3f17b6087cf2749e52c1e237de17e2e9addb6c06 /src/SMAPI/Metadata | |
parent | 4cd9eda1591c3908bf80b60c2902491a7595ee27 (diff) | |
parent | 8901218418693d610a17b22fe789ba6279f63446 (diff) | |
download | SMAPI-a78b1935928919694dfe8de823a1accd6d222732.tar.gz SMAPI-a78b1935928919694dfe8de823a1accd6d222732.tar.bz2 SMAPI-a78b1935928919694dfe8de823a1accd6d222732.zip |
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI/Metadata')
-rw-r--r-- | src/SMAPI/Metadata/CoreAssetPropagator.cs | 82 | ||||
-rw-r--r-- | src/SMAPI/Metadata/InstructionMetadata.cs | 80 |
2 files changed, 102 insertions, 60 deletions
diff --git a/src/SMAPI/Metadata/CoreAssetPropagator.cs b/src/SMAPI/Metadata/CoreAssetPropagator.cs index 8487b6be..d273c251 100644 --- a/src/SMAPI/Metadata/CoreAssetPropagator.cs +++ b/src/SMAPI/Metadata/CoreAssetPropagator.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using StardewModdingAPI.Framework.Reflection; using StardewValley; @@ -13,6 +14,7 @@ using StardewValley.Menus; using StardewValley.Objects; using StardewValley.Projectiles; using StardewValley.TerrainFeatures; +using xTile; using xTile.Tiles; namespace StardewModdingAPI.Metadata @@ -45,10 +47,11 @@ namespace StardewModdingAPI.Metadata /// <summary>Reload one of the game's core assets (if applicable).</summary> /// <param name="content">The content manager through which to reload the asset.</param> /// <param name="key">The asset key to reload.</param> + /// <param name="type">The asset type to reload.</param> /// <returns>Returns whether an asset was reloaded.</returns> - public bool Propagate(LocalizedContentManager content, string key) + public bool Propagate(LocalizedContentManager content, string key, Type type) { - object result = this.PropagateImpl(content, key); + object result = this.PropagateImpl(content, key, type); if (result is bool b) return b; return result != null; @@ -61,9 +64,12 @@ namespace StardewModdingAPI.Metadata /// <summary>Reload one of the game's core assets (if applicable).</summary> /// <param name="content">The content manager through which to reload the asset.</param> /// <param name="key">The asset key to reload.</param> - /// <returns>Returns any non-null value to indicate an asset was loaded.</returns> - private object PropagateImpl(LocalizedContentManager content, string key) + /// <param name="type">The asset type to reload.</param> + /// <returns>Returns whether an asset was loaded. The return value may be true or false, or a non-null value for true.</returns> + private object PropagateImpl(LocalizedContentManager content, string key, Type type) { + key = this.GetNormalisedPath(key); + /**** ** Special case: current map tilesheet ** We only need to do this for the current location, since tilesheets are reloaded when you enter a location. @@ -79,6 +85,24 @@ namespace StardewModdingAPI.Metadata } /**** + ** Propagate map changes + ****/ + if (type == typeof(Map)) + { + bool anyChanged = false; + foreach (GameLocation location in this.GetLocations()) + { + if (this.GetNormalisedPath(location.mapPath.Value) == key) + { + this.Reflection.GetMethod(location, "reloadMap").Invoke(); + this.Reflection.GetMethod(location, "updateWarps").Invoke(); + anyChanged = true; + } + } + return anyChanged; + } + + /**** ** Propagate by key ****/ Reflector reflection = this.Reflection; @@ -141,6 +165,9 @@ namespace StardewModdingAPI.Metadata case "data\\craftingrecipes": // CraftingRecipe.InitShared return CraftingRecipe.craftingRecipes = content.Load<Dictionary<string, string>>(key); + case "data\\npcdispositions": // NPC constructor + return this.ReloadNpcDispositions(content, key); + case "data\\npcgifttastes": // Game1.loadContent return Game1.NPCGiftTastes = content.Load<Dictionary<string, string>>(key); @@ -460,6 +487,35 @@ namespace StardewModdingAPI.Metadata return true; } + /// <summary>Reload the disposition data for matching NPCs.</summary> + /// <param name="content">The content manager through which to reload the asset.</param> + /// <param name="key">The asset key to reload.</param> + /// <returns>Returns whether any NPCs were affected.</returns> + private bool ReloadNpcDispositions(LocalizedContentManager content, string key) + { + IDictionary<string, string> dispositions = content.Load<Dictionary<string, string>>(key); + foreach (NPC character in this.GetCharacters()) + { + if (!character.isVillager() || !dispositions.ContainsKey(character.Name)) + continue; + + NPC clone = new NPC(null, Vector2.Zero, 0, character.Name); + character.Age = clone.Age; + character.Manners = clone.Manners; + character.SocialAnxiety = clone.SocialAnxiety; + character.Optimism = clone.Optimism; + character.Gender = clone.Gender; + character.datable.Value = clone.datable.Value; + character.homeRegion = clone.homeRegion; + character.Birthday_Season = clone.Birthday_Season; + character.Birthday_Day = clone.Birthday_Day; + character.id = clone.id; + character.displayName = clone.displayName; + } + + return true; + } + /// <summary>Reload the sprites for matching NPCs.</summary> /// <param name="content">The content manager through which to reload the asset.</param> /// <param name="key">The asset key to reload.</param> @@ -586,24 +642,6 @@ namespace StardewModdingAPI.Metadata this.Reflection.GetField<Texture2D>(sprite, "spriteTexture").SetValue(texture); } - /// <summary>Get an NPC name from the name of their file under <c>Content/Characters</c>.</summary> - /// <param name="name">The file name.</param> - /// <remarks>Derived from <see cref="NPC.reloadSprite"/>.</remarks> - private string GetNpcNameFromFileName(string name) - { - switch (name) - { - case "Mariner": - return "Old Mariner"; - case "DwarfKing": - return "Dwarf King"; - case "MrQi": - return "Mister Qi"; - default: - return name; - } - } - /// <summary>Get all NPCs in the game (excluding farm animals).</summary> private IEnumerable<NPC> GetCharacters() { diff --git a/src/SMAPI/Metadata/InstructionMetadata.cs b/src/SMAPI/Metadata/InstructionMetadata.cs index ff8d54e3..7c840b2f 100644 --- a/src/SMAPI/Metadata/InstructionMetadata.cs +++ b/src/SMAPI/Metadata/InstructionMetadata.cs @@ -24,51 +24,55 @@ namespace StardewModdingAPI.Metadata ** Public methods *********/ /// <summary>Get rewriters which detect or fix incompatible CIL instructions in mod assemblies.</summary> - public IEnumerable<IInstructionHandler> GetHandlers() + /// <param name="paranoidMode">Whether to detect paranoid mode issues.</param> + public IEnumerable<IInstructionHandler> GetHandlers(bool paranoidMode) { - return new IInstructionHandler[] - { - /**** - ** rewrite CIL to fix incompatible code - ****/ - // rewrite for crossplatform compatibility - new MethodParentRewriter(typeof(SpriteBatch), typeof(SpriteBatchMethods), onlyIfPlatformChanged: true), + /**** + ** rewrite CIL to fix incompatible code + ****/ + // rewrite for crossplatform compatibility + yield return new MethodParentRewriter(typeof(SpriteBatch), typeof(SpriteBatchMethods), onlyIfPlatformChanged: true); + + // rewrite for Stardew Valley 1.3 + yield return new StaticFieldToConstantRewriter<int>(typeof(Game1), "tileSize", Game1.tileSize); - // rewrite for Stardew Valley 1.3 - new StaticFieldToConstantRewriter<int>(typeof(Game1), "tileSize", Game1.tileSize), + /**** + ** detect mod issues + ****/ + // detect broken code + yield return new ReferenceToMissingMemberFinder(this.ValidateReferencesToAssemblies); + yield return new ReferenceToMemberWithUnexpectedTypeFinder(this.ValidateReferencesToAssemblies); - /**** - ** detect mod issues - ****/ - // detect broken code - new ReferenceToMissingMemberFinder(this.ValidateReferencesToAssemblies), - new ReferenceToMemberWithUnexpectedTypeFinder(this.ValidateReferencesToAssemblies), + /**** + ** detect code which may impact game stability + ****/ + yield return new TypeFinder("Harmony.HarmonyInstance", InstructionHandleResult.DetectedGamePatch); + yield return new TypeFinder("System.Runtime.CompilerServices.CallSite", InstructionHandleResult.DetectedDynamic); + yield return new FieldFinder(typeof(SaveGame).FullName, nameof(SaveGame.serializer), InstructionHandleResult.DetectedSaveSerialiser); + yield return new FieldFinder(typeof(SaveGame).FullName, nameof(SaveGame.farmerSerializer), InstructionHandleResult.DetectedSaveSerialiser); + yield return new FieldFinder(typeof(SaveGame).FullName, nameof(SaveGame.locationSerializer), InstructionHandleResult.DetectedSaveSerialiser); + yield return new TypeFinder(typeof(ISpecialisedEvents).FullName, InstructionHandleResult.DetectedUnvalidatedUpdateTick); +#if !SMAPI_3_0_STRICT + yield return new EventFinder(typeof(SpecialisedEvents).FullName, nameof(SpecialisedEvents.UnvalidatedUpdateTick), InstructionHandleResult.DetectedUnvalidatedUpdateTick); +#endif - /**** - ** detect code which may impact game stability - ****/ - new TypeFinder("Harmony.HarmonyInstance", InstructionHandleResult.DetectedGamePatch), - new TypeFinder("System.Runtime.CompilerServices.CallSite", InstructionHandleResult.DetectedDynamic), - new FieldFinder(typeof(SaveGame).FullName, nameof(SaveGame.serializer), InstructionHandleResult.DetectedSaveSerialiser), - new FieldFinder(typeof(SaveGame).FullName, nameof(SaveGame.farmerSerializer), InstructionHandleResult.DetectedSaveSerialiser), - new FieldFinder(typeof(SaveGame).FullName, nameof(SaveGame.locationSerializer), InstructionHandleResult.DetectedSaveSerialiser), - new EventFinder(typeof(SpecialisedEvents).FullName, nameof(SpecialisedEvents.UnvalidatedUpdateTick), InstructionHandleResult.DetectedUnvalidatedUpdateTick), - - /**** - ** detect paranoid issues - ****/ + /**** + ** detect paranoid issues + ****/ + if (paranoidMode) + { // filesystem access - new TypeFinder(typeof(System.IO.File).FullName, InstructionHandleResult.DetectedFilesystemAccess), - new TypeFinder(typeof(System.IO.FileStream).FullName, InstructionHandleResult.DetectedFilesystemAccess), - new TypeFinder(typeof(System.IO.FileInfo).FullName, InstructionHandleResult.DetectedFilesystemAccess), - new TypeFinder(typeof(System.IO.Directory).FullName, InstructionHandleResult.DetectedFilesystemAccess), - new TypeFinder(typeof(System.IO.DirectoryInfo).FullName, InstructionHandleResult.DetectedFilesystemAccess), - new TypeFinder(typeof(System.IO.DriveInfo).FullName, InstructionHandleResult.DetectedFilesystemAccess), - new TypeFinder(typeof(System.IO.FileSystemWatcher).FullName, InstructionHandleResult.DetectedFilesystemAccess), + yield return new TypeFinder(typeof(System.IO.File).FullName, InstructionHandleResult.DetectedFilesystemAccess); + yield return new TypeFinder(typeof(System.IO.FileStream).FullName, InstructionHandleResult.DetectedFilesystemAccess); + yield return new TypeFinder(typeof(System.IO.FileInfo).FullName, InstructionHandleResult.DetectedFilesystemAccess); + yield return new TypeFinder(typeof(System.IO.Directory).FullName, InstructionHandleResult.DetectedFilesystemAccess); + yield return new TypeFinder(typeof(System.IO.DirectoryInfo).FullName, InstructionHandleResult.DetectedFilesystemAccess); + yield return new TypeFinder(typeof(System.IO.DriveInfo).FullName, InstructionHandleResult.DetectedFilesystemAccess); + yield return new TypeFinder(typeof(System.IO.FileSystemWatcher).FullName, InstructionHandleResult.DetectedFilesystemAccess); // shell access - new TypeFinder(typeof(System.Diagnostics.Process).FullName, InstructionHandleResult.DetectedShellAccess) - }; + yield return new TypeFinder(typeof(System.Diagnostics.Process).FullName, InstructionHandleResult.DetectedShellAccess); + } } } } |