I made a class for the G2DA file format for Dragon Age: Origins modding and it all went well in C#. I want now a real challange and began doing so in C++. I start by reading in the header, which is a struct I know. Problem is, it doesn't always give me the same data and the conversion doesn't work.
This is in a method with (char* path, LoadError& error), the latter being an enum.
8 last bytes are two unsigned ints (little endian).
I try to cout the header.magic property and it doesn't give me "GFF " as I would anticipate, but a seemingly arbitrary string of four chars. GFF is DA:O's generic file format, hence fileType and fileVerison.
Is it something fundanmental about reading files the binary way I don't understand? I don't see it returning an int as C#'s counterpart did for how much it actually read, which was easy to work with.
Line 8 has one definite bug and one probable bug. The definite bug is that you're overwriting the pointer to dynamic memory, so you've created a memory leak. The probable bug is that if you try to return that pointer from a function, the memory it points to is on the stack, and is likely to get overwritten after the function returns.
Well, it's certainly not anything to do with how you're reading the file. Either they were previously written wrong, or there's something else overwriting their values.
Yeah, found out that. The pointer being 32-bit made it so I could ready magic[4] only.
Edit: for some pecular reason, cout << header->magic; returns the whole struct spewed out in chars. It seems to start off at the specified variable and go all the way to the structs end. I thought char[4] meant four chars. Edit2: It seems to go on until null-termination.
Edit3: As all these strings are char[4], I made a function that copies it to a char[5], adds a null terminator and returns it.