//IL2CPP can't process esp->ToObject() properly, so I can only use static function for this public static unsafe object ToObject(StackObject *esp, ILRuntime.Runtime.Enviorment.AppDomain appdomain, List <object> mStack) { switch (esp->ObjectType) { case ObjectTypes.Integer: return(esp->Value); case ObjectTypes.Long: { return(*(long *)&esp->Value); } case ObjectTypes.Float: { return(*(float *)&esp->Value); } case ObjectTypes.Double: { return(*(double *)&esp->Value); } case ObjectTypes.Object: return(mStack[esp->Value]); case ObjectTypes.FieldReference: { ILTypeInstance instance = mStack[esp->Value] as ILTypeInstance; if (instance != null) { return(instance[esp->ValueLow]); } else { var obj = mStack[esp->Value]; IType t = null; if (obj is CrossBindingAdaptorType) { t = appdomain.GetType(((CrossBindingAdaptor)((CrossBindingAdaptorType)obj).ILInstance.Type.FirstCLRBaseType).BaseCLRType); } else { t = appdomain.GetType(obj.GetType()); } var fi = ((CLRType)t).GetField(esp->ValueLow); return(fi.GetValue(obj)); } } case ObjectTypes.ArrayReference: { Array instance = mStack[esp->Value] as Array; return(instance.GetValue(esp->ValueLow)); } case ObjectTypes.StaticFieldReference: { var t = appdomain.GetType(esp->Value); if (t is CLR.TypeSystem.ILType) { CLR.TypeSystem.ILType type = (CLR.TypeSystem.ILType)t; return(type.StaticInstance[esp->ValueLow]); } else { CLR.TypeSystem.CLRType type = (CLR.TypeSystem.CLRType)t; var fi = type.GetField(esp->ValueLow); return(fi.GetValue(null)); } } case ObjectTypes.StackObjectReference: { var ptr = &esp->Value; return(ToObject((*(StackObject **)ptr), appdomain, mStack)); } case ObjectTypes.Null: return(null); default: throw new NotImplementedException(); } }
//IL2CPP can't process esp->ToObject() properly, so I can only use static function for this public static unsafe object ToObject(StackObject *esp, ILRuntime.Runtime.Enviorment.AppDomain appdomain, IList <object> mStack) { switch (esp->ObjectType) { case ObjectTypes.Integer: return(esp->Value); case ObjectTypes.Long: { return(*(long *)&esp->Value); } case ObjectTypes.Float: { return(*(float *)&esp->Value); } case ObjectTypes.Double: { return(*(double *)&esp->Value); } case ObjectTypes.Object: return(mStack[esp->Value]); case ObjectTypes.FieldReference: { ILTypeInstance instance = mStack[esp->Value] as ILTypeInstance; if (instance != null) { return(instance[esp->ValueLow]); } else { var obj = mStack[esp->Value]; IType t = null; if (obj is CrossBindingAdaptorType) { t = appdomain.GetType(((CrossBindingAdaptor)((CrossBindingAdaptorType)obj).ILInstance.Type.FirstCLRBaseType).BaseCLRType); } else { t = appdomain.GetType(obj.GetType()); } return(((CLRType)t).GetFieldValue(esp->ValueLow, obj)); } } case ObjectTypes.ArrayReference: { Array instance = mStack[esp->Value] as Array; return(instance.GetValue(esp->ValueLow)); } case ObjectTypes.StaticFieldReference: { var t = appdomain.GetType(esp->Value); if (t is CLR.TypeSystem.ILType) { CLR.TypeSystem.ILType type = (CLR.TypeSystem.ILType)t; return(type.StaticInstance[esp->ValueLow]); } else { CLR.TypeSystem.CLRType type = (CLR.TypeSystem.CLRType)t; return(type.GetFieldValue(esp->ValueLow, null)); } } case ObjectTypes.StackObjectReference: { return(ToObject((ILIntepreter.ResolveReference(esp)), appdomain, mStack)); } case ObjectTypes.ValueTypeObjectReference: { StackObject *dst = ILIntepreter.ResolveReference(esp); IType type = appdomain.GetType(dst->Value); if (type is ILType) { ILType iltype = (ILType)type; var ins = iltype.Instantiate(false); for (int i = 0; i < dst->ValueLow; i++) { var addr = ILIntepreter.Minus(dst, i + 1); ins.AssignFromStack(i, addr, appdomain, mStack); } return(ins); } else { return(((CLRType)type).ValueTypeBinder.ToObject(dst, mStack)); } } case ObjectTypes.Null: return(null); default: throw new NotImplementedException(); } }
public unsafe object ToObject(ILRuntime.Runtime.Enviorment.AppDomain appdomain, List <object> mStack) { switch (ObjectType) { case ObjectTypes.Integer: return(Value); case ObjectTypes.Long: { StackObject tmp = this; return(*(long *)&tmp.Value); } case ObjectTypes.Float: { StackObject tmp = this; return(*(float *)&tmp.Value); } case ObjectTypes.Double: { StackObject tmp = this; return(*(double *)&tmp.Value); } case ObjectTypes.Object: return(mStack[Value]); case ObjectTypes.FieldReference: { ILTypeInstance instance = mStack[Value] as ILTypeInstance; if (instance != null) { return(instance.Fields[ValueLow].ToObject(appdomain, instance.ManagedObjects)); } else { var obj = mStack[Value]; IType t = null; if (obj is CrossBindingAdaptorType) { t = appdomain.GetType(((CrossBindingAdaptor)((CrossBindingAdaptorType)obj).ILInstance.Type.BaseType).BaseCLRType); } else { t = appdomain.GetType(obj.GetType()); } var fi = ((CLRType)t).Fields[ValueLow]; return(fi.GetValue(obj)); } } case ObjectTypes.ArrayReference: { Array instance = mStack[Value] as Array; return(instance.GetValue(ValueLow)); } case ObjectTypes.StaticFieldReference: { var t = appdomain.GetType(Value); if (t is CLR.TypeSystem.ILType) { CLR.TypeSystem.ILType type = (CLR.TypeSystem.ILType)t; return(type.StaticInstance.Fields[ValueLow].ToObject(appdomain, type.StaticInstance.ManagedObjects)); } else { CLR.TypeSystem.CLRType type = (CLR.TypeSystem.CLRType)t; var fi = type.Fields[ValueLow]; return(fi.GetValue(null)); } } case ObjectTypes.StackObjectReference: { StackObject tmp = this; return((*(StackObject **)&tmp.Value)->ToObject(appdomain, mStack)); } case ObjectTypes.Null: return(null); default: throw new NotImplementedException(); } }