These scripts will ease the burden of saving/loading complex data like a real, a buffer or a string to a binary file as well as providing encryption/decryption as the file is created, updated and read... That is, no interim file is created that people can snoop.
Credit:
Davve For the Big Endian addition and current compile.
Example Here
Function List
BigEndian versions of the functions added with the suffix BE
GMBINInit
GMBINUnload
GMBINOpenFileRead
GMBINOpenFileReadPW
GMBINOpenFileWrite
GMBINOpenFileWritePW
GMBINOpenFileReadWrite
GMBINOpenFileReadWritePW
GMBINCloseFile
GMBINReadByte
GMBINReadUByte
GMBINReadByteChar
GMBINReadShort
GMBINReadUShort
GMBINReadInt
GMBINReadUInt
GMBINReadLong
GMBINReadULong
GMBINReadFloat
GMBINReadDouble
GMBINReadReal
GMBINReadBuffer
GMBINReadString
GMBINExtractFile <NEW>
GMBINWriteByte
GMBINWriteByteChar
GMBINWriteShort
GMBINWriteInt
GMBINWriteLong
GMBINWriteFloat
GMBINWriteDouble
GMBINWriteReal
GMBINWriteBuffer
GMBINWriteString
GMBINInsertFile <NEW>
GMBINIsEOF
GMBINIsError
GMBINGetPosition
GMBINGetActualSize
GMBINSeekBOF
GMBINSeekEOF
GMBINSeekFromCurrent
GMBINSetPosition
GMBINPackBits
GMBINUnpackBit
*NOTE: I have not tested my read/write (int dword float double and real versions) against binary files created by other application; the byte order may not be standard (reversed). However, byte and buffer should be 100% compatible.
If you are wondering why there is no WriteUxxx, It's because the system does not care if the value is signed or not while saving. The important thing to remember is to use ReadUxxx if you wrote a positive value packed in the type you specified and the positive value would be greater than the signed range...
GMBINWriteShort(hf,65535);
v = GMBINReadUShort(hf); //(0-65535)
Signed/Unsigned and Data Range Info
Buffer and String are different... Buffer reads/writes a buffer of a length specified by the caller and can be used to blindly read anything.... Where strings are saved with a header telling the size of the string, and read back according to that size. This should allow saving GM strings that have chr(0) in them.
I have not benchmarked against GM's file_bin functions, but the simple fact that you can write data other than bytes should make the dll faster and easier to use.
The just in time encryption is a bonus you should appreciate.
It's also a good replacement for file_text
To use, copy the dll to you project folder, merge the file with your game and replace your gm file io function calls with the included scripts.
The included room tests all the functions in the room code (button).
UPDATE
Now you can package multiple files in one binary file using
GMBINInsertFile - The function adds an entire file to the opened binary file. All you need is specify the source file.
GMBINExtractFile - The function extracts an entire file from the opened binary file. All you need is specify the destination file.
You are in charge of the file naming and what to do with the extracted files... You can use a temp file and delete it when done.
example
hf = GMBINFileOpenWrite("t.bin")
GMBINWriteShort(hf,2);
GMBINWriteString(hf,"File1.bmp");
GMBINInsertFile(hf,"File1.bmp");
GMBINWriteString(hf,"File2.bmp");
GMBINInsertFile(hf,"File2.bmp");
GMBINfileClose(hf);
hf = GMBINFileOpenRead("t.bin")
repeat(GMBINReadShort(hf))
{
filename = GMBINReadString(hf);
GMBINExtractFile(hf,filename);
}
GMBINfileClose(hf);
When part of the bin file, the data is encrypted if using password encryption.
Cheers!
Edited by icuurd12b42, 25 May 2011 - 04:12 AM.