Terraria 1.3.5.3 Source Code
This commit is contained in:
commit
4b21dac4b6
503 changed files with 409032 additions and 0 deletions
52
Graphics/Capture/CaptureBiome.cs
Normal file
52
Graphics/Capture/CaptureBiome.cs
Normal file
|
@ -0,0 +1,52 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Capture.CaptureBiome
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
namespace Terraria.Graphics.Capture
|
||||
{
|
||||
public class CaptureBiome
|
||||
{
|
||||
public static CaptureBiome[] Biomes = new CaptureBiome[12]
|
||||
{
|
||||
new CaptureBiome(0, 0, 0),
|
||||
null,
|
||||
new CaptureBiome(1, 2, 2, CaptureBiome.TileColorStyle.Corrupt),
|
||||
new CaptureBiome(3, 0, 3, CaptureBiome.TileColorStyle.Jungle),
|
||||
new CaptureBiome(6, 2, 4),
|
||||
new CaptureBiome(7, 4, 5),
|
||||
new CaptureBiome(2, 1, 6),
|
||||
new CaptureBiome(9, 6, 7, CaptureBiome.TileColorStyle.Mushroom),
|
||||
new CaptureBiome(0, 0, 8),
|
||||
null,
|
||||
new CaptureBiome(8, 5, 10, CaptureBiome.TileColorStyle.Crimson),
|
||||
null
|
||||
};
|
||||
public readonly int WaterStyle;
|
||||
public readonly int BackgroundIndex;
|
||||
public readonly int BackgroundIndex2;
|
||||
public readonly CaptureBiome.TileColorStyle TileColor;
|
||||
|
||||
public CaptureBiome(
|
||||
int backgroundIndex,
|
||||
int backgroundIndex2,
|
||||
int waterStyle,
|
||||
CaptureBiome.TileColorStyle tileColorStyle = CaptureBiome.TileColorStyle.Normal)
|
||||
{
|
||||
this.BackgroundIndex = backgroundIndex;
|
||||
this.BackgroundIndex2 = backgroundIndex2;
|
||||
this.WaterStyle = waterStyle;
|
||||
this.TileColor = tileColorStyle;
|
||||
}
|
||||
|
||||
public enum TileColorStyle
|
||||
{
|
||||
Normal,
|
||||
Jungle,
|
||||
Crimson,
|
||||
Corrupt,
|
||||
Mushroom,
|
||||
}
|
||||
}
|
||||
}
|
319
Graphics/Capture/CaptureCamera.cs
Normal file
319
Graphics/Capture/CaptureCamera.cs
Normal file
|
@ -0,0 +1,319 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Capture.CaptureCamera
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using Terraria.Localization;
|
||||
|
||||
namespace Terraria.Graphics.Capture
|
||||
{
|
||||
internal class CaptureCamera
|
||||
{
|
||||
private static bool CameraExists;
|
||||
public const int CHUNK_SIZE = 128;
|
||||
public const int FRAMEBUFFER_PIXEL_SIZE = 2048;
|
||||
public const int INNER_CHUNK_SIZE = 126;
|
||||
public const int MAX_IMAGE_SIZE = 4096;
|
||||
public const string CAPTURE_DIRECTORY = "Captures";
|
||||
private RenderTarget2D _frameBuffer;
|
||||
private RenderTarget2D _scaledFrameBuffer;
|
||||
private GraphicsDevice _graphics;
|
||||
private readonly object _captureLock = new object();
|
||||
private bool _isDisposed;
|
||||
private CaptureSettings _activeSettings;
|
||||
private Queue<CaptureCamera.CaptureChunk> _renderQueue = new Queue<CaptureCamera.CaptureChunk>();
|
||||
private SpriteBatch _spriteBatch;
|
||||
private byte[] _scaledFrameData;
|
||||
private byte[] _outputData;
|
||||
private Size _outputImageSize;
|
||||
private SamplerState _downscaleSampleState;
|
||||
private float _tilesProcessed;
|
||||
private float _totalTiles;
|
||||
|
||||
public bool IsCapturing
|
||||
{
|
||||
get
|
||||
{
|
||||
Monitor.Enter(this._captureLock);
|
||||
int num = this._activeSettings != null ? 1 : 0;
|
||||
Monitor.Exit(this._captureLock);
|
||||
return num != 0;
|
||||
}
|
||||
}
|
||||
|
||||
public CaptureCamera(GraphicsDevice graphics)
|
||||
{
|
||||
CaptureCamera.CameraExists = true;
|
||||
this._graphics = graphics;
|
||||
this._spriteBatch = new SpriteBatch(graphics);
|
||||
try
|
||||
{
|
||||
this._frameBuffer = new RenderTarget2D(graphics, 2048, 2048, false, graphics.PresentationParameters.BackBufferFormat, DepthFormat.Depth24);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Main.CaptureModeDisabled = true;
|
||||
return;
|
||||
}
|
||||
this._downscaleSampleState = SamplerState.AnisotropicClamp;
|
||||
}
|
||||
|
||||
~CaptureCamera() => this.Dispose();
|
||||
|
||||
public void Capture(CaptureSettings settings)
|
||||
{
|
||||
Main.GlobalTimerPaused = true;
|
||||
Monitor.Enter(this._captureLock);
|
||||
this._activeSettings = this._activeSettings == null ? settings : throw new InvalidOperationException("Capture called while another capture was already active.");
|
||||
Microsoft.Xna.Framework.Rectangle area = settings.Area;
|
||||
float num1 = 1f;
|
||||
if (settings.UseScaling)
|
||||
{
|
||||
if (area.Width << 4 > 4096)
|
||||
num1 = 4096f / (float) (area.Width << 4);
|
||||
if (area.Height << 4 > 4096)
|
||||
num1 = Math.Min(num1, 4096f / (float) (area.Height << 4));
|
||||
num1 = Math.Min(1f, num1);
|
||||
this._outputImageSize = new Size((int) MathHelper.Clamp((float) (int) ((double) num1 * (double) (area.Width << 4)), 1f, 4096f), (int) MathHelper.Clamp((float) (int) ((double) num1 * (double) (area.Height << 4)), 1f, 4096f));
|
||||
this._outputData = new byte[4 * this._outputImageSize.Width * this._outputImageSize.Height];
|
||||
int num2 = (int) Math.Floor((double) num1 * 2048.0);
|
||||
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 = 0.0f;
|
||||
this._totalTiles = (float) (area.Width * area.Height);
|
||||
for (int x1 = area.X; x1 < area.X + area.Width; x1 += 126)
|
||||
{
|
||||
for (int y1 = area.Y; y1 < area.Y + area.Height; y1 += 126)
|
||||
{
|
||||
int width1 = Math.Min(128, area.X + area.Width - x1);
|
||||
int height1 = Math.Min(128, area.Y + area.Height - y1);
|
||||
int width2 = (int) Math.Floor((double) num1 * (double) (width1 << 4));
|
||||
int height2 = (int) Math.Floor((double) num1 * (double) (height1 << 4));
|
||||
int x2 = (int) Math.Floor((double) num1 * (double) (x1 - area.X << 4));
|
||||
int y2 = (int) Math.Floor((double) num1 * (double) (y1 - area.Y << 4));
|
||||
this._renderQueue.Enqueue(new CaptureCamera.CaptureChunk(new Microsoft.Xna.Framework.Rectangle(x1, y1, width1, height1), new Microsoft.Xna.Framework.Rectangle(x2, y2, width2, height2)));
|
||||
}
|
||||
}
|
||||
Monitor.Exit(this._captureLock);
|
||||
}
|
||||
|
||||
public void DrawTick()
|
||||
{
|
||||
Monitor.Enter(this._captureLock);
|
||||
if (this._activeSettings == null)
|
||||
return;
|
||||
if (this._renderQueue.Count > 0)
|
||||
{
|
||||
CaptureCamera.CaptureChunk captureChunk = this._renderQueue.Dequeue();
|
||||
this._graphics.SetRenderTarget(this._frameBuffer);
|
||||
this._graphics.Clear(Microsoft.Xna.Framework.Color.Transparent);
|
||||
Main.instance.DrawCapture(captureChunk.Area, this._activeSettings);
|
||||
if (this._activeSettings.UseScaling)
|
||||
{
|
||||
this._graphics.SetRenderTarget(this._scaledFrameBuffer);
|
||||
this._graphics.Clear(Microsoft.Xna.Framework.Color.Transparent);
|
||||
this._spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, this._downscaleSampleState, DepthStencilState.Default, RasterizerState.CullNone);
|
||||
this._spriteBatch.Draw((Texture2D) this._frameBuffer, new Microsoft.Xna.Framework.Rectangle(0, 0, this._scaledFrameBuffer.Width, this._scaledFrameBuffer.Height), Microsoft.Xna.Framework.Color.White);
|
||||
this._spriteBatch.End();
|
||||
this._graphics.SetRenderTarget((RenderTarget2D) null);
|
||||
this._scaledFrameBuffer.GetData<byte>(this._scaledFrameData, 0, this._scaledFrameBuffer.Width * this._scaledFrameBuffer.Height * 4);
|
||||
this.DrawBytesToBuffer(this._scaledFrameData, this._outputData, this._scaledFrameBuffer.Width, this._outputImageSize.Width, captureChunk.ScaledArea);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._graphics.SetRenderTarget((RenderTarget2D) null);
|
||||
this.SaveImage((Texture2D) this._frameBuffer, captureChunk.ScaledArea.Width, captureChunk.ScaledArea.Height, ImageFormat.Png, this._activeSettings.OutputName, captureChunk.Area.X.ToString() + "-" + (object) captureChunk.Area.Y + ".png");
|
||||
}
|
||||
this._tilesProcessed += (float) (captureChunk.Area.Width * captureChunk.Area.Height);
|
||||
}
|
||||
if (this._renderQueue.Count == 0)
|
||||
this.FinishCapture();
|
||||
Monitor.Exit(this._captureLock);
|
||||
}
|
||||
|
||||
private unsafe void DrawBytesToBuffer(
|
||||
byte[] sourceBuffer,
|
||||
byte[] destinationBuffer,
|
||||
int sourceBufferWidth,
|
||||
int destinationBufferWidth,
|
||||
Microsoft.Xna.Framework.Rectangle area)
|
||||
{
|
||||
fixed (byte* numPtr1 = &destinationBuffer[0])
|
||||
fixed (byte* numPtr2 = &sourceBuffer[0])
|
||||
{
|
||||
byte* numPtr3 = numPtr2;
|
||||
byte* numPtr4 = numPtr1 + (destinationBufferWidth * area.Y + area.X << 2);
|
||||
for (int index1 = 0; index1 < area.Height; ++index1)
|
||||
{
|
||||
for (int index2 = 0; index2 < area.Width; ++index2)
|
||||
{
|
||||
numPtr4[2] = *numPtr3;
|
||||
numPtr4[1] = numPtr3[1];
|
||||
*numPtr4 = numPtr3[2];
|
||||
numPtr4[3] = numPtr3[3];
|
||||
numPtr3 += 4;
|
||||
numPtr4 += 4;
|
||||
}
|
||||
numPtr3 += sourceBufferWidth - area.Width << 2;
|
||||
numPtr4 += destinationBufferWidth - area.Width << 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public float GetProgress() => this._tilesProcessed / this._totalTiles;
|
||||
|
||||
private bool SaveImage(int width, int height, ImageFormat imageFormat, string filename)
|
||||
{
|
||||
try
|
||||
{
|
||||
string savePath = Main.SavePath;
|
||||
char directorySeparatorChar = Path.DirectorySeparatorChar;
|
||||
string str1 = directorySeparatorChar.ToString();
|
||||
directorySeparatorChar = Path.DirectorySeparatorChar;
|
||||
string str2 = directorySeparatorChar.ToString();
|
||||
Directory.CreateDirectory(savePath + str1 + "Captures" + str2);
|
||||
using (Bitmap bitmap = new Bitmap(width, height))
|
||||
{
|
||||
System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, width, height);
|
||||
BitmapData bitmapdata = bitmap.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppPArgb);
|
||||
Marshal.Copy(this._outputData, 0, bitmapdata.Scan0, width * height * 4);
|
||||
bitmap.UnlockBits(bitmapdata);
|
||||
bitmap.Save(filename, imageFormat);
|
||||
bitmap.Dispose();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine((object) ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveImage(
|
||||
Texture2D texture,
|
||||
int width,
|
||||
int height,
|
||||
ImageFormat imageFormat,
|
||||
string foldername,
|
||||
string filename)
|
||||
{
|
||||
string str = Main.SavePath + Path.DirectorySeparatorChar.ToString() + "Captures" + Path.DirectorySeparatorChar.ToString() + foldername;
|
||||
string filename1 = Path.Combine(str, filename);
|
||||
Directory.CreateDirectory(str);
|
||||
using (Bitmap bitmap = new Bitmap(width, height))
|
||||
{
|
||||
System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, width, height);
|
||||
int elementCount = texture.Width * texture.Height * 4;
|
||||
texture.GetData<byte>(this._outputData, 0, elementCount);
|
||||
int index1 = 0;
|
||||
int index2 = 0;
|
||||
for (int index3 = 0; index3 < height; ++index3)
|
||||
{
|
||||
for (int index4 = 0; index4 < width; ++index4)
|
||||
{
|
||||
byte num = this._outputData[index1 + 2];
|
||||
this._outputData[index2 + 2] = this._outputData[index1];
|
||||
this._outputData[index2] = num;
|
||||
this._outputData[index2 + 1] = this._outputData[index1 + 1];
|
||||
this._outputData[index2 + 3] = this._outputData[index1 + 3];
|
||||
index1 += 4;
|
||||
index2 += 4;
|
||||
}
|
||||
index1 += texture.Width - width << 2;
|
||||
}
|
||||
BitmapData bitmapdata = bitmap.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppPArgb);
|
||||
Marshal.Copy(this._outputData, 0, bitmapdata.Scan0, width * height * 4);
|
||||
bitmap.UnlockBits(bitmapdata);
|
||||
bitmap.Save(filename1, imageFormat);
|
||||
}
|
||||
}
|
||||
|
||||
private void FinishCapture()
|
||||
{
|
||||
if (this._activeSettings.UseScaling)
|
||||
{
|
||||
int num = 0;
|
||||
do
|
||||
{
|
||||
int width = this._outputImageSize.Width;
|
||||
int height = this._outputImageSize.Height;
|
||||
ImageFormat png = ImageFormat.Png;
|
||||
string[] strArray = new string[6];
|
||||
strArray[0] = Main.SavePath;
|
||||
char directorySeparatorChar = Path.DirectorySeparatorChar;
|
||||
strArray[1] = directorySeparatorChar.ToString();
|
||||
strArray[2] = "Captures";
|
||||
directorySeparatorChar = Path.DirectorySeparatorChar;
|
||||
strArray[3] = directorySeparatorChar.ToString();
|
||||
strArray[4] = this._activeSettings.OutputName;
|
||||
strArray[5] = ".png";
|
||||
string filename = string.Concat(strArray);
|
||||
if (!this.SaveImage(width, height, png, filename))
|
||||
{
|
||||
GC.Collect();
|
||||
Thread.Sleep(5);
|
||||
++num;
|
||||
Console.WriteLine(Language.GetTextValue("Error.CaptureError"));
|
||||
}
|
||||
else
|
||||
goto label_5;
|
||||
}
|
||||
while (num <= 5);
|
||||
Console.WriteLine(Language.GetTextValue("Error.UnableToCapture"));
|
||||
}
|
||||
label_5:
|
||||
this._outputData = (byte[]) null;
|
||||
this._scaledFrameData = (byte[]) null;
|
||||
Main.GlobalTimerPaused = false;
|
||||
CaptureInterface.EndCamera();
|
||||
if (this._scaledFrameBuffer != null)
|
||||
{
|
||||
this._scaledFrameBuffer.Dispose();
|
||||
this._scaledFrameBuffer = (RenderTarget2D) null;
|
||||
}
|
||||
this._activeSettings = (CaptureSettings) null;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Monitor.Enter(this._captureLock);
|
||||
if (this._isDisposed)
|
||||
return;
|
||||
this._frameBuffer.Dispose();
|
||||
if (this._scaledFrameBuffer != null)
|
||||
{
|
||||
this._scaledFrameBuffer.Dispose();
|
||||
this._scaledFrameBuffer = (RenderTarget2D) null;
|
||||
}
|
||||
CaptureCamera.CameraExists = false;
|
||||
this._isDisposed = true;
|
||||
Monitor.Exit(this._captureLock);
|
||||
}
|
||||
|
||||
private class CaptureChunk
|
||||
{
|
||||
public readonly Microsoft.Xna.Framework.Rectangle Area;
|
||||
public readonly Microsoft.Xna.Framework.Rectangle ScaledArea;
|
||||
|
||||
public CaptureChunk(Microsoft.Xna.Framework.Rectangle area, Microsoft.Xna.Framework.Rectangle scaledArea)
|
||||
{
|
||||
this.Area = area;
|
||||
this.ScaledArea = scaledArea;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
1342
Graphics/Capture/CaptureInterface.cs
Normal file
1342
Graphics/Capture/CaptureInterface.cs
Normal file
File diff suppressed because it is too large
Load diff
57
Graphics/Capture/CaptureManager.cs
Normal file
57
Graphics/Capture/CaptureManager.cs
Normal file
|
@ -0,0 +1,57 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Capture.CaptureManager
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace Terraria.Graphics.Capture
|
||||
{
|
||||
public class CaptureManager
|
||||
{
|
||||
public static CaptureManager Instance = new CaptureManager();
|
||||
private CaptureInterface _interface;
|
||||
private CaptureCamera _camera;
|
||||
|
||||
public bool IsCapturing => this._camera.IsCapturing;
|
||||
|
||||
public CaptureManager()
|
||||
{
|
||||
this._interface = new CaptureInterface();
|
||||
this._camera = new CaptureCamera(Main.instance.GraphicsDevice);
|
||||
}
|
||||
|
||||
public bool Active
|
||||
{
|
||||
get => this._interface.Active;
|
||||
set
|
||||
{
|
||||
if (Main.CaptureModeDisabled || this._interface.Active == value)
|
||||
return;
|
||||
this._interface.ToggleCamera(value);
|
||||
}
|
||||
}
|
||||
|
||||
public bool UsingMap => this.Active && this._interface.UsingMap();
|
||||
|
||||
public void Scrolling() => this._interface.Scrolling();
|
||||
|
||||
public void Update() => this._interface.Update();
|
||||
|
||||
public void Draw(SpriteBatch sb) => this._interface.Draw(sb);
|
||||
|
||||
public float GetProgress() => this._camera.GetProgress();
|
||||
|
||||
public void Capture() => this.Capture(new CaptureSettings()
|
||||
{
|
||||
Area = new Rectangle(2660, 100, 1000, 1000),
|
||||
UseScaling = false
|
||||
});
|
||||
|
||||
public void Capture(CaptureSettings settings) => this._camera.Capture(settings);
|
||||
|
||||
public void DrawTick() => this._camera.DrawTick();
|
||||
}
|
||||
}
|
28
Graphics/Capture/CaptureSettings.cs
Normal file
28
Graphics/Capture/CaptureSettings.cs
Normal file
|
@ -0,0 +1,28 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Capture.CaptureSettings
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
|
||||
namespace Terraria.Graphics.Capture
|
||||
{
|
||||
public class CaptureSettings
|
||||
{
|
||||
public Rectangle Area;
|
||||
public bool UseScaling = true;
|
||||
public string OutputName;
|
||||
public bool CaptureEntities = true;
|
||||
public CaptureBiome Biome = CaptureBiome.Biomes[0];
|
||||
public bool CaptureMech;
|
||||
public bool CaptureBackground;
|
||||
|
||||
public CaptureSettings()
|
||||
{
|
||||
DateTime localTime = DateTime.Now.ToLocalTime();
|
||||
this.OutputName = "Capture " + localTime.Year.ToString("D4") + "-" + localTime.Month.ToString("D2") + "-" + localTime.Day.ToString("D2") + " " + localTime.Hour.ToString("D2") + "_" + localTime.Minute.ToString("D2") + "_" + localTime.Second.ToString("D2");
|
||||
}
|
||||
}
|
||||
}
|
28
Graphics/Effects/CustomSky.cs
Normal file
28
Graphics/Effects/CustomSky.cs
Normal file
|
@ -0,0 +1,28 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Effects.CustomSky
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace Terraria.Graphics.Effects
|
||||
{
|
||||
public abstract class CustomSky : GameEffect
|
||||
{
|
||||
public abstract void Update(GameTime gameTime);
|
||||
|
||||
public abstract void Draw(SpriteBatch spriteBatch, float minDepth, float maxDepth);
|
||||
|
||||
public abstract bool IsActive();
|
||||
|
||||
public abstract void Reset();
|
||||
|
||||
public virtual Color OnTileColor(Color inColor) => inColor;
|
||||
|
||||
public virtual float GetCloudAlpha() => 1f;
|
||||
|
||||
public override bool IsVisible() => true;
|
||||
}
|
||||
}
|
69
Graphics/Effects/EffectManager`1.cs
Normal file
69
Graphics/Effects/EffectManager`1.cs
Normal file
|
@ -0,0 +1,69 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Effects.EffectManager`1
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Terraria.Graphics.Effects
|
||||
{
|
||||
public abstract class EffectManager<T> where T : GameEffect
|
||||
{
|
||||
protected bool _isLoaded;
|
||||
protected Dictionary<string, T> _effects = new Dictionary<string, T>();
|
||||
|
||||
public bool IsLoaded => this._isLoaded;
|
||||
|
||||
public T this[string key]
|
||||
{
|
||||
get
|
||||
{
|
||||
T obj;
|
||||
return this._effects.TryGetValue(key, out obj) ? obj : default (T);
|
||||
}
|
||||
set => this.Bind(key, value);
|
||||
}
|
||||
|
||||
public void Bind(string name, T effect)
|
||||
{
|
||||
this._effects[name] = effect;
|
||||
if (!this._isLoaded)
|
||||
return;
|
||||
effect.Load();
|
||||
}
|
||||
|
||||
public void Load()
|
||||
{
|
||||
if (this._isLoaded)
|
||||
return;
|
||||
this._isLoaded = true;
|
||||
foreach (T obj in this._effects.Values)
|
||||
obj.Load();
|
||||
}
|
||||
|
||||
public T Activate(string name, Vector2 position = default (Vector2), params object[] args)
|
||||
{
|
||||
T effect = this._effects.ContainsKey(name) ? this._effects[name] : throw new MissingEffectException("Unable to find effect named: " + name + ". Type: " + (object) typeof (T) + ".");
|
||||
this.OnActivate(effect, position);
|
||||
effect.Activate(position, args);
|
||||
return effect;
|
||||
}
|
||||
|
||||
public void Deactivate(string name, params object[] args)
|
||||
{
|
||||
T effect = this._effects.ContainsKey(name) ? this._effects[name] : throw new MissingEffectException("Unable to find effect named: " + name + ". Type: " + (object) typeof (T) + ".");
|
||||
this.OnDeactivate(effect);
|
||||
effect.Deactivate(args);
|
||||
}
|
||||
|
||||
public virtual void OnActivate(T effect, Vector2 position)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnDeactivate(T effect)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
17
Graphics/Effects/EffectPriority.cs
Normal file
17
Graphics/Effects/EffectPriority.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Effects.EffectPriority
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
namespace Terraria.Graphics.Effects
|
||||
{
|
||||
public enum EffectPriority
|
||||
{
|
||||
VeryLow,
|
||||
Low,
|
||||
Medium,
|
||||
High,
|
||||
VeryHigh,
|
||||
}
|
||||
}
|
49
Graphics/Effects/Filter.cs
Normal file
49
Graphics/Effects/Filter.cs
Normal file
|
@ -0,0 +1,49 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Effects.Filter
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using Terraria.Graphics.Shaders;
|
||||
|
||||
namespace Terraria.Graphics.Effects
|
||||
{
|
||||
public class Filter : GameEffect
|
||||
{
|
||||
public bool Active;
|
||||
private ScreenShaderData _shader;
|
||||
public bool IsHidden;
|
||||
|
||||
public Filter(ScreenShaderData shader, EffectPriority priority = EffectPriority.VeryLow)
|
||||
{
|
||||
this._shader = shader;
|
||||
this._priority = priority;
|
||||
}
|
||||
|
||||
public void Update(GameTime gameTime)
|
||||
{
|
||||
this._shader.UseGlobalOpacity(this.Opacity);
|
||||
this._shader.Update(gameTime);
|
||||
}
|
||||
|
||||
public void Apply() => this._shader.Apply();
|
||||
|
||||
public ScreenShaderData GetShader() => this._shader;
|
||||
|
||||
internal override void Activate(Vector2 position, params object[] args)
|
||||
{
|
||||
this._shader.UseGlobalOpacity(this.Opacity);
|
||||
this._shader.UseTargetPosition(position);
|
||||
this.Active = true;
|
||||
}
|
||||
|
||||
internal override void Deactivate(params object[] args) => this.Active = false;
|
||||
|
||||
public bool IsInUse() => this.Active || (double) this.Opacity != 0.0;
|
||||
|
||||
public bool IsActive() => this.Active;
|
||||
|
||||
public override bool IsVisible() => (double) this.GetShader().CombinedOpacity > 0.0 && !this.IsHidden;
|
||||
}
|
||||
}
|
193
Graphics/Effects/FilterManager.cs
Normal file
193
Graphics/Effects/FilterManager.cs
Normal file
|
@ -0,0 +1,193 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Effects.FilterManager
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Terraria.IO;
|
||||
|
||||
namespace Terraria.Graphics.Effects
|
||||
{
|
||||
public class FilterManager : EffectManager<Filter>
|
||||
{
|
||||
private const float OPACITY_RATE = 1f;
|
||||
private LinkedList<Filter> _activeFilters = new LinkedList<Filter>();
|
||||
private int _filterLimit = 16;
|
||||
private EffectPriority _priorityThreshold;
|
||||
private int _activeFilterCount;
|
||||
private bool _captureThisFrame;
|
||||
|
||||
public event Action OnPostDraw;
|
||||
|
||||
public FilterManager()
|
||||
{
|
||||
Main.Configuration.OnLoad += (Action<Preferences>) (preferences =>
|
||||
{
|
||||
this._filterLimit = preferences.Get<int>("FilterLimit", 16);
|
||||
EffectPriority result;
|
||||
if (!Enum.TryParse<EffectPriority>(preferences.Get<string>("FilterPriorityThreshold", "VeryLow"), out result))
|
||||
return;
|
||||
this._priorityThreshold = result;
|
||||
});
|
||||
Main.Configuration.OnSave += (Action<Preferences>) (preferences =>
|
||||
{
|
||||
preferences.Put("FilterLimit", (object) this._filterLimit);
|
||||
preferences.Put("FilterPriorityThreshold", (object) Enum.GetName(typeof (EffectPriority), (object) this._priorityThreshold));
|
||||
});
|
||||
}
|
||||
|
||||
public override void OnActivate(Filter effect, Vector2 position)
|
||||
{
|
||||
if (this._activeFilters.Contains(effect))
|
||||
{
|
||||
if (effect.Active)
|
||||
return;
|
||||
if (effect.Priority >= this._priorityThreshold)
|
||||
--this._activeFilterCount;
|
||||
this._activeFilters.Remove(effect);
|
||||
}
|
||||
else
|
||||
effect.Opacity = 0.0f;
|
||||
if (effect.Priority >= this._priorityThreshold)
|
||||
++this._activeFilterCount;
|
||||
if (this._activeFilters.Count == 0)
|
||||
{
|
||||
this._activeFilters.AddLast(effect);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (LinkedListNode<Filter> node = this._activeFilters.First; node != null; node = node.Next)
|
||||
{
|
||||
Filter filter = node.Value;
|
||||
if (effect.Priority <= filter.Priority)
|
||||
{
|
||||
this._activeFilters.AddAfter(node, effect);
|
||||
return;
|
||||
}
|
||||
}
|
||||
this._activeFilters.AddLast(effect);
|
||||
}
|
||||
}
|
||||
|
||||
public void BeginCapture()
|
||||
{
|
||||
if (this._activeFilterCount == 0 && this.OnPostDraw == null)
|
||||
{
|
||||
this._captureThisFrame = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._captureThisFrame = true;
|
||||
Main.instance.GraphicsDevice.SetRenderTarget(Main.screenTarget);
|
||||
Main.instance.GraphicsDevice.Clear(Color.Black);
|
||||
}
|
||||
}
|
||||
|
||||
public void Update(GameTime gameTime)
|
||||
{
|
||||
LinkedListNode<Filter> node = this._activeFilters.First;
|
||||
int count = this._activeFilters.Count;
|
||||
int num = 0;
|
||||
LinkedListNode<Filter> next;
|
||||
for (; node != null; node = next)
|
||||
{
|
||||
Filter filter = node.Value;
|
||||
next = node.Next;
|
||||
bool flag = false;
|
||||
if (filter.Priority >= this._priorityThreshold)
|
||||
{
|
||||
++num;
|
||||
if (num > this._activeFilterCount - this._filterLimit)
|
||||
{
|
||||
filter.Update(gameTime);
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
if (filter.Active & flag)
|
||||
filter.Opacity = Math.Min(filter.Opacity + (float) (gameTime.ElapsedGameTime.TotalSeconds * 1.0), 1f);
|
||||
else
|
||||
filter.Opacity = Math.Max(filter.Opacity - (float) (gameTime.ElapsedGameTime.TotalSeconds * 1.0), 0.0f);
|
||||
if (!filter.Active && (double) filter.Opacity == 0.0)
|
||||
{
|
||||
if (filter.Priority >= this._priorityThreshold)
|
||||
--this._activeFilterCount;
|
||||
this._activeFilters.Remove(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void EndCapture()
|
||||
{
|
||||
if (!this._captureThisFrame)
|
||||
return;
|
||||
LinkedListNode<Filter> linkedListNode = this._activeFilters.First;
|
||||
int count = this._activeFilters.Count;
|
||||
Filter filter1 = (Filter) null;
|
||||
RenderTarget2D renderTarget2D = Main.screenTarget;
|
||||
GraphicsDevice graphicsDevice = Main.instance.GraphicsDevice;
|
||||
int num = 0;
|
||||
if ((double) Main.player[Main.myPlayer].gravDir == -1.0)
|
||||
{
|
||||
RenderTarget2D screenTargetSwap = Main.screenTargetSwap;
|
||||
graphicsDevice.SetRenderTarget(screenTargetSwap);
|
||||
graphicsDevice.Clear(Color.Black);
|
||||
Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone, (Effect) null, Matrix.Invert(Main.GameViewMatrix.EffectMatrix));
|
||||
Main.spriteBatch.Draw((Texture2D) renderTarget2D, Vector2.Zero, Color.White);
|
||||
Main.spriteBatch.End();
|
||||
renderTarget2D = Main.screenTargetSwap;
|
||||
}
|
||||
LinkedListNode<Filter> next;
|
||||
for (; linkedListNode != null; linkedListNode = next)
|
||||
{
|
||||
Filter filter2 = linkedListNode.Value;
|
||||
next = linkedListNode.Next;
|
||||
if (filter2.Priority >= this._priorityThreshold)
|
||||
{
|
||||
++num;
|
||||
if (num > this._activeFilterCount - this._filterLimit && filter2.IsVisible())
|
||||
{
|
||||
if (filter1 != null)
|
||||
{
|
||||
RenderTarget2D renderTarget = renderTarget2D != Main.screenTarget ? Main.screenTarget : Main.screenTargetSwap;
|
||||
graphicsDevice.SetRenderTarget(renderTarget);
|
||||
graphicsDevice.Clear(Color.Black);
|
||||
Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
|
||||
filter1.Apply();
|
||||
Main.spriteBatch.Draw((Texture2D) renderTarget2D, Vector2.Zero, Main.bgColor);
|
||||
Main.spriteBatch.End();
|
||||
renderTarget2D = renderTarget2D != Main.screenTarget ? Main.screenTarget : Main.screenTargetSwap;
|
||||
}
|
||||
filter1 = filter2;
|
||||
}
|
||||
}
|
||||
}
|
||||
graphicsDevice.SetRenderTarget((RenderTarget2D) null);
|
||||
graphicsDevice.Clear(Color.Black);
|
||||
if ((double) Main.player[Main.myPlayer].gravDir == -1.0)
|
||||
Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone, (Effect) null, Main.GameViewMatrix.EffectMatrix);
|
||||
else
|
||||
Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
|
||||
if (filter1 != null)
|
||||
{
|
||||
filter1.Apply();
|
||||
Main.spriteBatch.Draw((Texture2D) renderTarget2D, Vector2.Zero, Main.bgColor);
|
||||
}
|
||||
else
|
||||
Main.spriteBatch.Draw((Texture2D) renderTarget2D, Vector2.Zero, Color.White);
|
||||
Main.spriteBatch.End();
|
||||
for (int index = 0; index < 8; ++index)
|
||||
graphicsDevice.Textures[index] = (Texture) null;
|
||||
if (this.OnPostDraw == null)
|
||||
return;
|
||||
this.OnPostDraw();
|
||||
}
|
||||
|
||||
public bool HasActiveFilter() => (uint) this._activeFilters.Count > 0U;
|
||||
|
||||
public bool CanCapture() => this.HasActiveFilter() || this.OnPostDraw != null;
|
||||
}
|
||||
}
|
13
Graphics/Effects/Filters.cs
Normal file
13
Graphics/Effects/Filters.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Effects.Filters
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
namespace Terraria.Graphics.Effects
|
||||
{
|
||||
public static class Filters
|
||||
{
|
||||
public static FilterManager Scene = new FilterManager();
|
||||
}
|
||||
}
|
39
Graphics/Effects/GameEffect.cs
Normal file
39
Graphics/Effects/GameEffect.cs
Normal file
|
@ -0,0 +1,39 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Effects.GameEffect
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace Terraria.Graphics.Effects
|
||||
{
|
||||
public abstract class GameEffect
|
||||
{
|
||||
public float Opacity;
|
||||
protected bool _isLoaded;
|
||||
protected EffectPriority _priority;
|
||||
|
||||
public bool IsLoaded => this._isLoaded;
|
||||
|
||||
public EffectPriority Priority => this._priority;
|
||||
|
||||
public void Load()
|
||||
{
|
||||
if (this._isLoaded)
|
||||
return;
|
||||
this._isLoaded = true;
|
||||
this.OnLoad();
|
||||
}
|
||||
|
||||
public virtual void OnLoad()
|
||||
{
|
||||
}
|
||||
|
||||
public abstract bool IsVisible();
|
||||
|
||||
internal abstract void Activate(Vector2 position, params object[] args);
|
||||
|
||||
internal abstract void Deactivate(params object[] args);
|
||||
}
|
||||
}
|
18
Graphics/Effects/MissingEffectException.cs
Normal file
18
Graphics/Effects/MissingEffectException.cs
Normal file
|
@ -0,0 +1,18 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Effects.MissingEffectException
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using System;
|
||||
|
||||
namespace Terraria.Graphics.Effects
|
||||
{
|
||||
public class MissingEffectException : Exception
|
||||
{
|
||||
public MissingEffectException(string text)
|
||||
: base(text)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
29
Graphics/Effects/Overlay.cs
Normal file
29
Graphics/Effects/Overlay.cs
Normal file
|
@ -0,0 +1,29 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Effects.Overlay
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace Terraria.Graphics.Effects
|
||||
{
|
||||
public abstract class Overlay : GameEffect
|
||||
{
|
||||
public OverlayMode Mode = OverlayMode.Inactive;
|
||||
private RenderLayers _layer = RenderLayers.All;
|
||||
|
||||
public RenderLayers Layer => this._layer;
|
||||
|
||||
public Overlay(EffectPriority priority, RenderLayers layer)
|
||||
{
|
||||
this._priority = priority;
|
||||
this._layer = layer;
|
||||
}
|
||||
|
||||
public abstract void Draw(SpriteBatch spriteBatch);
|
||||
|
||||
public abstract void Update(GameTime gameTime);
|
||||
}
|
||||
}
|
113
Graphics/Effects/OverlayManager.cs
Normal file
113
Graphics/Effects/OverlayManager.cs
Normal file
|
@ -0,0 +1,113 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Effects.OverlayManager
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Terraria.Graphics.Effects
|
||||
{
|
||||
public class OverlayManager : EffectManager<Overlay>
|
||||
{
|
||||
private const float OPACITY_RATE = 1f;
|
||||
private LinkedList<Overlay>[] _activeOverlays = new LinkedList<Overlay>[Enum.GetNames(typeof (EffectPriority)).Length];
|
||||
private int _overlayCount;
|
||||
|
||||
public OverlayManager()
|
||||
{
|
||||
for (int index = 0; index < this._activeOverlays.Length; ++index)
|
||||
this._activeOverlays[index] = new LinkedList<Overlay>();
|
||||
}
|
||||
|
||||
public override void OnActivate(Overlay overlay, Vector2 position)
|
||||
{
|
||||
LinkedList<Overlay> activeOverlay = this._activeOverlays[(int) overlay.Priority];
|
||||
if (overlay.Mode == OverlayMode.FadeIn || overlay.Mode == OverlayMode.Active)
|
||||
return;
|
||||
if (overlay.Mode == OverlayMode.FadeOut)
|
||||
{
|
||||
activeOverlay.Remove(overlay);
|
||||
--this._overlayCount;
|
||||
}
|
||||
else
|
||||
overlay.Opacity = 0.0f;
|
||||
if (activeOverlay.Count != 0)
|
||||
{
|
||||
foreach (Overlay overlay1 in activeOverlay)
|
||||
overlay1.Mode = OverlayMode.FadeOut;
|
||||
}
|
||||
activeOverlay.AddLast(overlay);
|
||||
++this._overlayCount;
|
||||
}
|
||||
|
||||
public void Update(GameTime gameTime)
|
||||
{
|
||||
LinkedListNode<Overlay> next;
|
||||
for (int index = 0; index < this._activeOverlays.Length; ++index)
|
||||
{
|
||||
for (LinkedListNode<Overlay> node = this._activeOverlays[index].First; node != null; node = next)
|
||||
{
|
||||
Overlay overlay = node.Value;
|
||||
next = node.Next;
|
||||
overlay.Update(gameTime);
|
||||
switch (overlay.Mode)
|
||||
{
|
||||
case OverlayMode.FadeIn:
|
||||
overlay.Opacity += (float) (gameTime.ElapsedGameTime.TotalSeconds * 1.0);
|
||||
if ((double) overlay.Opacity >= 1.0)
|
||||
{
|
||||
overlay.Opacity = 1f;
|
||||
overlay.Mode = OverlayMode.Active;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case OverlayMode.Active:
|
||||
overlay.Opacity = Math.Min(1f, overlay.Opacity + (float) (gameTime.ElapsedGameTime.TotalSeconds * 1.0));
|
||||
break;
|
||||
case OverlayMode.FadeOut:
|
||||
overlay.Opacity -= (float) (gameTime.ElapsedGameTime.TotalSeconds * 1.0);
|
||||
if ((double) overlay.Opacity <= 0.0)
|
||||
{
|
||||
overlay.Opacity = 0.0f;
|
||||
overlay.Mode = OverlayMode.Inactive;
|
||||
this._activeOverlays[index].Remove(node);
|
||||
--this._overlayCount;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, RenderLayers layer)
|
||||
{
|
||||
if (this._overlayCount == 0)
|
||||
return;
|
||||
bool flag = false;
|
||||
for (int index = 0; index < this._activeOverlays.Length; ++index)
|
||||
{
|
||||
for (LinkedListNode<Overlay> linkedListNode = this._activeOverlays[index].First; linkedListNode != null; linkedListNode = linkedListNode.Next)
|
||||
{
|
||||
Overlay overlay = linkedListNode.Value;
|
||||
if (overlay.Layer == layer && overlay.IsVisible())
|
||||
{
|
||||
if (!flag)
|
||||
{
|
||||
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone, (Effect) null, Main.Transform);
|
||||
flag = true;
|
||||
}
|
||||
overlay.Draw(spriteBatch);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!flag)
|
||||
return;
|
||||
spriteBatch.End();
|
||||
}
|
||||
}
|
||||
}
|
16
Graphics/Effects/OverlayMode.cs
Normal file
16
Graphics/Effects/OverlayMode.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Effects.OverlayMode
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
namespace Terraria.Graphics.Effects
|
||||
{
|
||||
public enum OverlayMode
|
||||
{
|
||||
FadeIn,
|
||||
Active,
|
||||
FadeOut,
|
||||
Inactive,
|
||||
}
|
||||
}
|
14
Graphics/Effects/Overlays.cs
Normal file
14
Graphics/Effects/Overlays.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Effects.Overlays
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
namespace Terraria.Graphics.Effects
|
||||
{
|
||||
public static class Overlays
|
||||
{
|
||||
public static OverlayManager Scene = new OverlayManager();
|
||||
public static OverlayManager FilterFallback = new OverlayManager();
|
||||
}
|
||||
}
|
22
Graphics/Effects/RenderLayers.cs
Normal file
22
Graphics/Effects/RenderLayers.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Effects.RenderLayers
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
namespace Terraria.Graphics.Effects
|
||||
{
|
||||
public enum RenderLayers
|
||||
{
|
||||
Sky,
|
||||
Landscape,
|
||||
Background,
|
||||
InWorldUI,
|
||||
BackgroundWater,
|
||||
Walls,
|
||||
TilesAndNPCs,
|
||||
Entities,
|
||||
ForegroundWater,
|
||||
All,
|
||||
}
|
||||
}
|
63
Graphics/Effects/SimpleOverlay.cs
Normal file
63
Graphics/Effects/SimpleOverlay.cs
Normal file
|
@ -0,0 +1,63 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Effects.SimpleOverlay
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Terraria.Graphics.Shaders;
|
||||
|
||||
namespace Terraria.Graphics.Effects
|
||||
{
|
||||
public class SimpleOverlay : Overlay
|
||||
{
|
||||
private Ref<Texture2D> _texture;
|
||||
private ScreenShaderData _shader;
|
||||
public Vector2 TargetPosition = Vector2.Zero;
|
||||
|
||||
public SimpleOverlay(
|
||||
string textureName,
|
||||
ScreenShaderData shader,
|
||||
EffectPriority priority = EffectPriority.VeryLow,
|
||||
RenderLayers layer = RenderLayers.All)
|
||||
: base(priority, layer)
|
||||
{
|
||||
this._texture = TextureManager.AsyncLoad(textureName == null ? "" : textureName);
|
||||
this._shader = shader;
|
||||
}
|
||||
|
||||
public SimpleOverlay(
|
||||
string textureName,
|
||||
string shaderName = "Default",
|
||||
EffectPriority priority = EffectPriority.VeryLow,
|
||||
RenderLayers layer = RenderLayers.All)
|
||||
: base(priority, layer)
|
||||
{
|
||||
this._texture = TextureManager.AsyncLoad(textureName == null ? "" : textureName);
|
||||
this._shader = new ScreenShaderData(Main.ScreenShaderRef, shaderName);
|
||||
}
|
||||
|
||||
public ScreenShaderData GetShader() => this._shader;
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
this._shader.UseGlobalOpacity(this.Opacity);
|
||||
this._shader.UseTargetPosition(this.TargetPosition);
|
||||
this._shader.Apply();
|
||||
spriteBatch.Draw(this._texture.Value, new Rectangle(0, 0, Main.screenWidth, Main.screenHeight), Main.bgColor);
|
||||
}
|
||||
|
||||
public override void Update(GameTime gameTime) => this._shader.Update(gameTime);
|
||||
|
||||
internal override void Activate(Vector2 position, params object[] args)
|
||||
{
|
||||
this.TargetPosition = position;
|
||||
this.Mode = OverlayMode.FadeIn;
|
||||
}
|
||||
|
||||
internal override void Deactivate(params object[] args) => this.Mode = OverlayMode.FadeOut;
|
||||
|
||||
public override bool IsVisible() => (double) this._shader.CombinedOpacity > 0.0;
|
||||
}
|
||||
}
|
86
Graphics/Effects/SkyManager.cs
Normal file
86
Graphics/Effects/SkyManager.cs
Normal file
|
@ -0,0 +1,86 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Effects.SkyManager
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Terraria.Graphics.Effects
|
||||
{
|
||||
public class SkyManager : EffectManager<CustomSky>
|
||||
{
|
||||
public static SkyManager Instance = new SkyManager();
|
||||
private float _lastDepth;
|
||||
private LinkedList<CustomSky> _activeSkies = new LinkedList<CustomSky>();
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
foreach (CustomSky customSky in this._effects.Values)
|
||||
customSky.Reset();
|
||||
this._activeSkies.Clear();
|
||||
}
|
||||
|
||||
public void Update(GameTime gameTime)
|
||||
{
|
||||
LinkedListNode<CustomSky> next;
|
||||
for (LinkedListNode<CustomSky> node = this._activeSkies.First; node != null; node = next)
|
||||
{
|
||||
CustomSky customSky = node.Value;
|
||||
next = node.Next;
|
||||
customSky.Update(gameTime);
|
||||
if (!customSky.IsActive())
|
||||
this._activeSkies.Remove(node);
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch) => this.DrawDepthRange(spriteBatch, float.MinValue, float.MaxValue);
|
||||
|
||||
public void DrawToDepth(SpriteBatch spriteBatch, float minDepth)
|
||||
{
|
||||
if ((double) this._lastDepth <= (double) minDepth)
|
||||
return;
|
||||
this.DrawDepthRange(spriteBatch, minDepth, this._lastDepth);
|
||||
this._lastDepth = minDepth;
|
||||
}
|
||||
|
||||
public void DrawDepthRange(SpriteBatch spriteBatch, float minDepth, float maxDepth)
|
||||
{
|
||||
foreach (CustomSky activeSky in this._activeSkies)
|
||||
activeSky.Draw(spriteBatch, minDepth, maxDepth);
|
||||
}
|
||||
|
||||
public void DrawRemainingDepth(SpriteBatch spriteBatch)
|
||||
{
|
||||
this.DrawDepthRange(spriteBatch, float.MinValue, this._lastDepth);
|
||||
this._lastDepth = float.MinValue;
|
||||
}
|
||||
|
||||
public void ResetDepthTracker() => this._lastDepth = float.MaxValue;
|
||||
|
||||
public void SetStartingDepth(float depth) => this._lastDepth = depth;
|
||||
|
||||
public override void OnActivate(CustomSky effect, Vector2 position)
|
||||
{
|
||||
this._activeSkies.Remove(effect);
|
||||
this._activeSkies.AddLast(effect);
|
||||
}
|
||||
|
||||
public Color ProcessTileColor(Color color)
|
||||
{
|
||||
foreach (CustomSky activeSky in this._activeSkies)
|
||||
color = activeSky.OnTileColor(color);
|
||||
return color;
|
||||
}
|
||||
|
||||
public float ProcessCloudAlpha()
|
||||
{
|
||||
float num = 1f;
|
||||
foreach (CustomSky activeSky in this._activeSkies)
|
||||
num *= activeSky.GetCloudAlpha();
|
||||
return MathHelper.Clamp(num, 0.0f, 1f);
|
||||
}
|
||||
}
|
||||
}
|
98
Graphics/Shaders/ArmorShaderData.cs
Normal file
98
Graphics/Shaders/ArmorShaderData.cs
Normal file
|
@ -0,0 +1,98 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Shaders.ArmorShaderData
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using Terraria.DataStructures;
|
||||
|
||||
namespace Terraria.Graphics.Shaders
|
||||
{
|
||||
public class ArmorShaderData : ShaderData
|
||||
{
|
||||
private Vector3 _uColor = Vector3.One;
|
||||
private Vector3 _uSecondaryColor = Vector3.One;
|
||||
private float _uSaturation = 1f;
|
||||
private float _uOpacity = 1f;
|
||||
private Ref<Texture2D> _uImage;
|
||||
|
||||
public ArmorShaderData(Ref<Effect> shader, string passName)
|
||||
: base(shader, passName)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void Apply(Entity entity, DrawData? drawData = null)
|
||||
{
|
||||
this.Shader.Parameters["uColor"].SetValue(this._uColor);
|
||||
this.Shader.Parameters["uSaturation"].SetValue(this._uSaturation);
|
||||
this.Shader.Parameters["uSecondaryColor"].SetValue(this._uSecondaryColor);
|
||||
this.Shader.Parameters["uTime"].SetValue(Main.GlobalTime);
|
||||
this.Shader.Parameters["uOpacity"].SetValue(this._uOpacity);
|
||||
if (drawData.HasValue)
|
||||
{
|
||||
DrawData drawData1 = drawData.Value;
|
||||
this.Shader.Parameters["uSourceRect"].SetValue(!drawData1.sourceRect.HasValue ? new Vector4(0.0f, 0.0f, (float) drawData1.texture.Width, (float) drawData1.texture.Height) : new Vector4((float) drawData1.sourceRect.Value.X, (float) drawData1.sourceRect.Value.Y, (float) drawData1.sourceRect.Value.Width, (float) drawData1.sourceRect.Value.Height));
|
||||
this.Shader.Parameters["uWorldPosition"].SetValue(Main.screenPosition + drawData1.position);
|
||||
this.Shader.Parameters["uImageSize0"].SetValue(new Vector2((float) drawData1.texture.Width, (float) drawData1.texture.Height));
|
||||
this.Shader.Parameters["uRotation"].SetValue(drawData1.rotation * (drawData1.effect.HasFlag((Enum) SpriteEffects.FlipHorizontally) ? -1f : 1f));
|
||||
this.Shader.Parameters["uDirection"].SetValue(drawData1.effect.HasFlag((Enum) SpriteEffects.FlipHorizontally) ? -1 : 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Shader.Parameters["uSourceRect"].SetValue(new Vector4(0.0f, 0.0f, 4f, 4f));
|
||||
this.Shader.Parameters["uRotation"].SetValue(0.0f);
|
||||
}
|
||||
if (this._uImage != null)
|
||||
{
|
||||
Main.graphics.GraphicsDevice.Textures[1] = (Texture) this._uImage.Value;
|
||||
this.Shader.Parameters["uImageSize1"].SetValue(new Vector2((float) this._uImage.Value.Width, (float) this._uImage.Value.Height));
|
||||
}
|
||||
if (entity != null)
|
||||
this.Shader.Parameters["uDirection"].SetValue((float) entity.direction);
|
||||
this.Apply();
|
||||
}
|
||||
|
||||
public ArmorShaderData UseColor(float r, float g, float b) => this.UseColor(new Vector3(r, g, b));
|
||||
|
||||
public ArmorShaderData UseColor(Color color) => this.UseColor(color.ToVector3());
|
||||
|
||||
public ArmorShaderData UseColor(Vector3 color)
|
||||
{
|
||||
this._uColor = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArmorShaderData UseImage(string path)
|
||||
{
|
||||
this._uImage = TextureManager.AsyncLoad(path);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArmorShaderData UseOpacity(float alpha)
|
||||
{
|
||||
this._uOpacity = alpha;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArmorShaderData UseSecondaryColor(float r, float g, float b) => this.UseSecondaryColor(new Vector3(r, g, b));
|
||||
|
||||
public ArmorShaderData UseSecondaryColor(Color color) => this.UseSecondaryColor(color.ToVector3());
|
||||
|
||||
public ArmorShaderData UseSecondaryColor(Vector3 color)
|
||||
{
|
||||
this._uSecondaryColor = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArmorShaderData UseSaturation(float saturation)
|
||||
{
|
||||
this._uSaturation = saturation;
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual ArmorShaderData GetSecondaryShader(Entity entity) => this;
|
||||
}
|
||||
}
|
47
Graphics/Shaders/ArmorShaderDataSet.cs
Normal file
47
Graphics/Shaders/ArmorShaderDataSet.cs
Normal file
|
@ -0,0 +1,47 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Shaders.ArmorShaderDataSet
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Terraria.DataStructures;
|
||||
|
||||
namespace Terraria.Graphics.Shaders
|
||||
{
|
||||
public class ArmorShaderDataSet
|
||||
{
|
||||
protected List<ArmorShaderData> _shaderData = new List<ArmorShaderData>();
|
||||
protected Dictionary<int, int> _shaderLookupDictionary = new Dictionary<int, int>();
|
||||
protected int _shaderDataCount;
|
||||
|
||||
public T BindShader<T>(int itemId, T shaderData) where T : ArmorShaderData
|
||||
{
|
||||
this._shaderLookupDictionary[itemId] = ++this._shaderDataCount;
|
||||
this._shaderData.Add((ArmorShaderData) shaderData);
|
||||
return shaderData;
|
||||
}
|
||||
|
||||
public void Apply(int shaderId, Entity entity, DrawData? drawData = null)
|
||||
{
|
||||
if (shaderId != 0 && shaderId <= this._shaderDataCount)
|
||||
this._shaderData[shaderId - 1].Apply(entity, drawData);
|
||||
else
|
||||
Main.pixelShader.CurrentTechnique.Passes[0].Apply();
|
||||
}
|
||||
|
||||
public void ApplySecondary(int shaderId, Entity entity, DrawData? drawData = null)
|
||||
{
|
||||
if (shaderId != 0 && shaderId <= this._shaderDataCount)
|
||||
this._shaderData[shaderId - 1].GetSecondaryShader(entity).Apply(entity, drawData);
|
||||
else
|
||||
Main.pixelShader.CurrentTechnique.Passes[0].Apply();
|
||||
}
|
||||
|
||||
public ArmorShaderData GetShaderFromItemId(int type) => this._shaderLookupDictionary.ContainsKey(type) ? this._shaderData[this._shaderLookupDictionary[type] - 1] : (ArmorShaderData) null;
|
||||
|
||||
public int GetShaderIdFromItemId(int type) => this._shaderLookupDictionary.ContainsKey(type) ? this._shaderLookupDictionary[type] : 0;
|
||||
|
||||
public ArmorShaderData GetSecondaryShader(int id, Player player) => id != 0 && id <= this._shaderDataCount && this._shaderData[id - 1] != null ? this._shaderData[id - 1].GetSecondaryShader((Entity) player) : (ArmorShaderData) null;
|
||||
}
|
||||
}
|
17
Graphics/Shaders/GameShaders.cs
Normal file
17
Graphics/Shaders/GameShaders.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Shaders.GameShaders
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Terraria.Graphics.Shaders
|
||||
{
|
||||
public class GameShaders
|
||||
{
|
||||
public static ArmorShaderDataSet Armor = new ArmorShaderDataSet();
|
||||
public static HairShaderDataSet Hair = new HairShaderDataSet();
|
||||
public static Dictionary<string, MiscShaderData> Misc = new Dictionary<string, MiscShaderData>();
|
||||
}
|
||||
}
|
97
Graphics/Shaders/HairShaderData.cs
Normal file
97
Graphics/Shaders/HairShaderData.cs
Normal file
|
@ -0,0 +1,97 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Shaders.HairShaderData
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Terraria.DataStructures;
|
||||
|
||||
namespace Terraria.Graphics.Shaders
|
||||
{
|
||||
public class HairShaderData : ShaderData
|
||||
{
|
||||
protected Vector3 _uColor = Vector3.One;
|
||||
protected Vector3 _uSecondaryColor = Vector3.One;
|
||||
protected float _uSaturation = 1f;
|
||||
protected float _uOpacity = 1f;
|
||||
protected Ref<Texture2D> _uImage;
|
||||
protected bool _shaderDisabled;
|
||||
|
||||
public bool ShaderDisabled => this._shaderDisabled;
|
||||
|
||||
public HairShaderData(Ref<Effect> shader, string passName)
|
||||
: base(shader, passName)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void Apply(Player player, DrawData? drawData = null)
|
||||
{
|
||||
if (this._shaderDisabled)
|
||||
return;
|
||||
this.Shader.Parameters["uColor"].SetValue(this._uColor);
|
||||
this.Shader.Parameters["uSaturation"].SetValue(this._uSaturation);
|
||||
this.Shader.Parameters["uSecondaryColor"].SetValue(this._uSecondaryColor);
|
||||
this.Shader.Parameters["uTime"].SetValue(Main.GlobalTime);
|
||||
this.Shader.Parameters["uOpacity"].SetValue(this._uOpacity);
|
||||
if (drawData.HasValue)
|
||||
{
|
||||
DrawData drawData1 = drawData.Value;
|
||||
this.Shader.Parameters["uSourceRect"].SetValue(new Vector4((float) drawData1.sourceRect.Value.X, (float) drawData1.sourceRect.Value.Y, (float) drawData1.sourceRect.Value.Width, (float) drawData1.sourceRect.Value.Height));
|
||||
this.Shader.Parameters["uWorldPosition"].SetValue(Main.screenPosition + drawData1.position);
|
||||
this.Shader.Parameters["uImageSize0"].SetValue(new Vector2((float) drawData1.texture.Width, (float) drawData1.texture.Height));
|
||||
}
|
||||
else
|
||||
this.Shader.Parameters["uSourceRect"].SetValue(new Vector4(0.0f, 0.0f, 4f, 4f));
|
||||
if (this._uImage != null)
|
||||
{
|
||||
Main.graphics.GraphicsDevice.Textures[1] = (Texture) this._uImage.Value;
|
||||
this.Shader.Parameters["uImageSize1"].SetValue(new Vector2((float) this._uImage.Value.Width, (float) this._uImage.Value.Height));
|
||||
}
|
||||
if (player != null)
|
||||
this.Shader.Parameters["uDirection"].SetValue((float) player.direction);
|
||||
this.Apply();
|
||||
}
|
||||
|
||||
public virtual Color GetColor(Player player, Color lightColor) => new Color(lightColor.ToVector4() * player.hairColor.ToVector4());
|
||||
|
||||
public HairShaderData UseColor(float r, float g, float b) => this.UseColor(new Vector3(r, g, b));
|
||||
|
||||
public HairShaderData UseColor(Color color) => this.UseColor(color.ToVector3());
|
||||
|
||||
public HairShaderData UseColor(Vector3 color)
|
||||
{
|
||||
this._uColor = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HairShaderData UseImage(string path)
|
||||
{
|
||||
this._uImage = TextureManager.AsyncLoad(path);
|
||||
return this;
|
||||
}
|
||||
|
||||
public HairShaderData UseOpacity(float alpha)
|
||||
{
|
||||
this._uOpacity = alpha;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HairShaderData UseSecondaryColor(float r, float g, float b) => this.UseSecondaryColor(new Vector3(r, g, b));
|
||||
|
||||
public HairShaderData UseSecondaryColor(Color color) => this.UseSecondaryColor(color.ToVector3());
|
||||
|
||||
public HairShaderData UseSecondaryColor(Vector3 color)
|
||||
{
|
||||
this._uSecondaryColor = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HairShaderData UseSaturation(float saturation)
|
||||
{
|
||||
this._uSaturation = saturation;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
43
Graphics/Shaders/HairShaderDataSet.cs
Normal file
43
Graphics/Shaders/HairShaderDataSet.cs
Normal file
|
@ -0,0 +1,43 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Shaders.HairShaderDataSet
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Terraria.DataStructures;
|
||||
|
||||
namespace Terraria.Graphics.Shaders
|
||||
{
|
||||
public class HairShaderDataSet
|
||||
{
|
||||
protected List<HairShaderData> _shaderData = new List<HairShaderData>();
|
||||
protected Dictionary<int, short> _shaderLookupDictionary = new Dictionary<int, short>();
|
||||
protected byte _shaderDataCount;
|
||||
|
||||
public T BindShader<T>(int itemId, T shaderData) where T : HairShaderData
|
||||
{
|
||||
if (this._shaderDataCount == byte.MaxValue)
|
||||
throw new Exception("Too many shaders bound.");
|
||||
this._shaderLookupDictionary[itemId] = (short) ++this._shaderDataCount;
|
||||
this._shaderData.Add((HairShaderData) shaderData);
|
||||
return shaderData;
|
||||
}
|
||||
|
||||
public void Apply(short shaderId, Player player, DrawData? drawData = null)
|
||||
{
|
||||
if (shaderId != (short) 0 && (int) shaderId <= (int) this._shaderDataCount)
|
||||
this._shaderData[(int) shaderId - 1].Apply(player, drawData);
|
||||
else
|
||||
Main.pixelShader.CurrentTechnique.Passes[0].Apply();
|
||||
}
|
||||
|
||||
public Color GetColor(short shaderId, Player player, Color lightColor) => shaderId != (short) 0 && (int) shaderId <= (int) this._shaderDataCount ? this._shaderData[(int) shaderId - 1].GetColor(player, lightColor) : new Color(lightColor.ToVector4() * player.hairColor.ToVector4());
|
||||
|
||||
public HairShaderData GetShaderFromItemId(int type) => this._shaderLookupDictionary.ContainsKey(type) ? this._shaderData[(int) this._shaderLookupDictionary[type] - 1] : (HairShaderData) null;
|
||||
|
||||
public short GetShaderIdFromItemId(int type) => this._shaderLookupDictionary.ContainsKey(type) ? this._shaderLookupDictionary[type] : (short) -1;
|
||||
}
|
||||
}
|
93
Graphics/Shaders/MiscShaderData.cs
Normal file
93
Graphics/Shaders/MiscShaderData.cs
Normal file
|
@ -0,0 +1,93 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Shaders.MiscShaderData
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Terraria.DataStructures;
|
||||
|
||||
namespace Terraria.Graphics.Shaders
|
||||
{
|
||||
public class MiscShaderData : ShaderData
|
||||
{
|
||||
private Vector3 _uColor = Vector3.One;
|
||||
private Vector3 _uSecondaryColor = Vector3.One;
|
||||
private float _uSaturation = 1f;
|
||||
private float _uOpacity = 1f;
|
||||
private Ref<Texture2D> _uImage;
|
||||
|
||||
public MiscShaderData(Ref<Effect> shader, string passName)
|
||||
: base(shader, passName)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void Apply(DrawData? drawData = null)
|
||||
{
|
||||
this.Shader.Parameters["uColor"].SetValue(this._uColor);
|
||||
this.Shader.Parameters["uSaturation"].SetValue(this._uSaturation);
|
||||
this.Shader.Parameters["uSecondaryColor"].SetValue(this._uSecondaryColor);
|
||||
this.Shader.Parameters["uTime"].SetValue(Main.GlobalTime);
|
||||
this.Shader.Parameters["uOpacity"].SetValue(this._uOpacity);
|
||||
if (drawData.HasValue)
|
||||
{
|
||||
DrawData drawData1 = drawData.Value;
|
||||
Vector4 vector4 = Vector4.Zero;
|
||||
if (drawData.Value.sourceRect.HasValue)
|
||||
vector4 = new Vector4((float) drawData1.sourceRect.Value.X, (float) drawData1.sourceRect.Value.Y, (float) drawData1.sourceRect.Value.Width, (float) drawData1.sourceRect.Value.Height);
|
||||
this.Shader.Parameters["uSourceRect"].SetValue(vector4);
|
||||
this.Shader.Parameters["uWorldPosition"].SetValue(Main.screenPosition + drawData1.position);
|
||||
this.Shader.Parameters["uImageSize0"].SetValue(new Vector2((float) drawData1.texture.Width, (float) drawData1.texture.Height));
|
||||
}
|
||||
else
|
||||
this.Shader.Parameters["uSourceRect"].SetValue(new Vector4(0.0f, 0.0f, 4f, 4f));
|
||||
if (this._uImage != null)
|
||||
{
|
||||
Main.graphics.GraphicsDevice.Textures[1] = (Texture) this._uImage.Value;
|
||||
this.Shader.Parameters["uImageSize1"].SetValue(new Vector2((float) this._uImage.Value.Width, (float) this._uImage.Value.Height));
|
||||
}
|
||||
this.Apply();
|
||||
}
|
||||
|
||||
public MiscShaderData UseColor(float r, float g, float b) => this.UseColor(new Vector3(r, g, b));
|
||||
|
||||
public MiscShaderData UseColor(Color color) => this.UseColor(color.ToVector3());
|
||||
|
||||
public MiscShaderData UseColor(Vector3 color)
|
||||
{
|
||||
this._uColor = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MiscShaderData UseImage(string path)
|
||||
{
|
||||
this._uImage = TextureManager.AsyncLoad(path);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MiscShaderData UseOpacity(float alpha)
|
||||
{
|
||||
this._uOpacity = alpha;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MiscShaderData UseSecondaryColor(float r, float g, float b) => this.UseSecondaryColor(new Vector3(r, g, b));
|
||||
|
||||
public MiscShaderData UseSecondaryColor(Color color) => this.UseSecondaryColor(color.ToVector3());
|
||||
|
||||
public MiscShaderData UseSecondaryColor(Vector3 color)
|
||||
{
|
||||
this._uSecondaryColor = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MiscShaderData UseSaturation(float saturation)
|
||||
{
|
||||
this._uSaturation = saturation;
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual MiscShaderData GetSecondaryShader(Entity entity) => this;
|
||||
}
|
||||
}
|
175
Graphics/Shaders/ScreenShaderData.cs
Normal file
175
Graphics/Shaders/ScreenShaderData.cs
Normal file
|
@ -0,0 +1,175 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Shaders.ScreenShaderData
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace Terraria.Graphics.Shaders
|
||||
{
|
||||
public class ScreenShaderData : ShaderData
|
||||
{
|
||||
private Vector3 _uColor = Vector3.One;
|
||||
private Vector3 _uSecondaryColor = Vector3.One;
|
||||
private float _uOpacity = 1f;
|
||||
private float _globalOpacity = 1f;
|
||||
private float _uIntensity = 1f;
|
||||
private Vector2 _uTargetPosition = Vector2.One;
|
||||
private Vector2 _uDirection = new Vector2(0.0f, 1f);
|
||||
private float _uProgress;
|
||||
private Vector2 _uImageOffset = Vector2.Zero;
|
||||
private Ref<Texture2D>[] _uImages = new Ref<Texture2D>[3];
|
||||
private SamplerState[] _samplerStates = new SamplerState[3];
|
||||
private Vector2[] _imageScales = new Vector2[3]
|
||||
{
|
||||
Vector2.One,
|
||||
Vector2.One,
|
||||
Vector2.One
|
||||
};
|
||||
|
||||
public float Intensity => this._uIntensity;
|
||||
|
||||
public float CombinedOpacity => this._uOpacity * this._globalOpacity;
|
||||
|
||||
public ScreenShaderData(string passName)
|
||||
: base(Main.ScreenShaderRef, passName)
|
||||
{
|
||||
}
|
||||
|
||||
public ScreenShaderData(Ref<Effect> shader, string passName)
|
||||
: base(shader, passName)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void Update(GameTime gameTime)
|
||||
{
|
||||
}
|
||||
|
||||
public new virtual void Apply()
|
||||
{
|
||||
Vector2 vector2_1 = new Vector2((float) Main.offScreenRange, (float) Main.offScreenRange);
|
||||
Vector2 vector2_2 = new Vector2((float) Main.screenWidth, (float) Main.screenHeight) / Main.GameViewMatrix.Zoom;
|
||||
Vector2 vector2_3 = new Vector2((float) Main.screenWidth, (float) Main.screenHeight) * 0.5f;
|
||||
Vector2 vector2_4 = Main.screenPosition + vector2_3 * (Vector2.One - Vector2.One / Main.GameViewMatrix.Zoom);
|
||||
this.Shader.Parameters["uColor"].SetValue(this._uColor);
|
||||
this.Shader.Parameters["uOpacity"].SetValue(this.CombinedOpacity);
|
||||
this.Shader.Parameters["uSecondaryColor"].SetValue(this._uSecondaryColor);
|
||||
this.Shader.Parameters["uTime"].SetValue(Main.GlobalTime);
|
||||
this.Shader.Parameters["uScreenResolution"].SetValue(vector2_2);
|
||||
this.Shader.Parameters["uScreenPosition"].SetValue(vector2_4 - vector2_1);
|
||||
this.Shader.Parameters["uTargetPosition"].SetValue(this._uTargetPosition - vector2_1);
|
||||
this.Shader.Parameters["uImageOffset"].SetValue(this._uImageOffset);
|
||||
this.Shader.Parameters["uIntensity"].SetValue(this._uIntensity);
|
||||
this.Shader.Parameters["uProgress"].SetValue(this._uProgress);
|
||||
this.Shader.Parameters["uDirection"].SetValue(this._uDirection);
|
||||
this.Shader.Parameters["uZoom"].SetValue(Main.GameViewMatrix.Zoom);
|
||||
for (int index = 0; index < this._uImages.Length; ++index)
|
||||
{
|
||||
if (this._uImages[index] != null && this._uImages[index].Value != null)
|
||||
{
|
||||
Main.graphics.GraphicsDevice.Textures[index + 1] = (Texture) this._uImages[index].Value;
|
||||
int width = this._uImages[index].Value.Width;
|
||||
int height = this._uImages[index].Value.Height;
|
||||
Main.graphics.GraphicsDevice.SamplerStates[index + 1] = this._samplerStates[index] == null ? (!Utils.IsPowerOfTwo(width) || !Utils.IsPowerOfTwo(height) ? SamplerState.AnisotropicClamp : SamplerState.LinearWrap) : this._samplerStates[index];
|
||||
this.Shader.Parameters["uImageSize" + (object) (index + 1)].SetValue(new Vector2((float) width, (float) height) * this._imageScales[index]);
|
||||
}
|
||||
}
|
||||
base.Apply();
|
||||
}
|
||||
|
||||
public ScreenShaderData UseImageOffset(Vector2 offset)
|
||||
{
|
||||
this._uImageOffset = offset;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ScreenShaderData UseIntensity(float intensity)
|
||||
{
|
||||
this._uIntensity = intensity;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ScreenShaderData UseColor(float r, float g, float b) => this.UseColor(new Vector3(r, g, b));
|
||||
|
||||
public ScreenShaderData UseProgress(float progress)
|
||||
{
|
||||
this._uProgress = progress;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ScreenShaderData UseImage(
|
||||
Texture2D image,
|
||||
int index = 0,
|
||||
SamplerState samplerState = null)
|
||||
{
|
||||
this._samplerStates[index] = samplerState;
|
||||
if (this._uImages[index] == null)
|
||||
this._uImages[index] = new Ref<Texture2D>(image);
|
||||
else
|
||||
this._uImages[index].Value = image;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ScreenShaderData UseImage(
|
||||
string path,
|
||||
int index = 0,
|
||||
SamplerState samplerState = null)
|
||||
{
|
||||
this._uImages[index] = TextureManager.AsyncLoad(path);
|
||||
this._samplerStates[index] = samplerState;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ScreenShaderData UseColor(Color color) => this.UseColor(color.ToVector3());
|
||||
|
||||
public ScreenShaderData UseColor(Vector3 color)
|
||||
{
|
||||
this._uColor = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ScreenShaderData UseDirection(Vector2 direction)
|
||||
{
|
||||
this._uDirection = direction;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ScreenShaderData UseGlobalOpacity(float opacity)
|
||||
{
|
||||
this._globalOpacity = opacity;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ScreenShaderData UseTargetPosition(Vector2 position)
|
||||
{
|
||||
this._uTargetPosition = position;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ScreenShaderData UseSecondaryColor(float r, float g, float b) => this.UseSecondaryColor(new Vector3(r, g, b));
|
||||
|
||||
public ScreenShaderData UseSecondaryColor(Color color) => this.UseSecondaryColor(color.ToVector3());
|
||||
|
||||
public ScreenShaderData UseSecondaryColor(Vector3 color)
|
||||
{
|
||||
this._uSecondaryColor = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ScreenShaderData UseOpacity(float opacity)
|
||||
{
|
||||
this._uOpacity = opacity;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ScreenShaderData UseImageScale(Vector2 scale, int index = 0)
|
||||
{
|
||||
this._imageScales[index] = scale;
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual ScreenShaderData GetSecondaryShader(Player player) => this;
|
||||
}
|
||||
}
|
41
Graphics/Shaders/ShaderData.cs
Normal file
41
Graphics/Shaders/ShaderData.cs
Normal file
|
@ -0,0 +1,41 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Shaders.ShaderData
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace Terraria.Graphics.Shaders
|
||||
{
|
||||
public class ShaderData
|
||||
{
|
||||
protected Ref<Effect> _shader;
|
||||
protected string _passName;
|
||||
private EffectPass _effectPass;
|
||||
private Effect _lastEffect;
|
||||
|
||||
public Effect Shader => this._shader != null ? this._shader.Value : (Effect) null;
|
||||
|
||||
public ShaderData(Ref<Effect> shader, string passName)
|
||||
{
|
||||
this._passName = passName;
|
||||
this._shader = shader;
|
||||
}
|
||||
|
||||
public void SwapProgram(string passName)
|
||||
{
|
||||
this._passName = passName;
|
||||
if (passName == null)
|
||||
return;
|
||||
this._effectPass = this.Shader.CurrentTechnique.Passes[passName];
|
||||
}
|
||||
|
||||
protected virtual void Apply()
|
||||
{
|
||||
if (this._shader != null && this._lastEffect != this._shader.Value && this.Shader != null && this._passName != null)
|
||||
this._effectPass = this.Shader.CurrentTechnique.Passes[this._passName];
|
||||
this._effectPass.Apply();
|
||||
}
|
||||
}
|
||||
}
|
128
Graphics/SpriteViewMatrix.cs
Normal file
128
Graphics/SpriteViewMatrix.cs
Normal file
|
@ -0,0 +1,128 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.SpriteViewMatrix
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
|
||||
namespace Terraria.Graphics
|
||||
{
|
||||
public class SpriteViewMatrix
|
||||
{
|
||||
private Vector2 _zoom = Vector2.One;
|
||||
private Vector2 _translation = Vector2.Zero;
|
||||
private Matrix _zoomMatrix = Matrix.Identity;
|
||||
private Matrix _transformationMatrix = Matrix.Identity;
|
||||
private SpriteEffects _effects;
|
||||
private Matrix _effectMatrix;
|
||||
private GraphicsDevice _graphicsDevice;
|
||||
private Viewport _viewport;
|
||||
private bool _overrideSystemViewport;
|
||||
private bool _needsRebuild = true;
|
||||
|
||||
public Vector2 Zoom
|
||||
{
|
||||
get => this._zoom;
|
||||
set
|
||||
{
|
||||
if (!(this._zoom != value))
|
||||
return;
|
||||
this._zoom = value;
|
||||
this._needsRebuild = true;
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2 Translation
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.ShouldRebuild())
|
||||
this.Rebuild();
|
||||
return this._translation;
|
||||
}
|
||||
}
|
||||
|
||||
public Matrix ZoomMatrix
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.ShouldRebuild())
|
||||
this.Rebuild();
|
||||
return this._zoomMatrix;
|
||||
}
|
||||
}
|
||||
|
||||
public Matrix TransformationMatrix
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.ShouldRebuild())
|
||||
this.Rebuild();
|
||||
return this._transformationMatrix;
|
||||
}
|
||||
}
|
||||
|
||||
public SpriteEffects Effects
|
||||
{
|
||||
get => this._effects;
|
||||
set
|
||||
{
|
||||
if (this._effects == value)
|
||||
return;
|
||||
this._effects = value;
|
||||
this._needsRebuild = true;
|
||||
}
|
||||
}
|
||||
|
||||
public Matrix EffectMatrix
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.ShouldRebuild())
|
||||
this.Rebuild();
|
||||
return this._effectMatrix;
|
||||
}
|
||||
}
|
||||
|
||||
public SpriteViewMatrix(GraphicsDevice graphicsDevice) => this._graphicsDevice = graphicsDevice;
|
||||
|
||||
private void Rebuild()
|
||||
{
|
||||
if (!this._overrideSystemViewport)
|
||||
this._viewport = this._graphicsDevice.Viewport;
|
||||
Vector2 vector2_1 = new Vector2((float) this._viewport.Width, (float) this._viewport.Height);
|
||||
Matrix identity = Matrix.Identity;
|
||||
if (this._effects.HasFlag((Enum) SpriteEffects.FlipHorizontally))
|
||||
identity *= Matrix.CreateScale(-1f, 1f, 1f) * Matrix.CreateTranslation(vector2_1.X, 0.0f, 0.0f);
|
||||
if (this._effects.HasFlag((Enum) SpriteEffects.FlipVertically))
|
||||
identity *= Matrix.CreateScale(1f, -1f, 1f) * Matrix.CreateTranslation(0.0f, vector2_1.Y, 0.0f);
|
||||
Vector2 vector2_2 = vector2_1 * 0.5f;
|
||||
Vector2 vector2_3 = vector2_2 - vector2_2 / this._zoom;
|
||||
this._translation = vector2_3;
|
||||
this._zoomMatrix = Matrix.CreateTranslation(-vector2_3.X, -vector2_3.Y, 0.0f) * Matrix.CreateScale(this._zoom.X, this._zoom.Y, 1f);
|
||||
this._effectMatrix = identity;
|
||||
this._transformationMatrix = identity * this._zoomMatrix;
|
||||
this._needsRebuild = false;
|
||||
}
|
||||
|
||||
public void SetViewportOverride(Viewport viewport)
|
||||
{
|
||||
this._viewport = viewport;
|
||||
this._overrideSystemViewport = true;
|
||||
}
|
||||
|
||||
public void ClearViewportOverride() => this._overrideSystemViewport = false;
|
||||
|
||||
private bool ShouldRebuild()
|
||||
{
|
||||
if (this._needsRebuild)
|
||||
return true;
|
||||
if (this._overrideSystemViewport)
|
||||
return false;
|
||||
return this._graphicsDevice.Viewport.Width != this._viewport.Width || this._graphicsDevice.Viewport.Height != this._viewport.Height;
|
||||
}
|
||||
}
|
||||
}
|
87
Graphics/TextureManager.cs
Normal file
87
Graphics/TextureManager.cs
Normal file
|
@ -0,0 +1,87 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.TextureManager
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading;
|
||||
|
||||
namespace Terraria.Graphics
|
||||
{
|
||||
public static class TextureManager
|
||||
{
|
||||
private static ConcurrentDictionary<string, Texture2D> _textures = new ConcurrentDictionary<string, Texture2D>();
|
||||
private static ConcurrentQueue<TextureManager.LoadPair> _loadQueue = new ConcurrentQueue<TextureManager.LoadPair>();
|
||||
private static Thread _loadThread;
|
||||
private static readonly object _loadThreadLock = new object();
|
||||
public static Texture2D BlankTexture;
|
||||
|
||||
public static void Initialize() => TextureManager.BlankTexture = new Texture2D(Main.graphics.GraphicsDevice, 4, 4);
|
||||
|
||||
public static Texture2D Load(string name)
|
||||
{
|
||||
if (TextureManager._textures.ContainsKey(name))
|
||||
return TextureManager._textures[name];
|
||||
Texture2D texture2D = TextureManager.BlankTexture;
|
||||
if (name != "")
|
||||
{
|
||||
if (name != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
texture2D = Main.instance.OurLoad<Texture2D>(name);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
texture2D = TextureManager.BlankTexture;
|
||||
}
|
||||
}
|
||||
}
|
||||
TextureManager._textures[name] = texture2D;
|
||||
return texture2D;
|
||||
}
|
||||
|
||||
public static Ref<Texture2D> AsyncLoad(string name) => new Ref<Texture2D>(TextureManager.Load(name));
|
||||
|
||||
private static void Run(object context)
|
||||
{
|
||||
bool looping = true;
|
||||
Main.instance.Exiting += (EventHandler<EventArgs>) ((obj, args) =>
|
||||
{
|
||||
looping = false;
|
||||
if (!Monitor.TryEnter(TextureManager._loadThreadLock))
|
||||
return;
|
||||
Monitor.Pulse(TextureManager._loadThreadLock);
|
||||
Monitor.Exit(TextureManager._loadThreadLock);
|
||||
});
|
||||
Monitor.Enter(TextureManager._loadThreadLock);
|
||||
while (looping)
|
||||
{
|
||||
if (TextureManager._loadQueue.Count != 0)
|
||||
{
|
||||
TextureManager.LoadPair result;
|
||||
if (TextureManager._loadQueue.TryDequeue(out result))
|
||||
result.TextureRef.Value = TextureManager.Load(result.Path);
|
||||
}
|
||||
else
|
||||
Monitor.Wait(TextureManager._loadThreadLock);
|
||||
}
|
||||
Monitor.Exit(TextureManager._loadThreadLock);
|
||||
}
|
||||
|
||||
private struct LoadPair
|
||||
{
|
||||
public string Path;
|
||||
public Ref<Texture2D> TextureRef;
|
||||
|
||||
public LoadPair(string path, Ref<Texture2D> textureRef)
|
||||
{
|
||||
this.Path = path;
|
||||
this.TextureRef = textureRef;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
368
Graphics/TileBatch.cs
Normal file
368
Graphics/TileBatch.cs
Normal file
|
@ -0,0 +1,368 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.TileBatch
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
|
||||
namespace Terraria.Graphics
|
||||
{
|
||||
public class TileBatch
|
||||
{
|
||||
private static readonly float[] CORNER_OFFSET_X = new float[4]
|
||||
{
|
||||
0.0f,
|
||||
1f,
|
||||
1f,
|
||||
0.0f
|
||||
};
|
||||
private static readonly float[] CORNER_OFFSET_Y = new float[4]
|
||||
{
|
||||
0.0f,
|
||||
0.0f,
|
||||
1f,
|
||||
1f
|
||||
};
|
||||
private GraphicsDevice _graphicsDevice;
|
||||
private TileBatch.SpriteData[] _spriteDataQueue = new TileBatch.SpriteData[2048];
|
||||
private Texture2D[] _spriteTextures;
|
||||
private int _queuedSpriteCount;
|
||||
private SpriteBatch _spriteBatch;
|
||||
private static Vector2 _vector2Zero;
|
||||
private static Rectangle? _nullRectangle;
|
||||
private DynamicVertexBuffer _vertexBuffer;
|
||||
private DynamicIndexBuffer _indexBuffer;
|
||||
private short[] _fallbackIndexData;
|
||||
private VertexPositionColorTexture[] _vertices = new VertexPositionColorTexture[8192];
|
||||
private int _vertexBufferPosition;
|
||||
|
||||
public TileBatch(GraphicsDevice graphicsDevice)
|
||||
{
|
||||
this._graphicsDevice = graphicsDevice;
|
||||
this._spriteBatch = new SpriteBatch(graphicsDevice);
|
||||
this.Allocate();
|
||||
}
|
||||
|
||||
private void Allocate()
|
||||
{
|
||||
if (this._vertexBuffer == null || this._vertexBuffer.IsDisposed)
|
||||
{
|
||||
this._vertexBuffer = new DynamicVertexBuffer(this._graphicsDevice, typeof (VertexPositionColorTexture), 8192, BufferUsage.WriteOnly);
|
||||
this._vertexBufferPosition = 0;
|
||||
this._vertexBuffer.ContentLost += (EventHandler<EventArgs>) ((sender, e) => this._vertexBufferPosition = 0);
|
||||
}
|
||||
if (this._indexBuffer != null && !this._indexBuffer.IsDisposed)
|
||||
return;
|
||||
if (this._fallbackIndexData == null)
|
||||
{
|
||||
this._fallbackIndexData = new short[12288];
|
||||
for (int index = 0; index < 2048; ++index)
|
||||
{
|
||||
this._fallbackIndexData[index * 6] = (short) (index * 4);
|
||||
this._fallbackIndexData[index * 6 + 1] = (short) (index * 4 + 1);
|
||||
this._fallbackIndexData[index * 6 + 2] = (short) (index * 4 + 2);
|
||||
this._fallbackIndexData[index * 6 + 3] = (short) (index * 4);
|
||||
this._fallbackIndexData[index * 6 + 4] = (short) (index * 4 + 2);
|
||||
this._fallbackIndexData[index * 6 + 5] = (short) (index * 4 + 3);
|
||||
}
|
||||
}
|
||||
this._indexBuffer = new DynamicIndexBuffer(this._graphicsDevice, typeof (short), 12288, BufferUsage.WriteOnly);
|
||||
this._indexBuffer.SetData<short>(this._fallbackIndexData);
|
||||
this._indexBuffer.ContentLost += (EventHandler<EventArgs>) ((sender, e) => this._indexBuffer.SetData<short>(this._fallbackIndexData));
|
||||
}
|
||||
|
||||
private void FlushRenderState()
|
||||
{
|
||||
this.Allocate();
|
||||
this._graphicsDevice.SetVertexBuffer((VertexBuffer) this._vertexBuffer);
|
||||
this._graphicsDevice.Indices = (IndexBuffer) this._indexBuffer;
|
||||
this._graphicsDevice.SamplerStates[0] = SamplerState.PointClamp;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (this._vertexBuffer != null)
|
||||
this._vertexBuffer.Dispose();
|
||||
if (this._indexBuffer == null)
|
||||
return;
|
||||
this._indexBuffer.Dispose();
|
||||
}
|
||||
|
||||
public void Begin(Matrix transformation)
|
||||
{
|
||||
this._spriteBatch.Begin(SpriteSortMode.Deferred, (BlendState) null, (SamplerState) null, (DepthStencilState) null, (RasterizerState) null, (Effect) null, transformation);
|
||||
this._spriteBatch.End();
|
||||
}
|
||||
|
||||
public void Begin()
|
||||
{
|
||||
this._spriteBatch.Begin();
|
||||
this._spriteBatch.End();
|
||||
}
|
||||
|
||||
public void Draw(Texture2D texture, Vector2 position, VertexColors colors) => this.InternalDraw(texture, ref new Vector4()
|
||||
{
|
||||
X = position.X,
|
||||
Y = position.Y,
|
||||
Z = 1f,
|
||||
W = 1f
|
||||
}, true, ref TileBatch._nullRectangle, ref colors, ref TileBatch._vector2Zero, SpriteEffects.None, 0.0f);
|
||||
|
||||
public void Draw(
|
||||
Texture2D texture,
|
||||
Vector2 position,
|
||||
Rectangle? sourceRectangle,
|
||||
VertexColors colors,
|
||||
Vector2 origin,
|
||||
float scale,
|
||||
SpriteEffects effects)
|
||||
{
|
||||
this.InternalDraw(texture, ref new Vector4()
|
||||
{
|
||||
X = position.X,
|
||||
Y = position.Y,
|
||||
Z = scale,
|
||||
W = scale
|
||||
}, true, ref sourceRectangle, ref colors, ref origin, effects, 0.0f);
|
||||
}
|
||||
|
||||
public void Draw(Texture2D texture, Vector4 destination, VertexColors colors) => this.InternalDraw(texture, ref destination, false, ref TileBatch._nullRectangle, ref colors, ref TileBatch._vector2Zero, SpriteEffects.None, 0.0f);
|
||||
|
||||
public void Draw(Texture2D texture, Vector2 position, VertexColors colors, Vector2 scale) => this.InternalDraw(texture, ref new Vector4()
|
||||
{
|
||||
X = position.X,
|
||||
Y = position.Y,
|
||||
Z = scale.X,
|
||||
W = scale.Y
|
||||
}, true, ref TileBatch._nullRectangle, ref colors, ref TileBatch._vector2Zero, SpriteEffects.None, 0.0f);
|
||||
|
||||
public void Draw(
|
||||
Texture2D texture,
|
||||
Vector4 destination,
|
||||
Rectangle? sourceRectangle,
|
||||
VertexColors colors)
|
||||
{
|
||||
this.InternalDraw(texture, ref destination, false, ref sourceRectangle, ref colors, ref TileBatch._vector2Zero, SpriteEffects.None, 0.0f);
|
||||
}
|
||||
|
||||
public void Draw(
|
||||
Texture2D texture,
|
||||
Vector4 destination,
|
||||
Rectangle? sourceRectangle,
|
||||
VertexColors colors,
|
||||
Vector2 origin,
|
||||
SpriteEffects effects,
|
||||
float rotation)
|
||||
{
|
||||
this.InternalDraw(texture, ref destination, false, ref sourceRectangle, ref colors, ref origin, effects, rotation);
|
||||
}
|
||||
|
||||
public void Draw(
|
||||
Texture2D texture,
|
||||
Rectangle destinationRectangle,
|
||||
Rectangle? sourceRectangle,
|
||||
VertexColors colors)
|
||||
{
|
||||
this.InternalDraw(texture, ref new Vector4()
|
||||
{
|
||||
X = (float) destinationRectangle.X,
|
||||
Y = (float) destinationRectangle.Y,
|
||||
Z = (float) destinationRectangle.Width,
|
||||
W = (float) destinationRectangle.Height
|
||||
}, false, ref sourceRectangle, ref colors, ref TileBatch._vector2Zero, SpriteEffects.None, 0.0f);
|
||||
}
|
||||
|
||||
private static short[] CreateIndexData()
|
||||
{
|
||||
short[] numArray = new short[12288];
|
||||
for (int index = 0; index < 2048; ++index)
|
||||
{
|
||||
numArray[index * 6] = (short) (index * 4);
|
||||
numArray[index * 6 + 1] = (short) (index * 4 + 1);
|
||||
numArray[index * 6 + 2] = (short) (index * 4 + 2);
|
||||
numArray[index * 6 + 3] = (short) (index * 4);
|
||||
numArray[index * 6 + 4] = (short) (index * 4 + 2);
|
||||
numArray[index * 6 + 5] = (short) (index * 4 + 3);
|
||||
}
|
||||
return numArray;
|
||||
}
|
||||
|
||||
private unsafe void InternalDraw(
|
||||
Texture2D texture,
|
||||
ref Vector4 destination,
|
||||
bool scaleDestination,
|
||||
ref Rectangle? sourceRectangle,
|
||||
ref VertexColors colors,
|
||||
ref Vector2 origin,
|
||||
SpriteEffects effects,
|
||||
float rotation)
|
||||
{
|
||||
if (this._queuedSpriteCount >= this._spriteDataQueue.Length)
|
||||
Array.Resize<TileBatch.SpriteData>(ref this._spriteDataQueue, this._spriteDataQueue.Length << 1);
|
||||
fixed (TileBatch.SpriteData* spriteDataPtr = &this._spriteDataQueue[this._queuedSpriteCount])
|
||||
{
|
||||
float z = destination.Z;
|
||||
float w = destination.W;
|
||||
if (sourceRectangle.HasValue)
|
||||
{
|
||||
Rectangle rectangle = sourceRectangle.Value;
|
||||
spriteDataPtr->Source.X = (float) rectangle.X;
|
||||
spriteDataPtr->Source.Y = (float) rectangle.Y;
|
||||
spriteDataPtr->Source.Z = (float) rectangle.Width;
|
||||
spriteDataPtr->Source.W = (float) rectangle.Height;
|
||||
if (scaleDestination)
|
||||
{
|
||||
z *= (float) rectangle.Width;
|
||||
w *= (float) rectangle.Height;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
float width = (float) texture.Width;
|
||||
float height = (float) texture.Height;
|
||||
spriteDataPtr->Source.X = 0.0f;
|
||||
spriteDataPtr->Source.Y = 0.0f;
|
||||
spriteDataPtr->Source.Z = width;
|
||||
spriteDataPtr->Source.W = height;
|
||||
if (scaleDestination)
|
||||
{
|
||||
z *= width;
|
||||
w *= height;
|
||||
}
|
||||
}
|
||||
spriteDataPtr->Destination.X = destination.X;
|
||||
spriteDataPtr->Destination.Y = destination.Y;
|
||||
spriteDataPtr->Destination.Z = z;
|
||||
spriteDataPtr->Destination.W = w;
|
||||
spriteDataPtr->Origin.X = origin.X;
|
||||
spriteDataPtr->Origin.Y = origin.Y;
|
||||
spriteDataPtr->Effects = effects;
|
||||
spriteDataPtr->Colors = colors;
|
||||
spriteDataPtr->Rotation = rotation;
|
||||
}
|
||||
if (this._spriteTextures == null || this._spriteTextures.Length != this._spriteDataQueue.Length)
|
||||
Array.Resize<Texture2D>(ref this._spriteTextures, this._spriteDataQueue.Length);
|
||||
this._spriteTextures[this._queuedSpriteCount++] = texture;
|
||||
}
|
||||
|
||||
public void End()
|
||||
{
|
||||
if (this._queuedSpriteCount == 0)
|
||||
return;
|
||||
this.FlushRenderState();
|
||||
this.Flush();
|
||||
}
|
||||
|
||||
private void Flush()
|
||||
{
|
||||
Texture2D texture = (Texture2D) null;
|
||||
int offset = 0;
|
||||
for (int index = 0; index < this._queuedSpriteCount; ++index)
|
||||
{
|
||||
if (this._spriteTextures[index] != texture)
|
||||
{
|
||||
if (index > offset)
|
||||
this.RenderBatch(texture, this._spriteDataQueue, offset, index - offset);
|
||||
offset = index;
|
||||
texture = this._spriteTextures[index];
|
||||
}
|
||||
}
|
||||
this.RenderBatch(texture, this._spriteDataQueue, offset, this._queuedSpriteCount - offset);
|
||||
Array.Clear((Array) this._spriteTextures, 0, this._queuedSpriteCount);
|
||||
this._queuedSpriteCount = 0;
|
||||
}
|
||||
|
||||
private unsafe void RenderBatch(
|
||||
Texture2D texture,
|
||||
TileBatch.SpriteData[] sprites,
|
||||
int offset,
|
||||
int count)
|
||||
{
|
||||
this._graphicsDevice.Textures[0] = (Texture) texture;
|
||||
float num1 = 1f / (float) texture.Width;
|
||||
float num2 = 1f / (float) texture.Height;
|
||||
int num3;
|
||||
for (; count > 0; count -= num3)
|
||||
{
|
||||
SetDataOptions options = SetDataOptions.NoOverwrite;
|
||||
num3 = count;
|
||||
if (num3 > 2048 - this._vertexBufferPosition)
|
||||
{
|
||||
num3 = 2048 - this._vertexBufferPosition;
|
||||
if (num3 < 256)
|
||||
{
|
||||
this._vertexBufferPosition = 0;
|
||||
options = SetDataOptions.Discard;
|
||||
num3 = count;
|
||||
if (num3 > 2048)
|
||||
num3 = 2048;
|
||||
}
|
||||
}
|
||||
fixed (TileBatch.SpriteData* spriteDataPtr1 = &sprites[offset])
|
||||
fixed (VertexPositionColorTexture* positionColorTexturePtr1 = &this._vertices[0])
|
||||
{
|
||||
TileBatch.SpriteData* spriteDataPtr2 = spriteDataPtr1;
|
||||
VertexPositionColorTexture* positionColorTexturePtr2 = positionColorTexturePtr1;
|
||||
for (int index1 = 0; index1 < num3; ++index1)
|
||||
{
|
||||
float num4;
|
||||
float num5;
|
||||
if ((double) spriteDataPtr2->Rotation != 0.0)
|
||||
{
|
||||
num4 = (float) Math.Cos((double) spriteDataPtr2->Rotation);
|
||||
num5 = (float) Math.Sin((double) spriteDataPtr2->Rotation);
|
||||
}
|
||||
else
|
||||
{
|
||||
num4 = 1f;
|
||||
num5 = 0.0f;
|
||||
}
|
||||
float num6 = spriteDataPtr2->Origin.X / spriteDataPtr2->Source.Z;
|
||||
float num7 = spriteDataPtr2->Origin.Y / spriteDataPtr2->Source.W;
|
||||
positionColorTexturePtr2->Color = spriteDataPtr2->Colors.TopLeftColor;
|
||||
positionColorTexturePtr2[1].Color = spriteDataPtr2->Colors.TopRightColor;
|
||||
positionColorTexturePtr2[2].Color = spriteDataPtr2->Colors.BottomRightColor;
|
||||
positionColorTexturePtr2[3].Color = spriteDataPtr2->Colors.BottomLeftColor;
|
||||
for (int index2 = 0; index2 < 4; ++index2)
|
||||
{
|
||||
float num8 = TileBatch.CORNER_OFFSET_X[index2];
|
||||
float num9 = TileBatch.CORNER_OFFSET_Y[index2];
|
||||
float num10 = (num8 - num6) * spriteDataPtr2->Destination.Z;
|
||||
float num11 = (num9 - num7) * spriteDataPtr2->Destination.W;
|
||||
float num12 = (float) ((double) spriteDataPtr2->Destination.X + (double) num10 * (double) num4 - (double) num11 * (double) num5);
|
||||
float num13 = (float) ((double) spriteDataPtr2->Destination.Y + (double) num10 * (double) num5 + (double) num11 * (double) num4);
|
||||
if ((spriteDataPtr2->Effects & SpriteEffects.FlipVertically) != SpriteEffects.None)
|
||||
num8 = 1f - num8;
|
||||
if ((spriteDataPtr2->Effects & SpriteEffects.FlipHorizontally) != SpriteEffects.None)
|
||||
num9 = 1f - num9;
|
||||
positionColorTexturePtr2->Position.X = num12;
|
||||
positionColorTexturePtr2->Position.Y = num13;
|
||||
positionColorTexturePtr2->Position.Z = 0.0f;
|
||||
positionColorTexturePtr2->TextureCoordinate.X = (spriteDataPtr2->Source.X + num8 * spriteDataPtr2->Source.Z) * num1;
|
||||
positionColorTexturePtr2->TextureCoordinate.Y = (spriteDataPtr2->Source.Y + num9 * spriteDataPtr2->Source.W) * num2;
|
||||
++positionColorTexturePtr2;
|
||||
}
|
||||
++spriteDataPtr2;
|
||||
}
|
||||
}
|
||||
this._vertexBuffer.SetData<VertexPositionColorTexture>(this._vertexBufferPosition * sizeof (VertexPositionColorTexture) * 4, this._vertices, 0, num3 * 4, sizeof (VertexPositionColorTexture), options);
|
||||
this._graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, this._vertexBufferPosition * 4, num3 * 4, this._vertexBufferPosition * 6, num3 * 2);
|
||||
this._vertexBufferPosition += num3;
|
||||
offset += num3;
|
||||
}
|
||||
}
|
||||
|
||||
private struct SpriteData
|
||||
{
|
||||
public Vector4 Source;
|
||||
public Vector4 Destination;
|
||||
public Vector2 Origin;
|
||||
public SpriteEffects Effects;
|
||||
public VertexColors Colors;
|
||||
public float Rotation;
|
||||
}
|
||||
}
|
||||
}
|
34
Graphics/VertexColors.cs
Normal file
34
Graphics/VertexColors.cs
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.VertexColors
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace Terraria.Graphics
|
||||
{
|
||||
public struct VertexColors
|
||||
{
|
||||
public Color TopLeftColor;
|
||||
public Color TopRightColor;
|
||||
public Color BottomLeftColor;
|
||||
public Color BottomRightColor;
|
||||
|
||||
public VertexColors(Color color)
|
||||
{
|
||||
this.TopLeftColor = color;
|
||||
this.TopRightColor = color;
|
||||
this.BottomRightColor = color;
|
||||
this.BottomLeftColor = color;
|
||||
}
|
||||
|
||||
public VertexColors(Color topLeft, Color topRight, Color bottomRight, Color bottomLeft)
|
||||
{
|
||||
this.TopLeftColor = topLeft;
|
||||
this.TopRightColor = topRight;
|
||||
this.BottomLeftColor = bottomLeft;
|
||||
this.BottomRightColor = bottomRight;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue