GS-Zone

Compressor/Descompressor Ir al Indice

Moderadores: Moderadores de Argentum, Especialistas de Argentum, Especialistas de Programación

14

Nota » 25 Ene 2012 16:32

Hola gente, bueno miren yo entoy tratando de hacer un descompressor de IMPERIUMAO 1.4 (O el qe liberò mannakia) como ya trae el mod compress yo intentè hacer que descomprima graficos. ¿Como? hice le uso de el Public Function Extract_File osea es el que supestamente servirìa para extraer los recursos. Ahora yo me pregunto algo hya que adaptar el mod compress porque el hacer eso dise o que no se puede decodificar el codigo binario o que el archivo està dañaado :S

Miren acà les dejo el mod:

  1. '*****************************************************************
  2. 'modCompression.bas - v1.0.0
  3. '
  4. 'All methods to handle resource files.
  5. '
  6. '*****************************************************************
  7. 'Respective portions copyrighted by contributors listed below.
  8. '
  9. 'This library is free software; you can redistribute it and/or
  10. 'modify it under the terms of the GNU Lesser General Public
  11. 'License as published by the Free Software Foundation version 2.1 of
  12. 'the License
  13. '
  14. 'This library is distributed in the hope that it will be useful,
  15. 'but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. 'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17. 'Lesser General Public License for more details.
  18. '
  19. 'You should have received a copy of the GNU Lesser General Public
  20. 'License along with this library; if not, write to the Free Software
  21. 'Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  22. '*****************************************************************
  23.  
  24. '*****************************************************************
  25. 'Contributors History
  26. '   When releasing modifications to this source file please add your
  27. '   date of release, name, email, and any info to the top of this list.
  28. '   Follow this template:
  29. '    XX/XX/200X - Your Name Here (Your Email Here)
  30. '       - Your Description Here
  31. '       Sub Release Contributors:
  32. '           XX/XX/2003 - Sub Contributor Name Here (SC Email Here)
  33. '               - SC Description Here
  34. '*****************************************************************
  35. '
  36. 'Juan Martín Sotuyo Dodero (juansotuyo@hotmail.com) - 10/13/2004
  37. '   - First Release
  38. '*****************************************************************
  39. Option Explicit
  40.  
  41. 'This structure will describe our binary file's
  42. 'size and number of contained files
  43. Public Type FILEHEADER
  44.     lngFileSize As Long                 'How big is this file? (Used to check integrity)
  45.     intNumFiles As Integer              'How many files are inside?
  46. End Type
  47.  
  48. 'This structure will describe each file contained
  49. 'in our binary file
  50. Public Type INFOHEADER
  51.     lngFileStart As Long            'Where does the chunk start?
  52.     lngFileSize As Long             'How big is this chunk of stored data?
  53.     strFileName As String * 32      'What's the name of the file this data came from?
  54.     lngFileSizeUncompressed As Long 'How big is the file compressed
  55. End Type
  56.  
  57. Public Enum resource_file_type
  58.     Graphics
  59.     Midi
  60.     MP3
  61.     Wav
  62.     Scripts
  63.     Patch
  64.     Interface
  65.     Maps
  66. End Enum
  67.  
  68. Private Const GRAPHIC_PATH As String = "\Graficos\"
  69. Private Const MIDI_PATH As String = "\Midi\"
  70. Private Const MP3_PATH As String = "\Mp3\"
  71. Private Const WAV_PATH As String = "\Wav\"
  72. Private Const MAP_PATH As String = "\Mapas\"
  73. Private Const INTERFACE_PATH As String = "\Interface\"
  74. Private Const SCRIPT_PATH As String = "\Init\"
  75. Private Const PATCH_PATH As String = "\Patches\"
  76. Private Const OUTPUT_PATH As String = "\Output\"
  77.  
  78. Private Declare Function Compress Lib "zlib.dll" Alias "compress" (dest As Any, destLen As Any, src As Any, ByVal srcLen As Long) As Long
  79. Private Declare Function UnCompress Lib "zlib.dll" Alias "uncompress" (dest As Any, destLen As Any, src As Any, ByVal srcLen As Long) As Long
  80. 'To get free bytes in drive
  81. Private Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceExA" (ByVal lpRootPathName As String, FreeBytesToCaller As Currency, BytesTotal As Currency, FreeBytesTotal As Currency) As Long
  82.  
  83. Public Sub Compress_Data(ByRef data() As Byte)
  84. '*****************************************************************
  85. 'Author: Juan Martín Dotuyo Dodero
  86. 'Last Modify Date: 10/13/2004
  87. 'Compresses binary data avoiding data loses
  88. '*****************************************************************
  89.     Dim Dimensions As Long
  90.     Dim DimBuffer As Long
  91.     Dim BufTemp() As Byte
  92.     Dim BufTemp2() As Byte
  93.     Dim loopc As Long
  94.    
  95.     'Get size of the uncompressed data
  96.     Dimensions = UBound(data)
  97.    
  98.     'Prepare a buffer 1.06 times as big as the original size
  99.     DimBuffer = Dimensions * 1.06
  100.     ReDim BufTemp(DimBuffer)
  101.    
  102.     'Compress data using zlib
  103.     Compress BufTemp(0), DimBuffer, data(0), Dimensions
  104.    
  105.     'Deallocate memory used by uncompressed data
  106.     Erase data
  107.    
  108.     'Get rid of unused bytes in the compressed data buffer
  109.     ReDim Preserve BufTemp(DimBuffer - 1)
  110.    
  111.     'Copy the compressed data buffer to the original data array so it will return to caller
  112.     data = BufTemp
  113.    
  114.     'Deallocate memory used by the temp buffer
  115.     Erase BufTemp
  116.    
  117.     'Encrypt the first byte of the compressed data for extra security
  118.     data(0) = data(0) Xor 189
  119. End Sub
  120.  
  121. Public Sub Decompress_Data(ByRef data() As Byte, ByVal OrigSize As Long)
  122. '*****************************************************************
  123. 'Author: Juan Martín Dotuyo Dodero
  124. 'Last Modify Date: 10/13/2004
  125. 'Decompresses binary data
  126. '*****************************************************************
  127.     Dim BufTemp() As Byte
  128.    
  129.     ReDim BufTemp(OrigSize - 1)
  130.    
  131.     'Des-encrypt the first byte of the compressed data
  132.     data(0) = data(0) Xor 189
  133.    
  134.     UnCompress BufTemp(0), OrigSize, data(0), UBound(data) + 1
  135.    
  136.     ReDim data(OrigSize - 1)
  137.    
  138.     data = BufTemp
  139.    
  140.     Erase BufTemp
  141. End Sub
  142.  
  143. Public Sub Encrypt_File_Header(ByRef FileHead As FILEHEADER)
  144. '*****************************************************************
  145. 'Author: Juan Martín Dotuyo Dodero
  146. 'Last Modify Date: 10/13/2004
  147. 'Encrypts normal data or turns encrypted data back to normal
  148. '*****************************************************************
  149.     'Each different variable is encrypted with a different key for extra security
  150.     With FileHead
  151.         .intNumFiles = .intNumFiles Xor 4725
  152.         .lngFileSize = .lngFileSize Xor 2435437
  153.     End With
  154. End Sub
  155.  
  156. Public Sub Encrypt_Info_Header(ByRef InfoHead As INFOHEADER)
  157. '*****************************************************************
  158. 'Author: Juan Martín Dotuyo Dodero
  159. 'Last Modify Date: 10/13/2004
  160. 'Encrypts normal data or turns encrypted data back to normal
  161. '*****************************************************************
  162.     Dim EncryptedFileName As String
  163.     Dim loopc As Long
  164.    
  165.     For loopc = 1 To Len(InfoHead.strFileName)
  166.         If loopc Mod 2 = 0 Then
  167.             EncryptedFileName = EncryptedFileName & Chr$(Asc(mid$(InfoHead.strFileName, loopc, 1)) Xor 161)
  168.         Else
  169.             EncryptedFileName = EncryptedFileName & Chr$(Asc(mid$(InfoHead.strFileName, loopc, 1)) Xor 47)
  170.         End If
  171.     Next loopc
  172.    
  173.     'Each different variable is encrypted with a different key for extra security
  174.     With InfoHead
  175.         .lngFileSize = .lngFileSize Xor 689947
  176.         .lngFileSizeUncompressed = .lngFileSizeUncompressed Xor 445275
  177.         .lngFileStart = .lngFileStart Xor 87540
  178.         .strFileName = EncryptedFileName
  179.     End With
  180. End Sub
  181.  
  182. Public Function Extract_All_Files(ByVal file_type As resource_file_type, ByVal resource_path As String, Optional ByVal UseOutputFolder As Boolean = False) As Boolean
  183. '*****************************************************************
  184. 'Author: Juan Martín Dotuyo Dodero
  185. 'Last Modify Date: 10/13/2004
  186. 'Extracts all files from a resource file
  187. '*****************************************************************
  188.     Dim loopc As Long
  189.     Dim SourceFilePath As String
  190.     Dim OutputFilePath As String
  191.     Dim SourceFile As Integer
  192.     Dim SourceData() As Byte
  193.     Dim FileHead As FILEHEADER
  194.     Dim InfoHead() As INFOHEADER
  195.     Dim handle As Integer
  196.     Dim tempbyte As Byte
  197.    
  198. 'Set up the error handler
  199. On Error Resume Next
  200. On Local Error GoTo ErrHandler
  201.    
  202.     Select Case file_type
  203.         Case Graphics
  204.             If UseOutputFolder Then
  205.                 SourceFilePath = resource_path & OUTPUT_PATH & "Graficos.iao"
  206.             Else
  207.                 SourceFilePath = resource_path & "\Graficos.iao"
  208.             End If
  209.             OutputFilePath = resource_path & GRAPHIC_PATH
  210.            
  211.         Case Midi
  212.             If UseOutputFolder Then
  213.                 SourceFilePath = resource_path & OUTPUT_PATH & "Midi.iao"
  214.             Else
  215.                 SourceFilePath = resource_path & "\MIDI.iao"
  216.             End If
  217.             OutputFilePath = resource_path & MIDI_PATH
  218.        
  219.         Case MP3
  220.             If UseOutputFolder Then
  221.                 SourceFilePath = resource_path & OUTPUT_PATH & "MP3.iao"
  222.             Else
  223.                 SourceFilePath = resource_path & "\MP3.iao"
  224.             End If
  225.             OutputFilePath = resource_path & MP3_PATH
  226.        
  227.         Case Wav
  228.             If UseOutputFolder Then
  229.                 SourceFilePath = resource_path & OUTPUT_PATH & "Sounds.iao"
  230.             Else
  231.                 SourceFilePath = resource_path & "\Sounds.iao"
  232.             End If
  233.             OutputFilePath = resource_path & WAV_PATH
  234.        
  235.         Case Scripts
  236.             If UseOutputFolder Then
  237.                 SourceFilePath = resource_path & OUTPUT_PATH & "Init.iao"
  238.             Else
  239.                 SourceFilePath = resource_path & "\Init.iao"
  240.             End If
  241.             OutputFilePath = resource_path & SCRIPT_PATH
  242.        
  243.         Case Interface
  244.             If UseOutputFolder Then
  245.                 SourceFilePath = resource_path & OUTPUT_PATH & "Interface.iao"
  246.             Else
  247.                 SourceFilePath = resource_path & "\Interface.iao"
  248.             End If
  249.             OutputFilePath = resource_path & INTERFACE_PATH
  250.        
  251.         Case Maps
  252.             If UseOutputFolder Then
  253.                 SourceFilePath = resource_path & OUTPUT_PATH & "Mapas.iao"
  254.             Else
  255.                 SourceFilePath = resource_path & "\Mapas.iao"
  256.             End If
  257.             OutputFilePath = resource_path & MAP_PATH
  258.         Case Else
  259.             Exit Function
  260.     End Select
  261.    
  262.     'Open the binary file
  263.     SourceFile = FreeFile
  264.     Open SourceFilePath For Binary Access Read Lock Write As SourceFile
  265.    
  266.     Get SourceFile, 1, tempbyte
  267.  
  268.     'Extract the FILEHEADER
  269.     Get SourceFile, , FileHead
  270.    
  271.     'Desencrypt FILEHEADER
  272.     Encrypt_File_Header FileHead
  273.    
  274.     'Check the file for validity
  275.     If LOF(SourceFile) <> FileHead.lngFileSize Then
  276.         MsgBox "Resource file " & SourceFilePath & " seems to be corrupted.", , "Error"
  277.         Close SourceFile
  278.         Erase InfoHead
  279.         Exit Function
  280.     End If
  281.    
  282.     'Size the InfoHead array
  283.     ReDim InfoHead(FileHead.intNumFiles - 1)
  284.    
  285.     Get SourceFile, , tempbyte
  286.     Get SourceFile, , tempbyte
  287.    
  288.     'Extract the INFOHEADER
  289.     Get SourceFile, , InfoHead
  290.    
  291.     Get SourceFile, , tempbyte
  292.     Get SourceFile, , tempbyte
  293.     Get SourceFile, , tempbyte
  294.     Get SourceFile, , tempbyte
  295.     Get SourceFile, , tempbyte
  296.     Get SourceFile, , tempbyte
  297.        
  298.     'Extract all of the files from the binary file
  299.     For loopc = 0 To UBound(InfoHead)
  300.         'Desencrypt each INFOHEADER before accessing the data
  301.         Encrypt_Info_Header InfoHead(loopc)
  302.        
  303.         'Check if there is enough memory
  304.         If InfoHead(loopc).lngFileSizeUncompressed > General_Drive_Get_Free_Bytes(Left(App.Path, 3)) Then
  305.             MsgBox "There is not enough free memory to continue extracting files."
  306.             Exit Function
  307.         End If
  308.        
  309.         'Resize the byte data array
  310.         ReDim SourceData(InfoHead(loopc).lngFileSize - 1)
  311.        
  312.         'Get the data
  313.         Get SourceFile, InfoHead(loopc).lngFileStart, SourceData
  314.        
  315.         'Decompress all data
  316.         'Decompress_Data SourceData, InfoHead(loopc).lngFileSizeUncompressed
  317.        
  318.         'Get a free handler
  319.         handle = FreeFile
  320.        
  321.         'Create a new file and put in the data
  322.         Open OutputFilePath & InfoHead(loopc).strFileName For Binary As handle
  323.        
  324.         Put handle, , SourceData
  325.        
  326.         Close handle
  327.        
  328.         Erase SourceData
  329.        
  330.         DoEvents
  331.     Next loopc
  332.    
  333.     'Close the binary file
  334.     Close SourceFile
  335.    
  336.     Erase InfoHead
  337.    
  338.     Extract_All_Files = True
  339. Exit Function
  340.  
  341. ErrHandler:
  342.     Close SourceFile
  343.     Erase SourceData
  344.     Erase InfoHead
  345.     'Display an error message if it didn't work
  346.     MsgBox "Unable to decode binary file. Reason: " & Err.Number & " : " & Err.Description, vbOKOnly, "Error"
  347. End Function
  348.  
  349. Public Function Extract_Patch(ByVal resource_path As String, ByVal file_name As String) As Boolean
  350. '*****************************************************************
  351. 'Author: Juan Martín Dotuyo Dodero
  352. 'Last Modify Date: 10/13/2004
  353. 'Comrpesses all files to a resource file
  354. '*****************************************************************
  355.     Dim loopc As Long
  356.     Dim LoopC2 As Long
  357.     Dim LoopC3 As Long
  358.     Dim OutputFile As Integer
  359.     Dim UpdatedFile As Integer
  360.     Dim SourceFilePath As String
  361.     Dim SourceFile As Integer
  362.     Dim SourceData() As Byte
  363.     Dim ResFileHead As FILEHEADER
  364.     Dim ResInfoHead() As INFOHEADER
  365.     Dim UpdatedInfoHead As INFOHEADER
  366.     Dim FileHead As FILEHEADER
  367.     Dim InfoHead() As INFOHEADER
  368.     Dim RequiredSpace As Currency
  369.     Dim FileExtension As String
  370.     Dim DataOffset As Long
  371.     Dim OutputFilePath As String
  372.    
  373.     'Done flags
  374.     Dim bmp_done As Boolean
  375.     Dim wav_done As Boolean
  376.     Dim mid_done As Boolean
  377.     Dim mp3_done As Boolean
  378.     Dim exe_done As Boolean
  379.     Dim gui_done As Boolean
  380.     Dim ind_done As Boolean
  381.     Dim dat_done As Boolean
  382.     Dim ini_done As Boolean
  383.    
  384.     '************************************************************************************************
  385.     'This is similar to Extract, but has some small differences to make sure what is being updated
  386.     '************************************************************************************************
  387. 'Set up the error handler
  388. On Local Error GoTo ErrHandler
  389.    
  390.     'Open the binary file
  391.     SourceFile = FreeFile
  392.     SourceFilePath = file_name
  393.     Open SourceFilePath For Binary Access Read Lock Write As SourceFile
  394.    
  395.     'Extract the FILEHEADER
  396.     Get SourceFile, 1, FileHead
  397.    
  398.     'Desencrypt File Header
  399.     Encrypt_File_Header FileHead
  400.    
  401.     'Check the file for validity
  402.     'If LOF(SourceFile) <> FileHead.lngFileSize Then
  403.     '    MsgBox "Resource file " & SourceFilePath & " seems to be corrupted.", , "Error"
  404.     '    Exit Function
  405.     'End If
  406.    
  407.     'Size the InfoHead array
  408.     ReDim InfoHead(FileHead.intNumFiles - 1)
  409.    
  410.     'Extract the INFOHEADER
  411.     Get SourceFile, , InfoHead
  412.    
  413.     'Check if there is enough hard drive space to extract all files
  414.     For loopc = 0 To UBound(InfoHead)
  415.         'Desencrypt each Info Header before accessing the data
  416.         Encrypt_Info_Header InfoHead(loopc)
  417.         RequiredSpace = RequiredSpace + InfoHead(loopc).lngFileSizeUncompressed
  418.     Next loopc
  419.    
  420.     If RequiredSpace >= General_Drive_Get_Free_Bytes(Left(App.Path, 3)) Then
  421.         Erase InfoHead
  422.         MsgBox "¡No hay espacio suficiente para extraer el archivo!", , "Error"
  423.         Exit Function
  424.     End If
  425.    
  426.     'Extract all of the files from the binary file
  427.     For loopc = 0 To UBound(InfoHead())
  428.         'Check the extension of the file
  429.         Select Case LCase(Right(Trim(InfoHead(loopc).strFileName), 3))
  430.             Case Is = "bmp"
  431.                 If bmp_done Then GoTo EndMainLoop
  432.                 FileExtension = "bmp"
  433.                 OutputFilePath = resource_path & "\Graficos.iao"
  434.                 bmp_done = True
  435.             Case Is = "mid"
  436.                 If mid_done Then GoTo EndMainLoop
  437.                 FileExtension = "mid"
  438.                 OutputFilePath = resource_path & "\MIDI.iao"
  439.                 mid_done = True
  440.             Case Is = "mp3"
  441.                 If mp3_done Then GoTo EndMainLoop
  442.                 FileExtension = "mp3"
  443.                 OutputFilePath = resource_path & "\MP3.iao"
  444.                 mp3_done = True
  445.             Case Is = "wav"
  446.                 If wav_done Then GoTo EndMainLoop
  447.                 FileExtension = "wav"
  448.                 OutputFilePath = resource_path & "\Sounds.iao"
  449.                 wav_done = True
  450.             Case Is = "jpg"
  451.                 If gui_done Then GoTo EndMainLoop
  452.                 FileExtension = "jpg"
  453.                 OutputFilePath = resource_path & "\Interface.iao"
  454.                 gui_done = True
  455.             Case Is = "ind"
  456.                 If ind_done Then GoTo EndMainLoop
  457.                 FileExtension = "ind"
  458.                 OutputFilePath = resource_path & "\Init.iao"
  459.                 ind_done = True
  460.             Case Is = "dat"
  461.                 If dat_done Then GoTo EndMainLoop
  462.                 FileExtension = "dat"
  463.                 OutputFilePath = resource_path & "\Init.iao"
  464.                 dat_done = True
  465.             Case Is = "ini"
  466.                 If ini_done Then GoTo EndMainLoop
  467.                 FileExtension = "ini"
  468.                 OutputFilePath = resource_path & "\Init.iao"
  469.                 ini_done = True
  470.         End Select
  471.        
  472.         OutputFile = FreeFile
  473.         Open OutputFilePath For Binary Access Read Lock Write As OutputFile
  474.        
  475.         'Get file header
  476.         Get OutputFile, 1, ResFileHead
  477.        
  478.         'Desencrypt file header
  479.         Encrypt_File_Header ResFileHead
  480.        
  481.         'Resize the Info Header array
  482.         ReDim ResInfoHead(ResFileHead.intNumFiles - 1)
  483.        
  484.         'Load the info header
  485.         Get OutputFile, , ResInfoHead
  486.        
  487.         'Desencrypt all Info Headers
  488.         For LoopC2 = 0 To UBound(ResInfoHead())
  489.             Encrypt_Info_Header ResInfoHead(LoopC2)
  490.         Next LoopC2
  491.        
  492.         'Check how many of the files are new, and how many are replacements
  493.         For LoopC2 = loopc To UBound(InfoHead())
  494.             If LCase$(Right$(Trim$(InfoHead(LoopC2).strFileName), 3)) = FileExtension Then
  495.                 'Look for same name in the resource file
  496.                 For LoopC3 = 0 To UBound(ResInfoHead())
  497.                     If ResInfoHead(LoopC3).strFileName = InfoHead(LoopC2).strFileName Then
  498.                         Exit For
  499.                     End If
  500.                 Next LoopC3
  501.                
  502.                 'Update the File Head
  503.                 If LoopC3 > UBound(ResInfoHead()) Then
  504.                     'Update number of files and size
  505.                     ResFileHead.intNumFiles = ResFileHead.intNumFiles + 1
  506.                     ResFileHead.lngFileSize = ResFileHead.lngFileSize + Len(InfoHead(0)) + InfoHead(LoopC2).lngFileSize
  507.                 Else
  508.                     'We substract the size of the old file and add the one of the new one
  509.                     ResFileHead.lngFileSize = ResFileHead.lngFileSize - ResInfoHead(LoopC3).lngFileSize + InfoHead(LoopC2).lngFileSize
  510.                 End If
  511.             End If
  512.         Next LoopC2
  513.        
  514.         'Get the offset of the compressed data
  515.         DataOffset = CLng(ResFileHead.intNumFiles) * Len(ResInfoHead(0)) + Len(FileHead) + 1
  516.        
  517.         'Encrypt file Header
  518.         Encrypt_File_Header ResFileHead
  519.        
  520.         'Now we start saving the updated file
  521.         UpdatedFile = FreeFile
  522.         Open OutputFilePath & "2" For Binary Access Write Lock Read As UpdatedFile
  523.        
  524.         'Store the filehead
  525.         Put UpdatedFile, 1, ResFileHead
  526.        
  527.         'Start storing the Info Heads
  528.         LoopC2 = loopc
  529.         For LoopC3 = 0 To UBound(ResInfoHead())
  530.             Do While LoopC2 <= UBound(InfoHead())
  531.                 If LCase$(ResInfoHead(LoopC3).strFileName) < LCase$(InfoHead(LoopC2).strFileName) Then Exit Do
  532.                 If LCase$(Right$(Trim$(InfoHead(LoopC2).strFileName), 3)) = FileExtension Then
  533.                     'Copy the info head data
  534.                     UpdatedInfoHead = InfoHead(LoopC2)
  535.                    
  536.                     'Set the file start pos and update the offset
  537.                     UpdatedInfoHead.lngFileStart = DataOffset
  538.                     DataOffset = DataOffset + UpdatedInfoHead.lngFileSize
  539.                    
  540.                     'Encrypt the info header and save it
  541.                     Encrypt_Info_Header UpdatedInfoHead
  542.                    
  543.                     Put UpdatedFile, , UpdatedInfoHead
  544.                    
  545.                     DoEvents
  546.                    
  547.                 End If
  548.                 LoopC2 = LoopC2 + 1
  549.             Loop
  550.            
  551.             'If the file was replaced in the patch, we skip it
  552.             If LoopC2 Then
  553.                 If LCase$(ResInfoHead(LoopC3).strFileName) <= LCase$(InfoHead(LoopC2 - 1).strFileName) Then GoTo EndLoop
  554.             End If
  555.            
  556.             'Copy the info head data
  557.             UpdatedInfoHead = ResInfoHead(LoopC3)
  558.            
  559.             'Set the file start pos and update the offset
  560.             UpdatedInfoHead.lngFileStart = DataOffset
  561.             DataOffset = DataOffset + UpdatedInfoHead.lngFileSize
  562.            
  563.             'Encrypt the info header and save it
  564.             Encrypt_Info_Header UpdatedInfoHead
  565.            
  566.             Put UpdatedFile, , UpdatedInfoHead
  567. EndLoop:
  568.         Next LoopC3
  569.        
  570.         'If there was any file in the patch that would go in the bottom of the list we put it now
  571.         For LoopC2 = LoopC2 To UBound(InfoHead())
  572.             If LCase$(Right$(Trim$(InfoHead(LoopC2).strFileName), 3)) = FileExtension Then
  573.                 'Copy the info head data
  574.                 UpdatedInfoHead = InfoHead(LoopC2)
  575.                
  576.                 'Set the file start pos and update the offset
  577.                 UpdatedInfoHead.lngFileStart = DataOffset
  578.                 DataOffset = DataOffset + UpdatedInfoHead.lngFileSize
  579.                
  580.                 'Encrypt the info header and save it
  581.                 Encrypt_Info_Header UpdatedInfoHead
  582.                
  583.                 Put UpdatedFile, , UpdatedInfoHead
  584.             End If
  585.         Next LoopC2
  586.        
  587.         'Now we start adding the compressed data
  588.         LoopC2 = loopc
  589.         For LoopC3 = 0 To UBound(ResInfoHead())
  590.             Do While LoopC2 <= UBound(InfoHead())
  591.                 If LCase$(ResInfoHead(LoopC3).strFileName) < LCase$(InfoHead(LoopC2).strFileName) Then Exit Do
  592.                 If LCase$(Right$(Trim$(InfoHead(LoopC2).strFileName), 3)) = FileExtension Then
  593.                     'Get the compressed data
  594.                     ReDim SourceData(InfoHead(LoopC2).lngFileSize - 1)
  595.                    
  596.                     Get SourceFile, InfoHead(LoopC2).lngFileStart, SourceData
  597.                    
  598.                     Put UpdatedFile, , SourceData
  599.                 End If
  600.                 LoopC2 = LoopC2 + 1
  601.             Loop
  602.            
  603.             'If the file was replaced in the patch, we skip it
  604.             If LoopC2 Then
  605.                 If LCase$(ResInfoHead(LoopC3).strFileName) <= LCase$(InfoHead(LoopC2 - 1).strFileName) Then GoTo EndLoop2
  606.             End If
  607.            
  608.             'Get the compressed data
  609.             ReDim SourceData(ResInfoHead(LoopC3).lngFileSize - 1)
  610.            
  611.             Get OutputFile, ResInfoHead(LoopC3).lngFileStart, SourceData
  612.            
  613.             Put UpdatedFile, , SourceData
  614. EndLoop2:
  615.         Next LoopC3
  616.        
  617.         'If there was any file in the patch that would go in the bottom of the lsit we put it now
  618.         For LoopC2 = LoopC2 To UBound(InfoHead())
  619.             If LCase$(Right$(Trim$(InfoHead(LoopC2).strFileName), 3)) = FileExtension Then
  620.                 'Get the compressed data
  621.                 ReDim SourceData(InfoHead(LoopC2).lngFileSize - 1)
  622.                
  623.                 Get SourceFile, InfoHead(LoopC2).lngFileStart, SourceData
  624.                
  625.                 Put UpdatedFile, , SourceData
  626.             End If
  627.         Next LoopC2
  628.        
  629.         'We are done updating the file
  630.         Close UpdatedFile
  631.        
  632.         'Close and delete the old resource file
  633.         Close OutputFile
  634.         Kill OutputFilePath
  635.        
  636.         'Rename the new one
  637.         Name OutputFilePath & "2" As OutputFilePath
  638.        
  639.         'Deallocate the memory used by the data array
  640.         Erase SourceData
  641. EndMainLoop:
  642.     Next loopc
  643.    
  644.     'Close the binary file
  645.     Close SourceFile
  646.    
  647.     Erase InfoHead
  648.     Erase ResInfoHead
  649.    
  650.     Extract_Patch = True
  651. Exit Function
  652.  
  653. ErrHandler:
  654.     Erase SourceData
  655.     Erase InfoHead
  656.  
  657. End Function
  658.  
  659. Public Function Compress_Files(ByVal file_type As resource_file_type, ByVal resource_path As String, ByVal dest_path As String) As Boolean
  660. '*****************************************************************
  661. 'Author: Juan Martín Dotuyo Dodero
  662. 'Last Modify Date: 10/13/2004
  663. 'Comrpesses all files to a resource file
  664. '*****************************************************************
  665.     Dim SourceFilePath As String
  666.     Dim SourceFileExtension As String
  667.     Dim OutputFilePath As String
  668.     Dim SourceFile As Long
  669.     Dim OutputFile As Long
  670.     Dim SourceFileName As String
  671.     Dim SourceData() As Byte
  672.     Dim FileHead As FILEHEADER
  673.     Dim InfoHead() As INFOHEADER
  674.     Dim FileNames() As String
  675.     Dim lngFileStart As Long
  676.     Dim loopc As Long
  677.    
  678. 'Set up the error handler
  679. On Local Error GoTo ErrHandler
  680.    
  681.     Select Case file_type
  682.         Case Graphics
  683.             SourceFilePath = resource_path & GRAPHIC_PATH
  684.             SourceFileExtension = ".bmp"
  685.             OutputFilePath = dest_path & "Graficos.iao"
  686.        
  687.         Case Midi
  688.             SourceFilePath = resource_path & MIDI_PATH
  689.             SourceFileExtension = ".mid"
  690.             OutputFilePath = dest_path & "MIDI.iao"
  691.        
  692.         Case MP3
  693.             SourceFilePath = resource_path & MP3_PATH
  694.             SourceFileExtension = ".mp3"
  695.             OutputFilePath = dest_path & "MP3.iao"
  696.        
  697.         Case Wav
  698.             SourceFilePath = resource_path & WAV_PATH
  699.             SourceFileExtension = ".wav"
  700.             OutputFilePath = dest_path & "Sounds.iao"
  701.                
  702.         Case Scripts
  703.             SourceFilePath = resource_path & SCRIPT_PATH
  704.             SourceFileExtension = ".*"
  705.             OutputFilePath = dest_path & "Init.iao"
  706.        
  707.         Case Patch
  708.             SourceFilePath = resource_path & PATCH_PATH
  709.             SourceFileExtension = ".*"
  710.             OutputFilePath = dest_path & "Patch.iao"
  711.    
  712.         Case Interface
  713.             SourceFilePath = resource_path & INTERFACE_PATH
  714.             SourceFileExtension = ".bmp"
  715.             OutputFilePath = dest_path & "Interface.iao"
  716.    
  717.         Case Maps
  718.             SourceFilePath = resource_path & MAP_PATH
  719.             SourceFileExtension = ".csm"
  720.             OutputFilePath = dest_path & "Mapas.iao"
  721.     End Select
  722.    
  723.     'Get first file in the directoy
  724.     SourceFileName = Dir$(SourceFilePath & "*" & SourceFileExtension, vbNormal)
  725.    
  726.     SourceFile = FreeFile
  727.    
  728.     'Get all other files i nthe directory
  729.     While SourceFileName <> ""
  730.         FileHead.intNumFiles = FileHead.intNumFiles + 1
  731.        
  732.         ReDim Preserve FileNames(FileHead.intNumFiles - 1)
  733.         FileNames(FileHead.intNumFiles - 1) = LCase(SourceFileName)
  734.        
  735.         'Search new file
  736.         SourceFileName = Dir$()
  737.     Wend
  738.    
  739.     'If we found none, be can't compress a thing, so we exit
  740.     If FileHead.intNumFiles = 0 Then
  741.         MsgBox "There are no files of extension " & SourceFileExtension & " in " & SourceFilePath & ".", , "Error"
  742.         Exit Function
  743.     End If
  744.    
  745.     'Sort file names alphabetically (this will make patching much easier).
  746.     General_Quick_Sort FileNames(), 0, UBound(FileNames)
  747.    
  748.     'Resize InfoHead array
  749.     ReDim InfoHead(FileHead.intNumFiles - 1)
  750.        
  751.     'Destroy file if it previuosly existed
  752.     If Dir(OutputFilePath, vbNormal) <> "" Then
  753.         Kill OutputFilePath
  754.     End If
  755.    
  756.     'Open a new file
  757.     OutputFile = FreeFile
  758.     Open OutputFilePath For Binary Access Read Write As OutputFile
  759.    
  760.     For loopc = 0 To FileHead.intNumFiles - 1
  761.         'Find a free file number to use and open the file
  762.         SourceFile = FreeFile
  763.         Open SourceFilePath & FileNames(loopc) For Binary Access Read Lock Write As SourceFile
  764.        
  765.         'Store file name
  766.         InfoHead(loopc).strFileName = FileNames(loopc)
  767.        
  768.         'Find out how large the file is and resize the data array appropriately
  769.         ReDim SourceData(LOF(SourceFile) - 1)
  770.        
  771.         'Store the value so we can decompress it later on
  772.         InfoHead(loopc).lngFileSizeUncompressed = LOF(SourceFile)
  773.        
  774.         'Get the data from the file
  775.         Get SourceFile, , SourceData
  776.        
  777.         'Compress it
  778.         'Compress_Data SourceData
  779.        
  780.         'Save it to a temp file
  781.         Put OutputFile, , SourceData
  782.        
  783.         'Set up the file header
  784.         FileHead.lngFileSize = FileHead.lngFileSize + UBound(SourceData) + 1
  785.        
  786.         'Set up the info headers
  787.         InfoHead(loopc).lngFileSize = UBound(SourceData) + 1
  788.        
  789.         Erase SourceData
  790.        
  791.         'Close temp file
  792.         Close SourceFile
  793.        
  794.         DoEvents
  795.     Next loopc
  796.    
  797.     'Finish setting the FileHeader data
  798.     FileHead.lngFileSize = FileHead.lngFileSize + CLng(FileHead.intNumFiles) * Len(InfoHead(0)) + Len(FileHead)
  799.    
  800.     'Set InfoHead data
  801.     lngFileStart = Len(FileHead) + CLng(FileHead.intNumFiles) * Len(InfoHead(0)) + 1
  802.     For loopc = 0 To FileHead.intNumFiles - 1
  803.         InfoHead(loopc).lngFileStart = lngFileStart
  804.         lngFileStart = lngFileStart + InfoHead(loopc).lngFileSize
  805.         'Once an InfoHead index is ready, we encrypt it
  806.         Encrypt_Info_Header InfoHead(loopc)
  807.     Next loopc
  808.    
  809.     'Encrypt the FileHeader
  810.     Encrypt_File_Header FileHead
  811.    
  812.     '************ Write Data
  813.    
  814.     'Get all data stored so far
  815.     ReDim SourceData(LOF(OutputFile) - 1)
  816.     Seek OutputFile, 1
  817.     Get OutputFile, , SourceData
  818.    
  819.     Seek OutputFile, 1
  820.    
  821.     'Store the data in the file
  822.     Put OutputFile, , FileHead
  823.     Put OutputFile, , InfoHead
  824.     Put OutputFile, , SourceData
  825.    
  826.     'Close the file
  827.     Close OutputFile
  828.    
  829.     Erase InfoHead
  830.     Erase SourceData
  831. Exit Function
  832.  
  833. ErrHandler:
  834.     Erase SourceData
  835.     Erase InfoHead
  836.     'Display an error message if it didn't work
  837.     MsgBox "Unable to create binary file. Reason: " & Err.Number & " : " & Err.Description, vbOKOnly, "Error"
  838. End Function
  839.  
  840. Public Function Extract_File(ByVal file_type As resource_file_type, ByVal resource_path As String, ByVal file_name As String, ByVal OutputFilePath As String, Optional ByVal UseOutputFolder As Boolean = False) As Boolean
  841. '*****************************************************************
  842. 'Author: Juan Martín Dotuyo Dodero
  843. 'Last Modify Date: 10/13/2004
  844. 'Extracts all files from a resource file
  845. '*****************************************************************
  846.     Dim loopc As Long
  847.     Dim SourceFilePath As String
  848.     Dim SourceData() As Byte
  849.     Dim InfoHead As INFOHEADER
  850.     Dim handle As Integer
  851.     Dim tempbyte As Byte
  852.    
  853. 'Set up the error handler
  854. On Local Error GoTo ErrHandler
  855.    
  856.     Select Case file_type
  857.         Case Graphics
  858.             If UseOutputFolder Then
  859.                 SourceFilePath = resource_path & OUTPUT_PATH & "Graficos.iao"
  860.             Else
  861.                 SourceFilePath = resource_path & "\Graficos.iao"
  862.             End If
  863.            
  864.         Case Midi
  865.             If UseOutputFolder Then
  866.                 SourceFilePath = resource_path & OUTPUT_PATH & "MIDI.iao"
  867.             Else
  868.                 SourceFilePath = resource_path & "\MIDI.iao"
  869.             End If
  870.        
  871.         Case MP3
  872.             If UseOutputFolder Then
  873.                 SourceFilePath = resource_path & OUTPUT_PATH & "MP3.iao"
  874.             Else
  875.                 SourceFilePath = resource_path & "\MP3.iao"
  876.             End If
  877.        
  878.         Case Wav
  879.             If UseOutputFolder Then
  880.                 SourceFilePath = resource_path & OUTPUT_PATH & "Sounds.iao"
  881.             Else
  882.                 SourceFilePath = resource_path & "\Sounds.iao"
  883.             End If
  884.        
  885.         Case Scripts
  886.             If UseOutputFolder Then
  887.                 SourceFilePath = resource_path & OUTPUT_PATH & "Init.iao"
  888.             Else
  889.                 SourceFilePath = resource_path & "\Init.iao"
  890.             End If
  891.        
  892.         Case Interface
  893.             If UseOutputFolder Then
  894.                 SourceFilePath = resource_path & OUTPUT_PATH & "Interface.iao"
  895.             Else
  896.                 SourceFilePath = resource_path & "\Interface.iao"
  897.             End If
  898.            
  899.         Case Maps
  900.             If UseOutputFolder Then
  901.                 SourceFilePath = resource_path & OUTPUT_PATH & "Mapas.iao"
  902.             Else
  903.                 SourceFilePath = resource_path & "\Mapas.iao"
  904.             End If
  905.            
  906.         Case Else
  907.             Exit Function
  908.     End Select
  909.    
  910.     file_name = LCase(file_name)
  911.    
  912.     'Find the Info Head of the desired file
  913.     InfoHead = File_Find(SourceFilePath, file_name)
  914.    
  915.     If InfoHead.strFileName = "" Or InfoHead.lngFileSize = 0 Then Exit Function
  916.  
  917.     'Open the binary file
  918.     handle = FreeFile
  919.     Open SourceFilePath For Binary Access Read Lock Write As handle
  920.    
  921.         'Make sure there is enough space in the HD
  922.         If InfoHead.lngFileSizeUncompressed > General_Drive_Get_Free_Bytes(Left$(App.Path, 3)) Then
  923.             Close handle
  924.             MsgBox "There is not enough drive space to extract the compressed file.", , "Error"
  925.             Exit Function
  926.         End If
  927.        
  928.         'Extract file from the binary file
  929.        
  930.         'Resize the byte data array
  931.         ReDim SourceData(InfoHead.lngFileSize - 1)
  932.        
  933.         'Get the data
  934.         Get handle, InfoHead.lngFileStart + 9, SourceData
  935.        
  936.         'Decompress all data
  937.         Decompress_Data SourceData, InfoHead.lngFileSizeUncompressed
  938.    
  939.     'Close the binary file
  940.     Close handle
  941.    
  942.     'Get a free handler
  943.     handle = FreeFile
  944.    
  945.     Open OutputFilePath & InfoHead.strFileName For Binary Access Write As handle
  946.    
  947.         Put handle, 1, SourceData
  948.    
  949.     Close handle
  950.    
  951.     Erase SourceData
  952.        
  953.     Extract_File = True
  954. Exit Function
  955.  
  956. ErrHandler:
  957.     Close handle
  958.     Erase SourceData
  959.     'Display an error message if it didn't work
  960.     'MsgBox "Unable to decode binary file. Reason: " & Err.number & " : " & Err.Description, vbOKOnly, "Error"
  961. End Function
  962. Public Function Extract_BMP_Memory(ByVal file_name As String, SourceData() As Byte) As Boolean
  963. '*****************************************************************
  964. 'Author: Juan Martín Dotuyo Dodero
  965. 'Last Modify Date: 10/13/2004
  966. 'Extracts all files from a resource file
  967. '*****************************************************************
  968.     Dim loopc As Long
  969.     Dim InfoHead As INFOHEADER
  970.     Dim handle As Integer
  971.    
  972. 'Set up the error handler
  973. On Local Error GoTo ErrHandler
  974.  
  975.     'Find the Info Head of the desired file
  976.     InfoHead = File_Find(App.Path & "\Resources\Graficos.iao", file_name)
  977.    
  978.     If InfoHead.strFileName = "" Or InfoHead.lngFileSize = 0 Then Exit Function
  979.  
  980.     'Open the binary file
  981.     handle = FreeFile
  982.     Open App.Path & "\Resources\Graficos.iao" For Binary Access Read Lock Write As handle
  983.    
  984.         'Resize the byte data array
  985.         ReDim SourceData(InfoHead.lngFileSize - 1)
  986.        
  987.         'Get the data
  988.         Get handle, InfoHead.lngFileStart + 9, SourceData
  989.        
  990.         'Decompress all data
  991.         Decompress_Data SourceData, InfoHead.lngFileSizeUncompressed
  992.    
  993.     'Close the binary file
  994.     Close handle
  995.        
  996.     Extract_BMP_Memory = True
  997. Exit Function
  998.  
  999. ErrHandler:
  1000.     Close handle
  1001.     Erase SourceData
  1002. End Function
  1003.  
  1004.  
  1005. Private Function File_Find(ByVal resource_file_path As String, ByVal file_name As String) As INFOHEADER
  1006. '**************************************************************
  1007. 'Author: Juan Martín Sotuyo Dodero
  1008. 'Last Modify Date: 5/04/2005
  1009. 'Looks for a compressed file in a resource file. Uses binary search ;)
  1010. '**************************************************************
  1011. On Error GoTo ErrHandler
  1012.     Dim max As Long  'Max index
  1013.     Dim min As Long  'Min index
  1014.     Dim mid As Long  'Middle index
  1015.     Dim file_handler As Integer
  1016.     Dim file_head As FILEHEADER
  1017.     Dim info_head As INFOHEADER
  1018.     Dim tempbyte As Byte
  1019.    
  1020.     'Fill file name with spaces for compatibility
  1021.     If Len(file_name) < Len(info_head.strFileName) Then _
  1022.         file_name = file_name & Space$(Len(info_head.strFileName) - Len(file_name))
  1023.    
  1024.     'Open resource file
  1025.     file_handler = FreeFile
  1026.     Open resource_file_path For Binary Access Read Lock Write As file_handler
  1027.    
  1028.     Get file_handler, 1, tempbyte
  1029.     'Get file head
  1030.     Get file_handler, , file_head
  1031.     Encrypt_File_Header file_head
  1032.     Get file_handler, , tempbyte
  1033.     Get file_handler, , tempbyte
  1034.     min = 1
  1035.     max = file_head.intNumFiles
  1036.    
  1037.     Do While min <= max
  1038.         mid = (min + max) / 2
  1039.        
  1040.         'Get the info header of the appropiate compressed file
  1041.         Get file_handler, CLng(Len(file_head) + CLng(Len(info_head)) * CLng((mid - 1)) + 1) + 3, info_head
  1042.         Encrypt_Info_Header info_head
  1043.                
  1044.         If file_name < info_head.strFileName Then
  1045.             If max = mid Then
  1046.                 max = max - 1
  1047.             Else
  1048.                 max = mid
  1049.             End If
  1050.         ElseIf file_name > info_head.strFileName Then
  1051.             If min = mid Then
  1052.                 min = min + 1
  1053.             Else
  1054.                 min = mid
  1055.             End If
  1056.         Else
  1057.             'Copy info head
  1058.             File_Find = info_head
  1059.            
  1060.             'Close file and exit
  1061.             Close file_handler
  1062.             Exit Function
  1063.         End If
  1064.     Loop
  1065.    
  1066. ErrHandler:
  1067.     'Close file
  1068.     Close file_handler
  1069.     File_Find.strFileName = ""
  1070.     File_Find.lngFileSize = 0
  1071. End Function
  1072.  
  1073. Public Function General_Drive_Get_Free_Bytes(ByVal DriveName As String) As Currency
  1074. '**************************************************************
  1075. 'Author: Juan Martín Sotuyo Dodero
  1076. 'Last Modify Date: 6/07/2004
  1077. '
  1078. '**************************************************************
  1079.     Dim RetVal As Long
  1080.     Dim FB As Currency
  1081.     Dim BT As Currency
  1082.     Dim FBT As Currency
  1083.    
  1084.     RetVal = GetDiskFreeSpace(Left(DriveName, 2), FB, BT, FBT)
  1085.    
  1086.     General_Drive_Get_Free_Bytes = FB * 10000 'convert result to actual size in bytes
  1087. End Function
  1088.  
  1089. Public Sub General_Quick_Sort(ByRef SortArray As Variant, ByVal first As Long, ByVal last As Long)
  1090. '**************************************************************
  1091. 'Author: juan Martín Sotuyo Dodero
  1092. 'Last Modify Date: 3/03/2005
  1093. 'Good old QuickSort algorithm :)
  1094. '**************************************************************
  1095.     Dim Low As Long, High As Long
  1096.     Dim temp As Variant
  1097.     Dim List_Separator As Variant
  1098.    
  1099.     Low = first
  1100.     High = last
  1101.     List_Separator = SortArray((first + last) / 2)
  1102.     Do While (Low <= High)
  1103.         Do While SortArray(Low) < List_Separator
  1104.             Low = Low + 1
  1105.         Loop
  1106.         Do While SortArray(High) > List_Separator
  1107.             High = High - 1
  1108.         Loop
  1109.         If Low <= High Then
  1110.             temp = SortArray(Low)
  1111.             SortArray(Low) = SortArray(High)
  1112.             SortArray(High) = temp
  1113.             Low = Low + 1
  1114.             High = High - 1
  1115.         End If
  1116.     Loop
  1117.     If first < High Then General_Quick_Sort SortArray, first, High
  1118.     If Low < last Then General_Quick_Sort SortArray, Low, last
  1119. End Sub
  1120.  
  1121. Public Sub Extract_Files(ByVal file_type As resource_file_type, ByVal resource_path As String, Optional ByVal UseOutputFolder As Boolean = False)
  1122. '*****************************************************************
  1123. 'Author: Juan Martín Dotuyo Dodero
  1124. 'Last Modify Date: 10/13/2004
  1125. 'Extracts all files from a resource file
  1126. '*****************************************************************
  1127.     Dim loopc As Long
  1128.     Dim SourceFilePath As String
  1129.     Dim OutputFilePath As String
  1130.     Dim SourceFile As Integer
  1131.     Dim SourceData() As Byte
  1132.     Dim FileHead As FILEHEADER
  1133.     Dim InfoHead() As INFOHEADER
  1134.     Dim handle As Integer
  1135.    
  1136. On Local Error GoTo ErrHandler
  1137.     Select Case file_type
  1138.         Case Graphics
  1139.                 SourceFilePath = resource_path & "\Graficos.iao"
  1140.                 OutputFilePath = App.Path & GRAPHIC_PATH
  1141.         Case Midi
  1142.                 SourceFilePath = resource_path & "\Midi.iao"
  1143.             OutputFilePath = App.Path & MIDI_PATH 'resource_path & MIDI_PATH
  1144.         Case MP3
  1145.                 SourceFilePath = resource_path & "\MP3.iao"
  1146.             OutputFilePath = App.Path & MP3_PATH
  1147.         Case Wav
  1148.                 SourceFilePath = resource_path & "\Sounds.iao"
  1149.             OutputFilePath = App.Path & WAV_PATH
  1150.         Case Scripts
  1151.                 SourceFilePath = resource_path & "\Init.iao"
  1152.             OutputFilePath = App.Path & SCRIPT_PATH
  1153.         Case Interface
  1154.                 SourceFilePath = resource_path & "\Interface.iao"
  1155.             OutputFilePath = App.Path & INTERFACE_PATH
  1156.          Case Maps
  1157.                 SourceFilePath = resource_path & "\Map.iao"
  1158.             OutputFilePath = App.Path & MAP_PATH
  1159.         Case Else
  1160.             Exit Sub
  1161.     End Select
  1162.  
  1163.     'Open the binary file
  1164.     SourceFile = FreeFile
  1165.     Open SourceFilePath For Binary Access Read Lock Write As SourceFile
  1166.     'Extract the FILEHEADER
  1167.     Get SourceFile, 1, FileHead
  1168.     'Check the file for validity
  1169.     If LOF(SourceFile) <> FileHead.lngFileSize Then ' - Pass1.lngFileSize - 1 Then
  1170.         MsgBox "Resource file " & SourceFilePath & " seems to be corrupted.", , "Error"
  1171.         Close SourceFile
  1172.         Erase InfoHead
  1173.         Exit Sub
  1174.     End If
  1175.     'Size the InfoHead array
  1176.     ReDim InfoHead(FileHead.intNumFiles - 1)
  1177.  
  1178.     'Extract the INFOHEADER
  1179.     Get SourceFile, , InfoHead
  1180.  
  1181.     'Extract all of the files from the binary file
  1182.     For loopc = 0 To UBound(InfoHead)
  1183.  
  1184.         'Check if there is enough memory
  1185.         If InfoHead(loopc).lngFileSizeUncompressed > General_Drive_Get_Free_Bytes(Left(App.Path, 3)) Then
  1186.             MsgBox "No tienes suficiente espacio en el disco para seguir descomprimiendo archivos."
  1187.             Exit Sub
  1188.         End If
  1189.         'Resize the byte data array
  1190.         ReDim SourceData(InfoHead(loopc).lngFileSize - 1)
  1191.         'Get the data
  1192.         Get SourceFile, InfoHead(loopc).lngFileStart, SourceData
  1193.         'Decompress all data
  1194.         Decompress_Data SourceData, InfoHead(loopc).lngFileSizeUncompressed
  1195.         'Get a free handler
  1196.         handle = FreeFile
  1197.         'Create a new file and put in the data
  1198.         Open OutputFilePath & InfoHead(loopc).strFileName For Binary As handle
  1199.         Put handle, , SourceData
  1200.         Close handle
  1201.         Erase SourceData
  1202.         DoEvents
  1203.     Next loopc
  1204.  
  1205.     'Close the binary file
  1206.     Close SourceFile
  1207.     Erase InfoHead
  1208. Exit Sub
  1209. ErrHandler:
  1210.     Close SourceFile
  1211.     Erase SourceData
  1212.     Erase InfoHead
  1213.     'Display an error message if it didn't work
  1214.     MsgBox "Unable to decode binary file. Reason: " & Err.Number & " : " & Err.Description, vbOKOnly, "Error"
  1215. End Sub
  1216.  


Y el commanddbut
  1. Private Sub Command1_Click()
  2. Call Extract_All_Files(Graphics, App.Path & "\Recursos")
  3. End Sub
  4.  


Saludos ^^
Usuario Registrado
90
Newbie [3]
Registrado: Diciembre 2011
Mensajes: 81

Nota » 25 Ene 2012 17:27

1 : Por que no usas el de leandor que ya esta aportado y sirve hasta la 1.4.5 no infra ??
2 : Por que no vas haciendo de a 1 fila usando Extract_File
3 : De donde sacaste el modulo compres de los codes del iao 1.4 ?

Imagen
Ninja en progreso
919
Dragon Ancestral [5]
Registrado: Años de membresía
Ubicación: • olivos •
Mensajes: 4096
Aportes: 13

Nota » 25 Ene 2012 17:34

1. No uso el de mannakia porqe no sirve para imperiumao 1.4
2. Es que si voy haciendo de a un file, lo que pasa es que cree un solo comandbutt para provar si funcionada, y si era asì hacia los demas
3. Ya venia con IAO CLON
4. Y aùn asi si uso el de mannakia, solo descomprime, yo quiero que comprima para meter todo ai adentro y cambiar la carga de interfaces, inits, etc
Saludos!
Usuario Registrado
90
Newbie [3]
Registrado: Diciembre 2011
Mensajes: 81

Nota » 25 Ene 2012 17:44

Kuk escribió:1. No uso el de mannakia porqe no sirve para imperiumao 1.4
2. Es que si voy haciendo de a un file, lo que pasa es que cree un solo comandbutt para provar si funcionada, y si era asì hacia los demas
3. Ya venia con IAO CLON
4. Y aùn asi si uso el de mannakia, solo descomprime, yo quiero que comprima para meter todo ai adentro y cambiar la carga de interfaces, inits, etc
Saludos!

1 : Si sirve para iao 1.4 por que yo lo use
2 : bueno
3 : xD Yo pense que lo sacaste del iao liberado
4 : No te entenidi un socotroco
nuevo ea ea ea
5 : Proba la opcion 2 de a file y con los case correspondientes ^^

Imagen
Ninja en progreso
919
Dragon Ancestral [5]
Registrado: Años de membresía
Ubicación: • olivos •
Mensajes: 4096
Aportes: 13

Nota » 25 Ene 2012 17:55

No creo que puedas hacerlo de esa forma. A pesar de que ese es el código que usó y usa ImperiumAO en la actualidad, debe estar modificado, aunquesea en lo más minimo, lo que hace que a vos no te funcione y te diga que el archivo es corrupto.
Al decir que esta modificado me refiero a alguna información adicional, no útil que sirva como obstáculo para quienes quieran descomprimirlo (Ya sea un header o agregar bytes inútiles u otras modificaciones).

Mannakia lo hizo con un software debugger corriendo el Imperium y viendo como trabaja, para así poder entenderlo y programar algo que funcione a lo que necesitaba. Obviamente debes saber asm.

Suerte !.
Usuario Registrado
166
Aprendiz [1]
Registrado: Años de membresía
Mensajes: 241

Nota » 25 Ene 2012 19:51

Què lastima, la verdad que necesitava hacer ese compressor porque al iao clon tiene todo suelto aì y yo quiero que se parezca màs al iao xD
Una pregunta ese software debugger es un programa o algo? porque la verdad nunca lo eh escuchado.
Igual otra cosa eso de que vos desis que està midificado, deve aver una lìnea en que te lo prohive porque no creo que midificaron todos los visual basics para que no te pueda correr un programa con ese mòdulo. Lorwir hizo algo parecido, pero apun asì basandome en esos còdigos no lo he logrado,
Usuario Registrado
90
Newbie [3]
Registrado: Diciembre 2011
Mensajes: 81

Nota » 25 Ene 2012 20:13

Kuk escribió:Què lastima, la verdad que necesitava hacer ese compressor porque al iao clon tiene todo suelto aì y yo quiero que se parezca màs al iao xD
Una pregunta ese software debugger es un programa o algo? porque la verdad nunca lo eh escuchado.
Igual otra cosa eso de que vos desis que està midificado, deve aver una lìnea en que te lo prohive porque no creo que midificaron todos los visual basics para que no te pueda correr un programa con ese mòdulo. Lorwir hizo algo parecido, pero apun asì basandome en esos còdigos no lo he logrado,


Como que iao clon tiene todo dispersado por hay ??? que los descomprime y jamas los borra ?

Imagen
Ninja en progreso
919
Dragon Ancestral [5]
Registrado: Años de membresía
Ubicación: • olivos •
Mensajes: 4096
Aportes: 13

Nota » 25 Ene 2012 20:25

miqueas150 escribió:
Kuk escribió:Què lastima, la verdad que necesitava hacer ese compressor porque al iao clon tiene todo suelto aì y yo quiero que se parezca màs al iao xD
Una pregunta ese software debugger es un programa o algo? porque la verdad nunca lo eh escuchado.
Igual otra cosa eso de que vos desis que està midificado, deve aver una lìnea en que te lo prohive porque no creo que midificaron todos los visual basics para que no te pueda correr un programa con ese mòdulo. Lorwir hizo algo parecido, pero apun asì basandome en esos còdigos no lo he logrado,


Como que iao clon tiene todo dispersado por hay ??? que los descomprime y jamas los borra ?


Y cuando vos descargas iao clon, no viene todo comprimido tenes la carpeta resources donde estan mezlcadas las interface con los ints, en el cliente hay como 15 graficos meditos que tendrian que estas encriptados, a mi me gustaria tenes el compressor para encriptar las interfaces, los inits, esos graficos sueltos, y cambiar la carga.
Usuario Registrado
90
Newbie [3]
Registrado: Diciembre 2011
Mensajes: 81

Nota » 25 Ene 2012 20:36

Kuk escribió:
miqueas150 escribió:
Kuk escribió:Què lastima, la verdad que necesitava hacer ese compressor porque al iao clon tiene todo suelto aì y yo quiero que se parezca màs al iao xD
Una pregunta ese software debugger es un programa o algo? porque la verdad nunca lo eh escuchado.
Igual otra cosa eso de que vos desis que està midificado, deve aver una lìnea en que te lo prohive porque no creo que midificaron todos los visual basics para que no te pueda correr un programa con ese mòdulo. Lorwir hizo algo parecido, pero apun asì basandome en esos còdigos no lo he logrado,


Como que iao clon tiene todo dispersado por hay ??? que los descomprime y jamas los borra ?


Y cuando vos descargas iao clon, no viene todo comprimido tenes la carpeta resources donde estan mezlcadas las interface con los ints, en el cliente hay como 15 graficos meditos que tendrian que estas encriptados, a mi me gustaria tenes el compressor para encriptar las interfaces, los inits, esos graficos sueltos, y cambiar la carga.


Los graficos sueltos son por que el cliente los descomprime pero nunca los borra
Trankilamente para evitarte la fatiga de hacer las interfaces haces 1 sola carga de interfaces y la pones de una en el frmmain y sacas toda la carga

Imagen
Ninja en progreso
919
Dragon Ancestral [5]
Registrado: Años de membresía
Ubicación: • olivos •
Mensajes: 4096
Aportes: 13

Nota » 25 Ene 2012 20:36

Kuk escribió:
miqueas150 escribió:
Kuk escribió:Què lastima, la verdad que necesitava hacer ese compressor porque al iao clon tiene todo suelto aì y yo quiero que se parezca màs al iao xD
Una pregunta ese software debugger es un programa o algo? porque la verdad nunca lo eh escuchado.
Igual otra cosa eso de que vos desis que està midificado, deve aver una lìnea en que te lo prohive porque no creo que midificaron todos los visual basics para que no te pueda correr un programa con ese mòdulo. Lorwir hizo algo parecido, pero apun asì basandome en esos còdigos no lo he logrado,


Como que iao clon tiene todo dispersado por hay ??? que los descomprime y jamas los borra ?


Y cuando vos descargas iao clon, no viene todo comprimido tenes la carpeta resources donde estan mezlcadas las interface con los ints, en el cliente hay como 15 graficos meditos que tendrian que estas encriptados, a mi me gustaria tenes el compressor para encriptar las interfaces, los inits, esos graficos sueltos, y cambiar la carga.


Los graficos sueltos son por que el cliente los descomprime pero nunca los borra
Trankilamente para evitarte la fatiga de hacer las interfaces haces 1 sola carga de interfaces y la pones de una en el frmmain y sacas toda la carga

Imagen
Ninja en progreso
919
Dragon Ancestral [5]
Registrado: Años de membresía
Ubicación: • olivos •
Mensajes: 4096
Aportes: 13

Nota » 25 Ene 2012 21:02

Si pero lo que yo quiero hacer es que las lea desde recursos (encriptadas) porque hay mezcladas bmp con jpg porque el main es bmp y las demas jpg xD
Usuario Registrado
90
Newbie [3]
Registrado: Diciembre 2011
Mensajes: 81

Nota » 25 Ene 2012 23:03

Si se puede... pero te doy un consejo, agarra* una version virgen y haz ambientando todo a iao, que luego mas tarde si tienes el juego bueno, siempre te diran, ah ese era de mannakia, blablabla, yo tambien habia perdido unas mil horas, hasta vi como hacer muchas cosas para avanzarlo,pero pense.. voy a estar dependiente del proyecto de mannakia? Nah paso... y prefiero tar dependiente de un inicio de proyecto de morgolock xDDD Enga Suerte

Administrador de CruzNegrAO (Servidor Mundial Style IAO Pero Mas Desarrollado...)
http://www.cruznegrao.webs.com
RaZoV - lLider de CruzNegra|
454
Aprendiz [2]
Registrado: Diciembre 2011
Ubicación: Portugal
Mensajes: 259
Aportes: 2

Nota » 26 Ene 2012 00:59

Kuk escribió:Què lastima, la verdad que necesitava hacer ese compressor porque al iao clon tiene todo suelto aì y yo quiero que se parezca màs al iao xD
Una pregunta ese software debugger es un programa o algo? porque la verdad nunca lo eh escuchado.
Igual otra cosa eso de que vos desis que està midificado, deve aver una lìnea en que te lo prohive porque no creo que midificaron todos los visual basics para que no te pueda correr un programa con ese mòdulo. Lorwir hizo algo parecido, pero apun asì basandome en esos còdigos no lo he logrado,


No me entendiste. Lo que está modificado es el algoritmo de encriptación. Por lo tanto, al tener un algoritmo modificado solamente podrá descomprimirlo el que tenga dicho algoritmo o el que tenga conocimientos avanzados y pase esa "seguridad". Nunca vas a poder descomprimir un archivo comprimido de IAO si no sabes cómo lo comprimieron. A lo que me refería es que ellos muy probablemente hicieron modificaciones en su código de compresión, por ende, modificaron tambien su código de descompresión. Ambos son distintos al que tenés vos y por eso obtenes un error de archivo corrupto, porque hay un error al intentar descomprimirlo ya que el archivo es distinto al esperado tu algoritmo.

En cuanto a el software debugger, hay muchos y para distintas necesidades, uno muy conocido para windows: es el querido OllyDbg.

Lo que podes hacer es tomar esos módulos de compresión, y hacer modificaciones al algoritmo. Organizar bien tus archivos y programar bien su compresión y descompresión. Despues te bajas los recursos ya extraidos, y los comprimis con tu compresor personalizado :P . Ahí no deberías tener más problemas.
Usuario Registrado
166
Aprendiz [1]
Registrado: Años de membresía
Mensajes: 241

Nota » 26 Ene 2012 04:44

agregame al msn qe yo te ayudo...
nuxer-ao@live.com.ar

Imagen
Director NieblasAO
158
Newbie [4]
Registrado: Años de membresíaAños de membresía
Ubicación: Villa Ballester, San Martín
Mensajes: 130
Aportes: 1
Premios: 1
Embajador (1)


Volver a Otras versiones

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 0 invitados