First off, set a binary variable:
/bset -t &moo 1 im the content&moo is the name of the binary variable.
1 is the byte offset at which the content should be added, since it's an empty variable we'll start from the first byte.
The
-t switch tells mIRC that you're specifying plain text, if you don't use that switch the content must be input as space-delimited ASCII codes. So the non-text equivalent would be:
/bset &moo 1 105 109 32 116 104 101 32 99 111 110 116 101 110 116and you'd have the exact same binary variable.
To add a binvar to a hash table is simple, /hadd has a -b switch specifically for this:
/hadd -b hashtable binaryitem &mooTo set a binvar to the value of a hash item you simply use $hget() like so:
var %bytes = $hget(hashtable, binaryitem, &moo)The
$hget() puts
binaryitem from the hash table
hashtable into binvar
&moo.
The
var %bytes = is nothing to do with the actual binvar assignment, it's simply there because the
$hget() returns the number of bytes that were written to the binvar (or in other words, the new length of the binvar), and you can't have the identifier alone on a line since mIRC will always interpret the first word on a line in a script to be a command. So to prevent that from happening we simply assign the returned value to a variable, sometimes it's useful information to have stored, but mostly it's just there for syntax purposes.
To save and load a hash table which contains binary data you simply need to use the -b switches for each. Since there's nothing special about the commands when you use the -b switch I won't go into detail on how to use them.
Unfortunately you can't save binary variables to INI files directly. An INI file is a plain-text format, and as far as I'm aware INI files have no way to support binary data. However, if you know the binary variable contains only plain text, you can retrieve the text from it using $bvar() (in chunks if necessary) and assign the contents to an ini file just as you would with any normal text data.
eg.
writeinibin {
; Usage: /writeinibin <inifile> <section> <&binvar>
if ($0 < 3) return
var %i = 1, %j = 1
while ($bvar($3, %j, 900).text != $null) {
writeini -n $1 $2 $+(binary, %i) $ifmatch
inc %i
inc %j 900
}
}
readinibin {
; Usage: /readinibin <inifile> <section> <&binvar>
if ($0 < 3) return
var %i = 1, %j = 1
while ($readini($1, n, $2, $+(binary, %i)) != $null) {
bset -t $3 %j $ifmatch
inc %i
inc %j $len($ifmatch)
}
}
You could then use
/writeinibin inifile section &binvar to write to INI files (only by section, you can't specify an item) and
/readinibin inifile section &binvar to retrieve the values. However, the content is still subject to the usual stripping rules of INI files (control codes stripped). It's not ideal but that's because INI files really aren't a good medium for binary-type data.
Hopefully you'll find some of this useful and not too confusing...