this code is for vb to call the unmanaged decompress function >>:
<DllImport("compress.dll", CallingConvention:=CallingConvention.Cdecl)> _
Public Shared Function lzo_compress(<Out()> ByVal decompressed_buffer As Byte(), ByVal decompressed_size As Integer, <[In]()> ByVal compressed_buffer As Byte(), ByVal compressed_size As Integer, ByVal type As Integer) As Integer
End Function
if the decompress Returns nulled or invalid data means the file ur decompressing does not use that type.
so to check if ur decompressing whent like it suposed to be, could be done like this :
'declare a varaible as integer to use for return result from the decompressor
Dim Result as Integer = lzo_decompress(buffer, buffer.Length, Decompressed, Length, 8)
if Result > -1 then msgbox("Succesfull Decompression") else msgbox("Failed decompressing file!")
if the decompressing when succesfully it will return the decompressed length else it will return a negative value. (-1)
Downloads : 166 || Uploads : 31 || Rep Power : 8715 || Posts : 1,660 || Thanks : 188 ||
Thanked 10,799 Times in 600 Posts
Programming is 10% science, 20% ingenuity, and 70% getting the ingenuity to work with the science.
~~~~~~~~~~~~~~~~~~~~~~~~~
Programming is like sex:
One mistake and you have to support it for the rest of your life.
Join Date : Dec 2010
Location : Germany
Age : 46
Posts : 722
Array
Re: Generic Xbox360 Compression Library
lmao my vault I have do a noob step this is why I have trouble but guys it's work and I can Decompress & Compress the Borderland 2 save. When kill_seph not update his Tool then I release my one and big big thanks to fairchild. All credits to him ;)
Here the translated code from fairchild to vb:
Code:
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports System.IO
Namespace example
Public Partial Class Form1
Inherits Form
Private Enum CompressionMethods
' decompressors
COMP_NONE = 0
' No compression
COMP_ZLIB
' RFC 1950
COMP_DEFLATE
' RFC 1951
COMP_LZO1
' LZO 1 Freeware
COMP_LZO1A
' LZO 1a Freeware
COMP_LZO1B
' LZO 1b (safe with overrun) Freeware
COMP_LZO1C
' LZO 1c (safe with overrun) Freeware
COMP_LZO1F
' LZO 1f (safe with overrun) Freeware
COMP_LZO1X
' LZO 1x (safe with overrun) Freeware
COMP_LZO1Y
' LZO 1y (safe with overrun) Freeware
COMP_LZO1Z
' LZO 1z (safe with overrun) Freeware
COMP_LZO2A
' LZO 2a (safe with overrun) Freeware
COMP_LZOPRO1X
' LZOPRO 1x (safe with overrun) Freeware
COMP_LZOPRO1Y
' LZOPRO 1y (safe with overrun) Freeware
' compressors
COMP_LZO1_COMPRESS
' LZO 1 Freeware
COMP_LZO1_99_COMPRESS
' better compression ratio at the cost of more memory and time
COMP_LZO1A_COMPRESS
' LZO 1a Freeware
COMP_LZO1A_99_COMPRESS
' better compression ratio at the cost of more memory and time
COMP_LZO1B_COMPRESS
' LZO 1b Freeware (Valid compression level: 1..9)
COMP_LZO1B_99_COMPRESS
' better compression ratio at the cost of more memory and time
COMP_LZO1B_999_COMPRESS
' even better compression ratio at the cost of more memory and time
COMP_LZO1C_COMPRESS
' LZO 1c Freeware (Valid compression level: 1..9)
COMP_LZO1C_99_COMPRESS
' better compression ratio at the cost of more memory and time
COMP_LZO1C_999_COMPRESS
' even better compression ratio at the cost of more memory and time
COMP_LZO1F_COMPRESS
' LZO 1f Freeware
COMP_LZO1F_999_COMPRESS
' even better compression ratio at the cost of more memory and time
COMP_LZO1X_COMPRESS
' LZO 1x Freeware
COMP_LZO1X_999_COMPRESS
' even better compression ratio at the cost of more memory and time
COMP_LZO1Y_COMPRESS
' LZO 1y Freeware
COMP_LZO1Y_999_COMPRESS
' even better compression ratio at the cost of more memory and time
COMP_LZO1Z_COMPRESS
' LZO 1z Freeware
COMP_LZO1Z_999_COMPRESS
' even better compression ratio at the cost of more memory and time
COMP_LZO2A_COMPRESS
' LZO 2a Freeware
COMP_LZO2A_999_COMPRESS
' even better compression ratio at the cost of more memory and time
COMP_LZOPRO1X_COMPRESS
' LZOPRO 1x (Valid compression level: 1..10)
COMP_LZOPRO1Y_COMPRESS
' LZOPRO 1y (Valid compression level: 1..10)
End Enum
Public Function ReadAllBytes(fileName As String, offset As Integer) As Byte()
Dim buffer As Byte() = Nothing
Using fs As New FileStream(fileName, FileMode.Open, FileAccess.Read)
'Console.Out.WriteLine("fs.Length: " + fs.Length + "\n");
'Console.Out.WriteLine("offset: " + offset + "\n");
buffer = New Byte((fs.Length - offset) - 1) {}
fs.Seek(offset, SeekOrigin.Begin)
fs.Read(buffer, 0, CInt(fs.Length - offset))
End Using
Return buffer
End Function
Public Sub New()
InitializeComponent()
End Sub
<DllImport("compress.dll", CallingConvention := CallingConvention.Cdecl)> _
Public Shared Function lzo_decompress(<Out> compressed_buffer As Byte(), compressed_size As UInteger, <[In]> decompressed_buffer As Byte(), decompressed_size As UInteger, method As UInteger) As UInteger
End Function
<DllImport("compress.dll", CallingConvention := CallingConvention.Cdecl)> _
Public Shared Function lzo_compress(<Out> decompressed_buffer As Byte(), decompressed_size As UInteger, <[In]> compressed_buffer As Byte(), compressed_size As UInteger, method As UInteger, compress_level As UInteger) As UInteger
End Function
Private Sub button1_Click(sender As Object, e As EventArgs)
Dim Pfad As String = String.Empty
Dim openFileDialog1 As New OpenFileDialog()
openFileDialog1.Filter = "Save (*.sav)|*.sav|All files (*.*)|*.*"
If openFileDialog1.ShowDialog() = DialogResult.OK Then
Pfad = openFileDialog1.FileName
End If
Dim decompressed_size As UInt32 = 24875
' Static for now on my testfile
Dim decompressed_buffer As Byte() = New Byte(decompressed_size - 1) {}
Dim compressed_buffer As Byte() = ReadAllBytes(Pfad, &H18)
Dim compressed_size As UInteger = CUInt(compressed_buffer.Length)
Dim result As UInteger = lzo_decompress(compressed_buffer, compressed_size, decompressed_buffer, decompressed_size, CUInt(CompressionMethods.COMP_LZOPRO1X))
richTextBox1.Text += vbLf & "Decompress result: " & result & vbLf
For i As Integer = 0 To 127
richTextBox1.Text += decompressed_buffer(i).ToString("X2")
Next
decompressed_size = result
result = lzo_compress(decompressed_buffer, decompressed_size, compressed_buffer, compressed_size, CUInt(CompressionMethods.COMP_LZOPRO1X_COMPRESS), 10)
richTextBox1.Text += vbLf & "Compress result: " & result & vbLf
For i As Integer = 0 To 127
richTextBox1.Text += compressed_buffer(i).ToString("X2")
Next
'
' for (int i = 0; i < result; i++)
' richTextBox1.Text += decompressed_buffer[i].ToString("X2");
'
End Sub
End Class
End Namespace
Did some more testing, and it seems the library isn't working correctly with the compression.
Code:
<DllImport("compress.dll", CallingConvention:=CallingConvention.Cdecl)> _
Public Shared Function lzo_compress(<Out> decompressed_buffer As Byte(), decompressed_size As UInteger, <[In]> compressed_buffer As Byte(), compressed_size As UInteger, type As UInteger, compression_level As UInteger) As UInteger
End Function
If OFD.ShowDialog = Windows.Forms.DialogResult.OK Then
gReader = New GPDPackage.GPD(OFD.FileName)
iReader = New IOPackage.RWStream(gReader.ExtractSaveData(GPDPackage.GPD.SaveData.TitleSpecific1))
SHA1 = iReader.ReadBytes(&H14)
decompressedSize = iReader.ReadUInt32()
Dim decompressedData As Byte() = New Byte(decompressedSize - 1) {}
Dim compressedData As Byte() = iReader.ReadBytes(iReader.Length - iReader.Position)
compressedSize = compressedData.Length
File.WriteAllBytes("Profile(compressed)", compressedData)
Dim result = lzo_decompress(compressedData, compressedSize, decompressedData, decompressedSize, 12)
Dim result2 = lzo_compress(decompressedData, decompressedSize, compressedData, compressedSize, 12, 10)
File.WriteAllBytes("Profile(decompressed)", decompressedData)
File.WriteAllBytes("Profile(recompressed)", compressedData)
End If
Doing that both the Profile(compressed) and Profile(recompressed) files are exactly the same. So at first, I thought I finally got it to work and decided to try something else. I edited the decompressed data and wrote a 1 to the first uint32 entry, then tried to recompress it. Turns out, both the files were exactly the same again. I even tried creating a recompressedData and recompressedSize, but then I just ended up with a null bytes once again. Thanks for all your hard work, and I hope we can figure this out!
Join Date : Dec 2010
Location : Germany
Age : 46
Posts : 722
Array
Re: Generic Xbox360 Compression Library
@kill the vault why it's return 0 is when you set CompressionMethods to 0 or none then it's return all bytes with "0" use for decompress CompressionMethods.COMP_LZOPRO1X or try around with another Enums. But I have the best result with Decompress this data using my own LZO 2.06 with custom setting.
Last edited by PUR3 RAF3X; 09-27-2012 at 10:52 AM.
Join Date : Dec 2010
Location : Germany
Age : 46
Posts : 722
Array
Re: Generic Xbox360 Compression Library
Originally Posted by Jappi88
Because in some compressions the decompressed size is discripted inside the data.
Lzo works that way.
@Pur3
there is nothing wrong with compress.dll(lzopro) works like it should... It jyst doesnt have the suported compression type for borderlands 2.
Ahh ok. Yes I see this the dll do the job and I have include this to my Tool so the guys can use it and try self around. The Tool support Packzip/offzip and this lib ;) work in progress are xextool I now many will love this.