コード例 #1
0
ファイル: WzFile.cs プロジェクト: Bia10/RazzleServer
        internal void ParseMainWzDirectory()
        {
            if (FilePath == null)
            {
                _log.Error("Path is null");
                return;
            }

            if (!File.Exists(FilePath))
            {
                var message = $"WZ File does not exist at path: '{FilePath}'";
                _log.Error(message);
                throw new FileNotFoundException(message);
            }

            var reader = new WzBinaryReader(File.Open(FilePath, FileMode.Open, FileAccess.Read, FileShare.Read), _wzIv);

            Header = new WzHeader
            {
                Ident     = reader.ReadString(4),
                FSize     = reader.ReadUInt64(),
                FStart    = reader.ReadUInt32(),
                Copyright = reader.ReadNullTerminatedString()
            };
            reader.ReadBytes((int)(Header.FStart - reader.BaseStream.Position));
            reader.Header = Header;
            _version      = reader.ReadInt16();
            if (Version == -1 && !CalculateVersion(reader))
            {
                throw new InvalidDataException(
                          "Error with game version hash : The specified game version is incorrect");
            }

            _versionHash = GetVersionHash(_version, Version);
            reader.Hash  = _versionHash;
            var tempDirectory = new WzDirectory(reader, Name, _versionHash, _wzIv, this);

            tempDirectory.ParseDirectory();
            WzDirectory = tempDirectory;
        }
コード例 #2
0
ファイル: WzFile.cs プロジェクト: york8817612/RazzleServer
        private void ParseMainWzDirectory(byte[] wzIv)
        {
            if (FilePath == null)
            {
                throw new ArgumentNullException(nameof(FilePath), "WZ File path is null");
            }

            if (!File.Exists(FilePath))
            {
                throw new FileNotFoundException($"WZ File does not exist at path: '{FilePath}'");
            }

            var mmf    = MemoryMappedFile.CreateFromFile(FilePath);
            var reader = new WzBinaryReader(mmf.CreateViewStream(), wzIv);

            Header = new WzHeader
            {
                Ident     = reader.ReadString(4),
                FSize     = reader.ReadUInt64(),
                FStart    = reader.ReadUInt32(),
                Copyright = reader.ReadNullTerminatedString()
            };
            reader.ReadBytes((int)(Header.FStart - reader.BaseStream.Position));
            reader.Header = Header;
            _version      = reader.ReadInt16();
            if (Version == -1 && !CalculateVersion(reader))
            {
                throw new InvalidDataException(
                          "Error with game version hash : The specified game version is incorrect");
            }

            _versionHash = GetVersionHash(_version, Version);
            reader.Hash  = _versionHash;
            var tempDirectory = new WzDirectory(reader, Name, _versionHash, wzIv, this);

            tempDirectory.ParseDirectory();
            WzDirectory = tempDirectory;
        }