diff options
| author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2020-08-25 22:49:00 -0400 | 
|---|---|---|
| committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2020-08-25 22:49:00 -0400 | 
| commit | abfe40bf691e4d384d444bf6f001de8d959b12bb (patch) | |
| tree | 2de21299dc48ac438a69f4486ce8ef812e208f2b /src/SMAPI | |
| parent | b9a9fe36bbaa1357b98a117400a62fecc0fc56cb (diff) | |
| download | SMAPI-abfe40bf691e4d384d444bf6f001de8d959b12bb.tar.gz SMAPI-abfe40bf691e4d384d444bf6f001de8d959b12bb.tar.bz2 SMAPI-abfe40bf691e4d384d444bf6f001de8d959b12bb.zip | |
fix some method references only partially rewritten
Thanks to Bepis on Discord for helping find the issue!
Diffstat (limited to 'src/SMAPI')
| -rw-r--r-- | src/SMAPI/Framework/ModLoading/Rewriters/MethodWithMissingOptionalParameterRewriter.cs | 28 | 
1 files changed, 8 insertions, 20 deletions
| diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/MethodWithMissingOptionalParameterRewriter.cs b/src/SMAPI/Framework/ModLoading/Rewriters/MethodWithMissingOptionalParameterRewriter.cs index 75182890..87ccf941 100644 --- a/src/SMAPI/Framework/ModLoading/Rewriters/MethodWithMissingOptionalParameterRewriter.cs +++ b/src/SMAPI/Framework/ModLoading/Rewriters/MethodWithMissingOptionalParameterRewriter.cs @@ -68,29 +68,17 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters              if (method == null)                  return false; -            // get instructions to inject -            var injectables = method.Parameters.Skip(methodRef.Parameters.Count) -                .Select(p => new { Parameter = p, LoadValueInstruction = this.GetLoadValueInstruction(p.Constant) }) +            // get instructions to inject parameter values +            var loadInstructions = method.Parameters.Skip(methodRef.Parameters.Count) +                .Select(p => this.GetLoadValueInstruction(p.Constant))                  .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 -            // inject new parameters -            foreach (var entry in injectables) -            { -                // load value onto stack -                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); -            } +            // rewrite method reference +            foreach (Instruction loadInstruction in loadInstructions) +                cil.InsertBefore(instruction, loadInstruction); +            instruction.Operand = module.ImportReference(method);              this.Phrases.Add($"{methodRef.DeclaringType.Name}.{methodRef.Name} (added missing optional parameters)");              return this.MarkRewritten(); | 
