From 771263299cae11d464c25c5291e59507c639e822 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 3 Jul 2017 01:03:13 -0400 Subject: add SMAPI 2.0 compile mode --- .../Finders/PropertyFinder.cs | 83 ++++++++++++++++++++++ .../StardewModdingAPI.AssemblyRewriters.csproj | 1 + 2 files changed, 84 insertions(+) create mode 100644 src/StardewModdingAPI.AssemblyRewriters/Finders/PropertyFinder.cs (limited to 'src/StardewModdingAPI.AssemblyRewriters') diff --git a/src/StardewModdingAPI.AssemblyRewriters/Finders/PropertyFinder.cs b/src/StardewModdingAPI.AssemblyRewriters/Finders/PropertyFinder.cs new file mode 100644 index 00000000..441f15f2 --- /dev/null +++ b/src/StardewModdingAPI.AssemblyRewriters/Finders/PropertyFinder.cs @@ -0,0 +1,83 @@ +using Mono.Cecil; +using Mono.Cecil.Cil; + +namespace StardewModdingAPI.AssemblyRewriters.Finders +{ + /// Finds incompatible CIL instructions that reference a given property and throws an . + public class PropertyFinder : IInstructionRewriter + { + /********* + ** Properties + *********/ + /// The full type name for which to find references. + private readonly string FullTypeName; + + /// The property name for which to find references. + private readonly string PropertyName; + + + /********* + ** Accessors + *********/ + /// A brief noun phrase indicating what the instruction finder matches. + public string NounPhrase { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The full type name for which to find references. + /// The property name for which to find references. + /// A brief noun phrase indicating what the instruction finder matches (or null to generate one). + public PropertyFinder(string fullTypeName, string propertyName, string nounPhrase = null) + { + this.FullTypeName = fullTypeName; + this.PropertyName = propertyName; + this.NounPhrase = nounPhrase ?? $"{fullTypeName}.{propertyName} property"; + } + + /// Rewrite a method definition for compatibility. + /// The module being rewritten. + /// The method definition to rewrite. + /// Metadata for mapping assemblies to the current platform. + /// Whether the mod was compiled on a different platform. + /// Returns whether the instruction was rewritten. + /// The CIL instruction is not compatible, and can't be rewritten. + public virtual bool Rewrite(ModuleDefinition module, MethodDefinition method, PlatformAssemblyMap assemblyMap, bool platformChanged) + { + return false; + } + + /// Rewrite a CIL instruction for compatibility. + /// The module being rewritten. + /// The CIL rewriter. + /// The instruction to rewrite. + /// Metadata for mapping assemblies to the current platform. + /// Whether the mod was compiled on a different platform. + /// Returns whether the instruction was rewritten. + /// The CIL instruction is not compatible, and can't be rewritten. + public virtual bool Rewrite(ModuleDefinition module, ILProcessor cil, Instruction instruction, PlatformAssemblyMap assemblyMap, bool platformChanged) + { + if (!this.IsMatch(instruction)) + return false; + + throw new IncompatibleInstructionException(this.NounPhrase); + } + + + /********* + ** Protected methods + *********/ + /// Get whether a CIL instruction matches. + /// The IL instruction. + protected bool IsMatch(Instruction instruction) + { + MethodReference methodRef = RewriteHelper.AsMethodReference(instruction); + return + methodRef != null + && methodRef.DeclaringType.FullName == this.FullTypeName + && (methodRef.Name == "get_" + this.PropertyName || methodRef.Name == "set_" + this.PropertyName); + } + } +} diff --git a/src/StardewModdingAPI.AssemblyRewriters/StardewModdingAPI.AssemblyRewriters.csproj b/src/StardewModdingAPI.AssemblyRewriters/StardewModdingAPI.AssemblyRewriters.csproj index e25b201e..7a12a8e9 100644 --- a/src/StardewModdingAPI.AssemblyRewriters/StardewModdingAPI.AssemblyRewriters.csproj +++ b/src/StardewModdingAPI.AssemblyRewriters/StardewModdingAPI.AssemblyRewriters.csproj @@ -49,6 +49,7 @@ Properties\GlobalAssemblyInfo.cs + -- cgit From 7e856106b89755e7e5f8f90cafe827c50eb62e39 Mon Sep 17 00:00:00 2001 From: spacechase0 Date: Fri, 7 Jul 2017 15:12:15 -0400 Subject: Tweak debug deploy to respect stardewvalley.targets --- .../StardewModdingAPI.AssemblyRewriters.csproj | 2 ++ src/StardewModdingAPI/StardewModdingAPI.csproj | 2 ++ src/TrainerMod/TrainerMod.csproj | 2 ++ 3 files changed, 6 insertions(+) (limited to 'src/StardewModdingAPI.AssemblyRewriters') diff --git a/src/StardewModdingAPI.AssemblyRewriters/StardewModdingAPI.AssemblyRewriters.csproj b/src/StardewModdingAPI.AssemblyRewriters/StardewModdingAPI.AssemblyRewriters.csproj index 7a12a8e9..b8515511 100644 --- a/src/StardewModdingAPI.AssemblyRewriters/StardewModdingAPI.AssemblyRewriters.csproj +++ b/src/StardewModdingAPI.AssemblyRewriters/StardewModdingAPI.AssemblyRewriters.csproj @@ -68,6 +68,8 @@ + + \ No newline at end of file diff --git a/src/StardewModdingAPI/StardewModdingAPI.csproj b/src/StardewModdingAPI/StardewModdingAPI.csproj index 03f810d1..33dd81b5 100644 --- a/src/StardewModdingAPI/StardewModdingAPI.csproj +++ b/src/StardewModdingAPI/StardewModdingAPI.csproj @@ -256,6 +256,8 @@ StardewModdingAPI.AssemblyRewriters + + diff --git a/src/TrainerMod/TrainerMod.csproj b/src/TrainerMod/TrainerMod.csproj index 99a15c8f..48cd429e 100644 --- a/src/TrainerMod/TrainerMod.csproj +++ b/src/TrainerMod/TrainerMod.csproj @@ -99,6 +99,8 @@ + + -- cgit From e61f060b965150a0dccfd032871fe905097881fd Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 7 Jul 2017 16:58:55 -0400 Subject: simplify stardewvalley.targets support, add to release notes (#319) --- release-notes.md | 1 + .../StardewModdingAPI.AssemblyRewriters.csproj | 2 -- src/StardewModdingAPI/StardewModdingAPI.csproj | 2 -- src/TrainerMod/TrainerMod.csproj | 2 -- src/crossplatform.targets | 2 ++ 5 files changed, 3 insertions(+), 6 deletions(-) (limited to 'src/StardewModdingAPI.AssemblyRewriters') diff --git a/release-notes.md b/release-notes.md index 5513d36a..6fac3b73 100644 --- a/release-notes.md +++ b/release-notes.md @@ -47,6 +47,7 @@ For SMAPI developers: * Added SMAPI 2.0 compile mode, for testing how mods will work with SMAPI 2.0. * Added prototype SMAPI 2.0 feature to override XNB files (not enabled for mods yet). * Added prototype SMAPI 2.0 support for version strings in `manifest.json` (not recommended for mods yet). +* Compiling SMAPI now uses your `~/stardewvalley.targets` file if present. ## 1.14 See [log](https://github.com/Pathoschild/SMAPI/compare/1.13...1.14). diff --git a/src/StardewModdingAPI.AssemblyRewriters/StardewModdingAPI.AssemblyRewriters.csproj b/src/StardewModdingAPI.AssemblyRewriters/StardewModdingAPI.AssemblyRewriters.csproj index b8515511..7a12a8e9 100644 --- a/src/StardewModdingAPI.AssemblyRewriters/StardewModdingAPI.AssemblyRewriters.csproj +++ b/src/StardewModdingAPI.AssemblyRewriters/StardewModdingAPI.AssemblyRewriters.csproj @@ -68,8 +68,6 @@ - - \ No newline at end of file diff --git a/src/StardewModdingAPI/StardewModdingAPI.csproj b/src/StardewModdingAPI/StardewModdingAPI.csproj index 33dd81b5..03f810d1 100644 --- a/src/StardewModdingAPI/StardewModdingAPI.csproj +++ b/src/StardewModdingAPI/StardewModdingAPI.csproj @@ -256,8 +256,6 @@ StardewModdingAPI.AssemblyRewriters - - diff --git a/src/TrainerMod/TrainerMod.csproj b/src/TrainerMod/TrainerMod.csproj index 48cd429e..99a15c8f 100644 --- a/src/TrainerMod/TrainerMod.csproj +++ b/src/TrainerMod/TrainerMod.csproj @@ -99,8 +99,6 @@ - - diff --git a/src/crossplatform.targets b/src/crossplatform.targets index 31d4722d..929aac6c 100644 --- a/src/crossplatform.targets +++ b/src/crossplatform.targets @@ -1,4 +1,6 @@ + + $(HOME)/GOG Games/Stardew Valley/game -- cgit