Terraria 1.4.0.5 Source Code

This commit is contained in:
MikeyIsBaeYT 2021-10-26 12:45:26 -04:00
commit 05205f009e
1059 changed files with 563450 additions and 0 deletions

13
Map/IMapLayer.cs Normal file
View file

@ -0,0 +1,13 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Map.IMapLayer
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
namespace Terraria.Map
{
public interface IMapLayer
{
void Draw(ref MapOverlayDrawContext context, ref string text);
}
}

2980
Map/MapHelper.cs Normal file

File diff suppressed because it is too large Load diff

35
Map/MapIconOverlay.cs Normal file
View file

@ -0,0 +1,35 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Map.MapIconOverlay
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// 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.Map
{
public class MapIconOverlay
{
private readonly List<IMapLayer> _layers = new List<IMapLayer>();
public MapIconOverlay AddLayer(IMapLayer layer)
{
this._layers.Add(layer);
return this;
}
public void Draw(
Vector2 mapPosition,
Vector2 mapOffset,
Rectangle? clippingRect,
float mapScale,
float drawScale,
ref string text)
{
MapOverlayDrawContext context = new MapOverlayDrawContext(mapPosition, mapOffset, clippingRect, mapScale, drawScale);
foreach (IMapLayer layer in this._layers)
layer.Draw(ref context, ref text);
}
}
}

View file

@ -0,0 +1,93 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Map.MapOverlayDrawContext
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// 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;
using Terraria.UI;
namespace Terraria.Map
{
public struct MapOverlayDrawContext
{
private readonly Vector2 _mapPosition;
private readonly Vector2 _mapOffset;
private readonly Rectangle? _clippingRect;
private readonly float _mapScale;
private readonly float _drawScale;
public MapOverlayDrawContext(
Vector2 mapPosition,
Vector2 mapOffset,
Rectangle? clippingRect,
float mapScale,
float drawScale)
{
this._mapPosition = mapPosition;
this._mapOffset = mapOffset;
this._clippingRect = clippingRect;
this._mapScale = mapScale;
this._drawScale = drawScale;
}
public MapOverlayDrawContext.DrawResult Draw(
Texture2D texture,
Vector2 position,
Alignment alignment)
{
return this.Draw(texture, position, new SpriteFrame((byte) 1, (byte) 1), alignment);
}
public MapOverlayDrawContext.DrawResult Draw(
Texture2D texture,
Vector2 position,
SpriteFrame frame,
Alignment alignment)
{
position = (position - this._mapPosition) * this._mapScale + this._mapOffset;
if (this._clippingRect.HasValue && !this._clippingRect.Value.Contains(position.ToPoint()))
return MapOverlayDrawContext.DrawResult.Culled;
Rectangle sourceRectangle = frame.GetSourceRectangle(texture);
Vector2 origin = sourceRectangle.Size() * alignment.OffsetMultiplier;
Main.spriteBatch.Draw(texture, position, new Rectangle?(sourceRectangle), Color.White, 0.0f, origin, this._drawScale, SpriteEffects.None, 0.0f);
position -= origin * this._drawScale;
return new MapOverlayDrawContext.DrawResult(new Rectangle((int) position.X, (int) position.Y, (int) ((double) texture.Width * (double) this._drawScale), (int) ((double) texture.Height * (double) this._drawScale)).Contains(Main.MouseScreen.ToPoint()));
}
public MapOverlayDrawContext.DrawResult Draw(
Texture2D texture,
Vector2 position,
Color color,
SpriteFrame frame,
float scaleIfNotSelected,
float scaleIfSelected,
Alignment alignment)
{
position = (position - this._mapPosition) * this._mapScale + this._mapOffset;
if (this._clippingRect.HasValue && !this._clippingRect.Value.Contains(position.ToPoint()))
return MapOverlayDrawContext.DrawResult.Culled;
Rectangle sourceRectangle = frame.GetSourceRectangle(texture);
Vector2 origin = sourceRectangle.Size() * alignment.OffsetMultiplier;
Vector2 position1 = position;
float num1 = this._drawScale * scaleIfNotSelected;
Vector2 vector2 = position - origin * num1;
int num2 = new Rectangle((int) vector2.X, (int) vector2.Y, (int) ((double) sourceRectangle.Width * (double) num1), (int) ((double) sourceRectangle.Height * (double) num1)).Contains(Main.MouseScreen.ToPoint()) ? 1 : 0;
float scale = num1;
if (num2 != 0)
scale = this._drawScale * scaleIfSelected;
Main.spriteBatch.Draw(texture, position1, new Rectangle?(sourceRectangle), color, 0.0f, origin, scale, SpriteEffects.None, 0.0f);
return new MapOverlayDrawContext.DrawResult(num2 != 0);
}
public struct DrawResult
{
public static readonly MapOverlayDrawContext.DrawResult Culled = new MapOverlayDrawContext.DrawResult(false);
public readonly bool IsMouseOver;
public DrawResult(bool isMouseOver) => this.IsMouseOver = isMouseOver;
}
}
}

55
Map/MapTile.cs Normal file
View file

@ -0,0 +1,55 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Map.MapTile
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
namespace Terraria.Map
{
public struct MapTile
{
public ushort Type;
public byte Light;
private byte _extraData;
public bool IsChanged
{
get => ((int) this._extraData & 128) == 128;
set
{
if (value)
this._extraData |= (byte) 128;
else
this._extraData &= (byte) 127;
}
}
public byte Color
{
get => (byte) ((uint) this._extraData & (uint) sbyte.MaxValue);
set => this._extraData = (byte) ((int) this._extraData & 128 | (int) value & (int) sbyte.MaxValue);
}
private MapTile(ushort type, byte light, byte extraData)
{
this.Type = type;
this.Light = light;
this._extraData = extraData;
}
public bool Equals(ref MapTile other) => (int) this.Light == (int) other.Light && (int) this.Type == (int) other.Type && (int) this.Color == (int) other.Color;
public bool EqualsWithoutLight(ref MapTile other) => (int) this.Type == (int) other.Type && (int) this.Color == (int) other.Color;
public void Clear()
{
this.Type = (ushort) 0;
this.Light = (byte) 0;
this._extraData = (byte) 0;
}
public MapTile WithLight(byte light) => new MapTile(this.Type, light, (byte) ((uint) this._extraData | 128U));
public static MapTile Create(ushort type, byte light, byte color) => new MapTile(type, light, (byte) ((uint) color | 128U));
}
}

58
Map/PingMapLayer.cs Normal file
View file

@ -0,0 +1,58 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Map.PingMapLayer
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using ReLogic.Utilities;
using System;
using System.Collections.Generic;
using Terraria.DataStructures;
using Terraria.GameContent;
using Terraria.UI;
namespace Terraria.Map
{
public class PingMapLayer : IMapLayer
{
private const double PING_DURATION_IN_SECONDS = 15.0;
private const double PING_FRAME_RATE = 10.0;
private readonly SlotVector<PingMapLayer.Ping> _pings = new SlotVector<PingMapLayer.Ping>(100);
public void Draw(ref MapOverlayDrawContext context, ref string text)
{
SpriteFrame frame = new SpriteFrame((byte) 1, (byte) 5);
DateTime now = DateTime.Now;
foreach (SlotVector<PingMapLayer.Ping>.ItemPair ping1 in (IEnumerable<SlotVector<PingMapLayer.Ping>.ItemPair>) this._pings)
{
PingMapLayer.Ping ping2 = (PingMapLayer.Ping) ping1.Value;
double totalSeconds = (now - ping2.Time).TotalSeconds;
int num = (int) (totalSeconds * 10.0);
frame.CurrentRow = (byte) ((uint) num % (uint) frame.RowCount);
context.Draw(TextureAssets.MapPing.Value, ping2.Position, frame, Alignment.Center);
if (totalSeconds > 15.0)
this._pings.Remove((SlotId) ping1.Id);
}
}
public void Add(Vector2 position)
{
if (this._pings.Count == this._pings.Capacity)
return;
this._pings.Add(new PingMapLayer.Ping(position));
}
private struct Ping
{
public readonly Vector2 Position;
public readonly DateTime Time;
public Ping(Vector2 position)
{
this.Position = position;
this.Time = DateTime.Now;
}
}
}
}

28
Map/SpawnMapLayer.cs Normal file
View file

@ -0,0 +1,28 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Map.SpawnMapLayer
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using Terraria.GameContent;
using Terraria.Localization;
using Terraria.UI;
namespace Terraria.Map
{
public class SpawnMapLayer : IMapLayer
{
public void Draw(ref MapOverlayDrawContext context, ref string text)
{
Player localPlayer = Main.LocalPlayer;
Vector2 position1 = new Vector2((float) localPlayer.SpawnX, (float) localPlayer.SpawnY);
Vector2 position2 = new Vector2((float) Main.spawnTileX, (float) Main.spawnTileY);
if (context.Draw(TextureAssets.SpawnPoint.Value, position2, Alignment.Bottom).IsMouseOver)
text = Language.GetTextValue("UI.SpawnPoint");
if (localPlayer.SpawnX == -1 || !context.Draw(TextureAssets.SpawnBed.Value, position1, Alignment.Bottom).IsMouseOver)
return;
text = Language.GetTextValue("UI.SpawnBed");
}
}
}

View file

@ -0,0 +1,52 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Map.TeleportPylonsMapLayer
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// 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;
using Terraria.Audio;
using Terraria.DataStructures;
using Terraria.GameContent;
using Terraria.GameContent.Tile_Entities;
using Terraria.UI;
namespace Terraria.Map
{
public class TeleportPylonsMapLayer : IMapLayer
{
public void Draw(ref MapOverlayDrawContext context, ref string text)
{
List<TeleportPylonInfo> pylons = Main.PylonSystem.Pylons;
float scaleIfNotSelected = 1f;
float scaleIfSelected = scaleIfNotSelected * 2f;
Texture2D texture = TextureAssets.Extra[182].Value;
int num = TeleportPylonsSystem.IsPlayerNearAPylon(Main.LocalPlayer) ? 1 : 0;
Color color = Color.White;
if (num == 0)
color = Color.Gray * 0.5f;
for (int index = 0; index < pylons.Count; ++index)
{
TeleportPylonInfo info = pylons[index];
if (context.Draw(texture, info.PositionInTiles.ToVector2() + new Vector2(1.5f, 2f), color, new SpriteFrame((byte) 9, (byte) 1, (byte) info.TypeOfPylon, (byte) 0)
{
PaddingY = 0
}, scaleIfNotSelected, scaleIfSelected, Alignment.Center).IsMouseOver)
{
Main.cancelWormHole = true;
string itemNameValue = Lang.GetItemNameValue(TETeleportationPylon.GetPylonItemTypeFromTileStyle((int) info.TypeOfPylon));
text = itemNameValue;
if (Main.mouseLeft && Main.mouseLeftRelease)
{
Main.mouseLeftRelease = false;
Main.mapFullscreen = false;
Main.PylonSystem.RequestTeleportation(info, Main.LocalPlayer);
SoundEngine.PlaySound(11);
}
}
}
}
}
}

158
Map/WorldMap.cs Normal file
View file

@ -0,0 +1,158 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Map.WorldMap
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using System;
using System.IO;
using Terraria.IO;
using Terraria.Social;
using Terraria.Utilities;
namespace Terraria.Map
{
public class WorldMap
{
public readonly int MaxWidth;
public readonly int MaxHeight;
public readonly int BlackEdgeWidth = 40;
private MapTile[,] _tiles;
public MapTile this[int x, int y] => this._tiles[x, y];
public WorldMap(int maxWidth, int maxHeight)
{
this.MaxWidth = maxWidth;
this.MaxHeight = maxHeight;
this._tiles = new MapTile[this.MaxWidth, this.MaxHeight];
}
public void ConsumeUpdate(int x, int y) => this._tiles[x, y].IsChanged = false;
public void Update(int x, int y, byte light) => this._tiles[x, y] = MapHelper.CreateMapTile(x, y, light);
public void SetTile(int x, int y, ref MapTile tile) => this._tiles[x, y] = tile;
public bool IsRevealed(int x, int y) => this._tiles[x, y].Light > (byte) 0;
public bool UpdateLighting(int x, int y, byte light)
{
MapTile tile = this._tiles[x, y];
if (light == (byte) 0 && tile.Light == (byte) 0)
return false;
MapTile mapTile = MapHelper.CreateMapTile(x, y, Math.Max(tile.Light, light));
if (mapTile.Equals(ref tile))
return false;
this._tiles[x, y] = mapTile;
return true;
}
public bool UpdateType(int x, int y)
{
MapTile mapTile = MapHelper.CreateMapTile(x, y, this._tiles[x, y].Light);
if (mapTile.Equals(ref this._tiles.Address(x, y)))
return false;
this._tiles[x, y] = mapTile;
return true;
}
public void UnlockMapSection(int sectionX, int sectionY)
{
}
public void Load()
{
Lighting.Clear();
bool isCloudSave = Main.ActivePlayerFileData.IsCloudSave;
if (isCloudSave && SocialAPI.Cloud == null || !Main.mapEnabled)
return;
string str1 = Main.playerPathName.Substring(0, Main.playerPathName.Length - 4) + Path.DirectorySeparatorChar.ToString();
string str2;
if (Main.ActiveWorldFileData.UseGuidAsMapName)
{
string str3 = str1;
str2 = str1 + (object) Main.ActiveWorldFileData.UniqueId + ".map";
if (!FileUtilities.Exists(str2, isCloudSave))
str2 = str3 + (object) Main.worldID + ".map";
}
else
str2 = str1 + (object) Main.worldID + ".map";
if (!FileUtilities.Exists(str2, isCloudSave))
{
Main.MapFileMetadata = FileMetadata.FromCurrentSettings(FileType.Map);
}
else
{
using (MemoryStream memoryStream = new MemoryStream(FileUtilities.ReadAllBytes(str2, isCloudSave)))
{
using (BinaryReader fileIO = new BinaryReader((Stream) memoryStream))
{
try
{
int release = fileIO.ReadInt32();
if (release > 230)
return;
if (release <= 91)
MapHelper.LoadMapVersion1(fileIO, release);
else
MapHelper.LoadMapVersion2(fileIO, release);
this.ClearEdges();
Main.clearMap = true;
Main.loadMap = true;
Main.loadMapLock = true;
Main.refreshMap = false;
}
catch (Exception ex)
{
using (StreamWriter streamWriter = new StreamWriter("client-crashlog.txt", true))
{
streamWriter.WriteLine((object) DateTime.Now);
streamWriter.WriteLine((object) ex);
streamWriter.WriteLine("");
}
if (!isCloudSave)
File.Copy(str2, str2 + ".bad", true);
this.Clear();
}
}
}
}
}
public void Save() => MapHelper.SaveMap();
public void Clear()
{
for (int index1 = 0; index1 < this.MaxWidth; ++index1)
{
for (int index2 = 0; index2 < this.MaxHeight; ++index2)
this._tiles[index1, index2].Clear();
}
}
public void ClearEdges()
{
for (int index1 = 0; index1 < this.MaxWidth; ++index1)
{
for (int index2 = 0; index2 < this.BlackEdgeWidth; ++index2)
this._tiles[index1, index2].Clear();
}
for (int index3 = 0; index3 < this.MaxWidth; ++index3)
{
for (int index4 = this.MaxHeight - this.BlackEdgeWidth; index4 < this.MaxHeight; ++index4)
this._tiles[index3, index4].Clear();
}
for (int index = 0; index < this.BlackEdgeWidth; ++index)
{
for (int blackEdgeWidth = this.BlackEdgeWidth; blackEdgeWidth < this.MaxHeight - this.BlackEdgeWidth; ++blackEdgeWidth)
this._tiles[index, blackEdgeWidth].Clear();
}
for (int index = this.MaxWidth - this.BlackEdgeWidth; index < this.MaxWidth; ++index)
{
for (int blackEdgeWidth = this.BlackEdgeWidth; blackEdgeWidth < this.MaxHeight - this.BlackEdgeWidth; ++blackEdgeWidth)
this._tiles[index, blackEdgeWidth].Clear();
}
}
}
}