GetPlayTime() public method

public GetPlayTime ( ) : System.TimeSpan
return System.TimeSpan
Beispiel #1
0
 public static void SavePlayer(PlayerFileData playerFile, bool skipMapSave = false)
 {
     Main.Achievements.Save();
     string path = playerFile.Path;
     Player player = playerFile.Player;
     bool isCloudSave = playerFile.IsCloudSave;
     if (!skipMapSave)
     {
         try
         {
             if (Main.mapEnabled)
             {
                 Main.Map.Save();
             }
         }
         catch
         {
         }
         try
         {
             if (!isCloudSave)
             {
                 Directory.CreateDirectory(Main.PlayerPath);
             }
         }
         catch
         {
         }
     }
     if (Main.ServerSideCharacter)
     {
         return;
     }
     if (path == null || path == "")
     {
         return;
     }
     if (FileUtilities.Exists(path, isCloudSave))
     {
         FileUtilities.Copy(path, path + ".bak", isCloudSave, true);
     }
     RijndaelManaged rijndaelManaged = new RijndaelManaged();
     using (Stream stream = isCloudSave ? (Stream)new MemoryStream(2000) : (Stream)new FileStream(path, FileMode.Create))
     {
         using (CryptoStream cryptoStream = new CryptoStream(stream, rijndaelManaged.CreateEncryptor(Player.ENCRYPTION_KEY, Player.ENCRYPTION_KEY), CryptoStreamMode.Write))
         {
             using (BinaryWriter binaryWriter = new BinaryWriter(cryptoStream))
             {
                 binaryWriter.Write(Main.curRelease);
                 playerFile.Metadata.Write(binaryWriter);
                 binaryWriter.Write(player.name);
                 binaryWriter.Write(player.difficulty);
                 binaryWriter.Write(playerFile.GetPlayTime().Ticks);
                 binaryWriter.Write(player.hair);
                 binaryWriter.Write(player.hairDye);
                 BitsByte bb = 0;
                 for (int i = 0; i < 8; i++)
                 {
                     bb[i] = player.hideVisual[i];
                 }
                 binaryWriter.Write(bb);
                 bb = 0;
                 for (int j = 0; j < 2; j++)
                 {
                     bb[j] = player.hideVisual[j + 8];
                 }
                 binaryWriter.Write(bb);
                 binaryWriter.Write(player.hideMisc);
                 binaryWriter.Write((byte)player.skinVariant);
                 binaryWriter.Write(player.statLife);
                 binaryWriter.Write(player.statLifeMax);
                 binaryWriter.Write(player.statMana);
                 binaryWriter.Write(player.statManaMax);
                 binaryWriter.Write(player.extraAccessory);
                 binaryWriter.Write(player.taxMoney);
                 binaryWriter.Write(player.hairColor.R);
                 binaryWriter.Write(player.hairColor.G);
                 binaryWriter.Write(player.hairColor.B);
                 binaryWriter.Write(player.skinColor.R);
                 binaryWriter.Write(player.skinColor.G);
                 binaryWriter.Write(player.skinColor.B);
                 binaryWriter.Write(player.eyeColor.R);
                 binaryWriter.Write(player.eyeColor.G);
                 binaryWriter.Write(player.eyeColor.B);
                 binaryWriter.Write(player.shirtColor.R);
                 binaryWriter.Write(player.shirtColor.G);
                 binaryWriter.Write(player.shirtColor.B);
                 binaryWriter.Write(player.underShirtColor.R);
                 binaryWriter.Write(player.underShirtColor.G);
                 binaryWriter.Write(player.underShirtColor.B);
                 binaryWriter.Write(player.pantsColor.R);
                 binaryWriter.Write(player.pantsColor.G);
                 binaryWriter.Write(player.pantsColor.B);
                 binaryWriter.Write(player.shoeColor.R);
                 binaryWriter.Write(player.shoeColor.G);
                 binaryWriter.Write(player.shoeColor.B);
                 for (int k = 0; k < player.armor.Length; k++)
                 {
                     if (player.armor[k].name == null)
                     {
                         player.armor[k].name = "";
                     }
                     binaryWriter.Write(player.armor[k].netID);
                     binaryWriter.Write(player.armor[k].prefix);
                 }
                 for (int l = 0; l < player.dye.Length; l++)
                 {
                     binaryWriter.Write(player.dye[l].netID);
                     binaryWriter.Write(player.dye[l].prefix);
                 }
                 for (int m = 0; m < 58; m++)
                 {
                     if (player.inventory[m].name == null)
                     {
                         player.inventory[m].name = "";
                     }
                     binaryWriter.Write(player.inventory[m].netID);
                     binaryWriter.Write(player.inventory[m].stack);
                     binaryWriter.Write(player.inventory[m].prefix);
                     binaryWriter.Write(player.inventory[m].favorited);
                 }
                 for (int n = 0; n < player.miscEquips.Length; n++)
                 {
                     binaryWriter.Write(player.miscEquips[n].netID);
                     binaryWriter.Write(player.miscEquips[n].prefix);
                     binaryWriter.Write(player.miscDyes[n].netID);
                     binaryWriter.Write(player.miscDyes[n].prefix);
                 }
                 for (int num = 0; num < 40; num++)
                 {
                     if (player.bank.item[num].name == null)
                     {
                         player.bank.item[num].name = "";
                     }
                     binaryWriter.Write(player.bank.item[num].netID);
                     binaryWriter.Write(player.bank.item[num].stack);
                     binaryWriter.Write(player.bank.item[num].prefix);
                 }
                 for (int num2 = 0; num2 < 40; num2++)
                 {
                     if (player.bank2.item[num2].name == null)
                     {
                         player.bank2.item[num2].name = "";
                     }
                     binaryWriter.Write(player.bank2.item[num2].netID);
                     binaryWriter.Write(player.bank2.item[num2].stack);
                     binaryWriter.Write(player.bank2.item[num2].prefix);
                 }
                 for (int num3 = 0; num3 < 22; num3++)
                 {
                     if (Main.buffNoSave[player.buffType[num3]])
                     {
                         binaryWriter.Write(0);
                         binaryWriter.Write(0);
                     }
                     else
                     {
                         binaryWriter.Write(player.buffType[num3]);
                         binaryWriter.Write(player.buffTime[num3]);
                     }
                 }
                 for (int num4 = 0; num4 < 200; num4++)
                 {
                     if (player.spN[num4] == null)
                     {
                         binaryWriter.Write(-1);
                         break;
                     }
                     binaryWriter.Write(player.spX[num4]);
                     binaryWriter.Write(player.spY[num4]);
                     binaryWriter.Write(player.spI[num4]);
                     binaryWriter.Write(player.spN[num4]);
                 }
                 binaryWriter.Write(player.hbLocked);
                 for (int num5 = 0; num5 < player.hideInfo.Length; num5++)
                 {
                     binaryWriter.Write(player.hideInfo[num5]);
                 }
                 binaryWriter.Write(player.anglerQuestsFinished);
                 binaryWriter.Flush();
                 cryptoStream.FlushFinalBlock();
                 stream.Flush();
                 if (isCloudSave && SocialAPI.Cloud != null)
                 {
                     SocialAPI.Cloud.Write(playerFile.Path, ((MemoryStream)stream).ToArray());
                 }
             }
         }
     }
 }
Beispiel #2
0
        public static void SavePlayer(PlayerFileData playerFile, bool skipMapSave = false)
        {
            Stream memoryStream;
            Main.Achievements.Save();
            string path = playerFile.Path;
            Player player = playerFile.Player;
            if (!skipMapSave)
            {
                try
                {
                    Directory.CreateDirectory(Main.PlayerPath);
                }
                catch (Exception ex)
                {
            #if DEBUG
                    Console.WriteLine(ex);
                    System.Diagnostics.Debugger.Break();

            #endif
                }
            }
            if (Main.ServerSideCharacter)
            {
                return;
            }
            if (path == null || path == "")
            {
                return;
            }
            if (FileUtilities.Exists(path))
            {
                FileUtilities.Copy(path, string.Concat(path, ".bak"), false, true);
            }
            RijndaelManaged rijndaelManaged = new RijndaelManaged();
            memoryStream = new FileStream(path, FileMode.Create);
            using (Stream stream = memoryStream)
            {
                using (CryptoStream cryptoStream = new CryptoStream(stream, rijndaelManaged.CreateEncryptor(Player.ENCRYPTION_KEY, Player.ENCRYPTION_KEY), CryptoStreamMode.Write))
                {
                    using (BinaryWriter binaryWriter = new BinaryWriter(cryptoStream))
                    {
                        binaryWriter.Write(Main.curRelease);
                        playerFile.Metadata.Write(binaryWriter);
                        binaryWriter.Write(player.name);
                        binaryWriter.Write(player.difficulty);
                        binaryWriter.Write(playerFile.GetPlayTime().Ticks);
                        binaryWriter.Write(player.hair);
                        binaryWriter.Write(player.hairDye);
                        BitsByte bitsByte = 0;
                        for (int i = 0; i < 8; i++)
                        {
                            bitsByte[i] = player.hideVisual[i];
                        }
                        binaryWriter.Write(bitsByte);
                        bitsByte = 0;
                        for (int j = 0; j < 2; j++)
                        {
                            bitsByte[j] = player.hideVisual[j + 8];
                        }
                        binaryWriter.Write(bitsByte);
                        binaryWriter.Write(player.hideMisc);
                        binaryWriter.Write((byte)player.skinVariant);
                        binaryWriter.Write(player.statLife);
                        binaryWriter.Write(player.statLifeMax);
                        binaryWriter.Write(player.statMana);
                        binaryWriter.Write(player.statManaMax);
                        binaryWriter.Write(player.extraAccessory);
                        binaryWriter.Write(player.taxMoney);
                        binaryWriter.Write(player.hairColor.R);
                        binaryWriter.Write(player.hairColor.G);
                        binaryWriter.Write(player.hairColor.B);
                        binaryWriter.Write(player.skinColor.R);
                        binaryWriter.Write(player.skinColor.G);
                        binaryWriter.Write(player.skinColor.B);
                        binaryWriter.Write(player.eyeColor.R);
                        binaryWriter.Write(player.eyeColor.G);
                        binaryWriter.Write(player.eyeColor.B);
                        binaryWriter.Write(player.shirtColor.R);
                        binaryWriter.Write(player.shirtColor.G);
                        binaryWriter.Write(player.shirtColor.B);
                        binaryWriter.Write(player.underShirtColor.R);
                        binaryWriter.Write(player.underShirtColor.G);
                        binaryWriter.Write(player.underShirtColor.B);
                        binaryWriter.Write(player.pantsColor.R);
                        binaryWriter.Write(player.pantsColor.G);
                        binaryWriter.Write(player.pantsColor.B);
                        binaryWriter.Write(player.shoeColor.R);
                        binaryWriter.Write(player.shoeColor.G);
                        binaryWriter.Write(player.shoeColor.B);
                        for (int k = 0; k < (int)player.armor.Length; k++)
                        {
                            if (player.armor[k].name == null)
                            {
                                player.armor[k].name = "";
                            }
                            binaryWriter.Write(player.armor[k].netID);
                            binaryWriter.Write(player.armor[k].prefix);
                        }
                        for (int l = 0; l < (int)player.dye.Length; l++)
                        {
                            binaryWriter.Write(player.dye[l].netID);
                            binaryWriter.Write(player.dye[l].prefix);
                        }
                        for (int m = 0; m < 58; m++)
                        {
                            if (player.inventory[m].name == null)
                            {
                                player.inventory[m].name = "";
                            }
                            binaryWriter.Write(player.inventory[m].netID);
                            binaryWriter.Write(player.inventory[m].stack);
                            binaryWriter.Write(player.inventory[m].prefix);
                            binaryWriter.Write(player.inventory[m].favorited);
                        }
                        for (int n = 0; n < (int)player.miscEquips.Length; n++)
                        {
                            binaryWriter.Write(player.miscEquips[n].netID);
                            binaryWriter.Write(player.miscEquips[n].prefix);
                            binaryWriter.Write(player.miscDyes[n].netID);
                            binaryWriter.Write(player.miscDyes[n].prefix);
                        }
                        for (int o = 0; o < 40; o++)
                        {
                            if (player.bank.item[o].name == null)
                            {
                                player.bank.item[o].name = "";
                            }
                            binaryWriter.Write(player.bank.item[o].netID);
                            binaryWriter.Write(player.bank.item[o].stack);
                            binaryWriter.Write(player.bank.item[o].prefix);
                        }
                        for (int p = 0; p < 40; p++)
                        {
                            if (player.bank2.item[p].name == null)
                            {
                                player.bank2.item[p].name = "";
                            }
                            binaryWriter.Write(player.bank2.item[p].netID);
                            binaryWriter.Write(player.bank2.item[p].stack);
                            binaryWriter.Write(player.bank2.item[p].prefix);
                        }
                        for (int q = 0; q < 22; q++)
                        {
                            if (!Main.buffNoSave[player.buffType[q]])
                            {
                                binaryWriter.Write(player.buffType[q]);
                                binaryWriter.Write(player.buffTime[q]);
                            }
                            else
                            {
                                binaryWriter.Write(0);
                                binaryWriter.Write(0);
                            }
                        }
                        int num = 0;
                        while (num < 200)
                        {
                            if (player.spN[num] != null)
                            {
                                binaryWriter.Write(player.spX[num]);
                                binaryWriter.Write(player.spY[num]);
                                binaryWriter.Write(player.spI[num]);
                                binaryWriter.Write(player.spN[num]);
                                num++;
                            }
                            else
                            {
                                binaryWriter.Write(-1);
                                break;
                            }
                        }
                        binaryWriter.Write(player.hbLocked);
                        for (int r = 0; r < (int)player.hideInfo.Length; r++)
                        {
                            binaryWriter.Write(player.hideInfo[r]);
                        }
                        binaryWriter.Write(player.anglerQuestsFinished);
                        binaryWriter.Flush();
                        cryptoStream.FlushFinalBlock();
                        stream.Flush();
                    }
                }
            }
        }
Beispiel #3
0
 public static void SavePlayer(PlayerFileData playerFile, bool skipMapSave = false)
 {
     Main.Achievements.Save();
     string path = playerFile.Path;
     Player player = playerFile.Player;
     if (!skipMapSave)
     {
         try
         {
             if (Main.mapEnabled)
                 Main.Map.Save();
             Directory.CreateDirectory(Main.PlayerPath);
         }
         catch
         {
         }
     }
     if (Main.ServerSideCharacter || path == null || path == "")
         return;
     if (FileUtilities.Exists(path))
         FileUtilities.Copy(path, path + ".bak");
     RijndaelManaged rijndaelManaged = new RijndaelManaged();
     using (Stream stream = new FileStream(path, FileMode.Create))
     {
         using (CryptoStream cryptoStream = new CryptoStream(stream, rijndaelManaged.CreateEncryptor(Player.ENCRYPTION_KEY, Player.ENCRYPTION_KEY), CryptoStreamMode.Write))
         {
             using (BinaryWriter writer = new BinaryWriter(cryptoStream))
             {
                 writer.Write(Main.curRelease);
                 playerFile.Metadata.Write(writer);
                 writer.Write(player.name);
                 writer.Write(player.difficulty);
                 writer.Write(playerFile.GetPlayTime().Ticks);
                 writer.Write(player.hair);
                 writer.Write(player.hairDye);
                 BitsByte bitsByte1 = (BitsByte)(byte)0;
                 for (int index = 0; index < 8; ++index)
                     bitsByte1[index] = player.hideVisual[index];
                 writer.Write((byte)bitsByte1);
                 BitsByte bitsByte2 = (BitsByte)(byte)0;
                 for (int index = 0; index < 2; ++index)
                     bitsByte2[index] = player.hideVisual[index + 8];
                 writer.Write((byte)bitsByte2);
                 writer.Write((byte)player.hideMisc);
                 writer.Write((byte)player.skinVariant);
                 writer.Write(player.statLife);
                 writer.Write(player.statLifeMax);
                 writer.Write(player.statMana);
                 writer.Write(player.statManaMax);
                 writer.Write(player.extraAccessory);
                 writer.Write(player.taxMoney);
                 writer.Write(player.hairColor.R);
                 writer.Write(player.hairColor.G);
                 writer.Write(player.hairColor.B);
                 writer.Write(player.skinColor.R);
                 writer.Write(player.skinColor.G);
                 writer.Write(player.skinColor.B);
                 writer.Write(player.eyeColor.R);
                 writer.Write(player.eyeColor.G);
                 writer.Write(player.eyeColor.B);
                 writer.Write(player.shirtColor.R);
                 writer.Write(player.shirtColor.G);
                 writer.Write(player.shirtColor.B);
                 writer.Write(player.underShirtColor.R);
                 writer.Write(player.underShirtColor.G);
                 writer.Write(player.underShirtColor.B);
                 writer.Write(player.pantsColor.R);
                 writer.Write(player.pantsColor.G);
                 writer.Write(player.pantsColor.B);
                 writer.Write(player.shoeColor.R);
                 writer.Write(player.shoeColor.G);
                 writer.Write(player.shoeColor.B);
                 for (int index = 0; index < player.armor.Length; ++index)
                 {
                     if (player.armor[index].name == null)
                         player.armor[index].name = "";
                     writer.Write(player.armor[index].netID);
                     writer.Write(player.armor[index].prefix);
                 }
                 for (int index = 0; index < player.dye.Length; ++index)
                 {
                     writer.Write(player.dye[index].netID);
                     writer.Write(player.dye[index].prefix);
                 }
                 for (int index = 0; index < 58; ++index)
                 {
                     if (player.inventory[index].name == null)
                         player.inventory[index].name = "";
                     writer.Write(player.inventory[index].netID);
                     writer.Write(player.inventory[index].stack);
                     writer.Write(player.inventory[index].prefix);
                     writer.Write(player.inventory[index].favorited);
                 }
                 for (int index = 0; index < player.miscEquips.Length; ++index)
                 {
                     writer.Write(player.miscEquips[index].netID);
                     writer.Write(player.miscEquips[index].prefix);
                     writer.Write(player.miscDyes[index].netID);
                     writer.Write(player.miscDyes[index].prefix);
                 }
                 for (int index = 0; index < 40; ++index)
                 {
                     if (player.bank.item[index].name == null)
                         player.bank.item[index].name = "";
                     writer.Write(player.bank.item[index].netID);
                     writer.Write(player.bank.item[index].stack);
                     writer.Write(player.bank.item[index].prefix);
                 }
                 for (int index = 0; index < 40; ++index)
                 {
                     if (player.bank2.item[index].name == null)
                         player.bank2.item[index].name = "";
                     writer.Write(player.bank2.item[index].netID);
                     writer.Write(player.bank2.item[index].stack);
                     writer.Write(player.bank2.item[index].prefix);
                 }
                 for (int index = 0; index < 22; ++index)
                 {
                     if (Main.buffNoSave[player.buffType[index]])
                     {
                         writer.Write(0);
                         writer.Write(0);
                     }
                     else
                     {
                         writer.Write(player.buffType[index]);
                         writer.Write(player.buffTime[index]);
                     }
                 }
                 for (int index = 0; index < 200; ++index)
                 {
                     if (player.spN[index] == null)
                     {
                         writer.Write(-1);
                         break;
                     }
                     writer.Write(player.spX[index]);
                     writer.Write(player.spY[index]);
                     writer.Write(player.spI[index]);
                     writer.Write(player.spN[index]);
                 }
                 writer.Write(player.hbLocked);
                 for (int index = 0; index < player.hideInfo.Length; ++index)
                     writer.Write(player.hideInfo[index]);
                 writer.Write(player.anglerQuestsFinished);
                 writer.Flush();
                 cryptoStream.FlushFinalBlock();
                 stream.Flush();
             }
         }
     }
 }