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

Binary file not shown.
Can't render this file because it is too large.

89
IO/FavoritesFile.cs Normal file
View file

@ -0,0 +1,89 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.IO.FavoritesFile
// 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 Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
using Terraria.UI;
using Terraria.Utilities;
namespace Terraria.IO
{
public class FavoritesFile
{
public readonly string Path;
public readonly bool IsCloudSave;
private Dictionary<string, Dictionary<string, bool>> _data = new Dictionary<string, Dictionary<string, bool>>();
public FavoritesFile(string path, bool isCloud)
{
this.Path = path;
this.IsCloudSave = isCloud;
}
public void SaveFavorite(FileData fileData)
{
if (!this._data.ContainsKey(fileData.Type))
this._data.Add(fileData.Type, new Dictionary<string, bool>());
this._data[fileData.Type][fileData.GetFileName()] = fileData.IsFavorite;
this.Save();
}
public void ClearEntry(FileData fileData)
{
if (!this._data.ContainsKey(fileData.Type))
return;
this._data[fileData.Type].Remove(fileData.GetFileName());
this.Save();
}
public bool IsFavorite(FileData fileData)
{
if (!this._data.ContainsKey(fileData.Type))
return false;
string fileName = fileData.GetFileName();
bool flag;
return this._data[fileData.Type].TryGetValue(fileName, out flag) && flag;
}
public void Save()
{
try
{
FileUtilities.WriteAllBytes(this.Path, Encoding.ASCII.GetBytes(JsonConvert.SerializeObject((object) this._data, (Formatting) 1)), this.IsCloudSave);
}
catch (Exception ex)
{
string path = this.Path;
FancyErrorPrinter.ShowFileSavingFailError(ex, path);
throw;
}
}
public void Load()
{
if (!FileUtilities.Exists(this.Path, this.IsCloudSave))
{
this._data.Clear();
}
else
{
try
{
this._data = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, bool>>>(Encoding.ASCII.GetString(FileUtilities.ReadAllBytes(this.Path, this.IsCloudSave)));
if (this._data != null)
return;
this._data = new Dictionary<string, Dictionary<string, bool>>();
}
catch (Exception ex)
{
Console.WriteLine("Unable to load favorites.json file ({0} : {1})", (object) this.Path, this.IsCloudSave ? (object) "Cloud Save" : (object) "Local Save");
}
}
}
}
}

54
IO/FileData.cs Normal file
View file

@ -0,0 +1,54 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.IO.FileData
// 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 Terraria.Utilities;
namespace Terraria.IO
{
public abstract class FileData
{
protected string _path;
protected bool _isCloudSave;
public FileMetadata Metadata;
public string Name;
public readonly string Type;
protected bool _isFavorite;
public string Path => this._path;
public bool IsCloudSave => this._isCloudSave;
public bool IsFavorite => this._isFavorite;
protected FileData(string type) => this.Type = type;
protected FileData(string type, string path, bool isCloud)
{
this.Type = type;
this._path = path;
this._isCloudSave = isCloud;
this._isFavorite = (isCloud ? Main.CloudFavoritesData : Main.LocalFavoriteData).IsFavorite(this);
}
public void ToggleFavorite() => this.SetFavorite(!this.IsFavorite);
public string GetFileName(bool includeExtension = true) => FileUtilities.GetFileName(this.Path, includeExtension);
public void SetFavorite(bool favorite, bool saveChanges = true)
{
this._isFavorite = favorite;
if (!saveChanges)
return;
(this.IsCloudSave ? Main.CloudFavoritesData : Main.LocalFavoriteData).SaveFavorite(this);
}
public abstract void SetAsActive();
public abstract void MoveToCloud();
public abstract void MoveToLocal();
}
}

74
IO/FileMetadata.cs Normal file
View file

@ -0,0 +1,74 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.IO.FileMetadata
// 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;
namespace Terraria.IO
{
public class FileMetadata
{
public const ulong MAGIC_NUMBER = 27981915666277746;
public const int SIZE = 20;
public FileType Type;
public uint Revision;
public bool IsFavorite;
private FileMetadata()
{
}
public void Write(BinaryWriter writer)
{
writer.Write((ulong) (27981915666277746L | (long) this.Type << 56));
writer.Write(this.Revision);
writer.Write((ulong) (this.IsFavorite.ToInt() & 1 | 0));
}
public void IncrementAndWrite(BinaryWriter writer)
{
++this.Revision;
this.Write(writer);
}
public static FileMetadata FromCurrentSettings(FileType type) => new FileMetadata()
{
Type = type,
Revision = 0,
IsFavorite = false
};
public static FileMetadata Read(BinaryReader reader, FileType expectedType)
{
FileMetadata fileMetadata = new FileMetadata();
fileMetadata.Read(reader);
if (fileMetadata.Type != expectedType)
throw new FileFormatException("Expected type \"" + Enum.GetName(typeof (FileType), (object) expectedType) + "\" but found \"" + Enum.GetName(typeof (FileType), (object) fileMetadata.Type) + "\".");
return fileMetadata;
}
private void Read(BinaryReader reader)
{
long num1 = (long) reader.ReadUInt64();
if ((num1 & 72057594037927935L) != 27981915666277746L)
throw new FileFormatException("Expected Re-Logic file format.");
byte num2 = (byte) ((ulong) num1 >> 56 & (ulong) byte.MaxValue);
FileType fileType = FileType.None;
FileType[] values = (FileType[]) Enum.GetValues(typeof (FileType));
for (int index = 0; index < values.Length; ++index)
{
if (values[index] == (FileType) num2)
{
fileType = values[index];
break;
}
}
this.Type = fileType != FileType.None ? fileType : throw new FileFormatException("Found invalid file type.");
this.Revision = reader.ReadUInt32();
this.IsFavorite = ((long) reader.ReadUInt64() & 1L) == 1L;
}
}
}

16
IO/FileType.cs Normal file
View file

@ -0,0 +1,16 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.IO.FileType
// 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.IO
{
public enum FileType : byte
{
None,
Map,
World,
Player,
}
}

19
IO/GameConfiguration.cs Normal file
View file

@ -0,0 +1,19 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.IO.GameConfiguration
// 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 Newtonsoft.Json.Linq;
namespace Terraria.IO
{
public class GameConfiguration
{
private readonly JObject _root;
public GameConfiguration(JObject configurationRoot) => this._root = configurationRoot;
public T Get<T>(string entry) => this._root[entry].ToObject<T>();
}
}

156
IO/PlayerFileData.cs Normal file
View file

@ -0,0 +1,156 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.IO.PlayerFileData
// 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.Diagnostics;
using System.IO;
using System.Linq;
using Terraria.Social;
using Terraria.Utilities;
namespace Terraria.IO
{
public class PlayerFileData : FileData
{
private Player _player;
private TimeSpan _playTime = TimeSpan.Zero;
private readonly Stopwatch _timer = new Stopwatch();
private bool _isTimerActive;
public Player Player
{
get => this._player;
set
{
this._player = value;
if (value == null)
return;
this.Name = this._player.name;
}
}
public PlayerFileData()
: base(nameof (Player))
{
}
public PlayerFileData(string path, bool cloudSave)
: base(nameof (Player), path, cloudSave)
{
}
public static PlayerFileData CreateAndSave(Player player)
{
PlayerFileData playerFile = new PlayerFileData();
playerFile.Metadata = FileMetadata.FromCurrentSettings(FileType.Player);
playerFile.Player = player;
playerFile._isCloudSave = SocialAPI.Cloud != null && SocialAPI.Cloud.EnabledByDefault;
playerFile._path = Main.GetPlayerPathFromName(player.name, playerFile.IsCloudSave);
(playerFile.IsCloudSave ? Main.CloudFavoritesData : Main.LocalFavoriteData).ClearEntry((FileData) playerFile);
Player.SavePlayer(playerFile, true);
return playerFile;
}
public override void SetAsActive()
{
Main.ActivePlayerFileData = this;
Main.player[Main.myPlayer] = this.Player;
}
public override void MoveToCloud()
{
if (this.IsCloudSave || SocialAPI.Cloud == null)
return;
string playerPathFromName = Main.GetPlayerPathFromName(this.Name, true);
if (!FileUtilities.MoveToCloud(this.Path, playerPathFromName))
return;
string fileName = this.GetFileName(false);
string path = Main.PlayerPath + Path.DirectorySeparatorChar.ToString() + fileName + Path.DirectorySeparatorChar.ToString();
if (Directory.Exists(path))
{
string[] files = Directory.GetFiles(path);
for (int index = 0; index < files.Length; ++index)
{
string cloudPath = Main.CloudPlayerPath + "/" + fileName + "/" + FileUtilities.GetFileName(files[index]);
FileUtilities.MoveToCloud(files[index], cloudPath);
}
}
Main.LocalFavoriteData.ClearEntry((FileData) this);
this._isCloudSave = true;
this._path = playerPathFromName;
Main.CloudFavoritesData.SaveFavorite((FileData) this);
}
public override void MoveToLocal()
{
if (!this.IsCloudSave || SocialAPI.Cloud == null)
return;
string playerPathFromName = Main.GetPlayerPathFromName(this.Name, false);
if (!FileUtilities.MoveToLocal(this.Path, playerPathFromName))
return;
string fileName = this.GetFileName(false);
string mapPath = Path.Combine(Main.CloudPlayerPath, fileName);
foreach (string str in SocialAPI.Cloud.GetFiles().Where<string>((Func<string, bool>) (path => path.StartsWith(mapPath, StringComparison.CurrentCultureIgnoreCase) && path.EndsWith(".map", StringComparison.CurrentCultureIgnoreCase))))
{
string localPath = Path.Combine(Main.PlayerPath, fileName, FileUtilities.GetFileName(str));
FileUtilities.MoveToLocal(str, localPath);
}
Main.CloudFavoritesData.ClearEntry((FileData) this);
this._isCloudSave = false;
this._path = playerPathFromName;
Main.LocalFavoriteData.SaveFavorite((FileData) this);
}
public void UpdatePlayTimer()
{
bool flag1 = Main.gamePaused && !Main.hasFocus;
bool flag2 = Main.instance.IsActive && !flag1;
if (Main.gameMenu)
flag2 = false;
if (flag2)
this.StartPlayTimer();
else
this.PausePlayTimer();
}
public void StartPlayTimer()
{
if (this._isTimerActive)
return;
this._isTimerActive = true;
if (this._timer.IsRunning)
return;
this._timer.Start();
}
public void PausePlayTimer() => this.StopPlayTimer();
public TimeSpan GetPlayTime() => this._timer.IsRunning ? this._playTime + this._timer.Elapsed : this._playTime;
public void UpdatePlayTimerAndKeepState()
{
int num = this._timer.IsRunning ? 1 : 0;
this._playTime += this._timer.Elapsed;
this._timer.Reset();
if (num == 0)
return;
this._timer.Start();
}
public void StopPlayTimer()
{
if (!this._isTimerActive)
return;
this._isTimerActive = false;
if (!this._timer.IsRunning)
return;
this._playTime += this._timer.Elapsed;
this._timer.Reset();
}
public void SetPlayTime(TimeSpan time) => this._playTime = time;
}
}

178
IO/Preferences.cs Normal file
View file

@ -0,0 +1,178 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.IO.Preferences
// 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 Newtonsoft.Json;
using Newtonsoft.Json.Bson;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Terraria.Localization;
namespace Terraria.IO
{
public class Preferences
{
private Dictionary<string, object> _data = new Dictionary<string, object>();
private readonly string _path;
private readonly JsonSerializerSettings _serializerSettings;
public readonly bool UseBson;
private readonly object _lock = new object();
public bool AutoSave;
public event Action<Preferences> OnSave;
public event Action<Preferences> OnLoad;
public event Preferences.TextProcessAction OnProcessText;
public Preferences(string path, bool parseAllTypes = false, bool useBson = false)
{
this._path = path;
this.UseBson = useBson;
if (parseAllTypes)
this._serializerSettings = new JsonSerializerSettings()
{
TypeNameHandling = (TypeNameHandling) 4,
MetadataPropertyHandling = (MetadataPropertyHandling) 1,
Formatting = (Formatting) 1
};
else
this._serializerSettings = new JsonSerializerSettings()
{
Formatting = (Formatting) 1
};
}
public bool Load()
{
lock (this._lock)
{
if (!File.Exists(this._path))
return false;
try
{
if (!this.UseBson)
{
this._data = JsonConvert.DeserializeObject<Dictionary<string, object>>(File.ReadAllText(this._path), this._serializerSettings);
}
else
{
using (FileStream fileStream = File.OpenRead(this._path))
{
using (BsonReader bsonReader = new BsonReader((Stream) fileStream))
this._data = JsonSerializer.Create(this._serializerSettings).Deserialize<Dictionary<string, object>>((JsonReader) bsonReader);
}
}
if (this._data == null)
this._data = new Dictionary<string, object>();
if (this.OnLoad != null)
this.OnLoad(this);
return true;
}
catch (Exception ex)
{
return false;
}
}
}
public bool Save(bool canCreateFile = true)
{
lock (this._lock)
{
try
{
if (this.OnSave != null)
this.OnSave(this);
if (!canCreateFile && !File.Exists(this._path))
return false;
Directory.GetParent(this._path).Create();
if (File.Exists(this._path))
File.SetAttributes(this._path, FileAttributes.Normal);
if (!this.UseBson)
{
string text = JsonConvert.SerializeObject((object) this._data, this._serializerSettings);
if (this.OnProcessText != null)
this.OnProcessText(ref text);
File.WriteAllText(this._path, text);
File.SetAttributes(this._path, FileAttributes.Normal);
}
else
{
using (FileStream fileStream = File.Create(this._path))
{
using (BsonWriter bsonWriter = new BsonWriter((Stream) fileStream))
{
File.SetAttributes(this._path, FileAttributes.Normal);
JsonSerializer.Create(this._serializerSettings).Serialize((JsonWriter) bsonWriter, (object) this._data);
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(Language.GetTextValue("Error.UnableToWritePreferences", (object) this._path));
Console.WriteLine(ex.ToString());
return false;
}
return true;
}
}
public void Clear() => this._data.Clear();
public void Put(string name, object value)
{
lock (this._lock)
{
this._data[name] = value;
if (!this.AutoSave)
return;
this.Save();
}
}
public bool Contains(string name)
{
lock (this._lock)
return this._data.ContainsKey(name);
}
public T Get<T>(string name, T defaultValue)
{
lock (this._lock)
{
try
{
object obj1;
if (!this._data.TryGetValue(name, out obj1))
return defaultValue;
switch (obj1)
{
case T obj:
return obj;
case JObject _:
return JsonConvert.DeserializeObject<T>(((object) (JObject) obj1).ToString());
default:
return (T) Convert.ChangeType(obj1, typeof (T));
}
}
catch
{
return defaultValue;
}
}
}
public void Get<T>(string name, ref T currentValue) => currentValue = this.Get<T>(name, currentValue);
public List<string> GetAllKeys() => this._data.Keys.ToList<string>();
public delegate void TextProcessAction(ref string text);
}
}

119
IO/ResourcePack.cs Normal file
View file

@ -0,0 +1,119 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.IO.ResourcePack
// 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 Ionic.Zip;
using Microsoft.Xna.Framework.Graphics;
using Newtonsoft.Json.Linq;
using ReLogic.Content;
using ReLogic.Content.Sources;
using ReLogic.Utilities;
using System;
using System.Collections.Generic;
using System.IO;
using Terraria.GameContent;
namespace Terraria.IO
{
public class ResourcePack
{
public readonly string FullPath;
public readonly string FileName;
private readonly IServiceProvider _services;
private readonly bool _isCompressed;
private readonly ZipFile _zipFile;
private Texture2D _icon;
private IContentSource _contentSource;
private bool _needsReload = true;
private const string ICON_FILE_NAME = "icon.png";
private const string PACK_FILE_NAME = "pack.json";
public Texture2D Icon
{
get
{
if (this._icon == null)
this._icon = this.CreateIcon();
return this._icon;
}
}
public string Name { get; private set; }
public string Description { get; private set; }
public string Author { get; private set; }
public ResourcePackVersion Version { get; private set; }
public bool IsEnabled { get; set; }
public int SortingOrder { get; set; }
public ResourcePack(IServiceProvider services, string path)
{
if (File.Exists(path))
this._isCompressed = true;
else if (!Directory.Exists(path))
throw new FileNotFoundException("Unable to find file or folder for resource pack at: " + path);
this.FileName = Path.GetFileName(path);
this._services = services;
this.FullPath = path;
if (this._isCompressed)
this._zipFile = ZipFile.Read(path);
this.LoadManifest();
}
public void Refresh() => this._needsReload = true;
public IContentSource GetContentSource()
{
if (this._needsReload)
{
this._contentSource = !this._isCompressed ? (IContentSource) new FileSystemContentSource(Path.Combine(this.FullPath, "Content")) : (IContentSource) new ZipContentSource(this.FullPath, "Content");
this._contentSource.ContentValidator = (IContentValidator) VanillaContentValidator.Instance;
this._needsReload = false;
}
return this._contentSource;
}
private Texture2D CreateIcon()
{
if (!this.HasFile("icon.png"))
return XnaExtensions.Get<IAssetRepository>(this._services).Request<Texture2D>("Images/UI/DefaultResourcePackIcon", (AssetRequestMode) 1).Value;
using (Stream stream = this.OpenStream("icon.png"))
return XnaExtensions.Get<AssetReaderCollection>(this._services).Read<Texture2D>(stream, ".png");
}
private void LoadManifest()
{
if (!this.HasFile("pack.json"))
throw new FileNotFoundException(string.Format("Resource Pack at \"{0}\" must contain a {1} file.", (object) this.FullPath, (object) "pack.json"));
JObject jobject;
using (Stream stream = this.OpenStream("pack.json"))
{
using (StreamReader streamReader = new StreamReader(stream))
jobject = JObject.Parse(streamReader.ReadToEnd());
}
this.Name = Extensions.Value<string>((IEnumerable<JToken>) jobject["Name"]);
this.Description = Extensions.Value<string>((IEnumerable<JToken>) jobject["Description"]);
this.Author = Extensions.Value<string>((IEnumerable<JToken>) jobject["Author"]);
this.Version = jobject["Version"].ToObject<ResourcePackVersion>();
}
private Stream OpenStream(string fileName)
{
if (!this._isCompressed)
return (Stream) File.OpenRead(Path.Combine(this.FullPath, fileName));
ZipEntry zipEntry = this._zipFile[fileName];
MemoryStream memoryStream = new MemoryStream((int) zipEntry.UncompressedSize);
zipEntry.Extract((Stream) memoryStream);
memoryStream.Position = 0L;
return (Stream) memoryStream;
}
private bool HasFile(string fileName) => !this._isCompressed ? File.Exists(Path.Combine(this.FullPath, fileName)) : this._zipFile.ContainsEntry(fileName);
}
}

130
IO/ResourcePackList.cs Normal file
View file

@ -0,0 +1,130 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.IO.ResourcePackList
// 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 Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Terraria.IO
{
public class ResourcePackList
{
private readonly List<ResourcePack> _resourcePacks = new List<ResourcePack>();
public IEnumerable<ResourcePack> EnabledPacks => (IEnumerable<ResourcePack>) this._resourcePacks.Where<ResourcePack>((Func<ResourcePack, bool>) (pack => pack.IsEnabled)).OrderBy<ResourcePack, int>((Func<ResourcePack, int>) (pack => pack.SortingOrder)).ThenBy<ResourcePack, string>((Func<ResourcePack, string>) (pack => pack.Name)).ThenBy<ResourcePack, ResourcePackVersion>((Func<ResourcePack, ResourcePackVersion>) (pack => pack.Version)).ThenBy<ResourcePack, string>((Func<ResourcePack, string>) (pack => pack.FileName));
public IEnumerable<ResourcePack> DisabledPacks => (IEnumerable<ResourcePack>) this._resourcePacks.Where<ResourcePack>((Func<ResourcePack, bool>) (pack => !pack.IsEnabled)).OrderBy<ResourcePack, string>((Func<ResourcePack, string>) (pack => pack.Name)).ThenBy<ResourcePack, ResourcePackVersion>((Func<ResourcePack, ResourcePackVersion>) (pack => pack.Version)).ThenBy<ResourcePack, string>((Func<ResourcePack, string>) (pack => pack.FileName));
public IEnumerable<ResourcePack> AllPacks => (IEnumerable<ResourcePack>) this._resourcePacks.OrderBy<ResourcePack, string>((Func<ResourcePack, string>) (pack => pack.Name)).ThenBy<ResourcePack, ResourcePackVersion>((Func<ResourcePack, ResourcePackVersion>) (pack => pack.Version)).ThenBy<ResourcePack, string>((Func<ResourcePack, string>) (pack => pack.FileName));
public ResourcePackList()
{
}
public ResourcePackList(IEnumerable<ResourcePack> resourcePacks) => this._resourcePacks.AddRange(resourcePacks);
public JArray ToJson()
{
List<ResourcePackList.ResourcePackEntry> resourcePackEntryList = new List<ResourcePackList.ResourcePackEntry>(this._resourcePacks.Count);
resourcePackEntryList.AddRange(this._resourcePacks.Select<ResourcePack, ResourcePackList.ResourcePackEntry>((Func<ResourcePack, ResourcePackList.ResourcePackEntry>) (pack => new ResourcePackList.ResourcePackEntry(pack.FileName, pack.IsEnabled, pack.SortingOrder))));
return JArray.FromObject((object) resourcePackEntryList);
}
public static ResourcePackList FromJson(
JArray serializedState,
IServiceProvider services,
string searchPath)
{
if (!Directory.Exists(searchPath))
return new ResourcePackList();
List<ResourcePack> source = new List<ResourcePack>();
foreach (ResourcePackList.ResourcePackEntry resourcePackEntry in ResourcePackList.CreatePackEntryListFromJson(serializedState))
{
if (resourcePackEntry.FileName != null)
{
string path = Path.Combine(searchPath, resourcePackEntry.FileName);
try
{
if (!File.Exists(path))
{
if (!Directory.Exists(path))
continue;
}
ResourcePack resourcePack = new ResourcePack(services, path)
{
IsEnabled = resourcePackEntry.Enabled,
SortingOrder = resourcePackEntry.SortingOrder
};
source.Add(resourcePack);
}
catch (Exception ex)
{
Console.WriteLine("Failed to read resource pack {0}: {1}", (object) path, (object) ex);
}
}
}
foreach (string file in Directory.GetFiles(searchPath, "*.zip"))
{
try
{
string fileName = Path.GetFileName(file);
if (source.All<ResourcePack>((Func<ResourcePack, bool>) (pack => pack.FileName != fileName)))
source.Add(new ResourcePack(services, file));
}
catch (Exception ex)
{
Console.WriteLine("Failed to read resource pack {0}: {1}", (object) file, (object) ex);
}
}
foreach (string directory in Directory.GetDirectories(searchPath))
{
try
{
string folderName = Path.GetFileName(directory);
if (source.All<ResourcePack>((Func<ResourcePack, bool>) (pack => pack.FileName != folderName)))
source.Add(new ResourcePack(services, directory));
}
catch (Exception ex)
{
Console.WriteLine("Failed to read resource pack {0}: {1}", (object) directory, (object) ex);
}
}
return new ResourcePackList((IEnumerable<ResourcePack>) source);
}
private static IEnumerable<ResourcePackList.ResourcePackEntry> CreatePackEntryListFromJson(
JArray serializedState)
{
try
{
if (((JContainer) serializedState).Count != 0)
return (IEnumerable<ResourcePackList.ResourcePackEntry>) ((JToken) serializedState).ToObject<List<ResourcePackList.ResourcePackEntry>>();
}
catch (JsonReaderException ex)
{
Console.WriteLine("Failed to parse configuration entry for resource pack list. {0}", (object) ex);
}
return (IEnumerable<ResourcePackList.ResourcePackEntry>) new List<ResourcePackList.ResourcePackEntry>();
}
private struct ResourcePackEntry
{
public string FileName;
public bool Enabled;
public int SortingOrder;
public ResourcePackEntry(string name, bool enabled, int sortingOrder)
{
this.FileName = name;
this.Enabled = enabled;
this.SortingOrder = sortingOrder;
}
}
}
}

51
IO/ResourcePackVersion.cs Normal file
View file

@ -0,0 +1,51 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.IO.ResourcePackVersion
// 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 Newtonsoft.Json;
using System;
using System.Diagnostics;
namespace Terraria.IO
{
[DebuggerDisplay("Version {Major}.{Minor}")]
public struct ResourcePackVersion : IComparable, IComparable<ResourcePackVersion>
{
[JsonProperty("major")]
public int Major { get; private set; }
[JsonProperty("minor")]
public int Minor { get; private set; }
public int CompareTo(object obj)
{
if (obj == null)
return 1;
if (!(obj is ResourcePackVersion other))
throw new ArgumentException("A RatingInformation object is required for comparison.", nameof (obj));
return this.CompareTo(other);
}
public int CompareTo(ResourcePackVersion other)
{
int num = this.Major.CompareTo(other.Major);
return num != 0 ? num : this.Minor.CompareTo(other.Minor);
}
public static bool operator ==(ResourcePackVersion lhs, ResourcePackVersion rhs) => lhs.CompareTo(rhs) == 0;
public static bool operator !=(ResourcePackVersion lhs, ResourcePackVersion rhs) => !(lhs == rhs);
public static bool operator <(ResourcePackVersion lhs, ResourcePackVersion rhs) => lhs.CompareTo(rhs) < 0;
public static bool operator >(ResourcePackVersion lhs, ResourcePackVersion rhs) => lhs.CompareTo(rhs) > 0;
public override bool Equals(object obj) => obj is ResourcePackVersion other && this.CompareTo(other) == 0;
public override int GetHashCode() => ((long) this.Major << 32 | (long) this.Minor).GetHashCode();
public string GetFormattedVersion() => this.Major.ToString() + "." + (object) this.Minor;
}
}

2682
IO/WorldFile.cs Normal file

File diff suppressed because it is too large Load diff

155
IO/WorldFileData.cs Normal file
View file

@ -0,0 +1,155 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.IO.WorldFileData
// 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 ReLogic.Utilities;
using System;
using System.IO;
using Terraria.Localization;
using Terraria.Utilities;
namespace Terraria.IO
{
public class WorldFileData : FileData
{
private const ulong GUID_IN_WORLD_FILE_VERSION = 777389080577;
public DateTime CreationTime;
public int WorldSizeX;
public int WorldSizeY;
public ulong WorldGeneratorVersion;
private string _seedText = "";
private int _seed;
public bool IsValid = true;
public Guid UniqueId;
public LocalizedText _worldSizeName;
public int GameMode;
public bool DrunkWorld;
public bool HasCorruption = true;
public bool IsHardMode;
public string SeedText => this._seedText;
public int Seed => this._seed;
public string WorldSizeName => this._worldSizeName.Value;
public bool HasCrimson
{
get => !this.HasCorruption;
set => this.HasCorruption = !value;
}
public bool HasValidSeed => this.WorldGeneratorVersion > 0UL;
public bool UseGuidAsMapName => this.WorldGeneratorVersion >= 777389080577UL;
public string GetFullSeedText()
{
int num1 = 0;
if (this.WorldSizeX == 4200 && this.WorldSizeY == 1200)
num1 = 1;
if (this.WorldSizeX == 6400 && this.WorldSizeY == 1800)
num1 = 2;
if (this.WorldSizeX == 8400 && this.WorldSizeY == 2400)
num1 = 3;
int num2 = 0;
if (this.HasCorruption)
num2 = 1;
if (this.HasCrimson)
num2 = 2;
int num3 = this.GameMode + 1;
return string.Format("{0}.{1}.{2}.{3}", (object) num1, (object) num3, (object) num2, (object) this._seedText);
}
public WorldFileData()
: base("World")
{
}
public WorldFileData(string path, bool cloudSave)
: base("World", path, cloudSave)
{
}
public override void SetAsActive() => Main.ActiveWorldFileData = this;
public void SetWorldSize(int x, int y)
{
this.WorldSizeX = x;
this.WorldSizeY = y;
switch (x)
{
case 4200:
this._worldSizeName = Language.GetText("UI.WorldSizeSmall");
break;
case 6400:
this._worldSizeName = Language.GetText("UI.WorldSizeMedium");
break;
case 8400:
this._worldSizeName = Language.GetText("UI.WorldSizeLarge");
break;
default:
this._worldSizeName = Language.GetText("UI.WorldSizeUnknown");
break;
}
}
public static WorldFileData FromInvalidWorld(string path, bool cloudSave)
{
WorldFileData worldFileData = new WorldFileData(path, cloudSave);
worldFileData.GameMode = 0;
worldFileData.SetSeedToEmpty();
worldFileData.WorldGeneratorVersion = 0UL;
worldFileData.Metadata = FileMetadata.FromCurrentSettings(FileType.World);
worldFileData.SetWorldSize(1, 1);
worldFileData.HasCorruption = true;
worldFileData.IsHardMode = false;
worldFileData.IsValid = false;
worldFileData.Name = FileUtilities.GetFileName(path, false);
worldFileData.UniqueId = Guid.Empty;
worldFileData.CreationTime = cloudSave ? DateTime.Now : File.GetCreationTime(path);
return worldFileData;
}
public void SetSeedToEmpty() => this.SetSeed("");
public void SetSeed(string seedText)
{
this._seedText = seedText;
WorldGen.currentWorldSeed = seedText;
if (!int.TryParse(seedText, out this._seed))
this._seed = Crc32.Calculate(seedText);
this._seed = this._seed == int.MinValue ? int.MaxValue : Math.Abs(this._seed);
}
public void SetSeedToRandom() => this.SetSeed(new UnifiedRandom().Next().ToString());
public override void MoveToCloud()
{
if (this.IsCloudSave)
return;
string worldPathFromName = Main.GetWorldPathFromName(this.Name, true);
if (!FileUtilities.MoveToCloud(this.Path, worldPathFromName))
return;
Main.LocalFavoriteData.ClearEntry((FileData) this);
this._isCloudSave = true;
this._path = worldPathFromName;
Main.CloudFavoritesData.SaveFavorite((FileData) this);
}
public override void MoveToLocal()
{
if (!this.IsCloudSave)
return;
string worldPathFromName = Main.GetWorldPathFromName(this.Name, false);
if (!FileUtilities.MoveToLocal(this.Path, worldPathFromName))
return;
Main.CloudFavoritesData.ClearEntry((FileData) this);
this._isCloudSave = false;
this._path = worldPathFromName;
Main.LocalFavoriteData.SaveFavorite((FileData) this);
}
}
}