Пример #1
0
 public WzFile(short pGameVersion, WzMapleVersion pVersion)
 {
     Header        = WzHeader.GetDefault();
     mFileVersion  = pGameVersion;
     mMapleVersion = pVersion;
     mWzIv         = WzTool.GetIvByMapleVersion(pVersion);
 }
Пример #2
0
		public override void Dispose()
		{
			wzDir.reader.Close();
			Header = null;
			path = null;
			name = null;
			WzDirectory.Dispose();
		}
Пример #3
0
 public override void Dispose()
 {
     wzDir.reader.Close();
     Header = null;
     path   = null;
     name   = null;
     WzDirectory.Dispose();
 }
Пример #4
0
 public WzFile(short gameVersion, WzMapleVersion version)
 {
     wzDir        = new WzDirectory();
     this.Header  = WzHeader.GetDefault();
     fileVersion  = gameVersion;
     mapleVersion = version;
     WzIv         = version.EncryptionKey();
     wzDir.WzIv   = WzIv;
 }
Пример #5
0
 /// <summary>
 /// Initialize MapleStory WZ file
 /// </summary>
 /// <param name="gameVersion"></param>
 /// <param name="version"></param>
 public WzFile(short gameVersion, WzMapleVersion version)
 {
     wzDir                  = new WzDirectory();
     this.Header            = WzHeader.GetDefault();
     mapleStoryPatchVersion = gameVersion;
     maplepLocalVersion     = version;
     WzIv       = WzTool.GetIvByMapleVersion(version);
     wzDir.WzIv = WzIv;
 }
Пример #6
0
		public static WzHeader GetDefault()
		{
			WzHeader header = new WzHeader();
			header.ident = "PKG1";
			header.copyright = "Package file v1.0 Copyright 2002 Wizet, ZMS";
			header.fstart = 60;
			header.fsize = 0;
			return header;
		}
Пример #7
0
		public WzFile(short gameVersion, WzMapleVersion version)
		{
			wzDir = new WzDirectory();
			this.Header = WzHeader.GetDefault();
			fileVersion = gameVersion;
			mapleVersion = version;
			WzIv = WzTool.GetIvByMapleVersion(version);
			wzDir.WzIv = WzIv;
		}
Пример #8
0
 public static WzHeader GetDefault()
 {
     WzHeader header = new WzHeader();
     header.ident = "PKG1";
     header.copyright = "Package file v1.0 Copyright 2002 Wizet, ZMS";
     header.fstart = 60;
     header.fsize = 0;
     return header;
 }
Пример #9
0
 public WzFile(short gameVersion, WzMapleVersion version)
 {
     WzDirectory      = new WzDirectory();
     Header           = WzHeader.GetDefault();
     FileVersion      = gameVersion;
     MapleVersion     = version;
     _wzIv            = WzTool.GetIvByMapleVersion(version);
     WzDirectory.WzIv = _wzIv;
 }
Пример #10
0
        public static WzHeader GetDefault()
        {
            WzHeader header = new WzHeader();

            header.Ident     = "PKG1";
            header.Copyright = "Package file v1.0 Copyright 2002 Wizet, ZMS";
            header.FStart    = 60;
            header.FSize     = 0;
            return(header);
        }
Пример #11
0
        public static WzHeader GetDefault()
        {
            WzHeader header = new WzHeader
            {
                ident     = "PKG1",
                copyright = DEFAULT_WZ_HEADER_COPYRIGHT,
                fstart    = 60,
                fsize     = 0
            };

            return(header);
        }
Пример #12
0
		internal void ParseMainWzDirectory()
		{
			if (this.path == null)
			{
				Console.WriteLine("[Error] Path is null");
				return;
			}

			WzBinaryReader reader = new WzBinaryReader(File.Open(this.path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), WzIv);

			this.Header = new WzHeader();
			this.Header.Ident = reader.ReadString(4);
			this.Header.FSize = reader.ReadUInt64();
			this.Header.FStart = reader.ReadUInt32();
			this.Header.Copyright = reader.ReadNullTerminatedString();
			reader.ReadBytes((int)(Header.FStart - reader.BaseStream.Position));
			reader.Header = this.Header;
			this.version = reader.ReadInt16();
			if (fileVersion == -1)
			{
				for (int j = 0; j < short.MaxValue; j++)
				{
					this.fileVersion = (short)j;
					this.versionHash = GetVersionHash(version, fileVersion);
					if (this.versionHash != 0)
					{
						reader.Hash = this.versionHash;
						long position = reader.BaseStream.Position;
						WzDirectory testDirectory = null;
						try
						{
							testDirectory = new WzDirectory(reader, this.name, this.versionHash, this.WzIv);
							testDirectory.ParseDirectory();
						}
						catch
						{
							reader.BaseStream.Position = position;
							continue;
						}
						WzImage testImage = testDirectory.GetChildImages()[0];

						try
						{
							reader.BaseStream.Position = testImage.Offset;
							byte checkByte = reader.ReadByte();
							reader.BaseStream.Position = position;
							testDirectory.Dispose();
							switch (checkByte)
							{
								case 0x73:
								case 0x1b:
									{
										WzDirectory directory = new WzDirectory(reader, this.name, this.versionHash, this.WzIv);
										directory.ParseDirectory();
										this.wzDir = directory;
										return;
									}
							}
							reader.BaseStream.Position = position;
						}
						catch
						{
							reader.BaseStream.Position = position;
						}
					}
				}
				throw new Exception("Error with game version hash : The specified game version is incorrect and WzLib was unable to determine the version itself");
			}
			else
			{
				this.versionHash = GetVersionHash(version, fileVersion);
				reader.Hash = this.versionHash;
				WzDirectory directory = new WzDirectory(reader, this.name, this.versionHash, this.WzIv);
				directory.ParseDirectory();
				this.wzDir = directory;
			}
		}
Пример #13
0
        internal void ParseMainWzDirectory(WzFile parentFile = null)
        {
            if (mPath == null)
            {
                Console.WriteLine("[Error] Path is null");
                return;
            }
            byte[] key = WzKeyGenerator.GenerateWzKey(mWzIv);
            mReader = new WzBinaryReader(File.Open(mPath, FileMode.Open, FileAccess.Read, FileShare.Read), key, true);
            Header  = new WzHeader {
                Ident = mReader.ReadString(4), FSize = mReader.ReadUInt64(), FStart = mReader.ReadUInt32(), Copyright = mReader.ReadNullTerminatedString()
            };
            int bytesToRead = (int)(Header.FStart - mReader.BaseStream.Position);

            if (bytesToRead < 0)
            {
                throw new Exception("Unable to parse WZ file header");
            }
            mReader.ReadBytes(bytesToRead);
            mReader.Header = Header;
            mVersion       = mReader.ReadInt16();
            if (mFileVersion == -1)
            {
                for (int j = 0; j < short.MaxValue; j++)
                {
                    mFileVersion = (short)j;
                    if (parentFile != null)
                    {
                        mFileVersion = parentFile.mFileVersion;
                    }
                    mVersionHash = GetVersionHash(mVersion, mFileVersion);
                    if (mVersionHash == 0)
                    {
                        continue;
                    }
                    mReader.Hash = mVersionHash;
                    long        position = mReader.BaseStream.Position;
                    WzDirectory testDirectory;
                    try {
                        testDirectory = new WzDirectory(mReader, mName, mVersionHash, mWzIv);
                        testDirectory.ParseDirectory();
                    } catch {
                        mReader.BaseStream.Position = position;
                        continue;
                    }
                    foreach (WzImage s in testDirectory.GetChildImages())
                    {
                        if (s.Name.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
                        {
                            testDirectory.Dispose();
                            throw new Exception("Invalid file names were detected. An invalid encryption may have been used.");
                        }
                    }
                    WzImage testImage = testDirectory.GetChildImages()[0];
                    try {
                        mReader.BaseStream.Position = testImage.Offset;
                        byte checkByte = mReader.ReadByte();
                        mReader.BaseStream.Position = position;
                        testDirectory.Dispose();
                        switch (checkByte)
                        {
                        case 0x73:
                        case 0x1b: {
                            mHash = mVersionHash;
                            ParseDirectory(parentFile);
                            return;
                        }
                        }
                        mReader.BaseStream.Position = position;
                    } catch {
                        mReader.BaseStream.Position = position;
                    }
                }
                throw new Exception("Error with game version hash : The specified game version is incorrect and WzLib was unable to determine the version itself");
            }
            mVersionHash = GetVersionHash(mVersion, mFileVersion);
            mReader.Hash = mVersionHash;
            mHash        = mVersionHash;
            ParseDirectory(parentFile);
        }
Пример #14
0
        internal void ParseMainWzDirectory()
        {
            if (FilePath == null)
            {
                Log.LogCritical("Path is null");
                return;
            }

            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 (FileVersion == -1)
            {
                for (var j = 0; j < short.MaxValue; j++)
                {
                    FileVersion  = (short)j;
                    _versionHash = GetVersionHash(_version, FileVersion);
                    if (_versionHash != 0)
                    {
                        reader.Hash = _versionHash;
                        var         position = reader.BaseStream.Position;
                        WzDirectory testDirectory;
                        try
                        {
                            testDirectory = new WzDirectory(reader, Name, _versionHash, _wzIv, this);
                            testDirectory.ParseDirectory();
                        }
                        catch
                        {
                            reader.BaseStream.Position = position;
                            continue;
                        }

                        var testImage = testDirectory.GetChildImages()[0];

                        try
                        {
                            reader.BaseStream.Position = testImage.Offset;
                            var checkByte = reader.ReadByte();
                            reader.BaseStream.Position = position;
                            testDirectory.Dispose();
                            switch (checkByte)
                            {
                            case 0x73:
                            case 0x1b:
                            {
                                var directory = new WzDirectory(reader, Name, _versionHash, _wzIv, this);
                                directory.ParseDirectory();
                                WzDirectory = directory;
                                return;
                            }
                            }

                            reader.BaseStream.Position = position;
                        }
                        catch
                        {
                            reader.BaseStream.Position = position;
                        }
                    }
                }

                throw new Exception(
                          "Error with game version hash : The specified game version is incorrect and WzLib was unable to determine the version itself");
            }

            {
                _versionHash = GetVersionHash(_version, FileVersion);
                reader.Hash  = _versionHash;
                var directory = new WzDirectory(reader, Name, _versionHash, _wzIv, this);
                directory.ParseDirectory();
                WzDirectory = directory;
            }
        }
Пример #15
0
        internal void ParseMainWzDirectory()
        {
            if (this.path == null)
            {
                Console.WriteLine("[Error] Path is null");
                return;
            }

            WzBinaryReader reader = new WzBinaryReader(File.Open(this.path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), WzIv);

            this.Header           = new WzHeader();
            this.Header.Ident     = reader.ReadString(4);
            this.Header.FSize     = reader.ReadUInt64();
            this.Header.FStart    = reader.ReadUInt32();
            this.Header.Copyright = reader.ReadNullTerminatedString();
            reader.ReadBytes((int)(Header.FStart - reader.BaseStream.Position));
            reader.Header = this.Header;
            this.version  = reader.ReadInt16();
            if (fileVersion == -1)
            {
                for (int j = 0; j < short.MaxValue; j++)
                {
                    this.fileVersion = (short)j;
                    this.versionHash = GetVersionHash(version, fileVersion);
                    if (this.versionHash != 0)
                    {
                        reader.Hash = this.versionHash;
                        long        position      = reader.BaseStream.Position;
                        WzDirectory testDirectory = null;
                        try
                        {
                            testDirectory = new WzDirectory(reader, this.name, this.versionHash, this.WzIv);
                            testDirectory.ParseDirectory();
                        }
                        catch
                        {
                            reader.BaseStream.Position = position;
                            continue;
                        }
                        WzImage testImage = testDirectory.GetChildImages()[0];

                        try
                        {
                            reader.BaseStream.Position = testImage.Offset;
                            byte checkByte = reader.ReadByte();
                            reader.BaseStream.Position = position;
                            testDirectory.Dispose();
                            switch (checkByte)
                            {
                            case 0x73:
                            case 0x1b:
                            {
                                WzDirectory directory = new WzDirectory(reader, this.name, this.versionHash, this.WzIv);
                                directory.ParseDirectory();
                                this.wzDir = directory;
                                return;
                            }
                            }
                            reader.BaseStream.Position = position;
                        }
                        catch
                        {
                            reader.BaseStream.Position = position;
                        }
                    }
                }
                throw new Exception("Error with game version hash : The specified game version is incorrect and WzLib was unable to determine the version itself");
            }
            else
            {
                this.versionHash = GetVersionHash(version, fileVersion);
                reader.Hash      = this.versionHash;
                WzDirectory directory = new WzDirectory(reader, this.name, this.versionHash, this.WzIv);
                directory.ParseDirectory();
                this.wzDir = directory;
            }
        }