fix: using mathematics in commands and rpcs (#2425)

Generating readers and writers for structs in other assemblies
could sometimes cause a
```
System.ArgumentException: Member 'xxx' is declared in another module and needs to be imported
```
This in particular affected unity mathematics.

fixes #2406
This commit is contained in:
Paul Pacheco 2020-11-14 10:25:48 -06:00 committed by GitHub
parent 59ed64f9d0
commit 037ac55937
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View File

@ -269,8 +269,8 @@ static void ReadAllFields(TypeReference variable, ILProcessor worker)
// mismatched ldloca/ldloc for struct/class combinations is invalid IL, which causes crash at runtime
OpCode opcode = variable.IsValueType ? OpCodes.Ldloca : OpCodes.Ldloc;
worker.Append(worker.Create(opcode, 0));
MethodReference readFunc = GetReadFunc(field.FieldType);
TypeReference fieldTypeRef = Weaver.CurrentAssembly.MainModule.ImportReference(field.FieldType);
MethodReference readFunc = GetReadFunc(fieldTypeRef);
if (readFunc != null)
{
worker.Append(worker.Create(OpCodes.Ldarg_0));

View File

@ -218,7 +218,8 @@ static bool WriteAllFields(TypeReference variable, ILProcessor worker)
uint fields = 0;
foreach (FieldDefinition field in variable.FindAllPublicFields())
{
MethodReference writeFunc = GetWriteFunc(field.FieldType);
TypeReference fieldTypeRef = Weaver.CurrentAssembly.MainModule.ImportReference(field.FieldType);
MethodReference writeFunc = GetWriteFunc(fieldTypeRef);
// need this null check till later PR when GetWriteFunc throws exception instead
if (writeFunc == null) { return false; }