dtd mods Posted October 22, 2009 Share Posted October 22, 2009 hi every 1 how can i read a binary file? 0A9A: 1@ = openfile "CLEO\DAT_FILES\SAVE.DAT" mode 0x6272 // IF and SET i want to read something i write in this file SAVE.DAT eg i write 2000 and to use this 017B: set_actor $PLAYER_ACTOR weapon 22 ammo_to 0@ to set or other situation like i write some coords to this file and teleport you there how? Link to comment https://gtaforums.com/topic/429460-text-read/ Share on other sites More sharing options...
dtd mods Posted October 28, 2009 Author Share Posted October 28, 2009 hi every 1 how can i read a binary file?0A9A: 1@ = openfile "CLEO\DAT_FILES\SAVE.DAT" mode 0x6272 // IF and SET i want to read something i write in this file SAVE.DAT eg i write 2000 and to use this 017B: set_actor $PLAYER_ACTOR weapon 22 ammo_to 0@ to set or other situation like i write some coords to this file and teleport you there how? NOBODY SEE THIS??!!?? Link to comment https://gtaforums.com/topic/429460-text-read/#findComment-1059592410 Share on other sites More sharing options...
Horny Quintus Posted October 29, 2009 Share Posted October 29, 2009 0A9D: readfile 1@ size 4 to 0@ Size is in bytes - 2000 will be stored as a 4 byte integer. Coordinates will be stored as 4 byte floats. When you open a file for reading you begin at start of file. Everytime you call 0A9D the file position will move by the Size. So, if you have a file with 3 coordinates - X,Y & Z: Bytes 1-4 == Coord X Bytes 5-8 == Coord Y Bytes 9-12 == Coord Z You could read the coordinates from the file like this: if 0A9A: 1@ = openfile "CLEO\DAT_FILES\Coordinates.DAT" mode 0x6272then 0A9D: readfile 1@ size 4 to 10@ 0A9D: readfile 1@ size 4 to 11@ 0A9D: readfile 1@ size 4 to 12@ 0A9B: closefile 1@end So 10@ is CoordX, 11@ is CoordY and 12@ is CoordZ Link to comment https://gtaforums.com/topic/429460-text-read/#findComment-1059593347 Share on other sites More sharing options...
dtd mods Posted October 29, 2009 Author Share Posted October 29, 2009 0A9D: readfile 1@ size 4 to 0@ Size is in bytes - 2000 will be stored as a 4 byte integer. Coordinates will be stored as 4 byte floats. When you open a file for reading you begin at start of file. Everytime you call 0A9D the file position will move by the Size. So, if you have a file with 3 coordinates - X,Y & Z: Bytes 1-4 == Coord X Bytes 5-8 == Coord Y Bytes 9-12 == Coord Z You could read the coordinates from the file like this: if 0A9A: 1@ = openfile "CLEO\DAT_FILES\Coordinates.DAT" mode 0x6272then 0A9D: readfile 1@ size 4 to 10@ 0A9D: readfile 1@ size 4 to 11@ 0A9D: readfile 1@ size 4 to 12@ 0A9B: closefile 1@end So 10@ is CoordX, 11@ is CoordY and 12@ is CoordZ its not working Link to comment https://gtaforums.com/topic/429460-text-read/#findComment-1059594332 Share on other sites More sharing options...
Deji Posted October 31, 2009 Share Posted October 31, 2009 Mhmm.. I find that every guide that has been given to me for these opcodes have not worked. Also, other mods which include the writing of text files never work on my GTA, either... They usually crash the game or make a blank file. After months of trying I think I've finally figured it out... But I'm not at my house right now so I don't have the source... Link to comment https://gtaforums.com/topic/429460-text-read/#findComment-1059601138 Share on other sites More sharing options...
james227uk Posted October 31, 2009 Share Posted October 31, 2009 if 0A9A: 1@ = openfile "CLEO\DAT_FILES\Coordinates.DAT" mode 0x6272then 0A9D: readfile 1@ size 4 to 10@ 0A9D: readfile 1@ size 4 to 11@ 0A9D: readfile 1@ size 4 to 12@ 0A9B: closefile 1@end While you gave a nice explanation, that script makes no sense. When using an IF you need a conditional opcode. Link to comment https://gtaforums.com/topic/429460-text-read/#findComment-1059601550 Share on other sites More sharing options...
NTAuthority Posted November 1, 2009 Share Posted November 1, 2009 When using an IF you need a conditional opcode. Surprise, 0A9A is a conditional opcode. For the people who say it's "not working", note that this reads binary files, not text files. Link to comment https://gtaforums.com/topic/429460-text-read/#findComment-1059602359 Share on other sites More sharing options...
Horny Quintus Posted November 1, 2009 Share Posted November 1, 2009 Exactly, it is conditional and therefore you don't have to check if the filename exists which is kinda handy. It will also of course work outside of a condition. There seems to be a bit of confusion about whether the OP wants to read text or binary files. To be honest I had a bit of trouble understanding exactly what he wanted in the first post but he does say he wants to read binary files so I gave a quick example. Regarding text files I am with Deji - I have no idea! Link to comment https://gtaforums.com/topic/429460-text-read/#findComment-1059602539 Share on other sites More sharing options...
Wesser Posted November 2, 2009 Share Posted November 2, 2009 (edited) For the people who say it's "not working", note that this reads binary files, not text files. That's true. It works ok ONLY if you write a file and then read it's data with the same written method. However, have a look here. {$CLEO}0000: NOP0@ = 0 // File handle1@ = 4 // File size2@ = 0 // Read buffer3@ = 0 // resultgosub @ReadFromTextFilewhile truewait 0 03F0: enable_text_draw 1 0341: unknown_text_draw_flag 0 0342: enable_text_draw_centered 1 045A: draw_text_1number 320.0 240.0 GXT 'NUMBER' number 3@ // ~1~end:ReadFromTextFileif 0A9A: 0@ = openfile ".\CLEO\test.txt" mode 0x6272 // Binary Text Readingthenrepeat wait 0 0A9D: readfile 0@ size 1 to 2@ for 4@ = 48 to 57 if 003B: 4@ == 2@ then 3@ *= 10 4@ -= 48 005A: 3@ += 4@ 5@ += 1 break end enduntil 003B: 5@ == 1@ 0A9B: closefile 0@ endreturn This won't work with letters, sorry. Edited November 2, 2009 by Wesser Link to comment https://gtaforums.com/topic/429460-text-read/#findComment-1059605913 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now