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); }
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(); }
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) }); } } } }