Пример #1
0
		/// <summary>
		/// Parses the wz list file
		/// </summary>
		public void ParseWzFile()
		{
			//WzTools.CreateWzKey(WzMapleVersion.GMS);//what?
			WzBinaryReader wzParser = new WzBinaryReader(new MemoryStream(wzFileBytes), WzIv);
			while (wzParser.PeekChar() != -1)
			{
				int Len = wzParser.ReadInt32();
				char[] List = new char[Len];
				for (int i = 0; i < Len; i++)
					List[i] = (char)wzParser.ReadInt16();
				wzParser.ReadUInt16();
				string Decrypted = wzParser.DecryptString(List);
				if (wzParser.PeekChar() == -1)
					if (Decrypted[Decrypted.Length - 1] == '/')
						Decrypted = Decrypted.TrimEnd("/".ToCharArray()) + "g"; // Last char should always be a g (.img)
				listEntries.Add(Decrypted);
			}
			wzParser.Close();
		}
Пример #2
0
 /// <summary>
 /// Parses a wz list file on the disk
 /// </summary>
 /// <param name="filePath">Path to the wz file</param>
 public static List<string> ParseListFile(string filePath, byte[] WzIv)
 {
     List<string> listEntries = new List<string>();
     byte[] wzFileBytes = File.ReadAllBytes(filePath);
     WzBinaryReader wzParser = new WzBinaryReader(new MemoryStream(wzFileBytes), WzIv);
     while (wzParser.PeekChar() != -1)
     {
         int len = wzParser.ReadInt32();
         char[] strChrs = new char[len];
         for (int i = 0; i < len; i++)
             strChrs[i] = (char)wzParser.ReadInt16();
         wzParser.ReadUInt16(); //encrypted null
         string decryptedStr = wzParser.DecryptString(strChrs);
         listEntries.Add(decryptedStr);
     }
     wzParser.Close();
     int lastIndex= listEntries.Count - 1;
     string lastEntry = listEntries[lastIndex];
     listEntries[lastIndex] = lastEntry.Substring(0, lastEntry.Length - 1) + "g";
     return listEntries;
 }
Пример #3
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;
			}
		}
Пример #4
0
 internal static List<WzImageProperty> ParsePropertyList(uint offset, WzBinaryReader reader, WzObject parent, WzImage parentImg)
 {
     int entryCount = reader.ReadCompressedInt();
     List<WzImageProperty> properties = new List<WzImageProperty>(entryCount);
     for (int i = 0; i < entryCount; i++)
     {
         string name = reader.ReadStringBlock(offset);
         byte ptype = reader.ReadByte();
         switch (ptype)
         {
             case 0:
                 properties.Add(new WzNullProperty(name) { Parent = parent });
                 break;
             case 11:
             case 2:
                 properties.Add(new WzShortProperty(name, reader.ReadInt16()) { Parent = parent });
                 break;
             case 3:
             case 19:
                 properties.Add(new WzIntProperty(name, reader.ReadCompressedInt()) { Parent = parent });
                 break;
             case 20:
                 properties.Add(new WzLongProperty(name, reader.ReadLong()) { Parent = parent });
                 break;
             case 4:
                 byte type = reader.ReadByte();
                 if (type == 0x80)
                     properties.Add(new WzFloatProperty(name, reader.ReadSingle()) { Parent = parent });
                 else if (type == 0)
                     properties.Add(new WzFloatProperty(name, 0f) { Parent = parent });
                 break;
             case 5:
                 properties.Add(new WzDoubleProperty(name, reader.ReadDouble()) { Parent = parent });
                 break;
             case 8:
                 properties.Add(new WzStringProperty(name, reader.ReadStringBlock(offset)) { Parent = parent });
                 break;
             case 9:
                 int eob = (int)(reader.ReadUInt32() + reader.BaseStream.Position);
                 WzImageProperty exProp = ParseExtendedProp(reader, offset, eob, name, parent, parentImg);
                 properties.Add(exProp);
                 if (reader.BaseStream.Position != eob) reader.BaseStream.Position = eob;
                 break;
             default:
                 throw new Exception("Unknown property type at ParsePropertyList");
         }
     }
     return properties;
 }