using LibW4M.Data.Highscores; using LibW4M.Data.Teams; using LibXom.Data; using LibXom.Streams; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace LibW4M.Data.Stats { public class StatsCollective : SaveDataCollective { public StatsCollective(W4SaveFile fileBelongs, XomContainer mainContainer) : base(fileBelongs, mainContainer) { } public override void Create() { StatsContainerData stat = new StatsContainerData(this.fileBelongs, this.fileBelongs.CreateContainer("StatsContainer"), false); this.collectiveEntries.Add(stat); } public override void Load() { int[] decompressedCollective = mainContainer.Decompress(); int numStats = decompressedCollective[0]; for (int i = 0; i < numStats; i++) { StatsContainerData stat = new StatsContainerData(this.fileBelongs, this.fileBelongs.LookupContainerById(decompressedCollective[i + 1])); this.collectiveEntries.Add(stat); } } public override void Save() { // Once again Team17 stores multiple different types of data here // a generic one i dunno whats for besides to make the filesize huge.. // and one for team stats .. // to make thins easier im gonna abstract it away as two different collectives // like i did on the highscores . int[] decompressedCollective = mainContainer.Decompress(); int oldLen = decompressedCollective[0]; // Copy Team Stats data. int[] teamStatsData = new int[(decompressedCollective.Length - (oldLen + 1))]; Array.ConstrainedCopy(decompressedCollective, oldLen + 1, teamStatsData, 0, teamStatsData.Length); // Recalculate collective size and offsets int sz = this.Length; int[] collective = new int[(sz + 1) + (teamStatsData.Length)]; collective[0] = sz; for (int i = 0; i < sz; i++) { StatsContainerData statsData = collectiveEntries[i] as StatsContainerData; if (statsData is null) continue; statsData.Save(); collective[i + 1] = statsData.mainContainer.Id; } // Copy Team Stats data back to the collective. Array.ConstrainedCopy(teamStatsData, 0, collective, sz + 1, teamStatsData.Length); mainContainer.CompressAndUpdate(collective); } } }