Modcraft - The community dedicated to quality WoW modding!
Wrath of the Lich King Modding => Miscellaneous => Topic started by: Keta on December 17, 2011, 12:42:01 pm
-
Hey Modcraft
Now this is mainly a question for all the C++ and C# devs out there, but if anyone just so happens to know the answer, feel free to tell.
I was hoping to see if someone had a template for reading ADTs laying around. Either in C++ or C#. And of course if they'd share it. Cause I'm gonna work with it in C#, but Im somewhat sure I can convert it to C# if it is in C++.
I've had programming on the education Im on atm, and we've been playing a bit with C# console programming, and I noticed that Cryects Tools is also a console application. However that isn't really that much up-to-date anymore... :/ So anyone got a template laying around that shows how to read the info in ADT files? :)
Thanks
Keta
-
cryectstools have a folder named sourcecode. If u dont have it i can upload it somewhere ;)
-
Keta? Why you don't want to learn C++? :D Qt is rly good framework. Support cross-platform. More better than MS Net Framework. And when you use C# you must use MS Net Framework. And this doesn't working on OSX. I heard "Linux can run C# program" so here is not problem with this. But OSX users ":("
-
u_u Im sure once I get further in my education, Ill be learning C++ too... But for now, I'd just like to learn C# :/ And I got the cpp folder from Cryects Tools. Thing is just, they aren't one combined file, with all the structures combined... And since I'm still not that much into C++, I don't completely know how to convert it :S
Thanks
Keta
-
Will you please answer me on skype? You havent come online for a while.
-
C++ to C# converter doesn't exists.
-
C++ to C# converter doesn't exists.
I meant manually convert it u.u As C++ and C# is very similar when still working with the console applications. So I'm pretty sure I can "draw the lines" between the C++ and C# differences ;)
Thanks
Keta
-
All dev languages are very similar in syntax. But c# and c++ are two different worlds.
c++ get compiled direct in an executable an c# get to bytecode that runs in the .net runtime environment. So .net is microsofts java.
-
True, but you can't argue with the fact that when working in the basic of C++ and C#, its all about knowing what code means what in the other language, to convert it.
Anyway, I think this is going a little off topic tbh x)
Anyone got a C++ or C# ADT reader code I may take a look at?
Thanks
Keta
-
Cryect's tools really seem to be the best start. They are small and easy to understand. Only problem here: They always only read parts of the file, not the whole file.
-
Cryect's tools really seem to be the best start. They are small and easy to understand. Only problem here: They always only read parts of the file, not the whole file.
But as far as I remember, I see a lot of places where people states that CryectsTools is outdated regarding reading of ADTs. The structure has changed since then, so it doesn't work 100%.
Or is that just all rubbish?
And yeah, it only reads parts of the file, whereas I would like a source code that reads the whole file... :/
Thanks
Keta
-
The only way to do it properly would be writing it yourself from the wiki and own reverse engineering. The wiki is wrong on some parts as well.
You can also try viewtopic.php?f=59&t=830 (http://modcraft.io/viewtopic.php?f=59&t=830" onclick="window.open(this.href);return false;).
-
So I've come to the conclusion that after reading up on Binary and getting some help from Steff, that CryectsTools CPP files would probably be the best way to go, for a quick understanding of the structure and such. However I've encountered a roadblock :s
I was hoping someone could help me translate this piece of C++ into C#...
void LoadMTEX()
{
unsigned int TexSize;
fseek(Input,0x14+0x04+MTEX_Offset,SEEK_SET);
fread(&TexSize,sizeof(int),1,Input);
Textures=new char[TexSize];
fread(Textures,sizeof(char),TexSize,Input);
for(int i=0;i<TexSize-1;i++)
if (Textures[i]==0)
Textures[i]='n';
}
Because this is what I got so far, and its still very filled with errors, according to Visual Studio:
void LoadMTEX()
{
uint TexSize;
using (BinaryReader b = new BinaryReader(File.Open("C:\Maruum_51_17.adt", FileMode.Open)))
{
b.BaseStream.Seek(0x14 + 0x04 + MTEX_Offset, SeekOrigin.Begin);
TexSize = b.ReadUInt32();
Textures = new char[TexSize];
for (int i = 0; i < TexSize - 1; i++) if (Textures[i] == 0) Textures[i] = 'n';
}
So yea, any help please? :)
Thanks
Keta
-
Mmmh, I've never done any C#, but I think there may be something wrong at that line :
Textures=new char[TexSize];
I tried : http://msdn.microsoft.com/en-us/library ... 53(v=vs.71 (http://msdn.microsoft.com/en-us/library/aa288453(v=vs.71" onclick="window.open(this.href);return false;)).aspx
This page mentions you have to the array beforehand, something like :
char[] Textures;
Hope that helps...
-
Mmmh, I've never done any C#, but I think there may be something wrong at that line :
Textures=new char[TexSize];
I tried : http://msdn.microsoft.com/en-us/library ... 53(v=vs.71 (http://msdn.microsoft.com/en-us/library/aa288453(v=vs.71" onclick="window.open(this.href);return false;)).aspx
This page mentions you have to the array beforehand, something like :
char[] Textures;
Hope that helps...
Oh yeah those parts I already got fixed. Thanks thought :)
Its mainly the "fread" and the "fseek" I find confusing u.u
Thanks
Keta
-
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, then
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.
[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;
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 (http://stackoverflow.com/questions/2384/read-binary-file-into-a-struct-c-sharp" onclick="window.open(this.href);return false;))
With these code fragments, you should be able to read from the file and query data. Writing back should be about the same.
-
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, then
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.
[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;
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 (http://stackoverflow.com/questions/2384/read-binary-file-into-a-struct-c-sharp" onclick="window.open(this.href);return false;))
With these code fragments, you should be able to read from the file and query data. Writing back should be about the same.
After studying the code a bit, I've come to the conclusion that this works for giving me the version of the ADT :P Thanks ^^ Anyhow, mind me when I ask what the "FieldOffset(X)" (where X is a number) means? I'm pretty sure its the location of the different things in the structure, but how exactly do I change them to something else? I mean, currently it reads the version. What number would I change it to, for it to read the texture files?
Thanks
Keta
PS. This is my code. I had to comment out the "if magic = MVER" thing, cause I couldn't make it work.
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 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.
Excuse me when I ask you what exactly you mean with the first two sentences. Either its my english, or my computing knowledge which fails me, but I don't exactly understand what you mean with "is fix in every adt." :s
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.
Thanks
Keta
-
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.
To continue, I'd suggest writing the next chunk from the wiki into a C# structure. Then read it in.
-
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.
Thanks
Keta
-
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.
Thanks
Keta
Sorry, MHDR. MPHD was WDTs.