Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Runtime.InteropServices;
- namespace BinaryReading
- {
- class Program
- {
- static void Main(string[] args)
- {
- BinaryReader foo = new BinaryReader(File.Open("C:\\Users\\Exitium\\Desktop\\WoW WoTLK\\World\\Maps\\Maruum\\Maruum_52_16.adt", FileMode.Open));
- MVER mver = ByteToType<MVER>(foo);
- MHDR mhdr = ByteToType<MHDR>(foo);
- foo.BaseStream.Seek(mhdr.mtex - 4, SeekOrigin.Begin);
- string[] mtex = ReadMTEX(foo, mhdr.mmdx, mhdr.mtex);
- /*if (mver.magic == 'MVER' && mver.size == 4 && mver.version == 18)
- {
- Console.WriteLine(mver.version);
- Console.WriteLine(mver.size);
- Console.WriteLine(mver.magic);
- Console.ReadLine();
- }
- else
- {
- Console.WriteLine("This is no WoTLK ADT");
- Console.ReadLine();
- }*/
- foo.BaseStream.Seek(mhdr.mtex, SeekOrigin.Begin);
- foreach (string str in mtex)
- {
- Console.WriteLine(str);
- }
- Console.ReadLine();
- }
- public static string[] ReadMTEX(BinaryReader reader, int mhdr, int mtex)
- {
- char c;
- int lines = 0;
- do
- {
- for (int i = Convert.ToInt32(reader.BaseStream.Position); i < reader.BaseStream.Length; i++)
- {
- if ((c = (char)reader.ReadByte()) == 0)
- {
- ++lines;
- break;
- }
- }
- }
- while (reader.BaseStream.Position < mhdr);
- reader.BaseStream.Seek(mtex - 4, SeekOrigin.Begin);
- string[] result = new string[lines - 1];
- int tæller = 0;
- do
- {
- for (int i = Convert.ToInt32(reader.BaseStream.Position); i < reader.BaseStream.Length; i++)
- {
- if ((c = (char)reader.ReadByte()) == 0)
- {
- if ((tæller + 2) < lines)
- {
- ++tæller;
- }
- break;
- }
- result[tæller] += c.ToString();
- }
- }
- while (reader.BaseStream.Position < mhdr);
- return result;
- }
- public static T ByteToType<T>(BinaryReader reader)
- {
- byte[] bytes = reader.ReadBytes(Marshal.SizeOf(typeof(T)));
- GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
- T theStructure = (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T));
- handle.Free();
- return theStructure;
- }
- [StructLayout(LayoutKind.Explicit)]
- public struct MVER
- {
- [FieldOffset(0)]
- public int magic;
- [FieldOffset(4)]
- public int size;
- [FieldOffset(8)]
- public int version;
- }
- [StructLayout(LayoutKind.Explicit)]
- public struct MHDR
- {
- [FieldOffset(0)]
- public int magic;
- [FieldOffset(4)]
- public int size;
- [FieldOffset(8)]
- public int flags;
- [FieldOffset(12)]
- public int mcin;
- [FieldOffset(16)]
- public int mtex;
- [FieldOffset(20)]
- public int mmdx;
- [FieldOffset(24)]
- public int mmid;
- [FieldOffset(28)]
- public int mwmo;
- [FieldOffset(32)]
- public int mwid;
- [FieldOffset(36)]
- public int mddf;
- [FieldOffset(40)]
- public int modf;
- [FieldOffset(44)]
- public int mfbo;
- [FieldOffset(48)]
- public int mh2o;
- [FieldOffset(52)]
- public int mtfx;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement