using Microsoft.Xna.Framework.Graphics;
using Mono.Cecil;
using Mono.Cecil.Cil;
using StardewModdingAPI.AssemblyRewriters.Wrappers;
namespace StardewModdingAPI.AssemblyRewriters.Rewriters
{
/// Rewrites references to to fix inconsistent method signatures between MonoGame and XNA.
/// MonoGame has one SpriteBatch.Begin method with optional arguments, but XNA has multiple method overloads. Incompatible method references are rewritten to use , which redirects all method signatures to the proper compiled MonoGame/XNA method.
public class SpriteBatchRewriter : BaseMethodRewriter
{
/// Get whether the given method reference can be rewritten.
/// The method reference.
public override bool ShouldRewrite(MethodReference methodRef)
{
return methodRef.DeclaringType.FullName == typeof(SpriteBatch).FullName && this.HasMatchingSignature(typeof(CompatibleSpriteBatch), methodRef);
}
/// Rewrite a method for compatibility.
/// The module being rewritten.
/// The CIL rewriter.
/// The instruction which calls the method.
/// The method reference invoked by the .
/// Metadata for mapping assemblies to the current platform.
public override void Rewrite(ModuleDefinition module, ILProcessor cil, Instruction callOp, MethodReference methodRef, PlatformAssemblyMap assemblyMap)
{
methodRef.DeclaringType = module.Import(typeof(CompatibleSpriteBatch));
}
}
}