Hello, I am Isaac. I am writing a Rom hacking tool in vb6 and have noticed that alot of very clever people are on these forums. And I would like some help with my code...
The games data is stored in compressed form, the algorithm is as follows:
Uncompressed: 00 43 43 43 43 22 05
Compressed: 00 43 43 03 22 05
A double byte in the compressed data triggers the copying of the compressed byte (after the first byte) however many times it says in the third byte.
eg: 22 22 would compress as 22 22 01
22 22 22 would compress as 22 22 02 etc...
I have written the decompression successfully, but i am unsure how to recompress it. I feel I am close, and I will post the code for you to look at below...
Decompression:
And my draft compression function is below:Code:Function Decompress(str As String) As String
'Variable declarations
Dim temp() As String
Dim temp2 As String
Dim prev_byte As Integer
Dim current_byte As Integer
Dim byte_count As Long
Dim outstring As String
Dim compr_flag As Boolean
'set up variables
temp2 = Trim(str)
temp2 = "f00 " & temp2
temp = Split(temp2, " ")
byte_count = UBound(temp)
current_byte = 0
compr_flag = False
'start of code
While current_byte <= byte_count
If compr_flag = True Then
byte_representation = CDec(" &H" & temp(current_byte))
For i = 1 To byte_representation - 1
outstr = outstr & " " & temp(prev_byte)
Next i
compr_flag = False
Else
outstr = outstr & " " & temp(current_byte)
If temp(current_byte) = temp(prev_byte) Then
compr_flag = True
End If
End If
prev_byte = current_byte
current_byte = current_byte + 1
Wend
Decompress = Trim(outstr)
End Function
Some advice on the compression would be greatly appreciated. I am puzzled :confused:Code:Function Compress(str As String) As String
'variables
Dim temp() As String
Dim temp2 As String
Dim prev_byte As Integer
Dim current_byte As Integer
Dim bytecount As Long
Dim outstring As String
Dim compr_flag As Boolean
Dim repcount As Integer
'set up array etc
temp2 = Trim(str)
temp2 = "f00 " & temp2
temp = Split(temp2, " ")
bytecount = UBound(temp)
current_byte = 0
outstr = ""
'code it dude
While current_byte < bytecount
If compr_flag = False Then
outstr = outstr & " " & temp(current_byte)
If temp(current_byte) = temp(prev_byte) Then
compr_flag = True
repcount = 1
End If
Else
While temp(current_byte) = temp(prev_byte)
prev_byte = current_byte
current_byte = current_byte + 1
repcount = repcount + 1
Wend
If rep_count < 15 Then
outstr = outstr & " 0" & Hex(rep_count)
Else
outstr = outstr & " " & Hex(rep_count)
End If
compr_flag = False
End If
Wend
Compress = Trim(outstring)
End Function
Thanks :)