SHARE
TWEET

__xmodel__

a guest Oct 17th, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!usr/bin/python
  2.  
  3. """
  4. =============== COD2 XMODEL definition ===================         =============== COD4 XMODEL definition ===============
  5.  
  6. 2 bytes -> version (20)                                            2 bytes -> version (25)
  7. 29 bytes ->                                                        25 bytes ->
  8.  
  9. 4 bytes -> float (LOD distance)    |                               4 bytes -> float (LOD distance) |
  10.                                    |--> Read until FFFF?                                           |--> Read these until FFFF?
  11. STRINGZ -> lod name                |                               STRINGZ -> lod name             |
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18. ==========================================================          ======================================================
  19.  
  20.  
  21.  
  22.  
  23.  
  24. """
  25.  
  26. XMODEL1 = 'cod4/xmodel_character_russian_farmer'
  27. XMODEL2 = 'cod4/xmodel_com_crate01'
  28.  
  29. import struct
  30.  
  31. def current_pos(f):
  32.     print("Current position: " + str(f.tell()) + " (d)")
  33.  
  34. def read_null_terminated_string1(f):
  35.     byte = f.read(1)
  36.     string = ""
  37.     while struct.unpack('B', byte)[0] != 0:
  38.         string += byte
  39.         byte = f.read(1)
  40.     return string
  41.  
  42. def read_null_terminated_string2(f):
  43.     string = b''
  44.     c = None
  45.     while(c != b'\x00'):
  46.         c = f.read(1)
  47.         string += c
  48.     string = string.decode('utf-8').rstrip('\x00')
  49.     return string
  50.  
  51. def read_xmodel(xmodel):
  52.     print("Reading in: " + xmodel)
  53.     with open(xmodel, 'rb') as f:
  54.         current_pos(f)
  55.         version = struct.unpack('H', f.read(2))[0]
  56.         print("Version: " + str(version))
  57.  
  58.         f.read(25)
  59.         read_null_terminated_string1(f)
  60.  
  61.         lods = []
  62.         for i in range(4):
  63.             some_int = struct.unpack('<I', f.read(4))
  64.             lod_file_name = read_null_terminated_string2(f)
  65.  
  66.             if(lod_file_name != ""):
  67.                 lods.append({"name":lod_file_name})
  68.  
  69.         #print("lods: ")
  70.         #print(lods)
  71.  
  72.         current_pos(f)
  73.         f.read(4)
  74.         current_pos(f)
  75.         count = struct.unpack('<I', f.read(4))[0]
  76.         print("count: " + str(count))
  77.         for i in range(count):
  78.             subcount = struct.unpack('<I', f.read(4))[0]
  79.             print("subcount: " + str(subcount))
  80.             current_pos(f)
  81.             f.read((subcount * 48) + 36) # ???
  82.             current_pos(f)
  83.  
  84.  
  85.  
  86. # ===================== TESTING ===========================
  87. read_xmodel(XMODEL2)
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