diff --git a/MareSynchronosAPI/API.cs b/MareSynchronosAPI/API.cs index e10aa58..2022a18 100644 --- a/MareSynchronosAPI/API.cs +++ b/MareSynchronosAPI/API.cs @@ -8,7 +8,7 @@ namespace MareSynchronos.API { public class Api { - public const int Version = 5; + public const int Version = 6; public const string Path = "/mare"; public const string SendFileAbortUpload = "AbortUpload"; diff --git a/MareSynchronosAPI/CharacterCacheDto.cs b/MareSynchronosAPI/CharacterCacheDto.cs index ce13618..61c6618 100644 --- a/MareSynchronosAPI/CharacterCacheDto.cs +++ b/MareSynchronosAPI/CharacterCacheDto.cs @@ -1,12 +1,50 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Linq; namespace MareSynchronos.API { - public record CharacterCacheDto + public class CharacterCacheDto { - public List FileReplacements { get; set; } = new(); - public string GlamourerData { get; set; } - public string ManipulationData { get; set; } - public string Hash { get; set; } + public Dictionary> FileReplacements { get; set; } = new(); + public Dictionary GlamourerData { get; set; } = new(); + public string ManipulationData { get; set; } = string.Empty; + public override string ToString() + { + return GetHashCode() + Environment.NewLine + "Manip:" + ManipulationData + Environment.NewLine + + string.Join(Environment.NewLine, GlamourerData.Select(g => g.Key + ":" + g.Value)) + Environment.NewLine + + string.Join(Environment.NewLine, FileReplacements.Select(g => g.Key + Environment.NewLine + string.Join(Environment.NewLine, g.Value))); + } + + public static int GetOrderIndependentHashCode(IEnumerable source) + { + int hash = 0; + foreach (T element in source) + { + hash = unchecked(hash + + EqualityComparer.Default.GetHashCode(element)); + } + return hash; + } + + public override int GetHashCode() + { + int fileReplacementsHash = 0; + foreach (var item in FileReplacements) + { + foreach (var values in item.Value) + { + fileReplacementsHash = unchecked(fileReplacementsHash + values.GetHashCode()); + } + } + + int glamourerHash = 0; + foreach (var item in GlamourerData) + { + glamourerHash = unchecked(glamourerHash + item.Value.GetHashCode()); + } + + return HashCode.Combine(fileReplacementsHash, glamourerHash, ManipulationData); + } } } diff --git a/MareSynchronosAPI/FileReplacementDto.cs b/MareSynchronosAPI/FileReplacementDto.cs index 57aa2cb..c6ae7bc 100644 --- a/MareSynchronosAPI/FileReplacementDto.cs +++ b/MareSynchronosAPI/FileReplacementDto.cs @@ -1,10 +1,39 @@ using System; +using System.Collections.Generic; +using System.Linq; namespace MareSynchronos.API { - public record FileReplacementDto + public class FileReplacementDto { public string[] GamePaths { get; set; } = Array.Empty(); public string Hash { get; set; } + + public override bool Equals(object? otherObj) + { + if (otherObj == null || otherObj is not FileReplacementDto other) return false; + return Hash == other.Hash && Enumerable.SequenceEqual(GamePaths, other.GamePaths); + } + + public override int GetHashCode() + { + return HashCode.Combine(GetOrderIndependentHashCode(GamePaths), Hash); + } + + public static int GetOrderIndependentHashCode(IEnumerable source) + { + int hash = 0; + foreach (T element in source) + { + hash = unchecked(hash + + EqualityComparer.Default.GetHashCode(element)); + } + return hash; + } + + public override string ToString() + { + return Hash + ":" + string.Join(",", GamePaths); + } } } \ No newline at end of file diff --git a/MareSynchronosAPI/ObjectKind.cs b/MareSynchronosAPI/ObjectKind.cs new file mode 100644 index 0000000..5bd4a33 --- /dev/null +++ b/MareSynchronosAPI/ObjectKind.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MareSynchronos.API +{ + public enum ObjectKind + { + Player = 0, + Minion = 1, + Companion = 2, + Pet = 3, + Mount = 4 + } +}