summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/StardewModdingAPI.AssemblyRewriters/Framework/BaseFieldFinder.cs7
-rw-r--r--src/StardewModdingAPI.AssemblyRewriters/Framework/BaseMethodFinder.cs7
-rw-r--r--src/StardewModdingAPI.AssemblyRewriters/IInstructionFinder.cs10
-rw-r--r--src/StardewModdingAPI.AssemblyRewriters/IInstructionRewriter.cs3
-rw-r--r--src/StardewModdingAPI.AssemblyRewriters/Rewriters/Crossplatform/SpriteBatch_MethodRewriter.cs7
-rw-r--r--src/StardewModdingAPI.AssemblyRewriters/Rewriters/SDV1_2/Game1_ActiveClickableMenu_FieldRewriter.cs7
-rw-r--r--src/StardewModdingAPI.AssemblyRewriters/Rewriters/SDV1_2/Game1_GameMode_FieldRewriter.cs7
-rw-r--r--src/StardewModdingAPI.AssemblyRewriters/Rewriters/SDV1_2/Game1_Player_FieldRewriter.cs7
-rw-r--r--src/StardewModdingAPI/Framework/AssemblyLoader.cs26
9 files changed, 77 insertions, 4 deletions
diff --git a/src/StardewModdingAPI.AssemblyRewriters/Framework/BaseFieldFinder.cs b/src/StardewModdingAPI.AssemblyRewriters/Framework/BaseFieldFinder.cs
index 96e8b1c0..f2074f22 100644
--- a/src/StardewModdingAPI.AssemblyRewriters/Framework/BaseFieldFinder.cs
+++ b/src/StardewModdingAPI.AssemblyRewriters/Framework/BaseFieldFinder.cs
@@ -7,6 +7,13 @@ namespace StardewModdingAPI.AssemblyRewriters.Framework
public abstract class BaseFieldFinder : IInstructionFinder
{
/*********
+ ** Accessors
+ *********/
+ /// <summary>A brief noun phrase indicating what the instruction finder matches.</summary>
+ public abstract string NounPhrase { get; }
+
+
+ /*********
** Public methods
*********/
/// <summary>Get whether a CIL instruction matches.</summary>
diff --git a/src/StardewModdingAPI.AssemblyRewriters/Framework/BaseMethodFinder.cs b/src/StardewModdingAPI.AssemblyRewriters/Framework/BaseMethodFinder.cs
index 7526286a..bb71a9d7 100644
--- a/src/StardewModdingAPI.AssemblyRewriters/Framework/BaseMethodFinder.cs
+++ b/src/StardewModdingAPI.AssemblyRewriters/Framework/BaseMethodFinder.cs
@@ -10,6 +10,13 @@ namespace StardewModdingAPI.AssemblyRewriters.Framework
public abstract class BaseMethodFinder : IInstructionFinder
{
/*********
+ ** Accessors
+ *********/
+ /// <summary>A brief noun phrase indicating what the instruction finder matches.</summary>
+ public abstract string NounPhrase { get; }
+
+
+ /*********
** Public methods
*********/
/// <summary>Get whether a CIL instruction matches.</summary>
diff --git a/src/StardewModdingAPI.AssemblyRewriters/IInstructionFinder.cs b/src/StardewModdingAPI.AssemblyRewriters/IInstructionFinder.cs
index 47a4247b..cc3006b9 100644
--- a/src/StardewModdingAPI.AssemblyRewriters/IInstructionFinder.cs
+++ b/src/StardewModdingAPI.AssemblyRewriters/IInstructionFinder.cs
@@ -5,6 +5,16 @@ namespace StardewModdingAPI.AssemblyRewriters
/// <summary>Finds CIL instructions considered incompatible.</summary>
public interface IInstructionFinder
{
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>A brief noun phrase indicating what the instruction finder matches.</summary>
+ string NounPhrase { get; }
+
+
+ /*********
+ ** Methods
+ *********/
/// <summary>Get whether a CIL instruction matches.</summary>
/// <param name="instruction">The IL instruction.</param>
/// <param name="platformChanged">Whether the mod was compiled on a different platform.</param>
diff --git a/src/StardewModdingAPI.AssemblyRewriters/IInstructionRewriter.cs b/src/StardewModdingAPI.AssemblyRewriters/IInstructionRewriter.cs
index f99a0a5a..b230f227 100644
--- a/src/StardewModdingAPI.AssemblyRewriters/IInstructionRewriter.cs
+++ b/src/StardewModdingAPI.AssemblyRewriters/IInstructionRewriter.cs
@@ -6,6 +6,9 @@ namespace StardewModdingAPI.AssemblyRewriters
/// <summary>Rewrites a CIL instruction for compatibility.</summary>
public interface IInstructionRewriter : IInstructionFinder
{
+ /*********
+ ** Methods
+ *********/
/// <summary>Rewrite a CIL instruction for compatibility.</summary>
/// <param name="module">The module being rewritten.</param>
/// <param name="cil">The CIL rewriter.</param>
diff --git a/src/StardewModdingAPI.AssemblyRewriters/Rewriters/Crossplatform/SpriteBatch_MethodRewriter.cs b/src/StardewModdingAPI.AssemblyRewriters/Rewriters/Crossplatform/SpriteBatch_MethodRewriter.cs
index a47b8410..1459ff17 100644
--- a/src/StardewModdingAPI.AssemblyRewriters/Rewriters/Crossplatform/SpriteBatch_MethodRewriter.cs
+++ b/src/StardewModdingAPI.AssemblyRewriters/Rewriters/Crossplatform/SpriteBatch_MethodRewriter.cs
@@ -13,6 +13,13 @@ namespace StardewModdingAPI.AssemblyRewriters.Rewriters.Crossplatform
public class SpriteBatch_MethodRewriter : BaseMethodRewriter
{
/*********
+ ** Accessors
+ *********/
+ /// <summary>A brief noun phrase indicating what the instruction finder matches.</summary>
+ public override string NounPhrase { get; } = $"{nameof(SpriteBatch)} methods";
+
+
+ /*********
** Protected methods
*********/
/// <summary>Get whether a method reference should be rewritten.</summary>
diff --git a/src/StardewModdingAPI.AssemblyRewriters/Rewriters/SDV1_2/Game1_ActiveClickableMenu_FieldRewriter.cs b/src/StardewModdingAPI.AssemblyRewriters/Rewriters/SDV1_2/Game1_ActiveClickableMenu_FieldRewriter.cs
index 66fe0369..bb49f16c 100644
--- a/src/StardewModdingAPI.AssemblyRewriters/Rewriters/SDV1_2/Game1_ActiveClickableMenu_FieldRewriter.cs
+++ b/src/StardewModdingAPI.AssemblyRewriters/Rewriters/SDV1_2/Game1_ActiveClickableMenu_FieldRewriter.cs
@@ -12,6 +12,13 @@ namespace StardewModdingAPI.AssemblyRewriters.Rewriters.SDV1_2
public class Game1_ActiveClickableMenu_FieldRewriter : BaseFieldRewriter
{
/*********
+ ** Accessors
+ *********/
+ /// <summary>A brief noun phrase indicating what the instruction finder matches.</summary>
+ public override string NounPhrase { get; } = $"{nameof(Game1)}.{nameof(Game1.activeClickableMenu)} field";
+
+
+ /*********
** Protected methods
*********/
/// <summary>Get whether a field reference should be rewritten.</summary>
diff --git a/src/StardewModdingAPI.AssemblyRewriters/Rewriters/SDV1_2/Game1_GameMode_FieldRewriter.cs b/src/StardewModdingAPI.AssemblyRewriters/Rewriters/SDV1_2/Game1_GameMode_FieldRewriter.cs
index 9cb6e13d..4d84d9ac 100644
--- a/src/StardewModdingAPI.AssemblyRewriters/Rewriters/SDV1_2/Game1_GameMode_FieldRewriter.cs
+++ b/src/StardewModdingAPI.AssemblyRewriters/Rewriters/SDV1_2/Game1_GameMode_FieldRewriter.cs
@@ -12,6 +12,13 @@ namespace StardewModdingAPI.AssemblyRewriters.Rewriters.SDV1_2
public class Game1_GameMode_FieldRewriter : BaseFieldRewriter
{
/*********
+ ** Accessors
+ *********/
+ /// <summary>A brief noun phrase indicating what the instruction finder matches.</summary>
+ public override string NounPhrase { get; } = $"{nameof(Game1)}.{nameof(Game1.gameMode)} field";
+
+
+ /*********
** Protected methods
*********/
/// <summary>Get whether a field reference should be rewritten.</summary>
diff --git a/src/StardewModdingAPI.AssemblyRewriters/Rewriters/SDV1_2/Game1_Player_FieldRewriter.cs b/src/StardewModdingAPI.AssemblyRewriters/Rewriters/SDV1_2/Game1_Player_FieldRewriter.cs
index 115e3d7d..f43f5d57 100644
--- a/src/StardewModdingAPI.AssemblyRewriters/Rewriters/SDV1_2/Game1_Player_FieldRewriter.cs
+++ b/src/StardewModdingAPI.AssemblyRewriters/Rewriters/SDV1_2/Game1_Player_FieldRewriter.cs
@@ -12,6 +12,13 @@ namespace StardewModdingAPI.AssemblyRewriters.Rewriters.SDV1_2
public class Game1_Player_FieldRewriter : BaseFieldRewriter
{
/*********
+ ** Accessors
+ *********/
+ /// <summary>A brief noun phrase indicating what the instruction finder matches.</summary>
+ public override string NounPhrase { get; } = $"{nameof(Game1)}.{nameof(Game1.player)} field";
+
+
+ /*********
** Protected methods
*********/
/// <summary>Get whether a field reference should be rewritten.</summary>
diff --git a/src/StardewModdingAPI/Framework/AssemblyLoader.cs b/src/StardewModdingAPI/Framework/AssemblyLoader.cs
index eb5d1cf4..8af67772 100644
--- a/src/StardewModdingAPI/Framework/AssemblyLoader.cs
+++ b/src/StardewModdingAPI/Framework/AssemblyLoader.cs
@@ -162,6 +162,7 @@ namespace StardewModdingAPI.Framework
private bool RewriteAssembly(AssemblyDefinition assembly)
{
ModuleDefinition module = assembly.MainModule;
+ HashSet<string> loggedRewrites = new HashSet<string>();
// swap assembly references if needed (e.g. XNA => MonoGame)
bool platformChanged = false;
@@ -170,6 +171,7 @@ namespace StardewModdingAPI.Framework
// remove old assembly reference
if (this.AssemblyMap.RemoveNames.Any(name => module.AssemblyReferences[i].Name == name))
{
+ this.LogOnce(this.Monitor, loggedRewrites, $"Rewriting {assembly.Name.Name} for OS...");
platformChanged = true;
module.AssemblyReferences.RemoveAt(i);
i--;
@@ -197,14 +199,16 @@ namespace StardewModdingAPI.Framework
if (!canRewrite)
continue;
- // prepare method
- ILProcessor cil = method.Body.GetILProcessor();
-
// rewrite instructions
+ ILProcessor cil = method.Body.GetILProcessor();
foreach (Instruction op in cil.Body.Instructions.ToArray())
{
IInstructionRewriter rewriter = rewriters.FirstOrDefault(p => p.IsMatch(op, platformChanged));
- rewriter?.Rewrite(module, cil, op, this.AssemblyMap);
+ if (rewriter != null)
+ {
+ this.LogOnce(this.Monitor, loggedRewrites, $"Rewriting {assembly.Name.Name} to fix {rewriter.NounPhrase}...");
+ rewriter.Rewrite(module, cil, op, this.AssemblyMap);
+ }
}
// finalise method
@@ -244,5 +248,19 @@ namespace StardewModdingAPI.Framework
select method
);
}
+
+ /// <summary>Log a message for the player or developer the first time it occurs.</summary>
+ /// <param name="monitor">The monitor through which to log the message.</param>
+ /// <param name="hash">The hash of logged messages.</param>
+ /// <param name="message">The message to log.</param>
+ /// <param name="level">The log severity level.</param>
+ private void LogOnce(IMonitor monitor, HashSet<string> hash, string message, LogLevel level = LogLevel.Trace)
+ {
+ if (!hash.Contains(message))
+ {
+ this.Monitor.Log(message, level);
+ hash.Add(message);
+ }
+ }
}
}