/// <summary> /// Configures query arguments and a field resolver for the specified <see cref="FieldType"/>, overwriting /// any existing configuration within <see cref="FieldType.Arguments"/>, <see cref="FieldType.Resolver"/> /// and <see cref="FieldType.StreamResolver"/>. /// <br/><br/> /// For fields and properties, no query arguments are added and the field resolver simply pulls the appropriate /// member from <see cref="IResolveFieldContext.Source"/>. /// <br/><br/> /// For methods, method arguments are iterated and processed by /// <see cref="GetArgumentInformation{TParameterType}(FieldType, ParameterInfo)">GetArgumentInformation</see>, building /// a list of query arguments and expressions as necessary. Then a field resolver is built around the method. /// </summary> protected void BuildFieldType(FieldType fieldType, MemberInfo memberInfo) { if (memberInfo is PropertyInfo propertyInfo) { var resolver = new MemberResolver(propertyInfo, BuildMemberInstanceExpression(memberInfo)); fieldType.Arguments = null; fieldType.Resolver = resolver; fieldType.StreamResolver = null; } else if (memberInfo is MethodInfo methodInfo) { List <LambdaExpression> expressions = new(); QueryArguments queryArguments = new(); foreach (var parameterInfo in methodInfo.GetParameters()) { var getArgumentInfoMethodInfo = _getArgumentInformationInternalMethodInfo.MakeGenericMethod(parameterInfo.ParameterType); var getArgumentInfoMethod = (Func <FieldType, ParameterInfo, ArgumentInformation>)getArgumentInfoMethodInfo.CreateDelegate(typeof(Func <FieldType, ParameterInfo, ArgumentInformation>), this); var argumentInfo = getArgumentInfoMethod(fieldType, parameterInfo); var(queryArgument, expression) = argumentInfo.ConstructQueryArgument(); if (queryArgument != null) { ApplyArgumentAttributes(parameterInfo, queryArgument); queryArguments.Add(queryArgument); } expression ??= AutoRegisteringHelper.GetParameterExpression( parameterInfo.ParameterType, queryArgument ?? throw new InvalidOperationException("Invalid response from ConstructQueryArgument: queryArgument and expression cannot both be null")); expressions.Add(expression); } var memberInstanceExpression = BuildMemberInstanceExpression(methodInfo); if (IsObservable(methodInfo.ReturnType)) { var resolver = new SourceStreamMethodResolver(methodInfo, memberInstanceExpression, expressions); fieldType.Resolver = resolver; fieldType.StreamResolver = resolver; } else { var resolver = new MemberResolver(methodInfo, memberInstanceExpression, expressions); fieldType.Resolver = resolver; fieldType.StreamResolver = null; } fieldType.Arguments = queryArguments; } else if (memberInfo is FieldInfo fieldInfo) { var resolver = new MemberResolver(fieldInfo, BuildMemberInstanceExpression(memberInfo)); fieldType.Arguments = null; fieldType.Resolver = resolver; fieldType.StreamResolver = null; } else if (memberInfo == null) { throw new ArgumentNullException(nameof(memberInfo)); } else { throw new ArgumentOutOfRangeException(nameof(memberInfo), "Member must be a field, property or method."); } }
//static void FixNewtonsoftJsonReferenceVersion() //{ // foreach (var ar in c.PrimaryAssembly.MainModule.AssemblyReferences) // if (ar.Name == "Newtonsoft.Json" && ar.Version == V7_0_0_0) // ar.Version = V4_5_0_0; //} public static void Patch(CecilContext context, string outputPath) { c = context; r = c.Resolver; c.PrimaryAssembly.Name.Name = "Prism.Terraria"; c.PrimaryAssembly.MainModule.Name = c.PrimaryAssembly.Name.Name + ".dll"; Publicify(); //AddInternalsVisibleToAttr(); //FixNewtonsoftJsonReferenceVersion(); ItemPatcher .Patch(); NpcPatcher .Patch(); ProjectilePatcher.Patch(); PlayerPatcher .Patch(); MainPatcher .Patch(); // do other stuff here // Newtonsoft.Json.dll, Steamworks.NET.dll and Ionic.Zip.CF.dll are required to write the assembly (and FNA and WindowsBase on mono, too) c.PrimaryAssembly.Write(outputPath); r = null; c = null; }
public static MemberInfo GetMember(Expression e) { MemberResolver visitor = new MemberResolver(); visitor.Visit(e); return(visitor.member); }
public static void Patch(CecilContext context, string outputPath) { TerrariaPatcher.context = context; memRes = TerrariaPatcher.context.Resolver; TerrariaPatcher.context.PrimaryAssembly.Name.Name = "Prism.Terraria"; TerrariaPatcher.context.PrimaryAssembly.MainModule.Name = TerrariaPatcher.context.PrimaryAssembly.Name.Name + ".dll"; FindPlatform(); Publicify(); //AddInternalsVisibleToAttr(); RemoveConsoleWriteLineInWndProcHook(); Fix1308AssemblyVersion(); ItemPatcher .Patch(); NpcPatcher .Patch(); ProjectilePatcher.Patch(); PlayerPatcher .Patch(); MountPatcher .Patch(); MainPatcher .Patch(); WorldFilePatcher .Patch(); // do other stuff here // Newtonsoft.Json.dll, Steamworks.NET.dll and Ionic.Zip.CF.dll are required to write the assembly (and FNA and WindowsBase on mono, too) TerrariaPatcher.context.PrimaryAssembly.Write(outputPath); memRes = null; TerrariaPatcher.context = null; }
public void testResolveTypeName2() { var userDir = System.getProperty("user.dir"); var alPath = PathHelper.combine(userDir, "bin/stabal.jar"); var rtPath = PathHelper.combine(userDir, "bin/stabrt.jar"); var typeSystem = new Library(new String[] { rtPath }); var annotatedTypeSystem = new Library(new String[] { alPath }, typeSystem); var memberResolver = new MemberResolver(typeSystem, annotatedTypeSystem); memberResolver.initialize(); memberResolver.usingDirective( new HashMap <String, MemberInfo>(), new ArrayList <String> { "java/awt", "java/util" }, new HashMap <String, Iterable <String> >()); var listType = memberResolver.resolveTypeName(typeSystem.getType("java/lang/Object").PackageName, "List"); Assert.assertNull(listType); Assert.assertTrue(memberResolver.isAmbiguousTypeName("List")); memberResolver.dispose(); }
public void GetMembers() { var resolver = new MemberResolver(); var members = resolver.GetMembers(new ClassWithUIAttribute()); Assert.IsTrue(members.All(m => m.Name.Equals("First"))); }
internal override void Bind(Binder binder) { Chain.Bind(binder); RedwoodType chainType = Chain.GetKnownType(); if (chainType == null) { return; } if (chainType.CSharpType == null) { KnownType = chainType.slotTypes?[chainType.slotMap[Element.Name]]; } else { PropertyInfo property; FieldInfo field; MemberResolver.TryResolveMember(chainType, Element.Name, false, out property, out field); if (property != null) { KnownType = RedwoodType.GetForCSharpType(property.PropertyType); } if (field != null) { KnownType = RedwoodType.GetForCSharpType(field.FieldType); } } }
public static void Patch(CecilContext context, string outputPath) { TerrariaPatcher.context = context; memRes = TerrariaPatcher.context.Resolver; TerrariaPatcher.context.PrimaryAssembly.Name.Name = "Prism.Terraria"; TerrariaPatcher.context.PrimaryAssembly.MainModule.Name = TerrariaPatcher.context.PrimaryAssembly.Name.Name + ".dll"; FindPlatform(); Publicify(); //AddInternalsVisibleToAttr(); RemoveConsoleWriteLineInWndProcHook(); Fix1308AssemblyVersion(); ItemPatcher.Patch(); NpcPatcher.Patch(); ProjectilePatcher.Patch(); PlayerPatcher.Patch(); MountPatcher.Patch(); MainPatcher.Patch(); WorldFilePatcher.Patch(); // do other stuff here // Newtonsoft.Json.dll, Steamworks.NET.dll and Ionic.Zip.CF.dll are required to write the assembly (and FNA and WindowsBase on mono, too) TerrariaPatcher.context.PrimaryAssembly.Write(outputPath); memRes = null; TerrariaPatcher.context = null; }
internal static void Patch() { context = TerrariaPatcher.context; memRes = TerrariaPatcher.memRes; typeSys = context.PrimaryAssembly.ManifestModule.CorLibTypes; AddZephyrFishBuffID(); }
internal static void Patch() { context = TerrariaPatcher.context; memRes = TerrariaPatcher.memRes ; typeSys = context.PrimaryAssembly.ManifestModule.CorLibTypes; AddZephyrFishBuffID(); }
internal static void Patch() { c = TerrariaPatcher.c; r = TerrariaPatcher.r; ts = c.PrimaryAssembly.MainModule.TypeSystem; player_t = r.GetType("Terraria.Player"); RemoveBuggyPlayerLoading(); }
internal static void Patch() { context = TerrariaPatcher.context; memRes = TerrariaPatcher.memRes; typeSys = context.PrimaryAssembly.MainModule.TypeSystem; typeDef_WorldFile = memRes.GetType("Terraria.IO.WorldFile"); InjectSaveHook(); InjectLoadHook(); }
internal static void Patch() { context = TerrariaPatcher.context; memRes = TerrariaPatcher.memRes ; typeSys = context.PrimaryAssembly.ManifestModule.CorLibTypes; typeDef_Recipe = memRes.GetType("Terraria.Recipe"); AddGroupRecipeField(); WrapMethods(); }
internal static void Patch() { context = TerrariaPatcher.context; memRes = TerrariaPatcher.memRes; typeSys = context.PrimaryAssembly.MainModule.TypeSystem; typeDef_Proj = memRes.GetType("Terraria.Projectile"); WrapMethods(); AddFieldForBHandler(); }
internal static void Patch() { context = TerrariaPatcher.context; memRes = TerrariaPatcher.memRes; typeSys = context.PrimaryAssembly.ManifestModule.CorLibTypes; typeDef_Recipe = memRes.GetType("Terraria.Recipe"); AddGroupRecipeField(); WrapMethods(); }
internal static void Patch() { context = TerrariaPatcher.context; memRes = TerrariaPatcher.memRes; typeSys = context.PrimaryAssembly.ManifestModule.CorLibTypes; typeDef_Proj = memRes.GetType("Terraria.Projectile"); WrapMethods(); AddFieldForBHandler(); }
public void GenerateDeserializePart(GenDeserializeContext context) { var g = context.Generator; g.BeginAssign(context.Member); { g.Load(context.Reader); g.Call(MemberResolver.GetReadMethod(_readMethodName, Type)); } g.EndAssign(); }
public void GenerateSerializePart(GenSerializeContext context) { var g = context.Generator; g.Load(context.Writer); g.BeginCall(MemberResolver.GetWriteMethod(_writeMethodName, Type)); { g.Load(context.Member); } g.EndCall(); }
internal static void Patch() { c = TerrariaPatcher.c; r = TerrariaPatcher.r; ts = c.PrimaryAssembly.MainModule.TypeSystem; npc_t = r.GetType("Terraria.NPC"); WrapSetDefaults(); AddFieldForBHandler(); }
protected override IEnumerable <ValueReference> GetMembers( EvaluationContext ctx, IObjectSource objectSource, object t, object co, BindingFlags bindingFlags) { var resolver = new MemberResolver(); return(resolver.GetMembers(ctx, objectSource, t, co, bindingFlags)); }
public IEnumerable <T> GetBy <T, TU>(string key, Expression <Func <T, TU> > e) { if (items.TryGetValue(typeof(T), out Box b)) { var member = MemberResolver.GetMember(e) as PropertyInfo; foreach (var item in b.GetBy <T>(key, member)) { yield return(item); } } }
internal static void Patch() { context = TerrariaPatcher.context; memRes = TerrariaPatcher.memRes; typeSys = context.PrimaryAssembly.MainModule.TypeSystem; typeDef_Item = memRes.GetType("Terraria.Item"); WrapSetDefaults(); AddFieldForBHandler(); AddFieldForSound(); }
internal static void Patch() { context = TerrariaPatcher.context; memRes = TerrariaPatcher.memRes; typeSys = context.PrimaryAssembly.ManifestModule.CorLibTypes; typeDef_WorldFile = memRes.GetType("Terraria.IO.WorldFile"); InjectSaveHook(); InjectLoadHook(); EnlargeFrameImportantArray(); }
internal static void Patch() { c = TerrariaPatcher.c; r = TerrariaPatcher.r; ts = c.PrimaryAssembly.MainModule.TypeSystem; main_t = r.GetType("Terraria.Main"); RemoveNetModeCheckFromChat(); RemoveVanillaNpcDrawLimitation(); InsertMusicHook(); }
internal static void Patch() { context = TerrariaPatcher.context; memRes = TerrariaPatcher.memRes; typeSys = context.PrimaryAssembly.ManifestModule.CorLibTypes; typeDef_Mount = memRes.GetType("Terraria.Mount"); WrapMethods(); AddFieldForBHandler(); Remove_FromFields(); RemoveTypeLimitations(); }
internal static void Patch() { context = TerrariaPatcher.context; memRes = TerrariaPatcher.memRes; typeSys = context.PrimaryAssembly.MainModule.TypeSystem; typeDef_Mount = memRes.GetType("Terraria.Mount"); WrapMethods(); AddFieldForBHandler(); Remove_FromFields(); RemoveTypeLimitations(); }
internal static void Patch() { context = TerrariaPatcher.context; memRes = TerrariaPatcher.memRes ; typeSys = context.PrimaryAssembly.ManifestModule.CorLibTypes; typeDef_Tile = memRes.GetType("Terraria.Tile"); ChangeFieldType (); ChangeLocalTypes(); //AddExtendedWallTypeField(); //ReplaceGetWallTypeCalls (); //ReplaceSetWallTypeCalls (); //HideWallField(); }
/*static bool IsGet2DArrCall(TypeReference arrayType, Instruction i) * { * var inner = arrayType.GetElementType(); * * if (i.OpCode.Code != Code.Call) * return false; * * var mtd = i.Operand as MethodReference; * * // for debugging * //if (mtd == null) * // return false; * //if (mtd.Name != "Get") * // return false; * //if (mtd.DeclaringType.FullName != arrayType.FullName) * // return false; * //if (!mtd.HasThis) * // return false; * //if (mtd.ReturnType != inner) * // return false; * //if (mtd.Parameters.Count != 2) * // return false; * //if (!mtd.Parameters.All(pd => pd.ParameterType == typeSys.Int32)) * // return false; * * //return true; * * return mtd != null && mtd.Name == "Get" && mtd.DeclaringType.FullName == arrayType.FullName && mtd.ReturnType == inner && !mtd.HasGenericParameters && mtd.Parameters.Count == 2 && mtd.Parameters.All(pd => pd.ParameterType == typeSys.Int32) && mtd.HasThis; * }*/ /*static void AddExtendedWallTypeField() * { * var wallTypeEx = new FieldDefinition("P_wallTypeEx", FieldAttributes.Assembly | FieldAttributes.Static, memRes.ReferenceOf(typeof(ushort[]))); * * var main_t = memRes.GetType("Terraria.Main"); * #region add field * { * typeDef_Tile.Fields.Add(wallTypeEx); * * // initialize in static ctor * var cb = typeDef_Tile.GetOrCreateStaticCtor().Body; * var cproc = cb.GetILProcessor(); * * var finalRet = cb.Instructions.Last(); * * cproc.InsertBefore(finalRet, Instruction.Create(OpCodes.Ldsfld, main_t.GetField("maxTilesX"))); * cproc.InsertBefore(finalRet, Instruction.Create(OpCodes.Ldsfld, main_t.GetField("maxTilesY"))); * cproc.InsertBefore(finalRet, Instruction.Create(OpCodes.Dup)); * cproc.InsertBefore(finalRet, Instruction.Create(OpCodes.Newarr, wallTypeEx.FieldType)); * cproc.InsertBefore(finalRet, Instruction.Create(OpCodes.Stsfld, wallTypeEx)); * } #endregion * #region add twodimentional getter * { * var getWallType = new MethodDefinition("GetWallType", MethodAttributes.Public | MethodAttributes.Static, typeSys.UInt16); * * getWallType.Parameters.Add(new ParameterDefinition("x", 0, typeSys.Int32)); * getWallType.Parameters.Add(new ParameterDefinition("y", 0, typeSys.Int32)); * * var gwproc = getWallType.Body.GetILProcessor(); * * gwproc.Emit(OpCodes.Ldsfld, wallTypeEx); * * // wallTypeEx[y * Main.maxTilesY + x] * gwproc.Emit(OpCodes.Ldarg_1); * //gwproc.Emit(OpCodes.Ldsfld, main_t.GetField("maxTilesY")); * gwproc.Emit(OpCodes.Ldc_I4, LARGEST_WLD_Y); * gwproc.Emit(OpCodes.Mul); * gwproc.Emit(OpCodes.Ldarg_0); * gwproc.Emit(OpCodes.Add); * gwproc.Emit(OpCodes.Ldelem_Ref); * gwproc.Emit(OpCodes.Ret); * * typeDef_Tile.Methods.Add(getWallType); * * // add an overload with a tile argument that ignores the tile, so the stack doesn't get messed up when using injected GetWallType(I) calls. * { * var getWallTypeI = new MethodDefinition("GetWallTypeI", MethodAttributes.Assembly | MethodAttributes.Static, typeSys.UInt16); * * getWallTypeI.Parameters.Add(new ParameterDefinition("tile", 0, typeSys.Object)); * getWallTypeI.Parameters.Add(new ParameterDefinition("x", 0, typeSys.Int32)); * getWallTypeI.Parameters.Add(new ParameterDefinition("y", 0, typeSys.Int32)); * * var gwiproc = getWallTypeI.Body.GetILProcessor(); * * gwiproc.Emit(OpCodes.Ldsfld, wallTypeEx); * * // wallTypeEx[y * Main.maxTilesY + x] * gwiproc.Emit(OpCodes.Ldarg_2); * //gwiproc.Emit(OpCodes.Ldsfld, main_t.GetField("maxTilesY")); * gwiproc.Emit(OpCodes.Ldc_I4, LARGEST_WLD_Y); * gwiproc.Emit(OpCodes.Mul); * gwiproc.Emit(OpCodes.Ldarg_1); * gwiproc.Emit(OpCodes.Add); * gwiproc.Emit(OpCodes.Ldelem_Ref); * gwiproc.Emit(OpCodes.Ret); * * typeDef_Tile.Methods.Add(getWallTypeI); * } * } #endregion * #region add twodimentional setter * { * var setWallType = new MethodDefinition("SetWallType", MethodAttributes.Public | MethodAttributes.Static, typeSys.Void); * * setWallType.Parameters.Add(new ParameterDefinition("x" , 0, typeSys. Int32)); * setWallType.Parameters.Add(new ParameterDefinition("y" , 0, typeSys. Int32)); * setWallType.Parameters.Add(new ParameterDefinition("value", 0, typeSys.UInt16)); * * var swproc = setWallType.Body.GetILProcessor(); * * swproc.Emit(OpCodes.Ldsfld, wallTypeEx); * * // wallTypeEx[y * Main.maxTilesY + x] * swproc.Emit(OpCodes.Ldarg_1); * //swproc.Emit(OpCodes.Ldsfld, main_t.GetField("maxTilesY")); * swproc.Emit(OpCodes.Ldc_I4, LARGEST_WLD_Y); * swproc.Emit(OpCodes.Mul); * swproc.Emit(OpCodes.Ldarg_0); * swproc.Emit(OpCodes.Add); * swproc.Emit(OpCodes.Ldarg_2); * swproc.Emit(OpCodes.Stelem_Ref); * swproc.Emit(OpCodes.Ret); * * typeDef_Tile.Methods.Add(setWallType); * * // add an overload with a tile argument that ignores the tile, so the stack doesn't get messed up when using injected SetWallType(I) calls. * { * var setWallTypeI = new MethodDefinition("SetWallTypeI", MethodAttributes.Assembly | MethodAttributes.Static, typeSys.Void); * * setWallTypeI.Parameters.Add(new ParameterDefinition("tile", 0, typeDef_Tile)); * setWallTypeI.Parameters.Add(new ParameterDefinition("x", 0, typeSys.Int32)); * setWallTypeI.Parameters.Add(new ParameterDefinition("y", 0, typeSys.Int32)); * setWallTypeI.Parameters.Add(new ParameterDefinition("value", 0, typeSys.UInt16)); * * var swb = setWallTypeI.Body; * * var swiproc = swb.GetILProcessor(); * * swiproc.Emit(OpCodes.Ldsfld, wallTypeEx); * * // wallTypeEx[y * Main.maxTilesY + x] * swiproc.Emit(OpCodes.Ldarg_2); * //swiproc.Emit(OpCodes.Ldsfld, main_t.GetField("maxTilesY")); * swiproc.Emit(OpCodes.Ldc_I4, LARGEST_WLD_Y); * swiproc.Emit(OpCodes.Mul); * swiproc.Emit(OpCodes.Ldarg_1); * swiproc.Emit(OpCodes.Add); * swiproc.Emit(OpCodes.Ldarg_3); * swiproc.Emit(OpCodes.Stelem_Ref); * swiproc.Emit(OpCodes.Ret); * * typeDef_Tile.Methods.Add(setWallTypeI); * } * } #endregion * }*/ /*static void ReplaceGetWallTypeCalls() * { * var gw = typeDef_Tile.GetMethod("GetWallTypeI"); // using the internal version * * var main_t = memRes.GetType("Terraria.Main"); * var main_tile = main_t.GetField("tile"); * var tile_wall = typeDef_Tile.GetField("wall"); * * foreach (var td in context.PrimaryAssembly.MainModule.Types) * foreach (var md in td.Methods) * { * if (!md.HasBody) * continue; * * var body = md.Body; * var ins = body.Instructions; * var proc = body.GetILProcessor(); * * for (int i = 0; i < ins.Count; i++) * { * var n = ins[i]; * * if (IsGet2DArrCall(main_tile.FieldType, n)) * { * n = n.Next; * * if (n == null) * continue; * * if (n.OpCode.Code == Code.Ldfld && n.Operand == tile_wall) * { * var p = ins[i].Previous; // shouldn't be null, tile array + indices are loaded on the IL stack * * proc.Remove(p.Next); * proc.Remove(n); * * proc.InsertAfter(p, Instruction.Create(OpCodes.Call, gw)); * * // rewire branch targets * foreach (var i_ in ins) * if (i_ != n && i_ != ins[i] && i_.Operand == ins[i]) * i_.Operand = p.Next; * * i--; * } * } * } * } * }*/ /*static void ReplaceSetWallTypeCalls() * { * var sw = typeDef_Tile.GetMethod("SetWallTypeI"); // using the internal version * * var main_t = memRes.GetType("Terraria.Main"); * var main_tile = main_t.GetField("tile"); * var tile_wall = typeDef_Tile.GetField("wall"); * * foreach (var td in context.PrimaryAssembly.MainModule.Types) * foreach (var md in td.Methods) * { * if (!md.HasBody) * continue; * * var body = md.Body; * var ins = body.Instructions; * var proc = body.GetILProcessor(); * * for (int i = 0; i < ins.Count; i++) * { * var n = ins[i]; * * if (n.OpCode.Code == Code.Stfld && n.Operand == tile_wall) * { * var p = ins[i].Previous; // shouldn't be null, tile array + indices are loaded on the IL stack * * proc.Remove(n); * * proc.InsertAfter(p, Instruction.Create(OpCodes.Call, sw)); * * // rewire branch targets * foreach (var i_ in ins) * if (i_ != n && i_.Operand == n) * i_.Operand = p.Next; * } * } * } * } * static void HideWallField() * { * var wall = typeDef_Tile.GetField("wall"); * * wall.Name = "P_wall"; * * wall.Attributes = FieldAttributes.Assembly; * }*/ #endregion internal static void Patch() { context = TerrariaPatcher.context; memRes = TerrariaPatcher.memRes; typeSys = context.PrimaryAssembly.ManifestModule.CorLibTypes; typeDef_Tile = memRes.GetType("Terraria.Tile"); ChangeFieldType(); ChangeLocalTypes(); //AddExtendedWallTypeField(); //ReplaceGetWallTypeCalls (); //ReplaceSetWallTypeCalls (); //HideWallField(); }
public int Execute(Frame frame) { RedwoodType leftType = leftKnownType ?? RuntimeUtil.GetTypeOf(frame.stack[leftIndex]); RedwoodType rightType = rightKnownType ?? RuntimeUtil.GetTypeOf(frame.stack[rightIndex]); string lambdaName = RuntimeUtil.NameForOperator(op); Lambda leftLambda; Lambda rightLambda; leftLambda = ResolveLambda(leftType, lambdaName); rightLambda = ResolveLambda(rightType, lambdaName); Lambda lambda = RuntimeUtil.CanonicalizeLambdas(leftLambda, rightLambda); lambda = RuntimeUtil.SelectSingleOverload( new RedwoodType[] { leftType, rightType }, lambda ); frame.result = lambda; return(1); Lambda ResolveLambda(RedwoodType type, string lambdaName) { Lambda lambda; if (type.CSharpType == null) { int slot = type.staticSlotMap.GetValueOrDefault(lambdaName, -1); if (slot == -1) { lambda = null; } else { lambda = type.staticLambdas[slot]; } } else { MemberResolver.TryResolveLambda(null, type, lambdaName, out lambda); } return(lambda); } }
internal static void Patch() { context = TerrariaPatcher.context; memRes = TerrariaPatcher.memRes; typeSys = context.PrimaryAssembly.MainModule.TypeSystem; typeDef_Player = memRes.GetType("Terraria.Player"); WrapMethods(); AddFieldForBHandler(); InsertSaveLoadHooks(); RemoveBuggyPlayerLoading(); ReplaceUseSoundCalls(); FixOnEnterWorldField(); InjectMidUpdate(); InitBuffBHandlerArray(); }
public int Execute(Frame frame) { if (frame.result is RedwoodObject) { frame.result = (frame.result as RedwoodObject)[member]; } else if (MemberResolver.TryResolveLambda(frame.result, knownType, member, out Lambda result)) { frame.result = result; } else { throw new NotImplementedException(); } return(1); }
internal static void Patch() { context = TerrariaPatcher.context; memRes = TerrariaPatcher.memRes; typeSys = context.PrimaryAssembly.MainModule.TypeSystem; typeDef_Main = memRes.GetType("Terraria.Main"); WrapMethods(); RemoveVanillaNpcDrawLimitation(); FixOnEngineLoadField(); RemoveArmourDrawLimitations(); AddOnUpdateKeyboardHook(); //These are causing System.InvalidProgramExceptions so I'm just commenting them out (pls don't remove them) //AddIsChatAllowedHook(); //AddLocalChatHook(); }
internal static void Patch() { context = TerrariaPatcher.context; memRes = TerrariaPatcher.memRes; typeSys = context.PrimaryAssembly.MainModule.TypeSystem; typeDef_NPC = memRes.GetType("Terraria.NPC" ); WrapMethods(); AddFieldForBHandler(); AddFieldsForAudio(); InsertInitialize(); ReplaceSoundHitCalls(); ReplaceSoundKilledCalls(); InjectBuffEffectsCall(); InitBuffBHandlerArray(); }
internal static void Patch() { context = TerrariaPatcher.context; memRes = TerrariaPatcher.memRes; typeSys = context.PrimaryAssembly.MainModule.TypeSystem; typeDef_NPC = memRes.GetType("Terraria.NPC"); WrapMethods(); AddFieldForBHandler(); AddFieldsForAudio(); InsertInitialize(); ReplaceSoundHitCalls(); ReplaceSoundKilledCalls(); InjectBuffEffectsCall(); InitBuffBHandlerArray(); }
private string GetSearchItemJSON() { MemberResolver memberResolver = new MemberResolver(); IEnumerable <Member> members = memberResolver.GetMembersForCodeCompletion(GetFullyQualifiedObjectType()); StringBuilder builder = new StringBuilder(); builder.Append("["); var lastMember = members.Last(); foreach (var member in members) { builder.Append("{ name : \"" + member.DisplayMemberName + "\", value: \"" + member.DisplayMemberName + "\", type: \"" + member.MemberType + "\"}"); if (members != lastMember) { builder.Append(","); } } builder.Append("]"); return(builder.ToString()); }
public void testResolveTypeName2() { var userDir = System.getProperty("user.dir"); var alPath = PathHelper.combine(userDir, "bin/stabal.jar"); var rtPath = PathHelper.combine(userDir, "bin/stabrt.jar"); var typeSystem = new Library(new String[] { rtPath }); var annotatedTypeSystem = new Library(new String[] { alPath }, typeSystem); var memberResolver = new MemberResolver(typeSystem, annotatedTypeSystem); memberResolver.initialize(); memberResolver.usingDirective( new HashMap<String, MemberInfo>(), new ArrayList<String> { "java/awt", "java/util" }, new HashMap<String, Iterable<String>>()); var listType = memberResolver.resolveTypeName(typeSystem.getType("java/lang/Object").PackageName, "List"); Assert.assertNull(listType); Assert.assertTrue(memberResolver.isAmbiguousTypeName("List")); memberResolver.dispose(); }
public void GenerateSerializePart(GenSerializeContext context) { var g = context.Generator; g.If(() => { g.Load(context.Member); return(BinaryOperator.IsNull); }); { g.Load(context.Writer); g.BeginCall(MemberResolver.GetWriteMethod("WriteVarInt32", typeof(int))); { g.Load(-1); } g.EndCall(); } g.Else(); { g.Load(context.Writer); g.BeginCall(MemberResolver.GetWriteMethod("WriteVarInt32", typeof(int))); { g.Load(context.Member); g.BeginCall(_getCount); g.EndCall(); } g.EndCall(); g.Load(context.Member); var item = g.BeginForEach(_elementType); { var innerContext = context.CreateChild(g.CreateExpression(item)); _innerBuilder.GenerateSerializePart(innerContext); } g.EndForEach(); } g.EndIf(); }
public int Execute(Frame frame) { Lambda lambda; if (functionName == null) { if (!RuntimeUtil.TryConvertToLambda(frame.result, out lambda)) { throw new NotImplementedException(); } } else { if (!MemberResolver.TryResolveLambda( frame.result, calleeTypeHint, functionName, out lambda)) { throw new NotImplementedException(); } } object[] args = new object[argLocations.Length]; for (int i = 0; i < argLocations.Length; i++) { args[i] = frame.stack[argLocations[i]]; } if (lambda is LambdaGroup group) { frame.result = group.RunWithExpectedTypes(argTypesHint, args); } else { frame.result = lambda.Run(args); } return(1); }
void IPartBuilder.GenerateSerializePart(GenSerializeContext context) { var g = context.Generator; g.If(() => { g.Load(context.Member, LoadOptions.ValueAsAddress); g.LoadMember("HasValue"); return(BinaryOperator.IsTrue); }); { g.Load(context.Writer); g.BeginCall(MemberResolver.GetWriteMethod(typeof(bool))); { g.Load(true); } g.EndCall(); g.BeginScope(); { _innerBuilder.GenerateSerializePart(context.CreateChild( context.Member .Copy() .AddMember("Value"))); } g.EndScope(); } g.Else(); { g.Load(context.Writer); g.BeginCall(MemberResolver.GetWriteMethod(typeof(bool))); { g.Load(false); } g.EndCall(); } g.EndIf(); }
void IPartBuilder.GenerateDeserializePart(GenDeserializeContext context) { var g = context.Generator; g.If(() => { g.Load(context.Reader); g.Call(MemberResolver.GetReadMethod(typeof(bool))); return(BinaryOperator.IsTrue); }); { var value = g.DeclareLocal(_innerType); g.BeginScope(); { var innerContext = context.CreateChild(g.CreateExpression(value)); _innerBuilder.GenerateDeserializePart(innerContext); } g.EndScope(); g.BeginAssign(context.Member); { g.BeginNewObject(_ctor); { g.Load(value); } g.EndNewObject(); } g.EndAssign(); } g.Else(); { g.Load(context.Member, LoadOptions.ValueAsAddress); g.InitializeValue(); } g.EndIf(); }
public static void Load() { c = new CecilContext("Terraria.exe"); r = c.Resolver; // this contains a lot of useful methods }
public void GetMethod_ReturnsTypeMethodInfo() { var expected = typeof(MockObject).GetMethod("StringMethod"); var actual = new MemberResolver<MockObject>().GetMethod(o => o.StringMethod()); Assert.IsNotNull(actual); Assert.AreEqual(expected, actual); }
public void GetField_ReturnsTypeFieldInfo() { var expected = typeof(MockObject).GetField("BoolField"); var actual = new MemberResolver<MockObject>().GetField(o => o.BoolField); Assert.IsNotNull(actual); Assert.AreEqual(expected, actual); }
public void GetProperty_ReturnsTypePropertyInfo() { var expected = typeof(MockObject).GetProperty("BoolProperty"); var actual = new MemberResolver<MockObject>().GetProperty(o => o.BoolProperty); Assert.IsNotNull(actual); Assert.AreEqual(expected, actual); }
void IPartBuilder.GenerateDeserializePart(GenDeserializeContext context) { var g = context.Generator; var count = g.DeclareLocal(typeof(int)); g.BeginAssign(count); { g.Load(context.Reader); g.Call(MemberResolver.GetReadMethod("ReadVarInt32", typeof(int))); } g.EndAssign(); g.If(() => { g.Load(count); g.Load(-1); return(BinaryOperator.AreEqual); }); { g.BeginAssign(context.Member); { g.LoadNull(); } g.EndAssign(); } g.Else(); { g.BeginAssign(context.Member); { g.BeginNewArray(_elementType); { g.Load(count); } g.EndNewArray(); } g.EndAssign(); var i = g.DeclareLocal(typeof(int)); i.Initialize(); g.While(() => { g.Load(i); g.Load(count); return(BinaryOperator.LessThan); }, () => { var element = g.DeclareLocal(_elementType); g.BeginScope(); { _elementBuilder.GenerateDeserializePart(context.CreateChild(g.CreateExpression(element))); } g.EndScope(); g.Load(context.Member); g.BeginStoreElement(); { g.Load(i); g.Load(element); } g.EndStoreElement(); g.BeginAssign(i); { g.Load(i); g.Increment(); } g.EndAssign(); }); } g.EndIf(); }
void IPartBuilder.GenerateSerializePart(GenSerializeContext context) { var g = context.Generator; g.If(() => { g.Load(context.Member); return(BinaryOperator.IsNull); }); { g.Load(context.Writer); g.BeginCall(MemberResolver.GetWriteMethod("WriteVarInt32", typeof(int))); { g.Load(-1); } g.EndCall(); } g.Else(); { g.Load(context.Writer); g.BeginCall(MemberResolver.GetWriteMethod("WriteVarInt32", typeof(int))); { g.Load(context.Member); g.LoadMember("Length"); } g.EndCall(); var i = g.DeclareLocal(typeof(int)); i.Initialize(); g.While(() => { g.Load(i); g.Load(context.Member); g.LoadMember("Length"); return(BinaryOperator.LessThan); }, () => { var element = g.DeclareLocal(_elementType); g.BeginAssign(element); { g.Load(context.Member); g.BeginLoadElement(); { g.Load(i); } g.EndLoadElement(); } g.EndAssign(); var elementContext = context.CreateChild(g.CreateExpression(element)); _elementBuilder.GenerateSerializePart(elementContext); g.BeginAssign(i); { g.Load(i); g.Increment(); } g.EndAssign(); }); } g.EndIf(); }