Skip to content

Commit aaf9b4d

Browse files
committed
Update to latest Oxide.References (Mono.Cecil update)
1 parent 8c599ee commit aaf9b4d

2 files changed

Lines changed: 22 additions & 22 deletions

File tree

src/DirectCallMethod.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,22 @@ public DirectCallMethod(ModuleDefinition module, TypeDefinition type, ReaderPara
4545
this.module = module;
4646
this.type = type;
4747

48-
getLength = module.Import(typeof(string).GetMethod("get_Length", new Type[0]));
49-
getChars = module.Import(typeof(string).GetMethod("get_Chars", new[] { typeof(int) }));
50-
isNullOrEmpty = module.Import(typeof(string).GetMethod("IsNullOrEmpty", new[] { typeof(string) }));
51-
stringEquals = module.Import(typeof(string).GetMethod("Equals", new[] { typeof(string) }));
48+
getLength = module.ImportReference(typeof(string).GetMethod("get_Length", new Type[0]));
49+
getChars = module.ImportReference(typeof(string).GetMethod("get_Chars", new[] { typeof(int) }));
50+
isNullOrEmpty = module.ImportReference(typeof(string).GetMethod("IsNullOrEmpty", new[] { typeof(string) }));
51+
stringEquals = module.ImportReference(typeof(string).GetMethod("Equals", new[] { typeof(string) }));
5252

5353
// Copy method definition from base class
5454
AssemblyDefinition base_assembly = AssemblyDefinition.ReadAssembly(Path.Combine(Interface.Oxide.ExtensionDirectory, "Oxide.CSharp.dll"), readerParameters);
5555
ModuleDefinition base_module = base_assembly.MainModule;
56-
TypeDefinition base_type = module.Import(base_assembly.MainModule.GetType("Oxide.Plugins.CSharpPlugin")).Resolve();
57-
MethodDefinition base_method = module.Import(base_type.Methods.First(method => method.Name == "DirectCallHook")).Resolve();
56+
TypeDefinition base_type = module.ImportReference(base_assembly.MainModule.GetType("Oxide.Plugins.CSharpPlugin")).Resolve();
57+
MethodDefinition base_method = module.ImportReference(base_type.Methods.First(method => method.Name == "DirectCallHook")).Resolve();
5858

5959
// Create method override based on virtual method signature
60-
method = new MethodDefinition(base_method.Name, base_method.Attributes, base_module.Import(base_method.ReturnType)) { DeclaringType = type };
60+
method = new MethodDefinition(base_method.Name, base_method.Attributes, base_module.ImportReference(base_method.ReturnType)) { DeclaringType = type };
6161
foreach (ParameterDefinition parameter in base_method.Parameters)
6262
{
63-
ParameterDefinition new_param = new ParameterDefinition(parameter.Name, parameter.Attributes, module.Import(parameter.ParameterType))
63+
ParameterDefinition new_param = new ParameterDefinition(parameter.Name, parameter.Attributes, module.ImportReference(parameter.ParameterType))
6464
{
6565
IsOut = parameter.IsOut,
6666
Constant = parameter.Constant,
@@ -69,15 +69,15 @@ public DirectCallMethod(ModuleDefinition module, TypeDefinition type, ReaderPara
6969
};
7070
foreach (CustomAttribute attribute in parameter.CustomAttributes)
7171
{
72-
new_param.CustomAttributes.Add(new CustomAttribute(module.Import(attribute.Constructor)));
72+
new_param.CustomAttributes.Add(new CustomAttribute(module.ImportReference(attribute.Constructor)));
7373
}
7474

7575
method.Parameters.Add(new_param);
7676
}
7777

7878
foreach (CustomAttribute attribute in base_method.CustomAttributes)
7979
{
80-
method.CustomAttributes.Add(new CustomAttribute(module.Import(attribute.Constructor)));
80+
method.CustomAttributes.Add(new CustomAttribute(module.ImportReference(attribute.Constructor)));
8181
}
8282

8383
method.ImplAttributes = base_method.ImplAttributes;
@@ -94,8 +94,8 @@ public DirectCallMethod(ModuleDefinition module, TypeDefinition type, ReaderPara
9494
type.Methods.Add(method);
9595

9696
// Create variables
97-
body.Variables.Add(new VariableDefinition("name_size", module.TypeSystem.Int32));
98-
body.Variables.Add(new VariableDefinition("i", module.TypeSystem.Int32));
97+
body.Variables.Add(new VariableDefinition(module.TypeSystem.Int32));
98+
body.Variables.Add(new VariableDefinition(module.TypeSystem.Int32));
9999

100100
// Initialize return value to null
101101
AddInstruction(OpCodes.Ldarg_2);
@@ -298,11 +298,11 @@ private void CallMethod(MethodDefinition method)
298298
ByReferenceType param = parameter.ParameterType as ByReferenceType;
299299
if (param != null)
300300
{
301-
VariableDefinition refParam = AddVariable(module.Import(param.ElementType));
301+
VariableDefinition refParam = AddVariable(module.ImportReference(param.ElementType));
302302
AddInstruction(OpCodes.Ldarg_3); // object[] params
303303
AddInstruction(Ldc_I4_n(i)); // param_number
304304
AddInstruction(OpCodes.Ldelem_Ref);
305-
AddInstruction(OpCodes.Unbox_Any, module.Import(param.ElementType));
305+
AddInstruction(OpCodes.Unbox_Any, module.ImportReference(param.ElementType));
306306
AddInstruction(OpCodes.Stloc_S, refParam);
307307
paramDict[parameter] = refParam;
308308
}
@@ -328,10 +328,10 @@ private void CallMethod(MethodDefinition method)
328328
AddInstruction(OpCodes.Ldarg_3); // object[] params
329329
AddInstruction(Ldc_I4_n(i)); // param_number
330330
AddInstruction(OpCodes.Ldelem_Ref);
331-
AddInstruction(OpCodes.Unbox_Any, module.Import(parameter.ParameterType));
331+
AddInstruction(OpCodes.Unbox_Any, module.ImportReference(parameter.ParameterType));
332332
}
333333
}
334-
AddInstruction(OpCodes.Call, module.Import(method));
334+
AddInstruction(OpCodes.Call, module.ImportReference(method));
335335

336336
//handle ref/out params
337337
for (int i = 0; i < method.Parameters.Count; i++)
@@ -343,7 +343,7 @@ private void CallMethod(MethodDefinition method)
343343
AddInstruction(OpCodes.Ldarg_3); // object[] params
344344
AddInstruction(Ldc_I4_n(i)); // param_number
345345
AddInstruction(OpCodes.Ldloc_S, paramDict[parameter]);
346-
AddInstruction(OpCodes.Box, module.Import(param.ElementType));
346+
AddInstruction(OpCodes.Box, module.ImportReference(param.ElementType));
347347
AddInstruction(OpCodes.Stelem_Ref);
348348
}
349349
}
@@ -352,7 +352,7 @@ private void CallMethod(MethodDefinition method)
352352
{
353353
if (method.ReturnType.Name != "Object")
354354
{
355-
AddInstruction(OpCodes.Box, module.Import(method.ReturnType));
355+
AddInstruction(OpCodes.Box, module.ImportReference(method.ReturnType));
356356
}
357357

358358
AddInstruction(OpCodes.Stind_Ref);
@@ -413,9 +413,9 @@ private Instruction AddInstruction(Instruction instruction)
413413
return instruction;
414414
}
415415

416-
public VariableDefinition AddVariable(TypeReference typeRef, string name = "")
416+
public VariableDefinition AddVariable(TypeReference typeRef)
417417
{
418-
VariableDefinition def = new VariableDefinition(name, typeRef);
418+
VariableDefinition def = new VariableDefinition(typeRef);
419419
body.Variables.Add(def);
420420
return def;
421421
}

src/Oxide.CSharp.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
</PropertyGroup>
1919
<ItemGroup>
2020
<PackageReference Include="Oxide.Core" Version="2.0.*" />
21-
<PackageReference Include="Oxide.Common" Version="2.0.*" />
22-
<PackageReference Include="Oxide.References" Version="2.0.*">
21+
<PackageReference Include="Oxide.Common" Version="2.0.40-develop" />
22+
<PackageReference Include="Oxide.References" Version="2.0.3801-develop">
2323
<PrivateAssets>contentfiles;analyzers;build</PrivateAssets>
2424
</PackageReference>
2525
<None Include="..\resources\icon.png" Pack="true" PackagePath="\" />

0 commit comments

Comments
 (0)