Beispiel #1
0
 private bool LoadPlayerFromDisk()
 {
     try
     {
         ZPackage zpackage = this.LoadPlayerDataFromDisk();
         if (zpackage == null)
         {
             ZLog.LogWarning((object)"No player data");
             return(false);
         }
         int version = zpackage.ReadInt();
         if (!Version.IsPlayerVersionCompatible(version))
         {
             ZLog.Log((object)"Player data is not compatible, ignoring");
             return(false);
         }
         if (version >= 28)
         {
             this.m_playerStats.m_kills  = zpackage.ReadInt();
             this.m_playerStats.m_deaths = zpackage.ReadInt();
             this.m_playerStats.m_crafts = zpackage.ReadInt();
             this.m_playerStats.m_builds = zpackage.ReadInt();
         }
         this.m_worldData.Clear();
         int num = zpackage.ReadInt();
         for (int index = 0; index < num; ++index)
         {
             long key = zpackage.ReadLong();
             PlayerProfile.WorldPlayerData worldPlayerData = new PlayerProfile.WorldPlayerData();
             worldPlayerData.m_haveCustomSpawnPoint = zpackage.ReadBool();
             worldPlayerData.m_spawnPoint           = zpackage.ReadVector3();
             worldPlayerData.m_haveLogoutPoint      = zpackage.ReadBool();
             worldPlayerData.m_logoutPoint          = zpackage.ReadVector3();
             if (version >= 30)
             {
                 worldPlayerData.m_haveDeathPoint = zpackage.ReadBool();
                 worldPlayerData.m_deathPoint     = zpackage.ReadVector3();
             }
             worldPlayerData.m_homePoint = zpackage.ReadVector3();
             if (version >= 29 && zpackage.ReadBool())
             {
                 worldPlayerData.m_mapData = zpackage.ReadByteArray();
             }
             this.m_worldData.Add(key, worldPlayerData);
         }
         this.m_playerName = zpackage.ReadString();
         this.m_playerID   = zpackage.ReadLong();
         this.m_startSeed  = zpackage.ReadString();
         this.m_playerData = !zpackage.ReadBool() ? (byte[])null : zpackage.ReadByteArray();
     }
     catch (Exception ex)
     {
         ZLog.LogWarning((object)("Exception while loading player profile:" + this.m_filename + " , " + ex.ToString()));
     }
     return(true);
 }
Beispiel #2
0
        //private const int dataVersion = 2;
        //private const float randomSkillRange = 0.15f;
        //private const float randomSkillMin = 0.4f;
        //public const float m_maxSkillLevel = 100f;
        //public const float m_skillCurve = 2f;
        //public bool m_useSkillCap;
        //private Player m_player;

        public void Save(ZPackage pkg)
        {
            pkg.Write(2);
            pkg.Write(this.SkillData.Count);
            foreach (KeyValuePair <Skills.SkillType, Skills.Skill> keyValuePair in this.SkillData)
            {
                pkg.Write((int)keyValuePair.Key);
                pkg.Write(keyValuePair.Value.m_level);
                pkg.Write(keyValuePair.Value.m_accumulator);
            }
        }
Beispiel #3
0
 public void LoadPlayerData(Player player)
 {
     player.SetPlayerID(this.m_playerID, this.m_playerName);
     if (this.m_playerData != null)
     {
         ZPackage pkg = new ZPackage(this.m_playerData);
         player.Load(pkg);
     }
     else
     {
         throw new Exception();
     }
     //player.GiveDefaultItems();
 }
Beispiel #4
0
 public void Save(ZPackage pkg)
 {
     pkg.Write(this.currentVersion);
     pkg.Write(this.m_inventory.Count(i => !string.IsNullOrWhiteSpace(i.m_name)));
     foreach (ItemData itemData in this.m_inventory.Where(i => !string.IsNullOrWhiteSpace(i.m_name)))
     {
         pkg.Write(itemData.m_name);
         pkg.Write(itemData.m_stack);
         pkg.Write(itemData.m_durability);
         pkg.Write(itemData.m_gridPos);
         pkg.Write(itemData.m_equiped);
         pkg.Write(itemData.m_quality);
         pkg.Write(itemData.m_variant);
         pkg.Write(itemData.m_crafterID);
         pkg.Write(itemData.m_crafterName);
     }
 }
Beispiel #5
0
        public void Load(ZPackage pkg)
        {
            int num1 = pkg.ReadInt();

            this.SkillData.Clear();
            int num2 = pkg.ReadInt();

            for (int index = 0; index < num2; ++index)
            {
                Skills.SkillType skillType = (Skills.SkillType)pkg.ReadInt();
                float            num3      = pkg.ReadSingle();
                float            num4      = num1 >= 2 ? pkg.ReadSingle() : 0.0f;
                if (this.IsSkillValid(skillType))
                {
                    Skills.Skill skill = this.GetSkill(skillType);
                    skill.m_level       = num3;
                    skill.m_accumulator = num4;
                }
            }
        }
Beispiel #6
0
        public void Load(ZPackage pkg)
        {
            this.m_isLoading = true;
            //this.UnequipAllItems();
            int num1 = pkg.ReadInt();

            if (num1 >= 7)
            {
                this.SetMaxHealth(pkg.ReadSingle(), false);
            }
            float num2      = pkg.ReadSingle();
            float maxHealth = this.GetMaxHealth();

            if ((double)num2 <= 0.0 || (double)num2 > (double)maxHealth || float.IsNaN(num2))
            {
                num2 = maxHealth;
            }
            this.SetHealth(num2);
            if (num1 >= 10)
            {
                float stamina = pkg.ReadSingle();
                this.SetMaxStamina(stamina, false);
                this.m_stamina = stamina;
            }
            if (num1 >= 8)
            {
                this.m_firstSpawn = pkg.ReadBool();
            }
            if (num1 >= 20)
            {
                this.m_timeSinceDeath = pkg.ReadSingle();
            }
            if (num1 >= 23)
            {
                this.SetGuardianPower(pkg.ReadString());
            }
            if (num1 >= 24)
            {
                this.m_guardianPowerCooldown = pkg.ReadSingle();
            }
            if (num1 == 2)
            {
                pkg.ReadZDOID();
            }
            this.m_inventory.Load(pkg);
            int num3 = pkg.ReadInt();

            for (int index = 0; index < num3; ++index)
            {
                this.m_knownRecipes.Add(pkg.ReadString());
            }
            if (num1 < 15)
            {
                int num4 = pkg.ReadInt();
                for (int index = 0; index < num4; ++index)
                {
                    pkg.ReadString();
                }
            }
            else
            {
                int num4 = pkg.ReadInt();
                for (int index = 0; index < num4; ++index)
                {
                    this.m_knownStations.Add(pkg.ReadString(), pkg.ReadInt());
                }
            }
            int num5 = pkg.ReadInt();

            for (int index = 0; index < num5; ++index)
            {
                this.m_knownMaterial.Add(pkg.ReadString());
            }
            if (num1 < 19 || num1 >= 21)
            {
                int num4 = pkg.ReadInt();
                for (int index = 0; index < num4; ++index)
                {
                    this.m_shownTutorials.Add(pkg.ReadString());
                }
            }
            if (num1 >= 6)
            {
                int num4 = pkg.ReadInt();
                for (int index = 0; index < num4; ++index)
                {
                    this.m_uniques.Add(pkg.ReadString());
                }
            }
            if (num1 >= 9)
            {
                int num4 = pkg.ReadInt();
                for (int index = 0; index < num4; ++index)
                {
                    this.m_trophies.Add(pkg.ReadString());
                }
            }
            if (num1 >= 18)
            {
                int num4 = pkg.ReadInt();
                for (int index = 0; index < num4; ++index)
                {
                    this.m_knownBiome.Add((Biome)pkg.ReadInt());
                }
            }
            if (num1 >= 22)
            {
                int num4 = pkg.ReadInt();
                for (int index = 0; index < num4; ++index)
                {
                    this.m_knownTexts.Add(pkg.ReadString(), pkg.ReadString());
                }
            }
            //=========================================
            if (num1 >= 4)
            {
                string name = pkg.ReadString();
                string hair = pkg.ReadString();
                this.SetBeard(name);
                this.SetHair(hair);
            }
            if (num1 >= 5)
            {
                Vector3 color1 = pkg.ReadVector3();
                Vector3 color2 = pkg.ReadVector3();
                this.SetSkinColor(color1);
                this.SetHairColor(color2);
            }
            if (num1 >= 11)
            {
                this.SetPlayerModel(pkg.ReadInt());
            }
            if (num1 >= 12)
            {
                this.m_foods.Clear();
                int num4 = pkg.ReadInt();
                for (int index = 0; index < num4; ++index)
                {
                    if (num1 >= 14)
                    {
                        Player.Food food = new Player.Food();
                        food.m_name   = pkg.ReadString();
                        food.m_health = pkg.ReadSingle();
                        if (num1 >= 16)
                        {
                            food.m_stamina = pkg.ReadSingle();
                        }
                        //GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(food.m_name);
                        //if ((UnityEngine.Object)itemPrefab == (UnityEngine.Object)null)
                        //{
                        //    ZLog.LogWarning((object)("FAiled to find food item " + food.m_name));
                        //}
                        //else
                        {
                            //food.m_item = itemPrefab.GetComponent<ItemDrop>().m_itemData;
                            this.m_foods.Add(food);
                        }
                    }
                    else
                    {
                        pkg.ReadString();
                        double num6  = (double)pkg.ReadSingle();
                        double num7  = (double)pkg.ReadSingle();
                        double num8  = (double)pkg.ReadSingle();
                        double num9  = (double)pkg.ReadSingle();
                        double num10 = (double)pkg.ReadSingle();
                        double num11 = (double)pkg.ReadSingle();
                        if (num1 >= 13)
                        {
                            double num12 = (double)pkg.ReadSingle();
                        }
                    }
                }
            }
            if (num1 >= 17)
            {
                this.Skills.Load(pkg);
            }
            this.m_isLoading = false;
            //this.UpdateAvailablePiecesList();
            //this.EquipIventoryItems();
        }
Beispiel #7
0
 public void Save(ZPackage pkg)
 {
     pkg.Write(24);
     pkg.Write(this.GetMaxHealth());
     pkg.Write(this.GetHealth());
     pkg.Write(this.GetMaxStamina());
     pkg.Write(this.m_firstSpawn);
     pkg.Write(this.m_timeSinceDeath);
     pkg.Write(this.m_guardianPower);
     pkg.Write(this.m_guardianPowerCooldown);
     this.m_inventory.Save(pkg);
     pkg.Write(this.m_knownRecipes.Count);
     foreach (string knownRecipe in this.m_knownRecipes)
     {
         pkg.Write(knownRecipe);
     }
     pkg.Write(this.m_knownStations.Count);
     foreach (KeyValuePair <string, int> knownStation in this.m_knownStations)
     {
         pkg.Write(knownStation.Key);
         pkg.Write(knownStation.Value);
     }
     pkg.Write(this.m_knownMaterial.Count);
     foreach (string data in this.m_knownMaterial)
     {
         pkg.Write(data);
     }
     pkg.Write(this.m_shownTutorials.Count);
     foreach (string shownTutorial in this.m_shownTutorials)
     {
         pkg.Write(shownTutorial);
     }
     pkg.Write(this.m_uniques.Count);
     foreach (string unique in this.m_uniques)
     {
         pkg.Write(unique);
     }
     pkg.Write(this.m_trophies.Count);
     foreach (string trophy in this.m_trophies)
     {
         pkg.Write(trophy);
     }
     pkg.Write(this.m_knownBiome.Count);
     foreach (Biome biome in this.m_knownBiome)
     {
         pkg.Write((int)biome);
     }
     pkg.Write(this.m_knownTexts.Count);
     foreach (KeyValuePair <string, string> knownText in this.m_knownTexts)
     {
         pkg.Write(knownText.Key);
         pkg.Write(knownText.Value);
     }
     pkg.Write(this.m_beardItem);
     pkg.Write(this.m_hairItem);
     pkg.Write(this.m_skinColor * (m_skinColorGlow + 1));
     pkg.Write(this.m_hairColor * (m_hairColorGlow + 1));
     pkg.Write(this.ModelIndex);
     pkg.Write(this.m_foods.Count);
     foreach (Player.Food food in this.m_foods)
     {
         pkg.Write(food.m_name);
         pkg.Write(food.m_health);
         pkg.Write(food.m_stamina);
     }
     this.Skills.Save(pkg);
 }
Beispiel #8
0
 public void Write(ZPackage pkg)
 {
     byte[] array = pkg.GetArray();
     this.m_writer.Write(array.Length);
     this.m_writer.Write(array);
 }
Beispiel #9
0
        public void Load(ZPackage pkg)
        {
            int num1 = pkg.ReadInt();
            int num2 = pkg.ReadInt();

            this.m_inventory.Clear();
            for (int index = 0; index < num2; ++index)
            {
                string   name       = pkg.ReadString();
                int      stack      = pkg.ReadInt();
                float    durability = pkg.ReadSingle();
                Vector2i pos        = pkg.ReadVector2i();
                bool     equiped    = pkg.ReadBool();
                int      quality    = 1;
                if (num1 >= 101)
                {
                    quality = pkg.ReadInt();
                }
                int variant = 0;
                if (num1 >= 102)
                {
                    variant = pkg.ReadInt();
                }
                long   crafterID   = 0;
                string crafterName = "";
                if (num1 >= 103)
                {
                    crafterID   = pkg.ReadLong();
                    crafterName = pkg.ReadString();
                }
                if (name != "")
                {
                    m_inventory.Add(new ItemData()
                    {
                        m_name        = name,
                        m_stack       = stack,
                        m_durability  = durability,
                        m_gridPos     = pos,
                        m_equiped     = equiped,
                        m_quality     = quality,
                        m_variant     = variant,
                        m_crafterID   = crafterID,
                        m_crafterName = crafterName
                    });
                }
            }

            for (int x = 0; x < m_width; x++)
            {
                for (int y = 0; y < m_height; y++)
                {
                    if (!m_inventory.Any(i => i.m_gridPos == new Vector2i(x, y)))
                    {
                        m_inventory.Add(new ItemData()
                        {
                            m_gridPos = new Vector2i(x, y)
                        });
                    }
                }
            }
        }
Beispiel #10
0
        //public void SaveLogoutPoint()
        //{
        //    if (!(bool)(UnityEngine.Object)Player.m_localPlayer || Player.m_localPlayer.IsDead() || Player.m_localPlayer.InIntro())
        //        return;
        //    this.SetLogoutPoint(Player.m_localPlayer.transform.position);
        //}

        private bool SavePlayerToDisk()
        {
            string   str1     = this.m_filename;
            string   str2     = this.m_filename + ".old";
            string   str3     = this.m_filename + ".new";
            ZPackage zpackage = new ZPackage();

            zpackage.Write(Version.m_playerVersion);
            zpackage.Write(this.m_playerStats.m_kills);
            zpackage.Write(this.m_playerStats.m_deaths);
            zpackage.Write(this.m_playerStats.m_crafts);
            zpackage.Write(this.m_playerStats.m_builds);
            zpackage.Write(this.m_worldData.Count);
            foreach (KeyValuePair <long, PlayerProfile.WorldPlayerData> keyValuePair in this.m_worldData)
            {
                zpackage.Write(keyValuePair.Key);
                zpackage.Write(keyValuePair.Value.m_haveCustomSpawnPoint);
                zpackage.Write(keyValuePair.Value.m_spawnPoint);
                zpackage.Write(keyValuePair.Value.m_haveLogoutPoint);
                zpackage.Write(keyValuePair.Value.m_logoutPoint);
                zpackage.Write(keyValuePair.Value.m_haveDeathPoint);
                zpackage.Write(keyValuePair.Value.m_deathPoint);
                zpackage.Write(keyValuePair.Value.m_homePoint);
                zpackage.Write(keyValuePair.Value.m_mapData != null);
                if (keyValuePair.Value.m_mapData != null)
                {
                    zpackage.Write(keyValuePair.Value.m_mapData);
                }
            }
            zpackage.Write(this.m_playerName);
            zpackage.Write(this.m_playerID);
            zpackage.Write(this.m_startSeed);
            if (this.m_playerData != null)
            {
                zpackage.Write(true);
                zpackage.Write(this.m_playerData);
            }
            else
            {
                zpackage.Write(false);
            }
            byte[]       hash         = zpackage.GenerateHash();
            byte[]       array        = zpackage.GetArray();
            FileStream   fileStream   = File.Create(str3);
            BinaryWriter binaryWriter = new BinaryWriter((Stream)fileStream);

            binaryWriter.Write(array.Length);
            binaryWriter.Write(array);
            binaryWriter.Write(hash.Length);
            binaryWriter.Write(hash);
            binaryWriter.Flush();
            fileStream.Flush(true);
            fileStream.Close();
            fileStream.Dispose();
            if (File.Exists(str1))
            {
                if (File.Exists(str2))
                {
                    File.Delete(str2);
                }
                File.Move(str1, str2);
            }
            File.Move(str3, str1);
            return(true);
        }