public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) { int tileType = (int)projectile.ai[0]; if (!Libvaxy.FallingTileTextures.ContainsKey(tileType)) { Libvaxy.FallingTileTextures[tileType] = Libvaxy.CreateFallingTileTexture(tileType); } spriteBatch.Draw(Libvaxy.FallingTileTextures[tileType], projectile.position - Main.screenPosition, null, lightColor, projectile.rotation, new Vector2(projectile.width / 2, projectile.height / 2), 1f, SpriteEffects.None, 0f); return(false); }
// TODO: Make it possible to call original method easily + pass in an instance of the caller internal static void ApplyDetours() { MonoModHooks.RequestNativeAccess(); foreach (MethodInfo method in Reflection.GetMethodsWithAttribute <DetourAttribute>()) { DetourAttribute attribute = method.GetCustomAttribute <DetourAttribute>(); string modName = attribute.typeName.Split('.')[0]; if (!Libvaxy.ModAssemblies.ContainsKey(modName)) { Libvaxy.Logger.Warn("Attempted to detour an unknown / unloaded mod, ignoring and moving on..."); continue; } Type targetMethodType = Libvaxy.ModAssemblies[modName].GetType(attribute.typeName); if (targetMethodType == null) { throw new LibvaxyException("Could not find the target type to perform detour"); } MethodInfo targetMethod = Reflection.GetMethodInfo(targetMethodType, attribute.methodName, attribute.parameterTypes ?? new Type[0]); // TODO: move these checks elsewhere as a utility if (targetMethod == null) { throw new LibvaxyException("Could not find the target method to perform detour"); } if (!Reflection.GetParameterTypes(method).SequenceEqual(Reflection.GetParameterTypes(targetMethod))) { throw new LibvaxyException("The target method and detour method do not have matching parameter types"); } if (method.ReturnType != targetMethod.ReturnType) { throw new LibvaxyException("The target method and detour method do not have matching return types"); } Libvaxy.DisposeOnUnload(new Detour(targetMethod, method)); Libvaxy.Logger.Info($"Registered detour from {targetMethod.FullMemberName()}\nTo: {method.FullMemberName()}"); } }