Ok, I have figured out a little bit of the encoded INI file and need some help to write some routines.
VBScript doesn't seem to handle binary files very well... I am trying to use the ADODB class and some sample code I found on the net and it kinda works...
I can get a file to read in in binary mode, but can't seem to do anything with the data once I have it in a variable. Using Typename() I can see it is BYTE type data, but nothing else.
Someone who knows VBScript better than me should be able to quickly figure this one out!
Here is the end result of what I need.
Open the binary file (which will be the EQ2 ini file), skip to a specific part of the file, read in a few bytes, then I'll convert them to Decimal based on what I've decoded them to mean (using HexDump and a slow process)
Below is some sample code to show what I have. For anyone who needs some good debugging code, my debugging Class from MegaBot is included here for reuse - good way to debug and have a log file for your scripts!
Rich
Code: Select all
Option Explicit
Class DebugClass
Private objLogFileFSO, objLogFile, DebugLevel, i
Private Sub Class_Initialize()
Dim sDir, cont
Dim sLogFile, sLogFileVersion
sLogFileVersion = 1
DebugLevel = 0 ' Default
cont = true
sDir = "c:\dl\logtest"
Set objLogFileFSO = CreateObject("Scripting.FileSystemObject")
do while cont
sLogFile = sDir & cStr(sLogFileVersion) & ".log"
If objLogFileFSO.FileExists(sLogFile) Then
sLogFileVersion = sLogFileVersion + 1
else
cont = false
end if
loop
Set objLogFile = objLogFileFSO.OpenTextFile(sLogFile, 8, True)
call Print ("", 0)
call Print ("", 0)
call Print ("*************************************", 0)
call Print ("*************************************", 0)
call Print ("*************************************", 0)
call Print("LOG File Opened: " & sLogFile, 0)
End Sub
Private Sub Class_Terminate()
' Close Log File
objLogFile.Close
End Sub
Public Sub SetDebugLevel(lvl)
DebugLevel = CInt(lvl)
End Sub
Public Sub PrintDebugLevel()
call Print("Debug Level is set to: " & DebugLevel, 0)
End Sub
Public Sub Print(str1, lvl)
if (DebugLevel >= lvl) then
'objLogFile.WriteLine(Date & " " & Time & ": " & str1)
objLogFile.WriteLine(CStr(str1))
end if
End Sub
End Class
Function SaveBinaryData(FileName, ByteArray)
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
'Create Stream object
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")
'Specify stream type - we want To save binary data.
BinaryStream.Type = adTypeBinary
'Open the stream And write binary data To the object
BinaryStream.Open
BinaryStream.Write 1
'BinaryStream.Write ByteArray
'Save binary data To disk
BinaryStream.SaveToFile FileName, adSaveCreateOverWrite
End Function
Function ReadBinaryFile(FileName)
Const adTypeBinary = 1
'Create Stream object
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")
'Specify stream type - we want To get binary data.
BinaryStream.Type = adTypeBinary
'Open the stream
BinaryStream.Open
'Load the file data from disk To stream object
BinaryStream.LoadFromFile FileName
'Open the stream And get binary data from the object
ReadBinaryFile = BinaryStream.Read
End Function
Function ReadTextFile(FileName, CharSet)
Const adTypeText = 2
'Create Stream object
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")
'Specify stream type - we want To get binary data.
BinaryStream.Type = adTypeText
'Specify charset For the source text (unicode) data.
If Len(CharSet) > 0 Then
BinaryStream.CharSet = CharSet
End If
'Open the stream
BinaryStream.Open
'Load the file data from disk To stream object
BinaryStream.LoadFromFile FileName
'Open the stream And get binary data from the object
ReadTextFile = BinaryStream.ReadText
End Function
Function SaveTextData(FileName, Text, CharSet)
Const adTypeText = 2
Const adSaveCreateOverWrite = 2
'Create Stream object
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")
'Specify stream type - we want To save text/string data.
BinaryStream.Type = adTypeText
'Specify charset For the source text (unicode) data.
If Len(CharSet) > 0 Then
BinaryStream.CharSet = CharSet
End If
'Open the stream And write binary data To the object
BinaryStream.Open
BinaryStream.WriteText Text
'Save binary data To disk
BinaryStream.SaveToFile FileName, adSaveCreateOverWrite
End Function
Dim objDebug, bin, txt, txt2
Set objDebug = New DebugClass
objDebug.Print "1", 0
'Call SaveBinaryData("c:\dl\savebin.txt", "12345")
bin = ReadBinaryFile("c:\dl\logtest1.log")
txt = ReadTextFile("c:\dl\logtest1.log", "")
objDebug.Print "2", 0
objDebug.Print TypeName(bin), 0
objDebug.Print TypeName(txt), 0
SaveTextData "c:\dl\output1.txt", txt, ""
'txt2=CStr(txt)
'objDebug.Print txt2, 0
'objDebug.Print CStr(bin(1)), 0
objDebug.Print "3", 0
Set objDebug = NOTHING