private void SaveAccounts(Stream stream) { using (BinaryWriter writer = new BinaryWriter(stream)) { writer.Write(Version); writer.Write(CustomVersion); writer.Write(NextAccountID); writer.Write(NextCharacterID); writer.Write(NextUserItemID); writer.Write(GuildList.Count); writer.Write(NextGuildID); writer.Write(AccountList.Count); for (int i = 0; i < AccountList.Count; i++) AccountList[i].Save(writer); writer.Write(NextAuctionID); writer.Write(Auctions.Count); foreach (AuctionInfo auction in Auctions) auction.Save(writer); writer.Write(NextMailID); writer.Write(Mail.Count); foreach (MailInfo mail in Mail) mail.Save(writer); writer.Write(GameshopLog.Count); foreach (var item in GameshopLog) { writer.Write(item.Key); writer.Write(item.Value); } writer.Write(SavedSpawns.Count); foreach (MapRespawn Spawn in SavedSpawns) { RespawnSave Save = new RespawnSave { RespawnIndex = Spawn.Info.RespawnIndex, NextSpawnTick = Spawn.NextSpawnTick, Spawned = (Spawn.Count >= (Spawn.Info.Count * spawnmultiplyer)) }; Save.save(writer); } } }
public void LoadAccounts() { lock (LoadLock) { if (!File.Exists(AccountPath)) SaveAccounts(); using (FileStream stream = File.OpenRead(AccountPath)) using (BinaryReader reader = new BinaryReader(stream)) { LoadVersion = reader.ReadInt32(); if (LoadVersion > 57) LoadCustomVersion = reader.ReadInt32(); NextAccountID = reader.ReadInt32(); NextCharacterID = reader.ReadInt32(); NextUserItemID = reader.ReadUInt64(); if (LoadVersion > 27) { GuildCount = reader.ReadInt32(); NextGuildID = reader.ReadInt32(); } int count = reader.ReadInt32(); AccountList.Clear(); CharacterList.Clear(); for (int i = 0; i < count; i++) { AccountList.Add(new AccountInfo(reader)); CharacterList.AddRange(AccountList[i].Characters); } if (LoadVersion < 7) return; foreach (AuctionInfo auction in Auctions) auction.CharacterInfo.AccountInfo.Auctions.Remove(auction); Auctions.Clear(); if (LoadVersion >= 8) NextAuctionID = reader.ReadUInt64(); count = reader.ReadInt32(); for (int i = 0; i < count; i++) { AuctionInfo auction = new AuctionInfo(reader, LoadVersion, LoadCustomVersion); if (!BindItem(auction.Item) || !BindCharacter(auction)) continue; Auctions.AddLast(auction); auction.CharacterInfo.AccountInfo.Auctions.AddLast(auction); } if (LoadVersion == 7) { foreach (AuctionInfo auction in Auctions) { if (auction.Sold && auction.Expired) auction.Expired = false; auction.AuctionID = ++NextAuctionID; } } if(LoadVersion > 43) { NextMailID = reader.ReadUInt64(); Mail.Clear(); count = reader.ReadInt32(); for (int i = 0; i < count; i++) { Mail.Add(new MailInfo(reader, LoadVersion, LoadCustomVersion)); } } if(LoadVersion >= 63) { int logCount = reader.ReadInt32(); for (int i = 0; i < logCount; i++) { GameshopLog.Add(reader.ReadInt32(), reader.ReadInt32()); } if (ResetGS) ClearGameshopLog(); } if (LoadVersion >= 68) { int SaveCount = reader.ReadInt32(); for (int i = 0; i < SaveCount; i++) { RespawnSave Saved = new RespawnSave(reader); foreach (MapRespawn Respawn in SavedSpawns) { if (Respawn.Info.RespawnIndex == Saved.RespawnIndex) { Respawn.NextSpawnTick = Saved.NextSpawnTick; if ((Saved.Spawned) && ((Respawn.Info.Count * spawnmultiplyer) > Respawn.Count)) { int mobcount = (Respawn.Info.Count * spawnmultiplyer) - Respawn.Count; for (int j = 0; j < mobcount; j++) { Respawn.Spawn(); } } } } } } } } }