public static Player LoadPlayer(string playerPath) { bool flag = false; if (Main.rand == null) { Main.rand = new Random((int) DateTime.Now.Ticks); } Player player = new Player(); try { string outputFile = playerPath + ".dat"; flag = DecryptFile(playerPath, outputFile); if (!flag) { using (FileStream stream = new FileStream(outputFile, FileMode.Open)) { using (BinaryReader reader = new BinaryReader(stream)) { reader.ReadInt32(); player.name = reader.ReadString(); player.hair = reader.ReadInt32(); player.statLife = reader.ReadInt32(); player.statLifeMax = reader.ReadInt32(); if (player.statLife > player.statLifeMax) { player.statLife = player.statLifeMax; } player.statMana = reader.ReadInt32(); player.statManaMax = reader.ReadInt32(); if (player.statMana > player.statManaMax) { player.statMana = player.statManaMax; } player.hairColor.R = reader.ReadByte(); player.hairColor.G = reader.ReadByte(); player.hairColor.B = reader.ReadByte(); player.skinColor.R = reader.ReadByte(); player.skinColor.G = reader.ReadByte(); player.skinColor.B = reader.ReadByte(); player.eyeColor.R = reader.ReadByte(); player.eyeColor.G = reader.ReadByte(); player.eyeColor.B = reader.ReadByte(); player.shirtColor.R = reader.ReadByte(); player.shirtColor.G = reader.ReadByte(); player.shirtColor.B = reader.ReadByte(); player.underShirtColor.R = reader.ReadByte(); player.underShirtColor.G = reader.ReadByte(); player.underShirtColor.B = reader.ReadByte(); player.pantsColor.R = reader.ReadByte(); player.pantsColor.G = reader.ReadByte(); player.pantsColor.B = reader.ReadByte(); player.shoeColor.R = reader.ReadByte(); player.shoeColor.G = reader.ReadByte(); player.shoeColor.B = reader.ReadByte(); for (int i = 0; i < 8; i++) { player.armor[i].SetDefaults(reader.ReadString()); } for (int j = 0; j < 0x2c; j++) { player.inventory[j].SetDefaults(reader.ReadString()); player.inventory[j].stack = reader.ReadInt32(); } for (int k = 0; k < Chest.maxItems; k++) { player.bank[k].SetDefaults(reader.ReadString()); player.bank[k].stack = reader.ReadInt32(); } for (int m = 0; m < 200; m++) { int num5 = reader.ReadInt32(); if (num5 == -1) { break; } player.spX[m] = num5; player.spY[m] = reader.ReadInt32(); player.spI[m] = reader.ReadInt32(); player.spN[m] = reader.ReadString(); } reader.Close(); } } player.PlayerFrame(); File.Delete(outputFile); return player; } } catch { flag = true; } if (flag) { string path = playerPath + ".bak"; if (File.Exists(path)) { File.Delete(playerPath); File.Move(path, playerPath); return LoadPlayer(playerPath); } } return new Player(); }
public static PlayerFileData LoadPlayer(string playerPath) { PlayerFileData playerFileDatum; PlayerFileData playerFileDatum1 = new PlayerFileData(playerPath); if (Main.rand == null) { Main.rand = new Random((int)DateTime.Now.Ticks); } Player player = new Player(); try { RijndaelManaged rijndaelManaged = new RijndaelManaged() { Padding = PaddingMode.None }; using (MemoryStream memoryStream = new MemoryStream(FileUtilities.ReadAllBytes(playerPath))) { using (CryptoStream cryptoStream = new CryptoStream(memoryStream, rijndaelManaged.CreateDecryptor(Player.ENCRYPTION_KEY, Player.ENCRYPTION_KEY), CryptoStreamMode.Read)) { using (BinaryReader binaryReader = new BinaryReader(cryptoStream)) { int num = binaryReader.ReadInt32(); if (num < 135) { playerFileDatum1.Metadata = FileMetadata.FromCurrentSettings(FileType.Player); } else { playerFileDatum1.Metadata = FileMetadata.Read(binaryReader, FileType.Player); } if (num <= Main.curRelease) { player.name = binaryReader.ReadString(); if (num >= 10) { if (num >= 17) { player.difficulty = binaryReader.ReadByte(); } else if (binaryReader.ReadBoolean()) { player.difficulty = 2; } } if (num < 138) { playerFileDatum1.SetPlayTime(TimeSpan.Zero); } else { playerFileDatum1.SetPlayTime(new TimeSpan(binaryReader.ReadInt64())); } player.hair = binaryReader.ReadInt32(); if (num >= 82) { player.hairDye = binaryReader.ReadByte(); } if (num >= 124) { BitsByte bitsByte = binaryReader.ReadByte(); for (int i = 0; i < 8; i++) { player.hideVisual[i] = bitsByte[i]; } bitsByte = binaryReader.ReadByte(); for (int j = 0; j < 2; j++) { player.hideVisual[j + 8] = bitsByte[j]; } } else if (num >= 83) { BitsByte bitsByte1 = binaryReader.ReadByte(); for (int k = 0; k < 8; k++) { player.hideVisual[k] = bitsByte1[k]; } } if (num >= 119) { player.hideMisc = binaryReader.ReadByte(); } if (num <= 17) { if (player.hair == 5 || player.hair == 6 || player.hair == 9 || player.hair == 11) { player.Male = false; } else { player.Male = true; } } else if (num >= 107) { player.skinVariant = binaryReader.ReadByte(); } else { player.Male = binaryReader.ReadBoolean(); } player.statLife = binaryReader.ReadInt32(); player.statLifeMax = binaryReader.ReadInt32(); if (player.statLifeMax > 500) { player.statLifeMax = 500; } player.statMana = binaryReader.ReadInt32(); player.statManaMax = binaryReader.ReadInt32(); if (player.statManaMax > 200) { player.statManaMax = 200; } if (player.statMana > 400) { player.statMana = 400; } if (num >= 125) { player.extraAccessory = binaryReader.ReadBoolean(); } if (num >= 128) { player.taxMoney = binaryReader.ReadInt32(); } player.hairColor = binaryReader.ReadRGB(); player.skinColor = binaryReader.ReadRGB(); player.eyeColor = binaryReader.ReadRGB(); player.shirtColor = binaryReader.ReadRGB(); player.underShirtColor = binaryReader.ReadRGB(); player.pantsColor = binaryReader.ReadRGB(); player.shoeColor = binaryReader.ReadRGB(); Main.player[Main.myPlayer].shirtColor = player.shirtColor; Main.player[Main.myPlayer].pantsColor = player.pantsColor; Main.player[Main.myPlayer].hairColor = player.hairColor; if (num < 38) { for (int l = 0; l < 8; l++) { player.armor[l].SetDefaults(Item.VersionName(binaryReader.ReadString(), num)); if (num >= 36) { player.armor[l].Prefix((int)binaryReader.ReadByte()); } } if (num >= 6) { for (int m = 8; m < 11; m++) { player.armor[m].SetDefaults(Item.VersionName(binaryReader.ReadString(), num)); if (num >= 36) { player.armor[m].Prefix((int)binaryReader.ReadByte()); } } } for (int n = 0; n < 44; n++) { player.inventory[n].SetDefaults(Item.VersionName(binaryReader.ReadString(), num)); player.inventory[n].stack = binaryReader.ReadInt32(); if (num >= 36) { player.inventory[n].Prefix((int)binaryReader.ReadByte()); } } if (num >= 15) { for (int o = 44; o < 48; o++) { player.inventory[o].SetDefaults(Item.VersionName(binaryReader.ReadString(), num)); player.inventory[o].stack = binaryReader.ReadInt32(); if (num >= 36) { player.inventory[o].Prefix((int)binaryReader.ReadByte()); } } } for (int p = 0; p < 20; p++) { player.bank.item[p].SetDefaults(Item.VersionName(binaryReader.ReadString(), num)); player.bank.item[p].stack = binaryReader.ReadInt32(); if (num >= 36) { player.bank.item[p].Prefix((int)binaryReader.ReadByte()); } } if (num >= 20) { for (int q = 0; q < 20; q++) { player.bank2.item[q].SetDefaults(Item.VersionName(binaryReader.ReadString(), num)); player.bank2.item[q].stack = binaryReader.ReadInt32(); if (num >= 36) { player.bank2.item[q].Prefix((int)binaryReader.ReadByte()); } } } } else { if (num >= 124) { int num1 = 20; for (int r = 0; r < num1; r++) { player.armor[r].netDefaults(binaryReader.ReadInt32()); player.armor[r].Prefix((int)binaryReader.ReadByte()); } } else { int num2 = 11; if (num >= 81) { num2 = 16; } for (int s = 0; s < num2; s++) { int num3 = s; if (num3 >= 8) { num3 = num3 + 2; } player.armor[num3].netDefaults(binaryReader.ReadInt32()); player.armor[num3].Prefix((int)binaryReader.ReadByte()); } } if (num >= 47) { int num4 = 3; if (num >= 81) { num4 = 8; } if (num >= 124) { num4 = 10; } for (int t = 0; t < num4; t++) { int num5 = t; player.dye[num5].netDefaults(binaryReader.ReadInt32()); player.dye[num5].Prefix((int)binaryReader.ReadByte()); } } if (num < 58) { for (int u = 0; u < 48; u++) { int num6 = binaryReader.ReadInt32(); if (num6 < Main.maxItemTypes) { player.inventory[u].netDefaults(num6); player.inventory[u].stack = binaryReader.ReadInt32(); player.inventory[u].Prefix((int)binaryReader.ReadByte()); } else { player.inventory[u].netDefaults(0); } } } else { for (int v = 0; v < 58; v++) { int num7 = binaryReader.ReadInt32(); if (num7 < Main.maxItemTypes) { player.inventory[v].netDefaults(num7); player.inventory[v].stack = binaryReader.ReadInt32(); player.inventory[v].Prefix((int)binaryReader.ReadByte()); if (num >= 114) { player.inventory[v].favorited = binaryReader.ReadBoolean(); } } else { player.inventory[v].netDefaults(0); } } } if (num >= 117) { if (num >= 136) { for (int w = 0; w < 5; w++) { int num8 = binaryReader.ReadInt32(); if (num8 < Main.maxItemTypes) { player.miscEquips[w].netDefaults(num8); player.miscEquips[w].Prefix((int)binaryReader.ReadByte()); } else { player.miscEquips[w].netDefaults(0); } num8 = binaryReader.ReadInt32(); if (num8 < Main.maxItemTypes) { player.miscDyes[w].netDefaults(num8); player.miscDyes[w].Prefix((int)binaryReader.ReadByte()); } else { player.miscDyes[w].netDefaults(0); } } } else { for (int x = 0; x < 5; x++) { if (x != 1) { int num9 = binaryReader.ReadInt32(); if (num9 < Main.maxItemTypes) { player.miscEquips[x].netDefaults(num9); player.miscEquips[x].Prefix((int)binaryReader.ReadByte()); } else { player.miscEquips[x].netDefaults(0); } num9 = binaryReader.ReadInt32(); if (num9 < Main.maxItemTypes) { player.miscDyes[x].netDefaults(num9); player.miscDyes[x].Prefix((int)binaryReader.ReadByte()); } else { player.miscDyes[x].netDefaults(0); } } } } } if (num < 58) { for (int y = 0; y < 20; y++) { player.bank.item[y].netDefaults(binaryReader.ReadInt32()); player.bank.item[y].stack = binaryReader.ReadInt32(); player.bank.item[y].Prefix((int)binaryReader.ReadByte()); } for (int a = 0; a < 20; a++) { player.bank2.item[a].netDefaults(binaryReader.ReadInt32()); player.bank2.item[a].stack = binaryReader.ReadInt32(); player.bank2.item[a].Prefix((int)binaryReader.ReadByte()); } } else { for (int b = 0; b < 40; b++) { player.bank.item[b].netDefaults(binaryReader.ReadInt32()); player.bank.item[b].stack = binaryReader.ReadInt32(); player.bank.item[b].Prefix((int)binaryReader.ReadByte()); } for (int c = 0; c < 40; c++) { player.bank2.item[c].netDefaults(binaryReader.ReadInt32()); player.bank2.item[c].stack = binaryReader.ReadInt32(); player.bank2.item[c].Prefix((int)binaryReader.ReadByte()); } } } if (num < 58) { for (int d = 40; d < 48; d++) { player.inventory[d + 10] = player.inventory[d].Clone(); player.inventory[d].SetDefaults(0, false); } } if (num >= 11) { int num10 = 22; if (num < 74) { num10 = 10; } for (int e = 0; e < num10; e++) { player.buffType[e] = binaryReader.ReadInt32(); player.buffTime[e] = binaryReader.ReadInt32(); if (player.buffType[e] == 0) { e--; num10--; } } } for (int f = 0; f < 200; f++) { int num11 = binaryReader.ReadInt32(); if (num11 == -1) { break; } player.spX[f] = num11; player.spY[f] = binaryReader.ReadInt32(); player.spI[f] = binaryReader.ReadInt32(); player.spN[f] = binaryReader.ReadString(); } if (num >= 16) { player.hbLocked = binaryReader.ReadBoolean(); } if (num >= 115) { int num12 = 13; for (int g = 0; g < num12; g++) { player.hideInfo[g] = binaryReader.ReadBoolean(); } } if (num >= 98) { player.anglerQuestsFinished = binaryReader.ReadInt32(); } player.skinVariant = (int)MathHelper.Clamp((float)player.skinVariant, 0f, 7f); for (int h = 3; h < 8 + player.extraAccessorySlots; h++) { int num13 = player.armor[h].type; if (num13 == 908) { Player player1 = player; player1.lavaMax = player1.lavaMax + 420; } if (num13 == 906) { Player player2 = player; player2.lavaMax = player2.lavaMax + 420; } if (player.wingsLogic == 0 && player.armor[h].wingSlot >= 0) { player.wingsLogic = player.armor[h].wingSlot; } if (num13 == 158 || num13 == 396 || num13 == 1250 || num13 == 1251 || num13 == 1252) { player.noFallDmg = true; } player.lavaTime = player.lavaMax; } } else { player.loadStatus = 1; player.name = binaryReader.ReadString(); playerFileDatum1.Player = player; playerFileDatum = playerFileDatum1; return playerFileDatum; } } } } player.PlayerFrame(); player.loadStatus = 0; playerFileDatum1.Player = player; playerFileDatum = playerFileDatum1; } catch { Player player3 = new Player() { loadStatus = 2 }; if (player.name == "") { char[] directorySeparatorChar = new char[] { Path.DirectorySeparatorChar }; string[] strArrays = playerPath.Split(directorySeparatorChar); string str = strArrays[(int)strArrays.Length - 1]; char[] chrArray = new char[] { '.' }; player.name = str.Split(chrArray)[0]; } else { player3.name = player.name; } playerFileDatum1.Player = player3; return playerFileDatum1; } return playerFileDatum; }
public static Player LoadPlayer(string playerPath) { bool flag = false; if (Main.rand == null) { Main.rand = new Random((int)DateTime.Now.Ticks); } Player player = new Player(); try { string text = playerPath + ".dat"; flag = Player.DecryptFile(playerPath, text); if (!flag) { using (FileStream fileStream = new FileStream(text, FileMode.Open)) { using (BinaryReader binaryReader = new BinaryReader(fileStream)) { int num = binaryReader.ReadInt32(); player.name = binaryReader.ReadString(); if (num >= 10) { if (num >= 17) { player.difficulty = binaryReader.ReadByte(); } else { bool flag2 = binaryReader.ReadBoolean(); if (flag2) { player.difficulty = 2; } } } player.hair = binaryReader.ReadInt32(); if (num <= 17) { if (player.hair == 5 || player.hair == 6 || player.hair == 9 || player.hair == 11) { player.male = false; } else { player.male = true; } } else { player.male = binaryReader.ReadBoolean(); } player.statLife = binaryReader.ReadInt32(); player.statLifeMax = binaryReader.ReadInt32(); if (player.statLife > player.statLifeMax) { player.statLife = player.statLifeMax; } player.statMana = binaryReader.ReadInt32(); player.statManaMax = binaryReader.ReadInt32(); if (player.statMana > 400) //Mod: no cap on max mana { //player.statMana = 400; } player.hairColor.R = binaryReader.ReadByte(); player.hairColor.G = binaryReader.ReadByte(); player.hairColor.B = binaryReader.ReadByte(); player.skinColor.R = binaryReader.ReadByte(); player.skinColor.G = binaryReader.ReadByte(); player.skinColor.B = binaryReader.ReadByte(); player.eyeColor.R = binaryReader.ReadByte(); player.eyeColor.G = binaryReader.ReadByte(); player.eyeColor.B = binaryReader.ReadByte(); player.shirtColor.R = binaryReader.ReadByte(); player.shirtColor.G = binaryReader.ReadByte(); player.shirtColor.B = binaryReader.ReadByte(); player.underShirtColor.R = binaryReader.ReadByte(); player.underShirtColor.G = binaryReader.ReadByte(); player.underShirtColor.B = binaryReader.ReadByte(); player.pantsColor.R = binaryReader.ReadByte(); player.pantsColor.G = binaryReader.ReadByte(); player.pantsColor.B = binaryReader.ReadByte(); player.shoeColor.R = binaryReader.ReadByte(); player.shoeColor.G = binaryReader.ReadByte(); player.shoeColor.B = binaryReader.ReadByte(); Main.player[Main.myPlayer].shirtColor = player.shirtColor; Main.player[Main.myPlayer].pantsColor = player.pantsColor; Main.player[Main.myPlayer].hairColor = player.hairColor; for (int i = 0; i < 8; i++) { player.armor[i].SetDefaults(Item.VersionName(binaryReader.ReadString(), num)); if (num >= 36) { player.armor[i].Prefix((int)binaryReader.ReadByte()); } } if (num >= 6) { for (int j = 8; j < 11; j++) { player.armor[j].SetDefaults(Item.VersionName(binaryReader.ReadString(), num)); if (num >= 36) { player.armor[j].Prefix((int)binaryReader.ReadByte()); } } } for (int k = 0; k < 44; k++) { player.inventory[k].SetDefaults(Item.VersionName(binaryReader.ReadString(), num)); player.inventory[k].stack = binaryReader.ReadInt32(); if (num >= 36) { player.inventory[k].Prefix((int)binaryReader.ReadByte()); } } if (num >= 15) { for (int l = 44; l < 48; l++) { player.inventory[l].SetDefaults(Item.VersionName(binaryReader.ReadString(), num)); player.inventory[l].stack = binaryReader.ReadInt32(); if (num >= 36) { player.inventory[l].Prefix((int)binaryReader.ReadByte()); } } } for (int m = 0; m < Chest.maxItems; m++) { player.bank[m].SetDefaults(Item.VersionName(binaryReader.ReadString(), num)); player.bank[m].stack = binaryReader.ReadInt32(); if (num >= 36) { player.bank[m].Prefix((int)binaryReader.ReadByte()); } } if (num >= 20) { for (int n = 0; n < Chest.maxItems; n++) { player.bank2[n].SetDefaults(Item.VersionName(binaryReader.ReadString(), num)); player.bank2[n].stack = binaryReader.ReadInt32(); if (num >= 36) { player.bank2[n].Prefix((int)binaryReader.ReadByte()); } } } if (num >= 11) { for (int num2 = 0; num2 < 10; num2++) { player.buffType[num2] = binaryReader.ReadInt32(); player.buffTime[num2] = binaryReader.ReadInt32(); } } for (int num3 = 0; num3 < 200; num3++) { int num4 = binaryReader.ReadInt32(); if (num4 == -1) { break; } player.spX[num3] = num4; player.spY[num3] = binaryReader.ReadInt32(); player.spI[num3] = binaryReader.ReadInt32(); player.spN[num3] = binaryReader.ReadString(); } if (num >= 16) { player.hbLocked = binaryReader.ReadBoolean(); } binaryReader.Close(); } } player.PlayerFrame(); File.Delete(text); Player result = player; return result; } } catch { flag = true; } if (flag) { try { string text2 = playerPath + ".bak"; Player result; if (File.Exists(text2)) { File.Delete(playerPath); File.Move(text2, playerPath); result = Player.LoadPlayer(playerPath); return result; } result = new Player(); return result; } catch { Player result = new Player(); return result; } } return new Player(); }
public static Player LoadPlayer(string playerPath) { if (Main.rand == null) Main.rand = new Random((int)DateTime.Now.Ticks); Player player = new Player(); bool flag; try { string str = playerPath + ".dat"; flag = Player.DecryptFile(playerPath, str); if (!flag) { using (FileStream fileStream = new FileStream(str, FileMode.Open)) { using (BinaryReader binaryReader = new BinaryReader((Stream)fileStream)) { int release = binaryReader.ReadInt32(); player.name = binaryReader.ReadString(); if (release >= 10) { if (release >= 17) player.difficulty = binaryReader.ReadByte(); else if (binaryReader.ReadBoolean()) player.difficulty = (byte)2; } player.hair = binaryReader.ReadInt32(); player.male = release > 17 ? binaryReader.ReadBoolean() : player.hair != 5 && player.hair != 6 && (player.hair != 9 && player.hair != 11) || false; player.statLife = binaryReader.ReadInt32(); player.statLifeMax = binaryReader.ReadInt32(); if (player.statLifeMax > 400) player.statLifeMax = 400; if (player.statLife > player.statLifeMax) player.statLife = player.statLifeMax; player.statMana = binaryReader.ReadInt32(); player.statManaMax = binaryReader.ReadInt32(); if (player.statManaMax > 200) player.statManaMax = 200; if (player.statMana > 400) player.statMana = 400; player.hairColor.R = binaryReader.ReadByte(); player.hairColor.G = binaryReader.ReadByte(); player.hairColor.B = binaryReader.ReadByte(); player.skinColor.R = binaryReader.ReadByte(); player.skinColor.G = binaryReader.ReadByte(); player.skinColor.B = binaryReader.ReadByte(); player.eyeColor.R = binaryReader.ReadByte(); player.eyeColor.G = binaryReader.ReadByte(); player.eyeColor.B = binaryReader.ReadByte(); player.shirtColor.R = binaryReader.ReadByte(); player.shirtColor.G = binaryReader.ReadByte(); player.shirtColor.B = binaryReader.ReadByte(); player.underShirtColor.R = binaryReader.ReadByte(); player.underShirtColor.G = binaryReader.ReadByte(); player.underShirtColor.B = binaryReader.ReadByte(); player.pantsColor.R = binaryReader.ReadByte(); player.pantsColor.G = binaryReader.ReadByte(); player.pantsColor.B = binaryReader.ReadByte(); player.shoeColor.R = binaryReader.ReadByte(); player.shoeColor.G = binaryReader.ReadByte(); player.shoeColor.B = binaryReader.ReadByte(); Main.player[Main.myPlayer].shirtColor = player.shirtColor; Main.player[Main.myPlayer].pantsColor = player.pantsColor; Main.player[Main.myPlayer].hairColor = player.hairColor; if (release >= 38) { for (int index = 0; index < 11; ++index) { player.armor[index].netDefaults(binaryReader.ReadInt32()); player.armor[index].Prefix((int)binaryReader.ReadByte()); } for (int index = 0; index < 48; ++index) { player.inventory[index].netDefaults(binaryReader.ReadInt32()); player.inventory[index].stack = binaryReader.ReadInt32(); player.inventory[index].Prefix((int)binaryReader.ReadByte()); } for (int index = 0; index < Chest.maxItems; ++index) { player.bank[index].netDefaults(binaryReader.ReadInt32()); player.bank[index].stack = binaryReader.ReadInt32(); player.bank[index].Prefix((int)binaryReader.ReadByte()); } for (int index = 0; index < Chest.maxItems; ++index) { player.bank2[index].netDefaults(binaryReader.ReadInt32()); player.bank2[index].stack = binaryReader.ReadInt32(); player.bank2[index].Prefix((int)binaryReader.ReadByte()); } } else { for (int index = 0; index < 8; ++index) { player.armor[index].SetDefaults(Item.VersionName(binaryReader.ReadString(), release)); if (release >= 36) player.armor[index].Prefix((int)binaryReader.ReadByte()); } if (release >= 6) { for (int index = 8; index < 11; ++index) { player.armor[index].SetDefaults(Item.VersionName(binaryReader.ReadString(), release)); if (release >= 36) player.armor[index].Prefix((int)binaryReader.ReadByte()); } } for (int index = 0; index < 44; ++index) { player.inventory[index].SetDefaults(Item.VersionName(binaryReader.ReadString(), release)); player.inventory[index].stack = binaryReader.ReadInt32(); if (release >= 36) player.inventory[index].Prefix((int)binaryReader.ReadByte()); } if (release >= 15) { for (int index = 44; index < 48; ++index) { player.inventory[index].SetDefaults(Item.VersionName(binaryReader.ReadString(), release)); player.inventory[index].stack = binaryReader.ReadInt32(); if (release >= 36) player.inventory[index].Prefix((int)binaryReader.ReadByte()); } } for (int index = 0; index < Chest.maxItems; ++index) { player.bank[index].SetDefaults(Item.VersionName(binaryReader.ReadString(), release)); player.bank[index].stack = binaryReader.ReadInt32(); if (release >= 36) player.bank[index].Prefix((int)binaryReader.ReadByte()); } if (release >= 20) { for (int index = 0; index < Chest.maxItems; ++index) { player.bank2[index].SetDefaults(Item.VersionName(binaryReader.ReadString(), release)); player.bank2[index].stack = binaryReader.ReadInt32(); if (release >= 36) player.bank2[index].Prefix((int)binaryReader.ReadByte()); } } } if (release >= 11) { for (int index = 0; index < 10; ++index) { player.buffType[index] = binaryReader.ReadInt32(); player.buffTime[index] = binaryReader.ReadInt32(); } } for (int index = 0; index < 200; ++index) { int num = binaryReader.ReadInt32(); if (num != -1) { player.spX[index] = num; player.spY[index] = binaryReader.ReadInt32(); player.spI[index] = binaryReader.ReadInt32(); player.spN[index] = binaryReader.ReadString(); } else break; } if (release >= 16) player.hbLocked = binaryReader.ReadBoolean(); binaryReader.Close(); } } player.PlayerFrame(); File.Delete(str); return player; } } catch { flag = true; } if (!flag) return new Player(); try { string str = playerPath + ".bak"; if (!File.Exists(str)) return new Player(); File.Delete(playerPath); File.Move(str, playerPath); return Player.LoadPlayer(playerPath); } catch { return new Player(); } }
public static Player LoadPlayer(string playerPath, bool decryptedCopy = false) { if (Main.rand == null) { Main.rand = new Random((int)DateTime.Now.Ticks); } Player player = new Player(); try { string text = playerPath + ".dat"; Player result; if (!decryptedCopy) { bool flag = Player.DecryptFile(playerPath, text); if (flag) { using (FileStream fileStream = new FileStream(playerPath, FileMode.Open)) { while (fileStream.Position < fileStream.Length && fileStream.ReadByte() == 0) { } if (fileStream.Position == fileStream.Length) { player.loadStatus = 3; } else { player.loadStatus = 4; } string[] array = playerPath.Split(new char[] { Path.DirectorySeparatorChar }); player.name = array[array.Length - 1].Split(new char[] { '.' })[0]; result = player; return result; } } } using (FileStream fileStream2 = new FileStream(text, FileMode.Open)) { using (BinaryReader binaryReader = new BinaryReader(fileStream2)) { int num = binaryReader.ReadInt32(); if (num > Main.curRelease) { player.loadStatus = 1; player.name = binaryReader.ReadString(); result = player; return result; } player.name = binaryReader.ReadString(); if (num >= 10) { if (num >= 17) { player.difficulty = binaryReader.ReadByte(); } else { bool flag2 = binaryReader.ReadBoolean(); if (flag2) { player.difficulty = 2; } } } player.hair = binaryReader.ReadInt32(); if (num >= 82) { player.hairDye = binaryReader.ReadByte(); } if (num >= 83) { player.hideVisual = binaryReader.ReadByte(); } if (num <= 17) { if (player.hair == 5 || player.hair == 6 || player.hair == 9 || player.hair == 11) { player.male = false; } else { player.male = true; } } else { player.male = binaryReader.ReadBoolean(); } player.statLife = binaryReader.ReadInt32(); player.statLifeMax = binaryReader.ReadInt32(); if (player.statLifeMax > 500) { player.statLifeMax = 500; } if (player.statLife > player.statLifeMax) { player.statLife = player.statLifeMax; } player.statMana = binaryReader.ReadInt32(); player.statManaMax = binaryReader.ReadInt32(); if (player.statManaMax > 200) { player.statManaMax = 200; } if (player.statMana > 400) { player.statMana = 400; } player.hairColor.R = binaryReader.ReadByte(); player.hairColor.G = binaryReader.ReadByte(); player.hairColor.B = binaryReader.ReadByte(); player.skinColor.R = binaryReader.ReadByte(); player.skinColor.G = binaryReader.ReadByte(); player.skinColor.B = binaryReader.ReadByte(); player.eyeColor.R = binaryReader.ReadByte(); player.eyeColor.G = binaryReader.ReadByte(); player.eyeColor.B = binaryReader.ReadByte(); player.shirtColor.R = binaryReader.ReadByte(); player.shirtColor.G = binaryReader.ReadByte(); player.shirtColor.B = binaryReader.ReadByte(); player.underShirtColor.R = binaryReader.ReadByte(); player.underShirtColor.G = binaryReader.ReadByte(); player.underShirtColor.B = binaryReader.ReadByte(); player.pantsColor.R = binaryReader.ReadByte(); player.pantsColor.G = binaryReader.ReadByte(); player.pantsColor.B = binaryReader.ReadByte(); player.shoeColor.R = binaryReader.ReadByte(); player.shoeColor.G = binaryReader.ReadByte(); player.shoeColor.B = binaryReader.ReadByte(); Main.player[Main.myPlayer].shirtColor = player.shirtColor; Main.player[Main.myPlayer].pantsColor = player.pantsColor; Main.player[Main.myPlayer].hairColor = player.hairColor; if (num >= 38) { int num2 = 11; if (num >= 81) { num2 = 16; } for (int i = 0; i < num2; i++) { player.armor[i].netDefaults(binaryReader.ReadInt32()); player.armor[i].Prefix((int)binaryReader.ReadByte()); } if (num >= 47) { int num3 = 3; if (num >= 81) { num3 = 8; } for (int j = 0; j < num3; j++) { player.dye[j].netDefaults(binaryReader.ReadInt32()); player.dye[j].Prefix((int)binaryReader.ReadByte()); } } if (num >= 58) { for (int k = 0; k < 58; k++) { int num4 = binaryReader.ReadInt32(); if (num4 >= 2289) { player.inventory[k].netDefaults(0); } else { player.inventory[k].netDefaults(num4); player.inventory[k].stack = binaryReader.ReadInt32(); player.inventory[k].Prefix((int)binaryReader.ReadByte()); } } } else { for (int l = 0; l < 48; l++) { int num5 = binaryReader.ReadInt32(); if (num5 >= 2289) { player.inventory[l].netDefaults(0); } else { player.inventory[l].netDefaults(num5); player.inventory[l].stack = binaryReader.ReadInt32(); player.inventory[l].Prefix((int)binaryReader.ReadByte()); } } } if (num >= 58) { for (int m = 0; m < 40; m++) { player.bank.item[m].netDefaults(binaryReader.ReadInt32()); player.bank.item[m].stack = binaryReader.ReadInt32(); player.bank.item[m].Prefix((int)binaryReader.ReadByte()); } for (int n = 0; n < 40; n++) { player.bank2.item[n].netDefaults(binaryReader.ReadInt32()); player.bank2.item[n].stack = binaryReader.ReadInt32(); player.bank2.item[n].Prefix((int)binaryReader.ReadByte()); } } else { for (int num6 = 0; num6 < 20; num6++) { player.bank.item[num6].netDefaults(binaryReader.ReadInt32()); player.bank.item[num6].stack = binaryReader.ReadInt32(); player.bank.item[num6].Prefix((int)binaryReader.ReadByte()); } for (int num7 = 0; num7 < 20; num7++) { player.bank2.item[num7].netDefaults(binaryReader.ReadInt32()); player.bank2.item[num7].stack = binaryReader.ReadInt32(); player.bank2.item[num7].Prefix((int)binaryReader.ReadByte()); } } } else { for (int num8 = 0; num8 < 8; num8++) { player.armor[num8].SetDefaults(Item.VersionName(binaryReader.ReadString(), num)); if (num >= 36) { player.armor[num8].Prefix((int)binaryReader.ReadByte()); } } if (num >= 6) { for (int num9 = 8; num9 < 11; num9++) { player.armor[num9].SetDefaults(Item.VersionName(binaryReader.ReadString(), num)); if (num >= 36) { player.armor[num9].Prefix((int)binaryReader.ReadByte()); } } } for (int num10 = 0; num10 < 44; num10++) { player.inventory[num10].SetDefaults(Item.VersionName(binaryReader.ReadString(), num)); player.inventory[num10].stack = binaryReader.ReadInt32(); if (num >= 36) { player.inventory[num10].Prefix((int)binaryReader.ReadByte()); } } if (num >= 15) { for (int num11 = 44; num11 < 48; num11++) { player.inventory[num11].SetDefaults(Item.VersionName(binaryReader.ReadString(), num)); player.inventory[num11].stack = binaryReader.ReadInt32(); if (num >= 36) { player.inventory[num11].Prefix((int)binaryReader.ReadByte()); } } } for (int num12 = 0; num12 < 20; num12++) { player.bank.item[num12].SetDefaults(Item.VersionName(binaryReader.ReadString(), num)); player.bank.item[num12].stack = binaryReader.ReadInt32(); if (num >= 36) { player.bank.item[num12].Prefix((int)binaryReader.ReadByte()); } } if (num >= 20) { for (int num13 = 0; num13 < 20; num13++) { player.bank2.item[num13].SetDefaults(Item.VersionName(binaryReader.ReadString(), num)); player.bank2.item[num13].stack = binaryReader.ReadInt32(); if (num >= 36) { player.bank2.item[num13].Prefix((int)binaryReader.ReadByte()); } } } } if (num < 58) { for (int num14 = 40; num14 < 48; num14++) { player.inventory[num14 + 10] = player.inventory[num14].Clone(); player.inventory[num14].SetDefaults(0, false); } } if (num >= 11) { int num15 = 22; if (num < 74) { num15 = 10; } for (int num16 = 0; num16 < num15; num16++) { player.buffType[num16] = binaryReader.ReadInt32(); player.buffTime[num16] = binaryReader.ReadInt32(); } } for (int num17 = 0; num17 < 200; num17++) { int num18 = binaryReader.ReadInt32(); if (num18 == -1) { break; } player.spX[num17] = num18; player.spY[num17] = binaryReader.ReadInt32(); player.spI[num17] = binaryReader.ReadInt32(); player.spN[num17] = binaryReader.ReadString(); } if (num >= 16) { player.hbLocked = binaryReader.ReadBoolean(); } binaryReader.Close(); } } player.PlayerFrame(); if (decryptedCopy) { Player.EncryptFile(text, playerPath); File.Delete(text); } else { File.Delete(text); } player.loadStatus = 0; result = player; return result; } catch { } Player player2 = new Player(); player2.loadStatus = 2; if (player.name != "") { player2.name = player.name; } else { string[] array2 = playerPath.Split(new char[] { Path.DirectorySeparatorChar }); player.name = array2[array2.Length - 1].Split(new char[] { '.' })[0]; } return player2; }
public static Player LoadPlayer(string playerPath) { if (Main.rand == null) Main.rand = new Random((int) DateTime.Now.Ticks); Player player = new Player(); bool flag; try { string str = playerPath + ".dat"; flag = Player.DecryptFile(playerPath, str); if (!flag) { using (FileStream fileStream = new FileStream(str, FileMode.Open)) { using (BinaryReader binaryReader = new BinaryReader((Stream) fileStream)) { int release = binaryReader.ReadInt32(); player.name = binaryReader.ReadString(); player.hair = binaryReader.ReadInt32(); player.statLife = binaryReader.ReadInt32(); player.statLifeMax = binaryReader.ReadInt32(); if (player.statLife > player.statLifeMax) player.statLife = player.statLifeMax; player.statMana = binaryReader.ReadInt32(); player.statManaMax = binaryReader.ReadInt32(); if (player.statMana > player.statManaMax) player.statMana = player.statManaMax; player.hairColor.R = binaryReader.ReadByte(); player.hairColor.G = binaryReader.ReadByte(); player.hairColor.B = binaryReader.ReadByte(); player.skinColor.R = binaryReader.ReadByte(); player.skinColor.G = binaryReader.ReadByte(); player.skinColor.B = binaryReader.ReadByte(); player.eyeColor.R = binaryReader.ReadByte(); player.eyeColor.G = binaryReader.ReadByte(); player.eyeColor.B = binaryReader.ReadByte(); player.shirtColor.R = binaryReader.ReadByte(); player.shirtColor.G = binaryReader.ReadByte(); player.shirtColor.B = binaryReader.ReadByte(); player.underShirtColor.R = binaryReader.ReadByte(); player.underShirtColor.G = binaryReader.ReadByte(); player.underShirtColor.B = binaryReader.ReadByte(); player.pantsColor.R = binaryReader.ReadByte(); player.pantsColor.G = binaryReader.ReadByte(); player.pantsColor.B = binaryReader.ReadByte(); player.shoeColor.R = binaryReader.ReadByte(); player.shoeColor.G = binaryReader.ReadByte(); player.shoeColor.B = binaryReader.ReadByte(); for (int index = 0; index < 8; ++index) player.armor[index].SetDefaults(Item.VersionName(binaryReader.ReadString(), release)); if (release >= 6) { for (int index = 8; index < 11; ++index) player.armor[index].SetDefaults(Item.VersionName(binaryReader.ReadString(), release)); } for (int index = 0; index < 44; ++index) { player.inventory[index].SetDefaults(Item.VersionName(binaryReader.ReadString(), release)); player.inventory[index].stack = binaryReader.ReadInt32(); } for (int index = 0; index < Chest.maxItems; ++index) { player.bank[index].SetDefaults(Item.VersionName(binaryReader.ReadString(), release)); player.bank[index].stack = binaryReader.ReadInt32(); } for (int index = 0; index < 200; ++index) { int num = binaryReader.ReadInt32(); if (num != -1) { player.spX[index] = num; player.spY[index] = binaryReader.ReadInt32(); player.spI[index] = binaryReader.ReadInt32(); player.spN[index] = binaryReader.ReadString(); } else break; } binaryReader.Close(); } } player.PlayerFrame(); File.Delete(str); return player; } } catch { flag = true; } if (flag) { string str = playerPath + ".bak"; if (File.Exists(str)) { File.Delete(playerPath); File.Move(str, playerPath); return Player.LoadPlayer(playerPath); } else return new Player(); } else return new Player(); }
public static Player LoadPlayer(string playerPath) { bool flag = false; if (Main.rand == null) { Main.rand = new System.Random((int)System.DateTime.Now.Ticks); } Player player = new Player(); Player result; try { string text = playerPath + ".dat"; flag = Player.DecryptFile(playerPath, text); if (!flag) { using (System.IO.FileStream fileStream = new System.IO.FileStream(text, System.IO.FileMode.Open)) { using (System.IO.BinaryReader binaryReader = new System.IO.BinaryReader(fileStream)) { int release = binaryReader.ReadInt32(); player.name = binaryReader.ReadString(); player.hair = binaryReader.ReadInt32(); player.statLife = binaryReader.ReadInt32(); player.statLifeMax = binaryReader.ReadInt32(); if (player.statLife > player.statLifeMax) { player.statLife = player.statLifeMax; } player.statMana = binaryReader.ReadInt32(); player.statManaMax = binaryReader.ReadInt32(); if (player.statMana > player.statManaMax) { player.statMana = player.statManaMax; } player.hairColor.R = binaryReader.ReadByte(); player.hairColor.G = binaryReader.ReadByte(); player.hairColor.B = binaryReader.ReadByte(); player.skinColor.R = binaryReader.ReadByte(); player.skinColor.G = binaryReader.ReadByte(); player.skinColor.B = binaryReader.ReadByte(); player.eyeColor.R = binaryReader.ReadByte(); player.eyeColor.G = binaryReader.ReadByte(); player.eyeColor.B = binaryReader.ReadByte(); player.shirtColor.R = binaryReader.ReadByte(); player.shirtColor.G = binaryReader.ReadByte(); player.shirtColor.B = binaryReader.ReadByte(); player.underShirtColor.R = binaryReader.ReadByte(); player.underShirtColor.G = binaryReader.ReadByte(); player.underShirtColor.B = binaryReader.ReadByte(); player.pantsColor.R = binaryReader.ReadByte(); player.pantsColor.G = binaryReader.ReadByte(); player.pantsColor.B = binaryReader.ReadByte(); player.shoeColor.R = binaryReader.ReadByte(); player.shoeColor.G = binaryReader.ReadByte(); player.shoeColor.B = binaryReader.ReadByte(); for (int i = 0; i < 8; i++) { player.armor[i].SetDefaults(Item.VersionName(binaryReader.ReadString(), release)); } for (int i = 0; i < 44; i++) { player.inventory[i].SetDefaults(Item.VersionName(binaryReader.ReadString(), release)); player.inventory[i].stack = binaryReader.ReadInt32(); } for (int i = 0; i < Chest.maxItems; i++) { player.bank[i].SetDefaults(Item.VersionName(binaryReader.ReadString(), release)); player.bank[i].stack = binaryReader.ReadInt32(); } for (int i = 0; i < 200; i++) { int num = binaryReader.ReadInt32(); if (num == -1) { break; } player.spX[i] = num; player.spY[i] = binaryReader.ReadInt32(); player.spI[i] = binaryReader.ReadInt32(); player.spN[i] = binaryReader.ReadString(); } binaryReader.Close(); } } player.PlayerFrame(); System.IO.File.Delete(text); result = player; return result; } } catch { flag = true; } if (flag) { string text2 = playerPath + ".bak"; if (System.IO.File.Exists(text2)) { System.IO.File.Delete(playerPath); System.IO.File.Move(text2, playerPath); result = Player.LoadPlayer(playerPath); } else { result = new Player(); } } else { result = new Player(); } return result; }
public static PlayerFileData LoadPlayer(string playerPath, bool cloudSave) { PlayerFileData playerFileData = new PlayerFileData(playerPath, cloudSave); if (cloudSave && SocialAPI.Cloud == null) { return playerFileData; } if (Main.rand == null) { Main.rand = new Random((int)DateTime.Now.Ticks); } Player player = new Player(); try { RijndaelManaged rijndaelManaged = new RijndaelManaged(); rijndaelManaged.Padding = PaddingMode.None; byte[] buffer = FileUtilities.ReadAllBytes(playerPath, cloudSave); PlayerFileData result; using (MemoryStream memoryStream = new MemoryStream(buffer)) { using (CryptoStream cryptoStream = new CryptoStream(memoryStream, rijndaelManaged.CreateDecryptor(Player.ENCRYPTION_KEY, Player.ENCRYPTION_KEY), CryptoStreamMode.Read)) { using (BinaryReader binaryReader = new BinaryReader(cryptoStream)) { int num = binaryReader.ReadInt32(); if (num >= 135) { playerFileData.Metadata = FileMetadata.Read(binaryReader, FileType.Player); } else { playerFileData.Metadata = FileMetadata.FromCurrentSettings(FileType.Player); } if (num > Main.curRelease) { player.loadStatus = 1; player.name = binaryReader.ReadString(); playerFileData.Player = player; result = playerFileData; return result; } player.name = binaryReader.ReadString(); if (num >= 10) { if (num >= 17) { player.difficulty = binaryReader.ReadByte(); } else { bool flag = binaryReader.ReadBoolean(); if (flag) { player.difficulty = 2; } } } if (num >= 138) { playerFileData.SetPlayTime(new TimeSpan(binaryReader.ReadInt64())); } else { playerFileData.SetPlayTime(TimeSpan.Zero); } player.hair = binaryReader.ReadInt32(); if (num >= 82) { player.hairDye = binaryReader.ReadByte(); } if (num >= 124) { BitsByte bitsByte = binaryReader.ReadByte(); for (int i = 0; i < 8; i++) { player.hideVisual[i] = bitsByte[i]; } bitsByte = binaryReader.ReadByte(); for (int j = 0; j < 2; j++) { player.hideVisual[j + 8] = bitsByte[j]; } } else if (num >= 83) { BitsByte bitsByte2 = binaryReader.ReadByte(); for (int k = 0; k < 8; k++) { player.hideVisual[k] = bitsByte2[k]; } } if (num >= 119) { player.hideMisc = binaryReader.ReadByte(); } if (num <= 17) { if (player.hair == 5 || player.hair == 6 || player.hair == 9 || player.hair == 11) { player.Male = false; } else { player.Male = true; } } else if (num < 107) { player.Male = binaryReader.ReadBoolean(); } else { player.skinVariant = (int)binaryReader.ReadByte(); } player.statLife = binaryReader.ReadInt32(); player.statLifeMax = binaryReader.ReadInt32(); if (player.statLifeMax > 500) { player.statLifeMax = 500; } player.statMana = binaryReader.ReadInt32(); player.statManaMax = binaryReader.ReadInt32(); if (player.statManaMax > 200) { player.statManaMax = 200; } if (player.statMana > 400) { player.statMana = 400; } if (num >= 125) { player.extraAccessory = binaryReader.ReadBoolean(); } if (num >= 128) { player.taxMoney = binaryReader.ReadInt32(); } player.hairColor = binaryReader.ReadRGB(); player.skinColor = binaryReader.ReadRGB(); player.eyeColor = binaryReader.ReadRGB(); player.shirtColor = binaryReader.ReadRGB(); player.underShirtColor = binaryReader.ReadRGB(); player.pantsColor = binaryReader.ReadRGB(); player.shoeColor = binaryReader.ReadRGB(); Main.player[Main.myPlayer].shirtColor = player.shirtColor; Main.player[Main.myPlayer].pantsColor = player.pantsColor; Main.player[Main.myPlayer].hairColor = player.hairColor; if (num >= 38) { if (num < 124) { int num2 = 11; if (num >= 81) { num2 = 16; } for (int l = 0; l < num2; l++) { int num3 = l; if (num3 >= 8) { num3 += 2; } player.armor[num3].netDefaults(binaryReader.ReadInt32()); player.armor[num3].Prefix((int)binaryReader.ReadByte()); } } else { int num4 = 20; for (int m = 0; m < num4; m++) { player.armor[m].netDefaults(binaryReader.ReadInt32()); player.armor[m].Prefix((int)binaryReader.ReadByte()); } } if (num >= 47) { int num5 = 3; if (num >= 81) { num5 = 8; } if (num >= 124) { num5 = 10; } for (int n = 0; n < num5; n++) { int num6 = n; player.dye[num6].netDefaults(binaryReader.ReadInt32()); player.dye[num6].Prefix((int)binaryReader.ReadByte()); } } if (num >= 58) { for (int num7 = 0; num7 < 58; num7++) { int num8 = binaryReader.ReadInt32(); if (num8 >= 3602) { player.inventory[num7].netDefaults(0); } else { player.inventory[num7].netDefaults(num8); player.inventory[num7].stack = binaryReader.ReadInt32(); player.inventory[num7].Prefix((int)binaryReader.ReadByte()); if (num >= 114) { player.inventory[num7].favorited = binaryReader.ReadBoolean(); } } } } else { for (int num9 = 0; num9 < 48; num9++) { int num10 = binaryReader.ReadInt32(); if (num10 >= 3602) { player.inventory[num9].netDefaults(0); } else { player.inventory[num9].netDefaults(num10); player.inventory[num9].stack = binaryReader.ReadInt32(); player.inventory[num9].Prefix((int)binaryReader.ReadByte()); } } } if (num >= 117) { if (num < 136) { for (int num11 = 0; num11 < 5; num11++) { if (num11 != 1) { int num12 = binaryReader.ReadInt32(); if (num12 >= 3602) { player.miscEquips[num11].netDefaults(0); } else { player.miscEquips[num11].netDefaults(num12); player.miscEquips[num11].Prefix((int)binaryReader.ReadByte()); } num12 = binaryReader.ReadInt32(); if (num12 >= 3602) { player.miscDyes[num11].netDefaults(0); } else { player.miscDyes[num11].netDefaults(num12); player.miscDyes[num11].Prefix((int)binaryReader.ReadByte()); } } } } else { for (int num13 = 0; num13 < 5; num13++) { int num14 = binaryReader.ReadInt32(); if (num14 >= 3602) { player.miscEquips[num13].netDefaults(0); } else { player.miscEquips[num13].netDefaults(num14); player.miscEquips[num13].Prefix((int)binaryReader.ReadByte()); } num14 = binaryReader.ReadInt32(); if (num14 >= 3602) { player.miscDyes[num13].netDefaults(0); } else { player.miscDyes[num13].netDefaults(num14); player.miscDyes[num13].Prefix((int)binaryReader.ReadByte()); } } } } if (num >= 58) { for (int num15 = 0; num15 < 40; num15++) { player.bank.item[num15].netDefaults(binaryReader.ReadInt32()); player.bank.item[num15].stack = binaryReader.ReadInt32(); player.bank.item[num15].Prefix((int)binaryReader.ReadByte()); } for (int num16 = 0; num16 < 40; num16++) { player.bank2.item[num16].netDefaults(binaryReader.ReadInt32()); player.bank2.item[num16].stack = binaryReader.ReadInt32(); player.bank2.item[num16].Prefix((int)binaryReader.ReadByte()); } } else { for (int num17 = 0; num17 < 20; num17++) { player.bank.item[num17].netDefaults(binaryReader.ReadInt32()); player.bank.item[num17].stack = binaryReader.ReadInt32(); player.bank.item[num17].Prefix((int)binaryReader.ReadByte()); } for (int num18 = 0; num18 < 20; num18++) { player.bank2.item[num18].netDefaults(binaryReader.ReadInt32()); player.bank2.item[num18].stack = binaryReader.ReadInt32(); player.bank2.item[num18].Prefix((int)binaryReader.ReadByte()); } } } else { for (int num19 = 0; num19 < 8; num19++) { player.armor[num19].SetDefaults(Item.VersionName(binaryReader.ReadString(), num)); if (num >= 36) { player.armor[num19].Prefix((int)binaryReader.ReadByte()); } } if (num >= 6) { for (int num20 = 8; num20 < 11; num20++) { player.armor[num20].SetDefaults(Item.VersionName(binaryReader.ReadString(), num)); if (num >= 36) { player.armor[num20].Prefix((int)binaryReader.ReadByte()); } } } for (int num21 = 0; num21 < 44; num21++) { player.inventory[num21].SetDefaults(Item.VersionName(binaryReader.ReadString(), num)); player.inventory[num21].stack = binaryReader.ReadInt32(); if (num >= 36) { player.inventory[num21].Prefix((int)binaryReader.ReadByte()); } } if (num >= 15) { for (int num22 = 44; num22 < 48; num22++) { player.inventory[num22].SetDefaults(Item.VersionName(binaryReader.ReadString(), num)); player.inventory[num22].stack = binaryReader.ReadInt32(); if (num >= 36) { player.inventory[num22].Prefix((int)binaryReader.ReadByte()); } } } for (int num23 = 0; num23 < 20; num23++) { player.bank.item[num23].SetDefaults(Item.VersionName(binaryReader.ReadString(), num)); player.bank.item[num23].stack = binaryReader.ReadInt32(); if (num >= 36) { player.bank.item[num23].Prefix((int)binaryReader.ReadByte()); } } if (num >= 20) { for (int num24 = 0; num24 < 20; num24++) { player.bank2.item[num24].SetDefaults(Item.VersionName(binaryReader.ReadString(), num)); player.bank2.item[num24].stack = binaryReader.ReadInt32(); if (num >= 36) { player.bank2.item[num24].Prefix((int)binaryReader.ReadByte()); } } } } if (num < 58) { for (int num25 = 40; num25 < 48; num25++) { player.inventory[num25 + 10] = player.inventory[num25].Clone(); player.inventory[num25].SetDefaults(0, false); } } if (num >= 11) { int num26 = 22; if (num < 74) { num26 = 10; } for (int num27 = 0; num27 < num26; num27++) { player.buffType[num27] = binaryReader.ReadInt32(); player.buffTime[num27] = binaryReader.ReadInt32(); if (player.buffType[num27] == 0) { num27--; num26--; } } } for (int num28 = 0; num28 < 200; num28++) { int num29 = binaryReader.ReadInt32(); if (num29 == -1) { break; } player.spX[num28] = num29; player.spY[num28] = binaryReader.ReadInt32(); player.spI[num28] = binaryReader.ReadInt32(); player.spN[num28] = binaryReader.ReadString(); } if (num >= 16) { player.hbLocked = binaryReader.ReadBoolean(); } if (num >= 115) { int num30 = 13; for (int num31 = 0; num31 < num30; num31++) { player.hideInfo[num31] = binaryReader.ReadBoolean(); } } if (num >= 98) { player.anglerQuestsFinished = binaryReader.ReadInt32(); } player.skinVariant = (int)MathHelper.Clamp((float)player.skinVariant, 0f, 7f); for (int num32 = 3; num32 < 8 + player.extraAccessorySlots; num32++) { int type = player.armor[num32].type; if (type == 908) { player.lavaMax += 420; } if (type == 906) { player.lavaMax += 420; } if (player.wingsLogic == 0 && player.armor[num32].wingSlot >= 0) { player.wingsLogic = (int)player.armor[num32].wingSlot; } if (type == 158 || type == 396 || type == 1250 || type == 1251 || type == 1252) { player.noFallDmg = true; } player.lavaTime = player.lavaMax; } } } } player.PlayerFrame(); player.loadStatus = 0; playerFileData.Player = player; result = playerFileData; return result; } catch { } Player player2 = new Player(); player2.loadStatus = 2; if (player.name != "") { player2.name = player.name; } else { string[] array = playerPath.Split(new char[] { Path.DirectorySeparatorChar }); player.name = array[array.Length - 1].Split(new char[] { '.' })[0]; } playerFileData.Player = player2; return playerFileData; }
public static Player LoadPlayer(string playerPath) { bool flag = false; if (Main.rand == null) { Main.rand = new Random((int)DateTime.Now.Ticks); } Player player = new Player(); try { string text = playerPath + ".dat"; flag = Player.DecryptFile(playerPath, text); if (!flag) { using (FileStream fileStream = new FileStream(text, FileMode.Open)) { using (BinaryReader binaryReader = new BinaryReader(fileStream)) { int num = binaryReader.ReadInt32(); player.name = binaryReader.ReadString(); if (num >= 10) { if (num >= 17) { player.difficulty = binaryReader.ReadByte(); } else { bool flag2 = binaryReader.ReadBoolean(); if (flag2) { player.difficulty = 2; } } } player.hair = binaryReader.ReadInt32(); if (num <= 17) { if (player.hair == 5 || player.hair == 6 || player.hair == 9 || player.hair == 11) { player.male = false; } else { player.male = true; } } else { player.male = binaryReader.ReadBoolean(); } player.statLife = binaryReader.ReadInt32(); player.statLifeMax = binaryReader.ReadInt32(); if (player.statLifeMax > 500) { player.statLifeMax = 500; } if (player.statLife > player.statLifeMax) { player.statLife = player.statLifeMax; } player.statMana = binaryReader.ReadInt32(); player.statManaMax = binaryReader.ReadInt32(); if (player.statManaMax > 200) { player.statManaMax = 200; } if (player.statMana > 400) { player.statMana = 400; } player.hairColor.R = binaryReader.ReadByte(); player.hairColor.G = binaryReader.ReadByte(); player.hairColor.B = binaryReader.ReadByte(); player.skinColor.R = binaryReader.ReadByte(); player.skinColor.G = binaryReader.ReadByte(); player.skinColor.B = binaryReader.ReadByte(); player.eyeColor.R = binaryReader.ReadByte(); player.eyeColor.G = binaryReader.ReadByte(); player.eyeColor.B = binaryReader.ReadByte(); player.shirtColor.R = binaryReader.ReadByte(); player.shirtColor.G = binaryReader.ReadByte(); player.shirtColor.B = binaryReader.ReadByte(); player.underShirtColor.R = binaryReader.ReadByte(); player.underShirtColor.G = binaryReader.ReadByte(); player.underShirtColor.B = binaryReader.ReadByte(); player.pantsColor.R = binaryReader.ReadByte(); player.pantsColor.G = binaryReader.ReadByte(); player.pantsColor.B = binaryReader.ReadByte(); player.shoeColor.R = binaryReader.ReadByte(); player.shoeColor.G = binaryReader.ReadByte(); player.shoeColor.B = binaryReader.ReadByte(); Main.player[Main.myPlayer].shirtColor = player.shirtColor; Main.player[Main.myPlayer].pantsColor = player.pantsColor; Main.player[Main.myPlayer].hairColor = player.hairColor; if (num >= 38) { for (int i = 0; i < 11; i++) { player.armor[i].netDefaults(binaryReader.ReadInt32()); player.armor[i].Prefix((int)binaryReader.ReadByte()); } if (num >= 47) { for (int j = 0; j < 3; j++) { player.dye[j].netDefaults(binaryReader.ReadInt32()); player.dye[j].Prefix((int)binaryReader.ReadByte()); } } if (num >= 58) { for (int k = 0; k < 58; k++) { int num2 = binaryReader.ReadInt32(); if (num2 >= 1725) { player.inventory[k].netDefaults(0); } else { player.inventory[k].netDefaults(num2); player.inventory[k].stack = binaryReader.ReadInt32(); player.inventory[k].Prefix((int)binaryReader.ReadByte()); } } } else { for (int l = 0; l < 48; l++) { int num3 = binaryReader.ReadInt32(); if (num3 >= 1725) { player.inventory[l].netDefaults(0); } else { player.inventory[l].netDefaults(num3); player.inventory[l].stack = binaryReader.ReadInt32(); player.inventory[l].Prefix((int)binaryReader.ReadByte()); } } } if (num >= 58) { for (int m = 0; m < 40; m++) { player.bank[m].netDefaults(binaryReader.ReadInt32()); player.bank[m].stack = binaryReader.ReadInt32(); player.bank[m].Prefix((int)binaryReader.ReadByte()); } for (int n = 0; n < 40; n++) { player.bank2[n].netDefaults(binaryReader.ReadInt32()); player.bank2[n].stack = binaryReader.ReadInt32(); player.bank2[n].Prefix((int)binaryReader.ReadByte()); } } else { for (int num4 = 0; num4 < 20; num4++) { player.bank[num4].netDefaults(binaryReader.ReadInt32()); player.bank[num4].stack = binaryReader.ReadInt32(); player.bank[num4].Prefix((int)binaryReader.ReadByte()); } for (int num5 = 0; num5 < 20; num5++) { player.bank2[num5].netDefaults(binaryReader.ReadInt32()); player.bank2[num5].stack = binaryReader.ReadInt32(); player.bank2[num5].Prefix((int)binaryReader.ReadByte()); } } } else { for (int num6 = 0; num6 < 8; num6++) { player.armor[num6].SetDefaults(Item.VersionName(binaryReader.ReadString(), num)); if (num >= 36) { player.armor[num6].Prefix((int)binaryReader.ReadByte()); } } if (num >= 6) { for (int num7 = 8; num7 < 11; num7++) { player.armor[num7].SetDefaults(Item.VersionName(binaryReader.ReadString(), num)); if (num >= 36) { player.armor[num7].Prefix((int)binaryReader.ReadByte()); } } } for (int num8 = 0; num8 < 44; num8++) { player.inventory[num8].SetDefaults(Item.VersionName(binaryReader.ReadString(), num)); player.inventory[num8].stack = binaryReader.ReadInt32(); if (num >= 36) { player.inventory[num8].Prefix((int)binaryReader.ReadByte()); } } if (num >= 15) { for (int num9 = 44; num9 < 48; num9++) { player.inventory[num9].SetDefaults(Item.VersionName(binaryReader.ReadString(), num)); player.inventory[num9].stack = binaryReader.ReadInt32(); if (num >= 36) { player.inventory[num9].Prefix((int)binaryReader.ReadByte()); } } } for (int num10 = 0; num10 < 20; num10++) { player.bank[num10].SetDefaults(Item.VersionName(binaryReader.ReadString(), num)); player.bank[num10].stack = binaryReader.ReadInt32(); if (num >= 36) { player.bank[num10].Prefix((int)binaryReader.ReadByte()); } } if (num >= 20) { for (int num11 = 0; num11 < 20; num11++) { player.bank2[num11].SetDefaults(Item.VersionName(binaryReader.ReadString(), num)); player.bank2[num11].stack = binaryReader.ReadInt32(); if (num >= 36) { player.bank2[num11].Prefix((int)binaryReader.ReadByte()); } } } } if (num < 58) { for (int num12 = 40; num12 < 48; num12++) { player.inventory[num12 + 10] = (Item)player.inventory[num12].Clone(); player.inventory[num12].SetDefaults(0, false); } } if (num >= 11) { for (int num13 = 0; num13 < 10; num13++) { player.buffType[num13] = binaryReader.ReadInt32(); player.buffTime[num13] = binaryReader.ReadInt32(); } } for (int num14 = 0; num14 < 200; num14++) { int num15 = binaryReader.ReadInt32(); if (num15 == -1) { break; } player.spX[num14] = num15; player.spY[num14] = binaryReader.ReadInt32(); player.spI[num14] = binaryReader.ReadInt32(); player.spN[num14] = binaryReader.ReadString(); } if (num >= 16) { player.hbLocked = binaryReader.ReadBoolean(); } binaryReader.Close(); } } player.PlayerFrame(); File.Delete(text); Player result = player; return result; } } catch { flag = true; } if (flag) { try { string text2 = playerPath + ".bak"; Player result; if (File.Exists(text2)) { File.Delete(playerPath); File.Move(text2, playerPath); result = Player.LoadPlayer(playerPath); return result; } result = new Player(); return result; } catch { Player result = new Player(); return result; } } return new Player(); }
public static PlayerFileData LoadPlayer(string playerPath, bool cloudSave) { PlayerFileData playerFileData = new PlayerFileData(playerPath); if (Main.rand == null) Main.rand = new Random((int)DateTime.Now.Ticks); Player player1 = new Player(); try { RijndaelManaged rijndaelManaged = new RijndaelManaged(); rijndaelManaged.Padding = PaddingMode.None; using (MemoryStream memoryStream = new MemoryStream(FileUtilities.ReadAllBytes(playerPath))) { using (CryptoStream cryptoStream = new CryptoStream((Stream)memoryStream, rijndaelManaged.CreateDecryptor(Player.ENCRYPTION_KEY, Player.ENCRYPTION_KEY), CryptoStreamMode.Read)) { using (BinaryReader binaryReader = new BinaryReader((Stream)cryptoStream)) { int release = binaryReader.ReadInt32(); if (release >= 135) playerFileData.Metadata = FileMetadata.Read(binaryReader, FileType.Player); else playerFileData.Metadata = FileMetadata.FromCurrentSettings(FileType.Player); if (release > Main.curRelease) { player1.loadStatus = 1; player1.name = binaryReader.ReadString(); playerFileData.Player = player1; return playerFileData; } player1.name = binaryReader.ReadString(); if (release >= 10) { if (release >= 17) player1.difficulty = binaryReader.ReadByte(); else if (binaryReader.ReadBoolean()) player1.difficulty = (byte)2; } if (release >= 138) playerFileData.SetPlayTime(new TimeSpan(binaryReader.ReadInt64())); else playerFileData.SetPlayTime(TimeSpan.Zero); player1.hair = binaryReader.ReadInt32(); if (release >= 82) player1.hairDye = binaryReader.ReadByte(); if (release >= 124) { BitsByte bitsByte = (BitsByte)binaryReader.ReadByte(); for (int index = 0; index < 8; ++index) player1.hideVisual[index] = bitsByte[index]; bitsByte = (BitsByte)binaryReader.ReadByte(); for (int index = 0; index < 2; ++index) player1.hideVisual[index + 8] = bitsByte[index]; } else if (release >= 83) { BitsByte bitsByte = (BitsByte)binaryReader.ReadByte(); for (int index = 0; index < 8; ++index) player1.hideVisual[index] = bitsByte[index]; } if (release >= 119) player1.hideMisc = (BitsByte)binaryReader.ReadByte(); if (release <= 17) player1.Male = player1.hair != 5 && player1.hair != 6 && (player1.hair != 9 && player1.hair != 11); else if (release < 107) player1.Male = binaryReader.ReadBoolean(); else player1.skinVariant = (int)binaryReader.ReadByte(); player1.statLife = binaryReader.ReadInt32(); player1.statLifeMax = binaryReader.ReadInt32(); if (player1.statLifeMax > 500) player1.statLifeMax = 500; player1.statMana = binaryReader.ReadInt32(); player1.statManaMax = binaryReader.ReadInt32(); if (player1.statManaMax > 200) player1.statManaMax = 200; if (player1.statMana > 400) player1.statMana = 400; if (release >= 125) player1.extraAccessory = binaryReader.ReadBoolean(); if (release >= 128) player1.taxMoney = binaryReader.ReadInt32(); player1.hairColor = Utils.ReadRGB(binaryReader); player1.skinColor = Utils.ReadRGB(binaryReader); player1.eyeColor = Utils.ReadRGB(binaryReader); player1.shirtColor = Utils.ReadRGB(binaryReader); player1.underShirtColor = Utils.ReadRGB(binaryReader); player1.pantsColor = Utils.ReadRGB(binaryReader); player1.shoeColor = Utils.ReadRGB(binaryReader); Main.player[Main.myPlayer].shirtColor = player1.shirtColor; Main.player[Main.myPlayer].pantsColor = player1.pantsColor; Main.player[Main.myPlayer].hairColor = player1.hairColor; if (release >= 38) { if (release < 124) { int num = 11; if (release >= 81) num = 16; for (int index1 = 0; index1 < num; ++index1) { int index2 = index1; if (index2 >= 8) index2 += 2; player1.armor[index2].netDefaults(binaryReader.ReadInt32()); player1.armor[index2].Prefix((int)binaryReader.ReadByte()); } } else { int num = 20; for (int index = 0; index < num; ++index) { player1.armor[index].netDefaults(binaryReader.ReadInt32()); player1.armor[index].Prefix((int)binaryReader.ReadByte()); } } if (release >= 47) { int num = 3; if (release >= 81) num = 8; if (release >= 124) num = 10; for (int index1 = 0; index1 < num; ++index1) { int index2 = index1; player1.dye[index2].netDefaults(binaryReader.ReadInt32()); player1.dye[index2].Prefix((int)binaryReader.ReadByte()); } } if (release >= 58) { for (int index = 0; index < 58; ++index) { int type = binaryReader.ReadInt32(); if (type >= 3601) { player1.inventory[index].netDefaults(0); } else { player1.inventory[index].netDefaults(type); player1.inventory[index].stack = binaryReader.ReadInt32(); player1.inventory[index].Prefix((int)binaryReader.ReadByte()); if (release >= 114) player1.inventory[index].favorited = binaryReader.ReadBoolean(); } } } else { for (int index = 0; index < 48; ++index) { int type = binaryReader.ReadInt32(); if (type >= 3601) { player1.inventory[index].netDefaults(0); } else { player1.inventory[index].netDefaults(type); player1.inventory[index].stack = binaryReader.ReadInt32(); player1.inventory[index].Prefix((int)binaryReader.ReadByte()); } } } if (release >= 117) { if (release < 136) { for (int index = 0; index < 5; ++index) { if (index != 1) { int type1 = binaryReader.ReadInt32(); if (type1 >= 3601) { player1.miscEquips[index].netDefaults(0); } else { player1.miscEquips[index].netDefaults(type1); player1.miscEquips[index].Prefix((int)binaryReader.ReadByte()); } int type2 = binaryReader.ReadInt32(); if (type2 >= 3601) { player1.miscDyes[index].netDefaults(0); } else { player1.miscDyes[index].netDefaults(type2); player1.miscDyes[index].Prefix((int)binaryReader.ReadByte()); } } } } else { for (int index = 0; index < 5; ++index) { int type1 = binaryReader.ReadInt32(); if (type1 >= 3601) { player1.miscEquips[index].netDefaults(0); } else { player1.miscEquips[index].netDefaults(type1); player1.miscEquips[index].Prefix((int)binaryReader.ReadByte()); } int type2 = binaryReader.ReadInt32(); if (type2 >= 3601) { player1.miscDyes[index].netDefaults(0); } else { player1.miscDyes[index].netDefaults(type2); player1.miscDyes[index].Prefix((int)binaryReader.ReadByte()); } } } } if (release >= 58) { for (int index = 0; index < 40; ++index) { player1.bank.item[index].netDefaults(binaryReader.ReadInt32()); player1.bank.item[index].stack = binaryReader.ReadInt32(); player1.bank.item[index].Prefix((int)binaryReader.ReadByte()); } for (int index = 0; index < 40; ++index) { player1.bank2.item[index].netDefaults(binaryReader.ReadInt32()); player1.bank2.item[index].stack = binaryReader.ReadInt32(); player1.bank2.item[index].Prefix((int)binaryReader.ReadByte()); } } else { for (int index = 0; index < 20; ++index) { player1.bank.item[index].netDefaults(binaryReader.ReadInt32()); player1.bank.item[index].stack = binaryReader.ReadInt32(); player1.bank.item[index].Prefix((int)binaryReader.ReadByte()); } for (int index = 0; index < 20; ++index) { player1.bank2.item[index].netDefaults(binaryReader.ReadInt32()); player1.bank2.item[index].stack = binaryReader.ReadInt32(); player1.bank2.item[index].Prefix((int)binaryReader.ReadByte()); } } } else { for (int index = 0; index < 8; ++index) { player1.armor[index].SetDefaults(Item.VersionName(binaryReader.ReadString(), release)); if (release >= 36) player1.armor[index].Prefix((int)binaryReader.ReadByte()); } if (release >= 6) { for (int index = 8; index < 11; ++index) { player1.armor[index].SetDefaults(Item.VersionName(binaryReader.ReadString(), release)); if (release >= 36) player1.armor[index].Prefix((int)binaryReader.ReadByte()); } } for (int index = 0; index < 44; ++index) { player1.inventory[index].SetDefaults(Item.VersionName(binaryReader.ReadString(), release)); player1.inventory[index].stack = binaryReader.ReadInt32(); if (release >= 36) player1.inventory[index].Prefix((int)binaryReader.ReadByte()); } if (release >= 15) { for (int index = 44; index < 48; ++index) { player1.inventory[index].SetDefaults(Item.VersionName(binaryReader.ReadString(), release)); player1.inventory[index].stack = binaryReader.ReadInt32(); if (release >= 36) player1.inventory[index].Prefix((int)binaryReader.ReadByte()); } } for (int index = 0; index < 20; ++index) { player1.bank.item[index].SetDefaults(Item.VersionName(binaryReader.ReadString(), release)); player1.bank.item[index].stack = binaryReader.ReadInt32(); if (release >= 36) player1.bank.item[index].Prefix((int)binaryReader.ReadByte()); } if (release >= 20) { for (int index = 0; index < 20; ++index) { player1.bank2.item[index].SetDefaults(Item.VersionName(binaryReader.ReadString(), release)); player1.bank2.item[index].stack = binaryReader.ReadInt32(); if (release >= 36) player1.bank2.item[index].Prefix((int)binaryReader.ReadByte()); } } } if (release < 58) { for (int index = 40; index < 48; ++index) { player1.inventory[index + 10] = player1.inventory[index].Clone(); player1.inventory[index].SetDefaults(0, false); } } if (release >= 11) { int num = 22; if (release < 74) num = 10; for (int index = 0; index < num; ++index) { player1.buffType[index] = binaryReader.ReadInt32(); player1.buffTime[index] = binaryReader.ReadInt32(); if (player1.buffType[index] == 0) { --index; --num; } } } for (int index = 0; index < 200; ++index) { int num = binaryReader.ReadInt32(); if (num != -1) { player1.spX[index] = num; player1.spY[index] = binaryReader.ReadInt32(); player1.spI[index] = binaryReader.ReadInt32(); player1.spN[index] = binaryReader.ReadString(); } else break; } if (release >= 16) player1.hbLocked = binaryReader.ReadBoolean(); if (release >= 115) { int num = 13; for (int index = 0; index < num; ++index) player1.hideInfo[index] = binaryReader.ReadBoolean(); } if (release >= 98) player1.anglerQuestsFinished = binaryReader.ReadInt32(); player1.skinVariant = (int)MathHelper.Clamp((float)player1.skinVariant, 0.0f, 7f); for (int index = 3; index < 8 + player1.extraAccessorySlots; ++index) { int num = player1.armor[index].itemId; if (num == 908) player1.lavaMax += 420; if (num == 906) player1.lavaMax += 420; if (player1.wingsLogic == 0 && (int)player1.armor[index].wingSlot >= 0) player1.wingsLogic = (int)player1.armor[index].wingSlot; if (num == 158 || num == 396 || (num == 1250 || num == 1251) || num == 1252) player1.noFallDmg = true; player1.lavaTime = player1.lavaMax; } } } } player1.PlayerFrame(); player1.loadStatus = 0; playerFileData.Player = player1; return playerFileData; } catch { } Player player2 = new Player(); player2.loadStatus = 2; if (player1.name != "") { player2.name = player1.name; } else { string[] strArray = playerPath.Split(Path.DirectorySeparatorChar); player1.name = strArray[strArray.Length - 1].Split('.')[0]; } playerFileData.Player = player2; return playerFileData; }