Delete Achievements directory

This commit is contained in:
MikeyIsBaeYT 2023-01-26 10:49:38 -05:00 committed by GitHub
parent 19f866ab25
commit 53c7881d76
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 0 additions and 589 deletions

View file

@ -1,138 +0,0 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Achievements.Achievement
// 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.Collections.Generic;
using Terraria.Localization;
using Terraria.Social;
namespace Terraria.Achievements
{
[JsonObject]
public class Achievement
{
private static int _totalAchievements;
public readonly string Name;
public readonly LocalizedText FriendlyName;
public readonly LocalizedText Description;
public readonly int Id = Achievement._totalAchievements++;
private AchievementCategory _category;
private IAchievementTracker _tracker;
[JsonProperty("Conditions")]
private Dictionary<string, AchievementCondition> _conditions = new Dictionary<string, AchievementCondition>();
private int _completedCount;
public AchievementCategory Category => this._category;
public event Achievement.AchievementCompleted OnCompleted;
public bool HasTracker => this._tracker != null;
public IAchievementTracker GetTracker() => this._tracker;
public bool IsCompleted => this._completedCount == this._conditions.Count;
public Achievement(string name)
{
this.Name = name;
this.FriendlyName = Language.GetText("Achievements." + name + "_Name");
this.Description = Language.GetText("Achievements." + name + "_Description");
}
public void ClearProgress()
{
this._completedCount = 0;
foreach (KeyValuePair<string, AchievementCondition> condition in this._conditions)
condition.Value.Clear();
if (this._tracker == null)
return;
this._tracker.Clear();
}
public void Load(Dictionary<string, JObject> conditions)
{
foreach (KeyValuePair<string, JObject> condition in conditions)
{
AchievementCondition achievementCondition;
if (this._conditions.TryGetValue(condition.Key, out achievementCondition))
{
achievementCondition.Load(condition.Value);
if (achievementCondition.IsCompleted)
++this._completedCount;
}
}
if (this._tracker == null)
return;
this._tracker.Load();
}
public void AddCondition(AchievementCondition condition)
{
this._conditions[condition.Name] = condition;
condition.OnComplete += new AchievementCondition.AchievementUpdate(this.OnConditionComplete);
}
private void OnConditionComplete(AchievementCondition condition)
{
++this._completedCount;
if (this._completedCount != this._conditions.Count)
return;
if (this._tracker == null && SocialAPI.Achievements != null)
SocialAPI.Achievements.CompleteAchievement(this.Name);
if (this.OnCompleted == null)
return;
this.OnCompleted(this);
}
private void UseTracker(IAchievementTracker tracker)
{
tracker.ReportAs("STAT_" + this.Name);
this._tracker = tracker;
}
public void UseTrackerFromCondition(string conditionName) => this.UseTracker(this.GetConditionTracker(conditionName));
public void UseConditionsCompletedTracker()
{
ConditionsCompletedTracker completedTracker = new ConditionsCompletedTracker();
foreach (KeyValuePair<string, AchievementCondition> condition in this._conditions)
completedTracker.AddCondition(condition.Value);
this.UseTracker((IAchievementTracker) completedTracker);
}
public void UseConditionsCompletedTracker(params string[] conditions)
{
ConditionsCompletedTracker completedTracker = new ConditionsCompletedTracker();
for (int index = 0; index < conditions.Length; ++index)
{
string condition = conditions[index];
completedTracker.AddCondition(this._conditions[condition]);
}
this.UseTracker((IAchievementTracker) completedTracker);
}
public void ClearTracker() => this._tracker = (IAchievementTracker) null;
private IAchievementTracker GetConditionTracker(string name) => this._conditions[name].GetAchievementTracker();
public void AddConditions(params AchievementCondition[] conditions)
{
for (int index = 0; index < conditions.Length; ++index)
this.AddCondition(conditions[index]);
}
public AchievementCondition GetCondition(string conditionName)
{
AchievementCondition achievementCondition;
return this._conditions.TryGetValue(conditionName, out achievementCondition) ? achievementCondition : (AchievementCondition) null;
}
public void SetCategory(AchievementCategory category) => this._category = category;
public delegate void AchievementCompleted(Achievement achievement);
}
}

View file

@ -1,17 +0,0 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Achievements.AchievementCategory
// 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.Achievements
{
public enum AchievementCategory
{
None = -1, // 0xFFFFFFFF
Slayer = 0,
Collector = 1,
Explorer = 2,
Challenger = 3,
}
}

View file

@ -1,51 +0,0 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Achievements.AchievementCondition
// 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;
namespace Terraria.Achievements
{
[JsonObject]
public abstract class AchievementCondition
{
public readonly string Name;
protected IAchievementTracker _tracker;
[JsonProperty("Completed")]
private bool _isCompleted;
public event AchievementCondition.AchievementUpdate OnComplete;
public bool IsCompleted => this._isCompleted;
protected AchievementCondition(string name) => this.Name = name;
public virtual void Load(JObject state) => this._isCompleted = JToken.op_Explicit(state["Completed"]);
public virtual void Clear() => this._isCompleted = false;
public virtual void Complete()
{
if (this._isCompleted)
return;
this._isCompleted = true;
if (this.OnComplete == null)
return;
this.OnComplete(this);
}
protected virtual IAchievementTracker CreateAchievementTracker() => (IAchievementTracker) null;
public IAchievementTracker GetAchievementTracker()
{
if (this._tracker == null)
this._tracker = this.CreateAchievementTracker();
return this._tracker;
}
public delegate void AchievementUpdate(AchievementCondition condition);
}
}

View file

@ -1,190 +0,0 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Achievements.AchievementManager
// 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 System.Security.Cryptography;
using System.Text;
using Terraria.Social;
using Terraria.UI;
using Terraria.Utilities;
namespace Terraria.Achievements
{
public class AchievementManager
{
private string _savePath;
private bool _isCloudSave;
private Dictionary<string, Achievement> _achievements = new Dictionary<string, Achievement>();
private readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings();
private byte[] _cryptoKey;
private Dictionary<string, int> _achievementIconIndexes = new Dictionary<string, int>();
private static object _ioLock = new object();
public event Achievement.AchievementCompleted OnAchievementCompleted;
public AchievementManager()
{
if (SocialAPI.Achievements != null)
{
this._savePath = SocialAPI.Achievements.GetSavePath();
this._isCloudSave = true;
this._cryptoKey = SocialAPI.Achievements.GetEncryptionKey();
}
else
{
this._savePath = Main.SavePath + Path.DirectorySeparatorChar.ToString() + "achievements.dat";
this._isCloudSave = false;
this._cryptoKey = Encoding.ASCII.GetBytes("RELOGIC-TERRARIA");
}
}
public void Save() => FileUtilities.ProtectedInvoke((Action) (() => this.Save(this._savePath, this._isCloudSave)));
private void Save(string path, bool cloud)
{
lock (AchievementManager._ioLock)
{
if (SocialAPI.Achievements != null)
SocialAPI.Achievements.StoreStats();
try
{
using (MemoryStream memoryStream = new MemoryStream())
{
using (CryptoStream cryptoStream = new CryptoStream((Stream) memoryStream, new RijndaelManaged().CreateEncryptor(this._cryptoKey, this._cryptoKey), CryptoStreamMode.Write))
{
using (BsonWriter bsonWriter = new BsonWriter((Stream) cryptoStream))
{
JsonSerializer.Create(this._serializerSettings).Serialize((JsonWriter) bsonWriter, (object) this._achievements);
((JsonWriter) bsonWriter).Flush();
cryptoStream.FlushFinalBlock();
FileUtilities.WriteAllBytes(path, memoryStream.ToArray(), cloud);
}
}
}
}
catch (Exception ex)
{
string savePath = this._savePath;
FancyErrorPrinter.ShowFileSavingFailError(ex, savePath);
}
}
}
public List<Achievement> CreateAchievementsList() => this._achievements.Values.ToList<Achievement>();
public void Load() => this.Load(this._savePath, this._isCloudSave);
private void Load(string path, bool cloud)
{
bool flag = false;
lock (AchievementManager._ioLock)
{
if (!FileUtilities.Exists(path, cloud))
return;
byte[] buffer = FileUtilities.ReadAllBytes(path, cloud);
Dictionary<string, AchievementManager.StoredAchievement> dictionary = (Dictionary<string, AchievementManager.StoredAchievement>) null;
try
{
using (MemoryStream memoryStream = new MemoryStream(buffer))
{
using (CryptoStream cryptoStream = new CryptoStream((Stream) memoryStream, new RijndaelManaged().CreateDecryptor(this._cryptoKey, this._cryptoKey), CryptoStreamMode.Read))
{
using (BsonReader bsonReader = new BsonReader((Stream) cryptoStream))
dictionary = JsonSerializer.Create(this._serializerSettings).Deserialize<Dictionary<string, AchievementManager.StoredAchievement>>((JsonReader) bsonReader);
}
}
}
catch (Exception ex)
{
FileUtilities.Delete(path, cloud);
return;
}
if (dictionary == null)
return;
foreach (KeyValuePair<string, AchievementManager.StoredAchievement> keyValuePair in dictionary)
{
if (this._achievements.ContainsKey(keyValuePair.Key))
this._achievements[keyValuePair.Key].Load(keyValuePair.Value.Conditions);
}
if (SocialAPI.Achievements != null)
{
foreach (KeyValuePair<string, Achievement> achievement in this._achievements)
{
if (achievement.Value.IsCompleted && !SocialAPI.Achievements.IsAchievementCompleted(achievement.Key))
{
flag = true;
achievement.Value.ClearProgress();
}
}
}
}
if (!flag)
return;
this.Save();
}
public void ClearAll()
{
if (SocialAPI.Achievements != null)
return;
foreach (KeyValuePair<string, Achievement> achievement in this._achievements)
achievement.Value.ClearProgress();
this.Save();
}
private void AchievementCompleted(Achievement achievement)
{
this.Save();
if (this.OnAchievementCompleted == null)
return;
this.OnAchievementCompleted(achievement);
}
public void Register(Achievement achievement)
{
this._achievements.Add(achievement.Name, achievement);
achievement.OnCompleted += new Achievement.AchievementCompleted(this.AchievementCompleted);
}
public void RegisterIconIndex(string achievementName, int iconIndex) => this._achievementIconIndexes.Add(achievementName, iconIndex);
public void RegisterAchievementCategory(string achievementName, AchievementCategory category) => this._achievements[achievementName].SetCategory(category);
public Achievement GetAchievement(string achievementName)
{
Achievement achievement;
return this._achievements.TryGetValue(achievementName, out achievement) ? achievement : (Achievement) null;
}
public T GetCondition<T>(string achievementName, string conditionName) where T : AchievementCondition => this.GetCondition(achievementName, conditionName) as T;
public AchievementCondition GetCondition(
string achievementName,
string conditionName)
{
Achievement achievement;
return this._achievements.TryGetValue(achievementName, out achievement) ? achievement.GetCondition(conditionName) : (AchievementCondition) null;
}
public int GetIconIndex(string achievementName)
{
int num;
return this._achievementIconIndexes.TryGetValue(achievementName, out num) ? num : 0;
}
private class StoredAchievement
{
[JsonProperty]
public Dictionary<string, JObject> Conditions;
}
}
}

View file

@ -1,56 +0,0 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Achievements.AchievementTracker`1
// 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.Social;
namespace Terraria.Achievements
{
public abstract class AchievementTracker<T> : IAchievementTracker
{
protected T _value;
protected T _maxValue;
protected string _name;
private TrackerType _type;
public T Value => this._value;
public T MaxValue => this._maxValue;
protected AchievementTracker(TrackerType type) => this._type = type;
void IAchievementTracker.ReportAs(string name) => this._name = name;
TrackerType IAchievementTracker.GetTrackerType() => this._type;
void IAchievementTracker.Clear() => this.SetValue(default (T));
public void SetValue(T newValue, bool reportUpdate = true)
{
if (newValue.Equals((object) this._value))
return;
this._value = newValue;
if (!reportUpdate)
return;
this.ReportUpdate();
if (!this._value.Equals((object) this._maxValue))
return;
this.OnComplete();
}
public abstract void ReportUpdate();
protected abstract void Load();
void IAchievementTracker.Load() => this.Load();
protected void OnComplete()
{
if (SocialAPI.Achievements == null)
return;
SocialAPI.Achievements.StoreStats();
}
}
}

View file

@ -1,35 +0,0 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Achievements.ConditionFloatTracker
// 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.Social;
namespace Terraria.Achievements
{
public class ConditionFloatTracker : AchievementTracker<float>
{
public ConditionFloatTracker(float maxValue)
: base(TrackerType.Float)
{
this._maxValue = maxValue;
}
public ConditionFloatTracker()
: base(TrackerType.Float)
{
}
public override void ReportUpdate()
{
if (SocialAPI.Achievements == null || this._name == null)
return;
SocialAPI.Achievements.UpdateFloatStat(this._name, this._value);
}
protected override void Load()
{
}
}
}

View file

@ -1,35 +0,0 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Achievements.ConditionIntTracker
// 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.Social;
namespace Terraria.Achievements
{
public class ConditionIntTracker : AchievementTracker<int>
{
public ConditionIntTracker()
: base(TrackerType.Int)
{
}
public ConditionIntTracker(int maxValue)
: base(TrackerType.Int)
{
this._maxValue = maxValue;
}
public override void ReportUpdate()
{
if (SocialAPI.Achievements == null || this._name == null)
return;
SocialAPI.Achievements.UpdateIntStat(this._name, this._value);
}
protected override void Load()
{
}
}
}

View file

@ -1,34 +0,0 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Achievements.ConditionsCompletedTracker
// 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.Collections.Generic;
namespace Terraria.Achievements
{
public class ConditionsCompletedTracker : ConditionIntTracker
{
private List<AchievementCondition> _conditions = new List<AchievementCondition>();
public void AddCondition(AchievementCondition condition)
{
++this._maxValue;
condition.OnComplete += new AchievementCondition.AchievementUpdate(this.OnConditionCompleted);
this._conditions.Add(condition);
}
private void OnConditionCompleted(AchievementCondition condition) => this.SetValue(Math.Min(this._value + 1, this._maxValue));
protected override void Load()
{
for (int index = 0; index < this._conditions.Count; ++index)
{
if (this._conditions[index].IsCompleted)
++this._value;
}
}
}
}

View file

@ -1,19 +0,0 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Achievements.IAchievementTracker
// 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.Achievements
{
public interface IAchievementTracker
{
void ReportAs(string name);
TrackerType GetTrackerType();
void Load();
void Clear();
}
}

View file

@ -1,14 +0,0 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Achievements.TrackerType
// 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.Achievements
{
public enum TrackerType
{
Float,
Int,
}
}