Managing Files

Many programs that are used for gaming have high scores. Most high scores are saved inside the program itself rather than in a new file.
How is this possible using true basic?

Comments

Managing files

Hi,

The easy way is for your program to read a start-up file so that it can load up high scores or any other data that might change with time. The TB editor does this with a file called TBedit.cfg which contains details of the last file you were using as well as details of fonts and window sizes.

The more difficult way is to write a sub-routine that reads your program file as a byte file. Then you look through the program string code for a special "signature".
For example suppose you write a line of code:
LET highscore$="ABCXYZ000000"
The ABCXYZ part is the "signature".
You would search the program string with:
LET signature=pos(byte$,"ABCXYZ")
As soon as you locate the signature you know the next 6 bytes of data refer to the highest score - so you can substitute the latest highest score into these 6 bytes. Then you re-write your program file. Obviously by putting more zeros after the signature you can increase the size of the number you want to insert.

This method works for source code as well as execuatble files.

Big John

An Easier Way

I was thinking of using the OPEN command to open the file itself.
OPEN #1: name "name.tr?"
Then, in a comment, you could have the high score.
!322
If the comment was at the start of the program, I could use:
INPUT #1: Highscore$
Let Highscore=val(Highscore$[2:len(Highscore$)]
However, I couldn't reprint the highscore in the same place.

If the comment was at the end of the program, I wouldn't be able to retrieve it.

Is there some way to use RESET #1 to Input from a specific location?

Using a "text" file is NOT a good idea!

funnytree ... You will likely have to "parse" your stored "name.tr?" data file to deduce where Highscore$ is in the "name.tr?" file, even if it is a "text" file. To parse the stored file you need to use READ #1: ... statements, NOT INPUT #1: ... statements. Extracting the "name.tr?" data bytes without altering the file bytes IN ANY WAY, you need to READ the file as a byte file.

Any TB data file type can be retrieved as a byte file - even files of type "text" (read the manual!). You will be able to decypher the data - what ever it is, and wherever it is located - successfully.

I would like to get your "name.tr$" file and parse it myself. Email it to me. Regards ... Tom M

Re: Managing files & finding a IEEE 8-byte number

Big John ... It's possible that, if the target number is an 8-byte IEEE-format number, the 8 bytes might be stored with its bytes in reverse order (the 'little endian problem'). That's what I had to deal with in the "FAWAVE" free Wavelet Analysis software package a couple of years ago. Accordingly, one may need to check the "high score" number for byte-reversal.

Attacking the "high score" string variable as a "byte file", as you suggest, is the very best choice one can choose. I totally agree. Regards ... Tom M

Byte Files

Hi Tom,

Even executable program files can be read as byte files. Not amny people understand that executable files preserve string constants intact so you can parse even program files for the occurence of "signatures".

I have a program that replaces the standard TB icon with any icon of your choice. This icon replacer uses the first few bytes of an icon files as the "signature" that indicates where the icon image bytes begin and hence where to insert the new image bytes.

This principle can be used to insert data of any sort into files of any sort. The important point is that you can only replace the same number of bytes if you are working with non-text files such as executables. Hence the use of a "signature" to indicate where the insertion must be made, and the number of characters following the signature indicate how many bytes can be replaced.

Typically this method is used to insert an installed date inside an executable program that is intended to only run for a fixed period before the licence expires.

Big John

Re: byte files

Big Jon ... What you say is a "signature", we in the colonys say is a "header". The time series data values of Jim Walker's "FAWAV" Wavelet Analysis software can be from 65 data points to 65,537 data points. That's 2^6+1 to 2^16+1. That's (2^n)+1 where n goes from 6 to 16. And, the number format must be IEEE_64_bit, and the 8-byte IEEE numbers must be reversed (little endian style).

The header (signature) has to comply with strict rules, that I won't take the time to reveal in this message, but the header does start with a 4-byte "long integer" (not IEEE double-precision format).

I parsed byte files to deduce the formats for numerous time-series data files. It took me four months to crack the time series data file mystery. Regards ... Tom M

Byte files

Hi Tom,

I can well believe it did take 4 months to unravel the mysteries. It took me ages to unravel the format of BOX KEEP images too.

I will remember to change "signatures" to headers in future. I like to think that I am reasonably good at translating UK to US English, but we all make mistakes from time to time. We are both old enough to be forgiven for making them.

The important point that we are both making here (for the benefit of TB users) is that using "byte" files can be a hugely powerful analytical tool.

Big John

Format of BOX KEEP images

Hi Bigjohn,

Would you please share with me the format of the BOX KEEP strings so that I need not go through the same pain and suffering ?

Thanks a bunch

Gary
GaryTG@kc.rr.com