// 解析WZ主目录 internal void ParseMainWzDirectory() { WzLib.WzDirectory directory; if (this.path == null) { return; } BinaryReader fileReader = new BinaryReader(File.Open(this.path, FileMode.Open)); this.ident = ""; // 前四个字节,文件标识:PKG1 for (int i = 0; i < 4; i++) { this.ident = this.ident + ((char)fileReader.ReadByte()); } this.fsize = fileReader.ReadUInt64(); // 8个字节,文件大小 this.fstart = fileReader.ReadUInt32(); // 4个字节,开始位置 this.copyright = WzTools.ReadNullTerminatedString(fileReader); // 字符串,版本信息:Package file v1.0 Copyright 2002 Wizet, ZMS this.version = fileReader.ReadInt16(); // 2个字节,文件版本 // 这个循环用于穷举versionHash值 for (int j = 0; j < 0xff; j++) { this.fileVersion = (byte)j; if (this.GetVersionHash()) { long pos = fileReader.BaseStream.Position; WzDirectory tdir = null; try { tdir = new WzDirectory(fileReader, fstart, name, versionHash); tdir.ParseDirectory(); } catch { fileReader.BaseStream.Position = pos; continue; } WzImage test = null; if (tdir.WzImages.Length != 0) { test = tdir.WzImages[0]; } else { test = GetTestImage(tdir.WzDirectories); } try { fileReader.BaseStream.Position = test.Offset; byte check = fileReader.ReadByte(); fileReader.BaseStream.Position = pos; tdir.Dispose(); if (check == 0x73 || check == 0x1B) { goto Label_00B1; } else { fileReader.BaseStream.Position = pos; } } catch { fileReader.BaseStream.Position = pos; continue; } } } throw new Exception("Error with game version hash : The specified game version is incorrect and WzLib was unable to determine the version itself"); Label_00B1: directory = new WzLib.WzDirectory(fileReader, this.fstart, this.name, this.versionHash); directory.ParseDirectory(); this.wzDir = directory; }