public static void StartCamera(MapCaptureSettings settings) { Main.PlaySound(40, -1, -1, 1); MapCaptureInterface.CameraSettings = settings; MapCaptureInterface.CameraLock = true; MapCaptureInterface.CameraWaiting = 0f; }
public void MapCapture(MapCaptureSettings settings) { Main.GlobalTimerPaused = true; Monitor.Enter(this._captureLock); if (this._activeSettings != null) { throw new InvalidOperationException("MapCapture called while another capture was already active."); } this._activeSettings = settings; Microsoft.Xna.Framework.Rectangle area = settings.Area; float num = 1f; if (settings.UseScaling) { if (area.Width << 4 > 4096) { num = 4096f / (float)(area.Width << 4); } if (area.Height << 4 > 4096) { num = Math.Min(num, 4096f / (float)(area.Height << 4)); } num = Math.Min(1f, num); this._outputImageSize = new Size((int)MathHelper.Clamp((float)((int)(num * (float)(area.Width << 4))), 1f, 4096f), (int)MathHelper.Clamp((float)((int)(num * (float)(area.Height << 4))), 1f, 4096f)); this._outputData = new byte[4 * this._outputImageSize.Width * this._outputImageSize.Height]; int num2 = (int)Math.Floor((double)(num * 2048f)); this._scaledFrameData = new byte[4 * num2 * num2]; this._scaledFrameBuffer = new RenderTarget2D(this._graphics, num2, num2, false, this._graphics.PresentationParameters.BackBufferFormat, DepthFormat.Depth24); } else { this._outputData = new byte[16777216]; } this._tilesProcessed = 0f; this._totalTiles = (float)(area.Width * area.Height); for (int i = area.X; i < area.X + area.Width; i += 126) { for (int j = area.Y; j < area.Y + area.Height; j += 126) { int num3 = Math.Min(128, area.X + area.Width - i); int num4 = Math.Min(128, area.Y + area.Height - j); int width = (int)Math.Floor((double)(num * (float)(num3 << 4))); int height = (int)Math.Floor((double)(num * (float)(num4 << 4))); int x = (int)Math.Floor((double)(num * (float)(i - area.X << 4))); int y = (int)Math.Floor((double)(num * (float)(j - area.Y << 4))); this._renderQueue.Enqueue(new MapCaptureCamera.MapCaptureChunk(new Microsoft.Xna.Framework.Rectangle(i, j, num3, num4), new Microsoft.Xna.Framework.Rectangle(x, y, width, height))); } } Monitor.Exit(this._captureLock); }
private void FinishMapCapture() { if (this._activeSettings.UseScaling) { int num = 0; while (!this.SaveImage(this._outputImageSize.Width, this._outputImageSize.Height, ImageFormat.Png, string.Concat(new object[] { Main.SavePath, Path.DirectorySeparatorChar, "Captures", Path.DirectorySeparatorChar, this._activeSettings.OutputName, ".png" }))) { GC.Collect(); Thread.Sleep(5); num++; Console.WriteLine("An error occured while saving the capture. Attempting again..."); if (num > 5) { Console.WriteLine("Unable to capture."); break; } } } this._outputData = null; this._scaledFrameData = null; Main.GlobalTimerPaused = false; MapCaptureInterface.EndCamera(); if (this._scaledFrameBuffer != null) { this._scaledFrameBuffer.Dispose(); this._scaledFrameBuffer = null; } this._activeSettings = null; }
public void MapCapture(MapCaptureSettings settings) { this._camera.MapCapture(settings); }