D:\ValheimDev\Dumps\Old\assembly_valheim\PlayerProfile.cs D:\ValheimDev\Dumps\Latest\assembly_valheim\PlayerProfile.cs
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using UnityEngine; using UnityEngine;
   
public class PlayerProfile public class PlayerProfile
{ {
    public PlayerProfile(string filename = null, FileHelpers.FileSource fileSource = FileHelpers.FileSource.Auto)     public PlayerProfile(string filename = null, FileHelpers.FileSource fileSource = FileHelpers.FileSource.Auto)
    {     {
        this.m_filename = filename;         this.m_filename = filename;
        if (fileSource == FileHelpers.FileSource.Auto)         if (fileSource == FileHelpers.FileSource.Auto)
        {         {
            this.m_fileSource = (FileHelpers.m_cloudEnabled ? FileHelpers.FileSource.Cloud : FileHelpers.FileSource.Local);             this.m_fileSource = (FileHelpers.m_cloudEnabled ? FileHelpers.FileSource.Cloud : FileHelpers.FileSource.Local);
        }         }
        else         else
        {         {
            this.m_fileSource = fileSource;             this.m_fileSource = fileSource;
        }         }
        this.m_playerName = "Stranger";         this.m_playerName = "Stranger";
        this.m_playerID = Utils.GenerateUID();         this.m_playerID = Utils.GenerateUID();
    }     }
   
    public bool Load()     public bool Load()
    {     {
        return this.m_filename != null && this.LoadPlayerFromDisk();         return this.m_filename != null && this.LoadPlayerFromDisk();
    }     }
   
    public bool Save()     public bool Save()
    {     {
        return this.m_filename != null && this.SavePlayerToDisk();         return this.m_filename != null && this.SavePlayerToDisk();
    }     }
   
    public bool HaveIncompatiblPlayerData()     public bool HaveIncompatiblPlayerData()
    {     {
        if (this.m_filename == null)         if (this.m_filename == null)
        {         {
            return false;             return false;
        }         }
        ZPackage zpackage = this.LoadPlayerDataFromDisk();         ZPackage zpackage = this.LoadPlayerDataFromDisk();
        if (zpackage == null)         if (zpackage == null)
        {         {
            return false;             return false;
        }         }
        if (!global::Version.IsPlayerVersionCompatible(zpackage.ReadInt()))         if (!global::Version.IsPlayerVersionCompatible(zpackage.ReadInt()))
        {         {
            ZLog.Log("Player data is not compatible, ignoring");             ZLog.Log("Player data is not compatible, ignoring");
            return true;             return true;
        }         }
        return false;         return false;
    }     }
   
    public void SavePlayerData(Player player)     public void SavePlayerData(Player player)
    {     {
        ZPackage zpackage = new ZPackage();         ZPackage zpackage = new ZPackage();
        player.Save(zpackage);         player.Save(zpackage);
        this.m_playerData = zpackage.GetArray();         this.m_playerData = zpackage.GetArray();
    }     }
   
    public void LoadPlayerData(Player player)     public void LoadPlayerData(Player player)
    {     {
        player.SetPlayerID(this.m_playerID, this.GetName());         player.SetPlayerID(this.m_playerID, this.GetName());
        if (this.m_playerData != null)         if (this.m_playerData != null)
        {         {
            ZPackage zpackage = new ZPackage(this.m_playerData);             ZPackage zpackage = new ZPackage(this.m_playerData);
            player.Load(zpackage);             player.Load(zpackage);
            return;             return;
        }         }
        player.GiveDefaultItems();         player.GiveDefaultItems();
    }     }
   
    public void SaveLogoutPoint()     public void SaveLogoutPoint()
    {     {
        if (Player.m_localPlayer && !Player.m_localPlayer.IsDead() && !Player.m_localPlayer.InIntro())         if (Player.m_localPlayer && !Player.m_localPlayer.IsDead() && !Player.m_localPlayer.InIntro())
        {         {
            this.SetLogoutPoint(Player.m_localPlayer.transform.position);             this.SetLogoutPoint(Player.m_localPlayer.transform.position);
        }         }
    }     }
   
    private bool SavePlayerToDisk()     private bool SavePlayerToDisk()
    {     {
        Action savingStarted = PlayerProfile.SavingStarted;         Action savingStarted = PlayerProfile.SavingStarted;
        if (savingStarted != null)         if (savingStarted != null)
        {         {
            savingStarted();             savingStarted();
        }         }
        DateTime now = DateTime.Now;         DateTime now = DateTime.Now;
        bool flag = SaveSystem.CheckMove(this.m_filename, SaveDataType.Character, ref this.m_fileSource, now, 0UL, false);         bool flag = SaveSystem.CheckMove(this.m_filename, SaveDataType.Character, ref this.m_fileSource, now, 0UL, false);
        if (this.m_createBackupBeforeSaving && !flag)         if (this.m_createBackupBeforeSaving && !flag)
        {         {
            SaveWithBackups saveWithBackups;             SaveWithBackups saveWithBackups;
            if (SaveSystem.TryGetSaveByName(this.m_filename, SaveDataType.Character, out saveWithBackups) && !saveWithBackups.IsDeleted)             if (SaveSystem.TryGetSaveByName(this.m_filename, SaveDataType.Character, out saveWithBackups) && !saveWithBackups.IsDeleted)
            {             {
                if (SaveSystem.CreateBackup(saveWithBackups.PrimaryFile, DateTime.Now, this.m_fileSource))                 if (SaveSystem.CreateBackup(saveWithBackups.PrimaryFile, DateTime.Now, this.m_fileSource))
                {                 {
                    ZLog.Log("Migrating character save from an old save format, created backup!");                     ZLog.Log("Migrating character save from an old save format, created backup!");
                }                 }
                else                 else
                {                 {
                    ZLog.LogError("Failed to create backup of character save " + this.m_filename + "!");                     ZLog.LogError("Failed to create backup of character save " + this.m_filename + "!");
                }                 }
            }             }
            else             else
            {             {
                ZLog.LogError("Failed to get character save " + this.m_filename + " from save system, so a backup couldn't be created!");                 ZLog.LogError("Failed to get character save " + this.m_filename + " from save system, so a backup couldn't be created!");
            }             }
        }         }
        this.m_createBackupBeforeSaving = false;         this.m_createBackupBeforeSaving = false;
        string text = PlayerProfile.GetCharacterFolderPath(this.m_fileSource) + this.m_filename + ".fch";         string text = PlayerProfile.GetCharacterFolderPath(this.m_fileSource) + this.m_filename + ".fch";
        string text2 = text + ".old";         string text2 = text + ".old";
        string text3 = text + ".new";         string text3 = text + ".new";
        string characterFolderPath = PlayerProfile.GetCharacterFolderPath(this.m_fileSource);         string characterFolderPath = PlayerProfile.GetCharacterFolderPath(this.m_fileSource);
        if (!Directory.Exists(characterFolderPath) && this.m_fileSource != FileHelpers.FileSource.Cloud)         if (!Directory.Exists(characterFolderPath) && this.m_fileSource != FileHelpers.FileSource.Cloud)
        {         {
            Directory.CreateDirectory(characterFolderPath);             Directory.CreateDirectory(characterFolderPath);
        }         }
        ZPackage zpackage = new ZPackage();         ZPackage zpackage = new ZPackage();
.        zpackage.Write(38);         zpackage.Write(39);
        zpackage.Write(105);         zpackage.Write(105);
        for (int i = 0; i < 105; i++)         for (int i = 0; i < 105; i++)
        {         {
            zpackage.Write(this.m_playerStats.m_stats[(PlayerStatType)i]);             zpackage.Write(this.m_playerStats.m_stats[(PlayerStatType)i]);
        }         }
        zpackage.Write(this.m_worldData.Count);         zpackage.Write(this.m_worldData.Count);
        foreach (KeyValuePair<long, PlayerProfile.WorldPlayerData> keyValuePair in this.m_worldData)         foreach (KeyValuePair<long, PlayerProfile.WorldPlayerData> keyValuePair in this.m_worldData)
        {         {
            zpackage.Write(keyValuePair.Key);             zpackage.Write(keyValuePair.Key);
            zpackage.Write(keyValuePair.Value.m_haveCustomSpawnPoint);             zpackage.Write(keyValuePair.Value.m_haveCustomSpawnPoint);
            zpackage.Write(keyValuePair.Value.m_spawnPoint);             zpackage.Write(keyValuePair.Value.m_spawnPoint);
            zpackage.Write(keyValuePair.Value.m_haveLogoutPoint);             zpackage.Write(keyValuePair.Value.m_haveLogoutPoint);
            zpackage.Write(keyValuePair.Value.m_logoutPoint);             zpackage.Write(keyValuePair.Value.m_logoutPoint);
            zpackage.Write(keyValuePair.Value.m_haveDeathPoint);             zpackage.Write(keyValuePair.Value.m_haveDeathPoint);
            zpackage.Write(keyValuePair.Value.m_deathPoint);             zpackage.Write(keyValuePair.Value.m_deathPoint);
            zpackage.Write(keyValuePair.Value.m_homePoint);             zpackage.Write(keyValuePair.Value.m_homePoint);
            zpackage.Write(keyValuePair.Value.m_mapData != null);             zpackage.Write(keyValuePair.Value.m_mapData != null);
            if (keyValuePair.Value.m_mapData != null)             if (keyValuePair.Value.m_mapData != null)
            {             {
                zpackage.Write(keyValuePair.Value.m_mapData);                 zpackage.Write(keyValuePair.Value.m_mapData);
            }             }
        }         }
        zpackage.Write(this.m_playerName);         zpackage.Write(this.m_playerName);
        zpackage.Write(this.m_playerID);         zpackage.Write(this.m_playerID);
        zpackage.Write(this.m_startSeed);         zpackage.Write(this.m_startSeed);
        int num = (int)(DateTime.Now - this.m_lastSaveLoad).TotalSeconds;         int num = (int)(DateTime.Now - this.m_lastSaveLoad).TotalSeconds;
        this.m_lastSaveLoad = DateTime.Now;         this.m_lastSaveLoad = DateTime.Now;
        zpackage.Write(this.m_usedCheats);         zpackage.Write(this.m_usedCheats);
        zpackage.Write(new DateTimeOffset(this.m_dateCreated).ToUnixTimeSeconds());         zpackage.Write(new DateTimeOffset(this.m_dateCreated).ToUnixTimeSeconds());
        if (ZNet.instance && ZoneSystem.instance && ZNet.World != null)         if (ZNet.instance && ZoneSystem.instance && ZNet.World != null)
        {         {
            this.m_knownWorlds.IncrementOrSet(ZNet.instance.GetWorldName(), (float)num);             this.m_knownWorlds.IncrementOrSet(ZNet.instance.GetWorldName(), (float)num);
.            for (int j = 0; j < 41; j++)             for (int j = 0; j < 42; j++)
            {             {
                string text4;                 string text4;
                if (ZoneSystem.instance.GetGlobalKey((GlobalKeys)j, out text4))                 if (ZoneSystem.instance.GetGlobalKey((GlobalKeys)j, out text4))
                {                 {
                    Dictionary<string, float> knownWorldKeys = this.m_knownWorldKeys;                     Dictionary<string, float> knownWorldKeys = this.m_knownWorldKeys;
                    GlobalKeys globalKeys = (GlobalKeys)j;                     GlobalKeys globalKeys = (GlobalKeys)j;
                    knownWorldKeys.IncrementOrSet(globalKeys.ToString().ToLower() + " " + text4, (float)num);                     knownWorldKeys.IncrementOrSet(globalKeys.ToString().ToLower() + " " + text4, (float)num);
                }                 }
                else                 else
                {                 {
                    Dictionary<string, float> knownWorldKeys2 = this.m_knownWorldKeys;                     Dictionary<string, float> knownWorldKeys2 = this.m_knownWorldKeys;
                    GlobalKeys globalKeys = (GlobalKeys)j;                     GlobalKeys globalKeys = (GlobalKeys)j;
                    knownWorldKeys2.IncrementOrSet(globalKeys.ToString().ToLower() + " default", (float)num);                     knownWorldKeys2.IncrementOrSet(globalKeys.ToString().ToLower() + " default", (float)num);
                }                 }
            }             }
        }         }
        zpackage.Write(this.m_knownWorlds.Count);         zpackage.Write(this.m_knownWorlds.Count);
        foreach (KeyValuePair<string, float> keyValuePair2 in this.m_knownWorlds)         foreach (KeyValuePair<string, float> keyValuePair2 in this.m_knownWorlds)
        {         {
            zpackage.Write(keyValuePair2.Key);             zpackage.Write(keyValuePair2.Key);
            zpackage.Write(keyValuePair2.Value);             zpackage.Write(keyValuePair2.Value);
        }         }
        zpackage.Write(this.m_knownWorldKeys.Count);         zpackage.Write(this.m_knownWorldKeys.Count);
        foreach (KeyValuePair<string, float> keyValuePair3 in this.m_knownWorldKeys)         foreach (KeyValuePair<string, float> keyValuePair3 in this.m_knownWorldKeys)
        {         {
            zpackage.Write(keyValuePair3.Key);             zpackage.Write(keyValuePair3.Key);
            zpackage.Write(keyValuePair3.Value);             zpackage.Write(keyValuePair3.Value);
        }         }
        zpackage.Write(this.m_knownCommands.Count);         zpackage.Write(this.m_knownCommands.Count);
        foreach (KeyValuePair<string, float> keyValuePair4 in this.m_knownCommands)         foreach (KeyValuePair<string, float> keyValuePair4 in this.m_knownCommands)
        {         {
            zpackage.Write(keyValuePair4.Key);             zpackage.Write(keyValuePair4.Key);
            zpackage.Write(keyValuePair4.Value);             zpackage.Write(keyValuePair4.Value);
        }         }
        if (this.m_playerData != null)         if (this.m_playerData != null)
        {         {
            zpackage.Write(true);             zpackage.Write(true);
            zpackage.Write(this.m_playerData);             zpackage.Write(this.m_playerData);
        }         }
        else         else
        {         {
            zpackage.Write(false);             zpackage.Write(false);
        }         }
        byte[] array = zpackage.GenerateHash();         byte[] array = zpackage.GenerateHash();
        byte[] array2 = zpackage.GetArray();         byte[] array2 = zpackage.GetArray();
        FileWriter fileWriter = new FileWriter(text3, FileHelpers.FileHelperType.Binary, this.m_fileSource);         FileWriter fileWriter = new FileWriter(text3, FileHelpers.FileHelperType.Binary, this.m_fileSource);
        fileWriter.m_binary.Write(array2.Length);         fileWriter.m_binary.Write(array2.Length);
        fileWriter.m_binary.Write(array2);         fileWriter.m_binary.Write(array2);
        fileWriter.m_binary.Write(array.Length);         fileWriter.m_binary.Write(array.Length);
        fileWriter.m_binary.Write(array);         fileWriter.m_binary.Write(array);
        fileWriter.Finish();         fileWriter.Finish();
        SaveSystem.InvalidateCache();         SaveSystem.InvalidateCache();
        if (fileWriter.Status != FileWriter.WriterStatus.CloseSucceeded && this.m_fileSource == FileHelpers.FileSource.Cloud)         if (fileWriter.Status != FileWriter.WriterStatus.CloseSucceeded && this.m_fileSource == FileHelpers.FileSource.Cloud)
        {         {
            string text5 = string.Concat(new string[]             string text5 = string.Concat(new string[]
            {             {
                PlayerProfile.GetCharacterFolderPath(FileHelpers.FileSource.Local),                 PlayerProfile.GetCharacterFolderPath(FileHelpers.FileSource.Local),
                this.m_filename,                 this.m_filename,
                "_backup_cloud-",                 "_backup_cloud-",
                now.ToString("yyyyMMdd-HHmmss"),                 now.ToString("yyyyMMdd-HHmmss"),
                ".fch"                  ".fch" 
            });             });
            fileWriter.DumpCloudWriteToLocalFile(text5);             fileWriter.DumpCloudWriteToLocalFile(text5);
            SaveSystem.InvalidateCache();             SaveSystem.InvalidateCache();
            ZLog.LogError(string.Concat(new string[] { "Cloud save to location \"", text, "\" failed! Saved as local backup \"", text5, "\". Use the \"Manage saves\" menu to restore this backup." }));             ZLog.LogError(string.Concat(new string[] { "Cloud save to location \"", text, "\" failed! Saved as local backup \"", text5, "\". Use the \"Manage saves\" menu to restore this backup." }));
        }         }
        else         else
        {         {
            FileHelpers.ReplaceOldFile(text, text3, text2, this.m_fileSource);             FileHelpers.ReplaceOldFile(text, text3, text2, this.m_fileSource);
            SaveSystem.InvalidateCache();             SaveSystem.InvalidateCache();
            ZNet.ConsiderAutoBackup(this.m_filename, SaveDataType.Character, now);             ZNet.ConsiderAutoBackup(this.m_filename, SaveDataType.Character, now);
        }         }
        Action savingFinished = PlayerProfile.SavingFinished;         Action savingFinished = PlayerProfile.SavingFinished;
        if (savingFinished != null)         if (savingFinished != null)
        {         {
            savingFinished();             savingFinished();
        }         }
        return true;         return true;
    }     }
   
    private bool LoadPlayerFromDisk()     private bool LoadPlayerFromDisk()
    {     {
        try         try
        {         {
            ZPackage zpackage = this.LoadPlayerDataFromDisk();             ZPackage zpackage = this.LoadPlayerDataFromDisk();
            if (zpackage == null)             if (zpackage == null)
            {             {
                ZLog.LogWarning("No player data");                 ZLog.LogWarning("No player data");
                return false;                 return false;
            }             }
            int num = zpackage.ReadInt();             int num = zpackage.ReadInt();
            if (!global::Version.IsPlayerVersionCompatible(num))             if (!global::Version.IsPlayerVersionCompatible(num))
            {             {
                ZLog.Log("Player data is not compatible, ignoring");                 ZLog.Log("Player data is not compatible, ignoring");
                return false;                 return false;
            }             }
.            if (num != 38)             if (num != 39)
            {             {
                this.m_createBackupBeforeSaving = true;                 this.m_createBackupBeforeSaving = true;
            }             }
            if (num >= 38)             if (num >= 38)
            {             {
                int num2 = zpackage.ReadInt();                 int num2 = zpackage.ReadInt();
                for (int i = 0; i < num2; i++)                 for (int i = 0; i < num2; i++)
                {                 {
                    this.m_playerStats[(PlayerStatType)i] = zpackage.ReadSingle();                     this.m_playerStats[(PlayerStatType)i] = zpackage.ReadSingle();
                }                 }
            }             }
            else if (num >= 28)             else if (num >= 28)
            {             {
                this.m_playerStats[PlayerStatType.EnemyKills] = (float)zpackage.ReadInt();                 this.m_playerStats[PlayerStatType.EnemyKills] = (float)zpackage.ReadInt();
                this.m_playerStats[PlayerStatType.Deaths] = (float)zpackage.ReadInt();                 this.m_playerStats[PlayerStatType.Deaths] = (float)zpackage.ReadInt();
                this.m_playerStats[PlayerStatType.CraftsOrUpgrades] = (float)zpackage.ReadInt();                 this.m_playerStats[PlayerStatType.CraftsOrUpgrades] = (float)zpackage.ReadInt();
                this.m_playerStats[PlayerStatType.Builds] = (float)zpackage.ReadInt();                 this.m_playerStats[PlayerStatType.Builds] = (float)zpackage.ReadInt();
            }             }
            this.m_worldData.Clear();             this.m_worldData.Clear();
            int num3 = zpackage.ReadInt();             int num3 = zpackage.ReadInt();
            for (int j = 0; j < num3; j++)             for (int j = 0; j < num3; j++)
            {             {
                long num4 = zpackage.ReadLong();                 long num4 = zpackage.ReadLong();
                PlayerProfile.WorldPlayerData worldPlayerData = new PlayerProfile.WorldPlayerData();                 PlayerProfile.WorldPlayerData worldPlayerData = new PlayerProfile.WorldPlayerData();
                worldPlayerData.m_haveCustomSpawnPoint = zpackage.ReadBool();                 worldPlayerData.m_haveCustomSpawnPoint = zpackage.ReadBool();
                worldPlayerData.m_spawnPoint = zpackage.ReadVector3();                 worldPlayerData.m_spawnPoint = zpackage.ReadVector3();
                worldPlayerData.m_haveLogoutPoint = zpackage.ReadBool();                 worldPlayerData.m_haveLogoutPoint = zpackage.ReadBool();
                worldPlayerData.m_logoutPoint = zpackage.ReadVector3();                 worldPlayerData.m_logoutPoint = zpackage.ReadVector3();
                if (num >= 30)                 if (num >= 30)
                {                 {
                    worldPlayerData.m_haveDeathPoint = zpackage.ReadBool();                     worldPlayerData.m_haveDeathPoint = zpackage.ReadBool();
                    worldPlayerData.m_deathPoint = zpackage.ReadVector3();                     worldPlayerData.m_deathPoint = zpackage.ReadVector3();
                }                 }
                worldPlayerData.m_homePoint = zpackage.ReadVector3();                 worldPlayerData.m_homePoint = zpackage.ReadVector3();
                if (num >= 29 && zpackage.ReadBool())                 if (num >= 29 && zpackage.ReadBool())
                {                 {
                    worldPlayerData.m_mapData = zpackage.ReadByteArray();                     worldPlayerData.m_mapData = zpackage.ReadByteArray();
                }                 }
                this.m_worldData.Add(num4, worldPlayerData);                 this.m_worldData.Add(num4, worldPlayerData);
            }             }
            this.SetName(zpackage.ReadString());             this.SetName(zpackage.ReadString());
            this.m_playerID = zpackage.ReadLong();             this.m_playerID = zpackage.ReadLong();
            this.m_startSeed = zpackage.ReadString();             this.m_startSeed = zpackage.ReadString();
            if (num >= 38)             if (num >= 38)
            {             {
                this.m_usedCheats = zpackage.ReadBool();                 this.m_usedCheats = zpackage.ReadBool();
                this.m_dateCreated = DateTimeOffset.FromUnixTimeSeconds(zpackage.ReadLong()).Date;                 this.m_dateCreated = DateTimeOffset.FromUnixTimeSeconds(zpackage.ReadLong()).Date;
                int num5 = zpackage.ReadInt();                 int num5 = zpackage.ReadInt();
                for (int k = 0; k < num5; k++)                 for (int k = 0; k < num5; k++)
                {                 {
                    this.m_knownWorlds[zpackage.ReadString()] = zpackage.ReadSingle();                     this.m_knownWorlds[zpackage.ReadString()] = zpackage.ReadSingle();
                }                 }
                num5 = zpackage.ReadInt();                 num5 = zpackage.ReadInt();
                for (int l = 0; l < num5; l++)                 for (int l = 0; l < num5; l++)
                {                 {
                    this.m_knownWorldKeys[zpackage.ReadString()] = zpackage.ReadSingle();                     this.m_knownWorldKeys[zpackage.ReadString()] = zpackage.ReadSingle();
                }                 }
                num5 = zpackage.ReadInt();                 num5 = zpackage.ReadInt();
                for (int m = 0; m < num5; m++)                 for (int m = 0; m < num5; m++)
                {                 {
                    this.m_knownCommands[zpackage.ReadString()] = zpackage.ReadSingle();                     this.m_knownCommands[zpackage.ReadString()] = zpackage.ReadSingle();
                }                 }
            }             }
            else             else
            {             {
                this.m_dateCreated = new DateTime(2021, 2, 2);                 this.m_dateCreated = new DateTime(2021, 2, 2);
            }             }
            if (zpackage.ReadBool())             if (zpackage.ReadBool())
            {             {
                this.m_playerData = zpackage.ReadByteArray();                 this.m_playerData = zpackage.ReadByteArray();
            }             }
            else             else
            {             {
                this.m_playerData = null;                 this.m_playerData = null;
            }             }
            this.m_lastSaveLoad = DateTime.Now;             this.m_lastSaveLoad = DateTime.Now;
        }         }
        catch (Exception ex)         catch (Exception ex)
        {         {
            ZLog.LogWarning("Exception while loading player profile:" + this.m_filename + " , " + ex.ToString());             ZLog.LogWarning("Exception while loading player profile:" + this.m_filename + " , " + ex.ToString());
        }         }
        return true;         return true;
    }     }
   
    private ZPackage LoadPlayerDataFromDisk()     private ZPackage LoadPlayerDataFromDisk()
    {     {
        string path = PlayerProfile.GetPath(this.m_fileSource, this.m_filename);         string path = PlayerProfile.GetPath(this.m_fileSource, this.m_filename);
        FileReader fileReader;         FileReader fileReader;
        try         try
        {         {
            fileReader = new FileReader(path, this.m_fileSource, FileHelpers.FileHelperType.Binary);             fileReader = new FileReader(path, this.m_fileSource, FileHelpers.FileHelperType.Binary);
        }         }
        catch (Exception ex)         catch (Exception ex)
        {         {
            ZLog.Log(string.Concat(new string[] { "  failed to load: ", path, " (", ex.Message, ")" }));             ZLog.Log(string.Concat(new string[] { "  failed to load: ", path, " (", ex.Message, ")" }));
            return null;             return null;
        }         }
        byte[] array;         byte[] array;
        try         try
        {         {
            BinaryReader binary = fileReader.m_binary;             BinaryReader binary = fileReader.m_binary;
            int num = binary.ReadInt32();             int num = binary.ReadInt32();
            array = binary.ReadBytes(num);             array = binary.ReadBytes(num);
            int num2 = binary.ReadInt32();             int num2 = binary.ReadInt32();
            binary.ReadBytes(num2);             binary.ReadBytes(num2);
        }         }
        catch (Exception ex2)         catch (Exception ex2)
        {         {
            ZLog.LogError(string.Format("  error loading player.dat. Source: {0}, Path: {1}, Error: {2}", this.m_fileSource, path, ex2.Message));             ZLog.LogError(string.Format("  error loading player.dat. Source: {0}, Path: {1}, Error: {2}", this.m_fileSource, path, ex2.Message));
            fileReader.Dispose();             fileReader.Dispose();
            return null;             return null;
        }         }
        fileReader.Dispose();         fileReader.Dispose();
        return new ZPackage(array);         return new ZPackage(array);
    }     }
   
    public void SetLogoutPoint(Vector3 point)     public void SetLogoutPoint(Vector3 point)
    {     {
        this.GetWorldData(ZNet.instance.GetWorldUID()).m_haveLogoutPoint = true;         this.GetWorldData(ZNet.instance.GetWorldUID()).m_haveLogoutPoint = true;
        this.GetWorldData(ZNet.instance.GetWorldUID()).m_logoutPoint = point;         this.GetWorldData(ZNet.instance.GetWorldUID()).m_logoutPoint = point;
    }     }
   
    public void SetDeathPoint(Vector3 point)     public void SetDeathPoint(Vector3 point)
    {     {
        this.GetWorldData(ZNet.instance.GetWorldUID()).m_haveDeathPoint = true;         this.GetWorldData(ZNet.instance.GetWorldUID()).m_haveDeathPoint = true;
        this.GetWorldData(ZNet.instance.GetWorldUID()).m_deathPoint = point;         this.GetWorldData(ZNet.instance.GetWorldUID()).m_deathPoint = point;
    }     }
   
    public void SetMapData(byte[] data)     public void SetMapData(byte[] data)
    {     {
        long worldUID = ZNet.instance.GetWorldUID();         long worldUID = ZNet.instance.GetWorldUID();
        if (worldUID != 0L)         if (worldUID != 0L)
        {         {
            this.GetWorldData(worldUID).m_mapData = data;             this.GetWorldData(worldUID).m_mapData = data;
        }         }
    }     }
   
    public byte[] GetMapData()     public byte[] GetMapData()
    {     {
        return this.GetWorldData(ZNet.instance.GetWorldUID()).m_mapData;         return this.GetWorldData(ZNet.instance.GetWorldUID()).m_mapData;
    }     }
   
    public void ClearLoguoutPoint()     public void ClearLoguoutPoint()
    {     {
        this.GetWorldData(ZNet.instance.GetWorldUID()).m_haveLogoutPoint = false;         this.GetWorldData(ZNet.instance.GetWorldUID()).m_haveLogoutPoint = false;
    }     }
   
    public bool HaveLogoutPoint()     public bool HaveLogoutPoint()
    {     {
        return this.GetWorldData(ZNet.instance.GetWorldUID()).m_haveLogoutPoint;         return this.GetWorldData(ZNet.instance.GetWorldUID()).m_haveLogoutPoint;
    }     }
   
    public Vector3 GetLogoutPoint()     public Vector3 GetLogoutPoint()
    {     {
        return this.GetWorldData(ZNet.instance.GetWorldUID()).m_logoutPoint;         return this.GetWorldData(ZNet.instance.GetWorldUID()).m_logoutPoint;
    }     }
   
    public bool HaveDeathPoint()     public bool HaveDeathPoint()
    {     {
        return this.GetWorldData(ZNet.instance.GetWorldUID()).m_haveDeathPoint;         return this.GetWorldData(ZNet.instance.GetWorldUID()).m_haveDeathPoint;
    }     }
   
    public Vector3 GetDeathPoint()     public Vector3 GetDeathPoint()
    {     {
        return this.GetWorldData(ZNet.instance.GetWorldUID()).m_deathPoint;         return this.GetWorldData(ZNet.instance.GetWorldUID()).m_deathPoint;
    }     }
   
    public void SetCustomSpawnPoint(Vector3 point)     public void SetCustomSpawnPoint(Vector3 point)
    {     {
        this.GetWorldData(ZNet.instance.GetWorldUID()).m_haveCustomSpawnPoint = true;         this.GetWorldData(ZNet.instance.GetWorldUID()).m_haveCustomSpawnPoint = true;
        this.GetWorldData(ZNet.instance.GetWorldUID()).m_spawnPoint = point;         this.GetWorldData(ZNet.instance.GetWorldUID()).m_spawnPoint = point;
    }     }
   
    public Vector3 GetCustomSpawnPoint()     public Vector3 GetCustomSpawnPoint()
    {     {
        return this.GetWorldData(ZNet.instance.GetWorldUID()).m_spawnPoint;         return this.GetWorldData(ZNet.instance.GetWorldUID()).m_spawnPoint;
    }     }
   
    public bool HaveCustomSpawnPoint()     public bool HaveCustomSpawnPoint()
    {     {
        return this.GetWorldData(ZNet.instance.GetWorldUID()).m_haveCustomSpawnPoint;         return this.GetWorldData(ZNet.instance.GetWorldUID()).m_haveCustomSpawnPoint;
    }     }
   
    public void ClearCustomSpawnPoint()     public void ClearCustomSpawnPoint()
    {     {
        this.GetWorldData(ZNet.instance.GetWorldUID()).m_haveCustomSpawnPoint = false;         this.GetWorldData(ZNet.instance.GetWorldUID()).m_haveCustomSpawnPoint = false;
    }     }
   
    public void SetHomePoint(Vector3 point)     public void SetHomePoint(Vector3 point)
    {     {
        this.GetWorldData(ZNet.instance.GetWorldUID()).m_homePoint = point;         this.GetWorldData(ZNet.instance.GetWorldUID()).m_homePoint = point;
    }     }
   
    public Vector3 GetHomePoint()     public Vector3 GetHomePoint()
    {     {
        return this.GetWorldData(ZNet.instance.GetWorldUID()).m_homePoint;         return this.GetWorldData(ZNet.instance.GetWorldUID()).m_homePoint;
    }     }
   
    public void SetName(string name)     public void SetName(string name)
    {     {
        this.m_playerName = name;         this.m_playerName = name;
    }     }
   
    public string GetName()     public string GetName()
    {     {
        return this.m_playerName;         return this.m_playerName;
    }     }
   
    public long GetPlayerID()     public long GetPlayerID()
    {     {
        return this.m_playerID;         return this.m_playerID;
    }     }
   
    public static void RemoveProfile(string name, FileHelpers.FileSource fileSource = FileHelpers.FileSource.Auto)     public static void RemoveProfile(string name, FileHelpers.FileSource fileSource = FileHelpers.FileSource.Auto)
    {     {
        SaveWithBackups saveWithBackups;         SaveWithBackups saveWithBackups;
        if (SaveSystem.TryGetSaveByName(name, SaveDataType.Character, out saveWithBackups) && !saveWithBackups.IsDeleted)         if (SaveSystem.TryGetSaveByName(name, SaveDataType.Character, out saveWithBackups) && !saveWithBackups.IsDeleted)
        {         {
            SaveSystem.Delete(saveWithBackups.PrimaryFile);             SaveSystem.Delete(saveWithBackups.PrimaryFile);
        }         }
    }     }
   
    public static bool HaveProfile(string name)     public static bool HaveProfile(string name)
    {     {
        SaveWithBackups saveWithBackups;         SaveWithBackups saveWithBackups;
        return SaveSystem.TryGetSaveByName(name, SaveDataType.Character, out saveWithBackups) && !saveWithBackups.IsDeleted;         return SaveSystem.TryGetSaveByName(name, SaveDataType.Character, out saveWithBackups) && !saveWithBackups.IsDeleted;
    }     }
   
    public void IncrementStat(PlayerStatType stat, float amount = 1f)     public void IncrementStat(PlayerStatType stat, float amount = 1f)
    {     {
        PlayerProfile.PlayerStats playerStats = this.m_playerStats;         PlayerProfile.PlayerStats playerStats = this.m_playerStats;
        playerStats[stat] += amount;         playerStats[stat] += amount;
    }     }
   
    private static string GetCharacterFolder(FileHelpers.FileSource fileSource)     private static string GetCharacterFolder(FileHelpers.FileSource fileSource)
    {     {
        if (fileSource != FileHelpers.FileSource.Local)         if (fileSource != FileHelpers.FileSource.Local)
        {         {
            return "/characters/";             return "/characters/";
        }         }
        return "/characters_local/";         return "/characters_local/";
    }     }
   
    public static string GetCharacterFolderPath(FileHelpers.FileSource fileSource)     public static string GetCharacterFolderPath(FileHelpers.FileSource fileSource)
    {     {
        return Utils.GetSaveDataPath(fileSource) + PlayerProfile.GetCharacterFolder(fileSource);         return Utils.GetSaveDataPath(fileSource) + PlayerProfile.GetCharacterFolder(fileSource);
    }     }
   
    public string GetFilename()     public string GetFilename()
    {     {
        return this.m_filename;         return this.m_filename;
    }     }
   
    public string GetPath()     public string GetPath()
    {     {
        return PlayerProfile.GetPath(this.m_fileSource, this.m_filename);         return PlayerProfile.GetPath(this.m_fileSource, this.m_filename);
    }     }
   
    public static string GetPath(FileHelpers.FileSource fileSource, string name)     public static string GetPath(FileHelpers.FileSource fileSource, string name)
    {     {
        return PlayerProfile.GetCharacterFolderPath(fileSource) + name + ".fch";         return PlayerProfile.GetCharacterFolderPath(fileSource) + name + ".fch";
    }     }
   
    private PlayerProfile.WorldPlayerData GetWorldData(long worldUID)     private PlayerProfile.WorldPlayerData GetWorldData(long worldUID)
    {     {
        PlayerProfile.WorldPlayerData worldPlayerData;         PlayerProfile.WorldPlayerData worldPlayerData;
        if (this.m_worldData.TryGetValue(worldUID, out worldPlayerData))         if (this.m_worldData.TryGetValue(worldUID, out worldPlayerData))
        {         {
            return worldPlayerData;             return worldPlayerData;
        }         }
        worldPlayerData = new PlayerProfile.WorldPlayerData();         worldPlayerData = new PlayerProfile.WorldPlayerData();
        this.m_worldData.Add(worldUID, worldPlayerData);         this.m_worldData.Add(worldUID, worldPlayerData);
        return worldPlayerData;         return worldPlayerData;
    }     }
   
    public static Action SavingStarted;     public static Action SavingStarted;
   
    public static Action SavingFinished;     public static Action SavingFinished;
   
    public static Vector3 m_originalSpawnPoint = new Vector3(-676f, 50f, 299f);     public static Vector3 m_originalSpawnPoint = new Vector3(-676f, 50f, 299f);
   
    public readonly PlayerProfile.PlayerStats m_playerStats = new PlayerProfile.PlayerStats();     public readonly PlayerProfile.PlayerStats m_playerStats = new PlayerProfile.PlayerStats();
   
    public FileHelpers.FileSource m_fileSource = FileHelpers.FileSource.Local;     public FileHelpers.FileSource m_fileSource = FileHelpers.FileSource.Local;
   
    public readonly string m_filename = "";     public readonly string m_filename = "";
   
    private string m_playerName = "";     private string m_playerName = "";
   
    private long m_playerID;     private long m_playerID;
   
    private string m_startSeed = "";     private string m_startSeed = "";
   
    private readonly Dictionary<long, PlayerProfile.WorldPlayerData> m_worldData = new Dictionary<long, PlayerProfile.WorldPlayerData>();     private readonly Dictionary<long, PlayerProfile.WorldPlayerData> m_worldData = new Dictionary<long, PlayerProfile.WorldPlayerData>();
   
    private bool m_createBackupBeforeSaving;     private bool m_createBackupBeforeSaving;
   
    private DateTime m_lastSaveLoad = DateTime.Now;     private DateTime m_lastSaveLoad = DateTime.Now;
   
    public Dictionary<string, float> m_knownWorlds = new Dictionary<string, float>();     public Dictionary<string, float> m_knownWorlds = new Dictionary<string, float>();
   
    public Dictionary<string, float> m_knownWorldKeys = new Dictionary<string, float>();     public Dictionary<string, float> m_knownWorldKeys = new Dictionary<string, float>();
   
    public Dictionary<string, float> m_knownCommands = new Dictionary<string, float>();     public Dictionary<string, float> m_knownCommands = new Dictionary<string, float>();
   
    public Dictionary<string, float> m_enemyStats = new Dictionary<string, float>();     public Dictionary<string, float> m_enemyStats = new Dictionary<string, float>();
   
    public Dictionary<string, float> m_itemPickupStats = new Dictionary<string, float>();     public Dictionary<string, float> m_itemPickupStats = new Dictionary<string, float>();
   
    public Dictionary<string, float> m_itemCraftStats = new Dictionary<string, float>();     public Dictionary<string, float> m_itemCraftStats = new Dictionary<string, float>();
   
    public bool m_usedCheats;     public bool m_usedCheats;
   
    public DateTime m_dateCreated = DateTime.Now;     public DateTime m_dateCreated = DateTime.Now;
   
    private byte[] m_playerData;     private byte[] m_playerData;
   
    public static Dictionary<PlayerStatType, string> m_statTypeDates = new Dictionary<PlayerStatType, string>     public static Dictionary<PlayerStatType, string> m_statTypeDates = new Dictionary<PlayerStatType, string>
    {     {
        {         {
            PlayerStatType.Deaths,             PlayerStatType.Deaths,
            "Since beginning"              "Since beginning" 
        },         },
        {         {
            PlayerStatType.Jumps,             PlayerStatType.Jumps,
            "Hildirs Request (2023-06-16)"              "Hildirs Request (2023-06-16)" 
        }         }
    };     };
   
    private class WorldPlayerData     private class WorldPlayerData
    {     {
        public Vector3 m_spawnPoint = Vector3.zero;         public Vector3 m_spawnPoint = Vector3.zero;
   
        public bool m_haveCustomSpawnPoint;         public bool m_haveCustomSpawnPoint;
   
        public Vector3 m_logoutPoint = Vector3.zero;         public Vector3 m_logoutPoint = Vector3.zero;
   
        public bool m_haveLogoutPoint;         public bool m_haveLogoutPoint;
   
        public Vector3 m_deathPoint = Vector3.zero;         public Vector3 m_deathPoint = Vector3.zero;
   
        public bool m_haveDeathPoint;         public bool m_haveDeathPoint;
   
        public Vector3 m_homePoint = Vector3.zero;         public Vector3 m_homePoint = Vector3.zero;
   
        public byte[] m_mapData;         public byte[] m_mapData;
    }     }
   
    public class PlayerStats     public class PlayerStats
    {     {
        public float this[PlayerStatType type]         public float this[PlayerStatType type]
        {         {
            get             get
            {             {
                return this.m_stats[type];                 return this.m_stats[type];
            }             }
            set             set
            {             {
                this.m_stats[type] = value;                 this.m_stats[type] = value;
            }             }
        }         }
   
        public PlayerStats()         public PlayerStats()
        {         {
            for (int i = 0; i < 105; i++)             for (int i = 0; i < 105; i++)
            {             {
                this.m_stats[(PlayerStatType)i] = 0f;                 this.m_stats[(PlayerStatType)i] = 0f;
            }             }
        }         }
   
        public Dictionary<PlayerStatType, float> m_stats = new Dictionary<PlayerStatType, float>();         public Dictionary<PlayerStatType, float> m_stats = new Dictionary<PlayerStatType, float>();
    }     }
} }