Skip to content

Commit a6e2ca2

Browse files
committed
Improve relinking for callsites
1 parent a484ee7 commit a6e2ca2

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

ModFramework/Modder.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,15 @@ public void RelinkAssembly(string fromAssemblyName, ModuleDefinition? toModule =
239239
this.RelinkModuleMap[fromAssemblyName] = toModule ?? this.Module;
240240
}
241241

242+
public override IMetadataTokenProvider MainRelinker(IMetadataTokenProvider mtp, IGenericParameterProvider context)
243+
{
244+
// TODO: remove this when monomod is updated - this is missing from the utilised version.
245+
if(mtp is CallSite)
246+
return Module.ImportReference(mtp);
247+
248+
return base.MainRelinker(mtp, context);
249+
}
250+
242251
public override void Write(Stream? output = null, string? outputPath = null)
243252
{
244253
ModContext.Apply(ModType.PreWrite, this);

ModFramework/Relinker/TypeRelinker.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public override void PreWrite()
4545
bool CheckType<TRef>(TRef type, Action<TRef>? update = null)
4646
where TRef : TypeReference
4747
{
48+
if (type is null) return false;
4849
if (NoChangeCache.Contains(type)) return false;
4950

5051
if (ChangeCache.TryGetValue(type, out TypeReference? tref))
@@ -179,6 +180,16 @@ public void Relink(Instruction instr)
179180
foreach (var ins in instructions)
180181
Relink(ins);
181182
}
183+
else if (instr.Operand is CallSite callSite)
184+
{
185+
CheckType(callSite.ReturnType, nt => callSite.ReturnType = nt);
186+
187+
foreach (var prm in callSite.Parameters)
188+
{
189+
CheckType(prm.ParameterType, nt => prm.ParameterType = nt);
190+
FixAttributes(prm.CustomAttributes);
191+
}
192+
}
182193
else if (!(
183194
instr.Operand is null
184195
|| instr.Operand is Instruction

0 commit comments

Comments
 (0)