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)]struct MVER{ [FieldOffset(0)] public int magic; [FieldOffset(4)] public int size; [FieldOffset(8)] public int version;}
BinaryReader foo;MVER mver = ByteToType<MVER> (foo);if (mver.magic == 'MVER' && mver.size == 4 && mver.version == 18) proceed;else this_is_no_wotlk_adt;
fopen: open file.fseek: modify reading / writing position in file.fread: read from there.fwrite: write there.fclose: close the file.What exactly is your problem? That it's not even a bit like this in C#? Well, C is not object orientated and old as fuck. [I DID NOT READ THIS WHOLE THREAD. ALL I KNOW IS THAT YOU SEARCHED SOME C APPLICATIONS TO BASE YOUR C# STUFF ON IT AND THAT YOU ARE CONFUSED BY FSEEK AND FREAD.]I don't really understand why you want to base your C# application on some other C one. It would be way better just writing your own stuff and read the wiki for the format.I can write you a lot of code in C/C++ you can't really "port" to C# without changing pretty much everything. There is no sense in trying to "port" stuff when writing a completely new application.What you want is a BinaryReader for the file, thenCode: [Select] 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; }You can then read stuff from the file to your structures — the ones from the wiki.Code: [Select][StructLayout(LayoutKind.Explicit)]struct MVER{ [FieldOffset(0)] public int magic; [FieldOffset(4)] public int size; [FieldOffset(8)] public int version;}Code: [Select]BinaryReader foo;MVER mver = ByteToType<MVER> (foo);if (mver.magic == 'MVER' && mver.size == 4 && mver.version == 18) proceed;else this_is_no_wotlk_adt;And I know _nothing_ about C# (I therefore don't guarantee anything is working in this code). This has just been some googling. (http://stackoverflow.com/questions/2384 ... ct-c-sharp)With these code fragments, you should be able to read from the file and query data. Writing back should be about the same.
static void Main(string[] args) { BinaryReader foo = new BinaryReader(File.Open("E:\WoW WoTLK\World\Maps\Azeroth\Azeroth_31_35.adt", FileMode.Open)); MVER mver = ByteToType<MVER>(foo); 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(); } } 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)] struct MVER { [FieldOffset(0)] public int magic; [FieldOffset(4)] public int size; [FieldOffset(8)] public int version; }
You have first the version and then the file header.This you must read and is fix in every adt. Then the data chunks follow.Try to implement this in a class.
You mean that I should read the file header cause it tells me where in the file I can find the different numbers and whatnot? Please, explain.
Yes. MPHD holds offsets to other positions of chunks. You can then "fseek" into the file (the stream) and read from there..
Quote from: "schlumpf"Yes. MPHD holds offsets to other positions of chunks. You can then "fseek" into the file (the stream) and read from there..What exactly is MPHD? Cause there was nothing about it on the Wiki. :s Not in the ADT section anyway.ThanksKeta