Writing a custom exporter for the PSK format?

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.
I'm not sure whether this belongs into this cathegory, but here it goes anyway:

I've decided to write an export script for PSK files based on the specifications on UDN for Blender. Because the specs were like "this struct then that struct" I had to use C++ to transcribe it into binary. So there are two scripts involved, one Python script, which dumps the data into an ASCII format (works, included only for completeness) and one that makes a PSK (and later a PSA as well) out of the file. Well, should make, that is, since the only thing the resulting file does is crash UnrealED (General Protection Fault in MeshSkelLOD or something). Since PSK is binary I cannot get any feedback on what I'm doing wrong except that something crashes UED. I had to guess on a few instances (like in what order the members of a struct need to be written into a file, I assumed in order of declaration).

http://mitglied.lycos.de/KDR_11k/files/code/export_ask.py.txt
http://mitglied.lycos.de/KDR_11k/files/code/psk_compiler.cpp.txt
http://mitglied.lycos.de/KDR_11k/files/code/bla.ask.txt
All files are txt for better hotlinking (they're ASCII so you can view them with that extension as well). The CPP requires the struct definitions you can get from UDN (where they describe the binary file formats). The ASK (ASCII PSK...) is the model I tried to import.
Can anyone figure out what I did wrong?
 

heschi

New Member
Mar 20, 2004
11
0
0
I've only taken a cursory look at the UDN page (this one? http://udn.epicgames.com/Technical/BinaryFormatSpecifications#C_structures_used) but based on your code I think you need to be just using a raw fwrite call. The linked page mentions that all data is assumed to be 32-bit aligned, which would agree with that. Their code is probably statements like fwrite(outfile, &Head, sizeof(VChunkHeader)) which is basically just copying the raw memory to the output file. Basically their data looks like:

(byte)(align)(align)(align)(byte)(align)(align)(align)(floooooooooooooooat)
where yours looks like
(byte)(byte)(flooooooooooooooooat)
...if you see what I mean. This is because you're just <<'ing the numbers which of course doesn't align them (what if they're bigger than 255, btw? you can't just cast them to char, that'll clip them to a byte...)

You might be better off learning to *import* the file format to make sure you understand it before you learn to *export* it, since you know you have good data in the format you don't understand when you try to import.
-Heschi
 
Ah, didn't know about the fwrite command. When I looked for file output I only got the fstreams back. I expected the (char) cast to treat it as a char array (since it's a multi-byte value), not just a single char and just write the memory to the file.
Is there a "correct" way to cast from char* to char[20]? Currently I get random memory fragments in the file, I'd like to avoid that, but I can't find a converter function.
 
Last edited: