private static void TileGrid_RenderAt(ILContext il) { ILCursor cursor = new ILCursor(il); //cursor.Emit(OpCodes.Ldarg_0); // this //cursor.EmitDelegate<Func<TileGrid, RainbowTilesetController>>((TileGrid self) => self.Scene.Tracker.GetEntity<RainbowTilesetController>()); //cursor.Emit(OpCodes.Stloc_S, (byte)5); while (cursor.TryGotoNext(MoveType.After, instr => instr.MatchCallvirt <MTexture>("Draw"))) { cursor.Index--; // go back to the last step, which is when the color is loaded cursor.Emit(OpCodes.Ldloc_3); // x cursor.Emit(OpCodes.Ldloc_S, (byte)4); // y cursor.Emit(OpCodes.Ldarg_0); // this //cursor.Emit(OpCodes.Ldloc_S, (byte)5); // controller cursor.EmitDelegate <Func <Color, int, int, TileGrid /*, RainbowTilesetController*/, Color> >((Color c, int x, int y, TileGrid self /*, RainbowTilesetController controller*/) => { RainbowTilesetController controller = self.Scene.Tracker.GetEntity <RainbowTilesetController>(); if (controller != null && controller.TilesetTexturePaths.Contains(self.Tiles[x, y].Parent.AtlasPath)) { return(ColorHelper.GetHue(Engine.Scene, new Vector2(x * self.TileWidth + self.Position.X + self.Entity.Position.X, y * self.TileWidth + self.Position.Y + self.Entity.Position.Y))); } return(c); }); return; } }
public override void Render() { base.Render(); foreach (var item in Entity.Components.OfType <Image>()) { item.Color = ColorHelper.GetHue(Scene, item.RenderPosition); } }
//[Command("createrainbow", "REMOVE THIS JA AAAAAA")] public static void CmdCreateRainbowImg() { int width = 1920; int height = 1080; Texture2D texture = new Texture2D(Engine.Graphics.GraphicsDevice, width, height); Color[] colors = new Color[width * height]; for (int i = 0; i < width * height; i++) { colors[i] = ColorHelper.GetHue(Engine.Scene, new Vector2(i % width, i / width)); } texture.SetData(colors); using (FileStream stream = File.Create(@"C:\Users\Jasio\Desktop\rainbow4.png")) texture.SaveAsPng(stream, width, height); texture.Dispose(); }