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