fix some method references only partially rewritten
Thanks to Bepis on Discord for helping find the issue!
This commit is contained in:
parent
b9a9fe36bb
commit
abfe40bf69
|
@ -68,29 +68,17 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters
|
||||||
if (method == null)
|
if (method == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// get instructions to inject
|
// get instructions to inject parameter values
|
||||||
var injectables = method.Parameters.Skip(methodRef.Parameters.Count)
|
var loadInstructions = method.Parameters.Skip(methodRef.Parameters.Count)
|
||||||
.Select(p => new { Parameter = p, LoadValueInstruction = this.GetLoadValueInstruction(p.Constant) })
|
.Select(p => this.GetLoadValueInstruction(p.Constant))
|
||||||
.ToArray();
|
.ToArray();
|
||||||
if (injectables.Any(p => p.LoadValueInstruction == null))
|
if (loadInstructions.Any(p => p == null))
|
||||||
return false; // SMAPI needs to load the value onto the stack before the method call, but the optional parameter type wasn't recognized
|
return false; // SMAPI needs to load the value onto the stack before the method call, but the optional parameter type wasn't recognized
|
||||||
|
|
||||||
// inject new parameters
|
// rewrite method reference
|
||||||
foreach (var entry in injectables)
|
foreach (Instruction loadInstruction in loadInstructions)
|
||||||
{
|
cil.InsertBefore(instruction, loadInstruction);
|
||||||
// load value onto stack
|
instruction.Operand = module.ImportReference(method);
|
||||||
cil.InsertBefore(instruction, entry.LoadValueInstruction);
|
|
||||||
|
|
||||||
// add parameter
|
|
||||||
ParameterDefinition parameter = entry.Parameter;
|
|
||||||
var newParameter = new ParameterDefinition(
|
|
||||||
name: parameter.Name,
|
|
||||||
attributes: parameter.Attributes,
|
|
||||||
parameterType: module.ImportReference(parameter.ParameterType)
|
|
||||||
);
|
|
||||||
newParameter.Constant = parameter.Constant;
|
|
||||||
methodRef.Parameters.Add(newParameter);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Phrases.Add($"{methodRef.DeclaringType.Name}.{methodRef.Name} (added missing optional parameters)");
|
this.Phrases.Add($"{methodRef.DeclaringType.Name}.{methodRef.Name} (added missing optional parameters)");
|
||||||
return this.MarkRewritten();
|
return this.MarkRewritten();
|
||||||
|
|
Loading…
Reference in New Issue