private static bool DrawPrefix4(SpriteBatch __instance, Texture2D texture, Vector2 position, Rectangle?sourceRectangle, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) { DrawingInfo info = new DrawingInfo(__instance, texture, sourceRectangle, position, color, origin, rotation, effects, layerDepth); info.SetScale(scale); return(!DrawingDelegator.DrawReplaced(info)); }
private static bool DrawReplaced(DrawingInfo info) { // Don't override if currently patching if (DrawingDelegator._drawing) { return(false); } // Check if this texture is being tracked if (!DrawingDelegator._textureToTrackedTexture.TryGetValue(info.Texture, out TrackedTexture trackedTexture)) { return(false); } // Check if any overrides handle this drawing call bool modified = false; foreach (EventHandler <IDrawingInfo> drawingHandler in trackedTexture.GetDrawingHandlers()) { // Set the drawing info's Modified property to false, then execute the overrider info.Reset(); drawingHandler(null, info); // Check if modified if (info.Modified) { modified = true; } // Check if should continue propagating if (!info.Propagate || info.Cancelled) { break; } } // Check if any handlers modified the drawing info if (!modified) { RaiseAfterDrawn(); return(false); } // Call the native draw code if not cancelled if (!info.Cancelled) { DrawingDelegator._drawing = true; info.Draw(); DrawingDelegator._drawing = false; RaiseAfterDrawn(); } // Return whether it was handled return(true); void RaiseAfterDrawn() { ReadonlyDrawingInfo finalInfo = new ReadonlyDrawingInfo(info); foreach (EventHandler <IReadonlyDrawingInfo> drawnHandler in trackedTexture.GetDrawnHandlers()) { drawnHandler(null, finalInfo); } } }