Compression in vb6


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Compression in vb6

  1. #1
    Join Date
    Jan 2010
    Location
    Australia
    Posts
    1

    Question Compression in vb6

    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:

    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
    And my draft compression function is below:

    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
    Some advice on the compression would be greatly appreciated. I am puzzled

    Thanks
    Share on Google+

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Quote Originally Posted by partyatmine38 View Post
    Hello, I am Isaac. I am writing a Rom hacking tool in vb6
    We do not support this type of activity in any way size, shape, form or manner.

    If you bothered to read the AUP you agreed to when joining this site, you would have found that out.

    This thread is closed.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista
    Share on Google+

Similar Threads

  1. Replies: 0
    Last Post: 10-17-2006, 05:19 AM
  2. Speaking of strings...
    By Harlow in forum .NET
    Replies: 246
    Last Post: 10-26-2002, 12:30 AM
  3. Replies: 3
    Last Post: 07-21-2001, 02:32 PM
  4. Replies: 24
    Last Post: 02-09-2001, 12:18 PM
  5. Com Interop and VB6 Collections
    By Esmond Hart in forum .NET
    Replies: 2
    Last Post: 01-29-2001, 06:44 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center