SHARE
TWEET

UmodTest.pbi

a guest Nov 18th, 2018 134 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; http://www.unrealtexture.com/Unreal/Downloads/3DEditing/UnrealEd/Tutorials/unrealwiki-offline/umod-file-format.html
  2.  
  3. #UMOD_DECALSTAY$ = "DecalStay.umod"
  4. #UMOD_EXCESSIVE$ = "Excessive100.umod"
  5.  
  6. ; .l type (4bytes)
  7. #UMOD_MAGIC_NBR = $9FE3C5A3
  8. ;#UMOD_MAGIC_NBR = $A3C5E3FE
  9.  
  10. #UMOD_FILE_REGULAR = $00
  11. #UMOD_FILE_MANIFEST = $03
  12.  
  13. ; All variables using the .l type are technically unsigned in the format...
  14. ; And it is located at the end of the file, because header==footer...
  15. Structure UMOD_HEADER
  16.     DirectoryOffset.l
  17.     UmodSize.l
  18.     UmodFileVersion.l
  19.     CRC32.l ; Not sure.
  20. EndStructure
  21.  
  22. Structure UMOD_DIRECTORY_ENTRY
  23.     FilenameLength.a ; 0x00 is counted in !
  24.     Filename$
  25.     FileByteOffset.l
  26.     FileLength.l
  27.     FileBitFields.l
  28. EndStructure
  29.  
  30. Structure Umod
  31.     Header.UMOD_HEADER
  32.     Array DirectoryEntries.UMOD_DIRECTORY_ENTRY(0)
  33.     Array *FileData(0)
  34. EndStructure
  35.  
  36.  
  37. ; Umod thingy
  38.  
  39. Procedure ReadUmod(Path$)
  40.     Protected i.i, *Umod.Umod = AllocateStructure(Umod)
  41.     If Not *Umod : ProcedureReturn 0 : EndIf
  42.    
  43.     Protected FileId = ReadFile(#PB_Any, Path$)
  44.     If Not FileId : ProcedureReturn 0 : EndIf
  45.    
  46.     ;Protected Header.UMOD_HEADER
  47.     FileSeek(FileId, Lof(FileId)-SizeOf(UMOD_HEADER)-4, #PB_Absolute)
  48.    
  49.     If UCase(Hex(ReadLong(FileId), #PB_Long)) = UCase("9FE3C5A3")
  50.         *Umod\Header\DirectoryOffset = ReadLong(FileId)
  51.         *Umod\Header\UmodSize = ReadLong(FileId)
  52.         *Umod\Header\UmodFileVersion = ReadLong(FileId)
  53.         *Umod\Header\CRC32 = ReadLong(FileId)
  54.        
  55.         FileSeek(FileId, *Umod\Header\DirectoryOffset + 1, #PB_Absolute)
  56.        
  57.         Repeat
  58.             Protected Filename$ = "", CurrentArrayIndex = ArraySize(*Umod\DirectoryEntries())
  59.            
  60.             ReDim *Umod\DirectoryEntries(CurrentArrayIndex+1)
  61.             ReDim *Umod\FileData(CurrentArrayIndex+1)
  62.            
  63.             *Umod\DirectoryEntries(CurrentArrayIndex)\FilenameLength = ReadAsciiCharacter(FileId)
  64.            
  65.             For i=0 To *Umod\DirectoryEntries(CurrentArrayIndex)\FilenameLength -2
  66.                 Filename$ = Filename$ + Chr(ReadAsciiCharacter(FileId))
  67.             Next
  68.             ReadAsciiCharacter(FileId)
  69.            
  70.             *Umod\DirectoryEntries(CurrentArrayIndex)\Filename$ = Filename$
  71.            
  72.             *Umod\DirectoryEntries(CurrentArrayIndex)\FileByteOffset = ReadLong(FileId)
  73.             *Umod\DirectoryEntries(CurrentArrayIndex)\FileLength = ReadLong(FileId)
  74.             *Umod\DirectoryEntries(CurrentArrayIndex)\FileBitFields = ReadLong(FileId)
  75.         Until Loc(FileId) >= Lof(FileId)-SizeOf(UMOD_HEADER)-4
  76.        
  77.         ; for over files
  78.         For i=0 To ArraySize(*Umod\DirectoryEntries())-1
  79.             *Umod\FileData(i) = AllocateMemory(*Umod\DirectoryEntries(i)\FileLength, #PB_Memory_NoClear)
  80.             FileSeek(FileId, *Umod\DirectoryEntries(i)\FileByteOffset, #PB_Absolute)
  81.             ReadData(FileId, *Umod\FileData(i), MemorySize(*Umod\FileData(i)))
  82.         Next
  83.     Else
  84.         FreeStructure(*Umod)
  85.         *Umod = 0
  86.     EndIf
  87.    
  88.     CloseFile(FileId)
  89.    
  90.     ProcedureReturn *Umod
  91. EndProcedure
  92.  
  93. Procedure DebugUmodStructure(*Umod.Umod)
  94.     Protected i.i
  95.    
  96.     If Not *Umod
  97.         ProcedureReturn
  98.     EndIf
  99.    
  100.     Debug "Header:"
  101.     Debug #TAB$+"Dir. Offset: 0x" + Hex(*Umod\Header\DirectoryOffset)
  102.     Debug #TAB$+"Size (B):    " + Str(*Umod\Header\UmodSize)
  103.     Debug #TAB$+"UMOD Ver.:   0x" + Hex(*Umod\Header\UmodFileVersion) + " ("+Str(*Umod\Header\UmodFileVersion)+")"
  104.     Debug #TAB$+"CRC?:        0x" + Hex(*Umod\Header\CRC32)
  105.     Debug ""
  106.    
  107.     Debug "File directory:"
  108.     For i=0 To ArraySize(*Umod\DirectoryEntries())-1
  109.         Debug #TAB$+"Filename len.: "+*Umod\DirectoryEntries(i)\FilenameLength
  110.         Debug #TAB$+"Filename:      "+*Umod\DirectoryEntries(i)\Filename$
  111.         Debug #TAB$+"Data offset:   0x"+Hex(*Umod\DirectoryEntries(i)\FileByteOffset) + " ("+Str(*Umod\DirectoryEntries(i)\FileByteOffset)+")"
  112.         Debug #TAB$+"Data length:   "+*Umod\DirectoryEntries(i)\FileLength+" (bytes)"
  113.         Debug #TAB$+"Bit fields:    0x"+Hex(*Umod\DirectoryEntries(i)\FileBitFields)+" | 0b"+Bin(*Umod\DirectoryEntries(i)\FileBitFields)
  114.         Debug ""
  115.     Next
  116.    
  117.     Debug "File content: (Base64)"
  118.     For i=0 To ArraySize(*Umod\DirectoryEntries())-1
  119.         Debug #TAB$+*Umod\DirectoryEntries(i)\Filename$+":"
  120.         Debug Base64Encoder(*Umod\FileData(i), MemorySize(*Umod\FileData(i)))
  121.         Debug ""
  122.     Next
  123.    
  124.     Debug "END"
  125. EndProcedure
  126.  
  127. DebugUmodStructure(ReadUmod(#UMOD_DECALSTAY$))
  128. Debug #CRLF$+#CRLF$+"###############################"+#CRLF$+#CRLF$
  129. DebugUmodStructure(ReadUmod(#UMOD_EXCESSIVE$))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top