示例#1
0
        /// <summary>
        /// Scans for saves. Returns true if anything was found, or false on any error.
        /// </summary>
        /// <returns></returns>
        public bool ScanForSaves()
        {
            bool bSuccess = false;

            m_Savegames.Clear();
            try
            {
                bSuccess = LoadSteamSaves();
            }
            catch (Exception ex)
            {
                m_AppAPI.LogException(ex, "ScanForSaves");
            }
            return(bSuccess);
        }
示例#2
0
        /// <summary>
        /// Tries to load from m_Filename. Returns false on errors.
        /// </summary>
        /// <returns></returns>
        internal bool TryLoad()
        {
            bool bSuccess = false;

            try
            {
                // Very early out if no filename or can't find file
                if (string.IsNullOrWhiteSpace(m_Filename) || !File.Exists(m_Filename))
                {
                    return(bSuccess);
                }

                m_FileBytes  = File.ReadAllBytes(m_Filename);
                m_FileInfo   = new FileInfo(m_Filename);
                FileSaveTime = m_FileInfo.LastWriteTime;

                bSuccess = m_FileBytes.Length > MIN_SAVE_FILE_SIZE;
                if (!bSuccess)
                {
                    return(bSuccess);
                }

                // Assume success for now, unless header mismatch
                for (int i = 0; i < s_RequiredHeaderBytes.Length; ++i)
                {
                    if (s_RequiredHeaderBytes[i] != m_FileBytes[i])
                    {
                        m_AppAPI.LogLine(string.Format("Filename '{0}', header byte #{1} mismatch, {2} != {3}", m_Filename, i, s_RequiredHeaderBytes[i], m_FileBytes[i]));
                        bSuccess = false;
                        return(bSuccess);
                    }
                }

                // Header passed. Now try and read out fields.
                int offset = s_RequiredHeaderBytes.Length;


                // Not sure what this byte is, seems to be always 0.
                int versionByte = Read8Bits(ref offset);
                RequireByte(versionByte, 0x0A, offset);

                m_InitialOffset = Read32Bits(ref offset);
                ReadTimePlayed(ref offset);
                PlayerName           = ReadPString32(ref offset);
                PlayerLocation       = ReadPString32(ref offset);
                PlayerClass          = ReadPString32(ref offset);
                PlayerQuest          = ReadPString32(ref offset);
                PlayerSpecialization = ReadPString32(ref offset);

                m_PlayerLevelByte = Read8Bits(ref offset);

                // And then the 48 bytes after that that seem unlike the following section
                for (int i = 0; i < m_PostPlayerBlock.Length; ++i)
                {
                    m_PostPlayerBlock[i] = Read32Bits(ref offset);
                }

                // Store for later...
                m_PostPlayerStringOffset = offset;
                DebugText = string.Format("Init 0x{0:X} postPlayer=0x{1:X}", m_InitialOffset, m_PostPlayerStringOffset);

                // Find end of this next block.
                int endOffset = FirstOffsetOf(s_RepeatingPatternBytes, offset);
                if (endOffset < 0)
                {
                    DebugText = "Could not find s_RepeatingPatternBytes";
                    m_AppAPI.LogLine(string.Format("Error: could not find s_RepeatingPatternBytes starting at offset {0} in file", offset));
                }
                else
                {
                    // Seem to have a section of 24-bit values here. Ensure that.
                    int blockCount = (endOffset - offset) / SIZEOF_INT32;
                    // DebugText = string.Format("0x{0:X} ({0}) to s_RepeatingPatternBytes. Count={1}", endOffset, blockCount);
                    for (int i = 0; i < blockCount; ++i)
                    {
                        int  value = Read32Bits(ref offset);
                        bool sane  = WarnIfIntIsNotWithin(value, 0, 16777216, offset);
                        if (!sane)
                        {
                            break; // No further logging for this file.
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                m_AppAPI.LogException(ex, string.Format("TryLoad, m_Filename='{0}'", m_Filename));
            }
            return(bSuccess);
        }