Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!usr/bin/python
- """
- =============== COD2 XMODEL definition =================== =============== COD4 XMODEL definition ===============
- 2 bytes -> version (20) 2 bytes -> version (25)
- 29 bytes -> 25 bytes ->
- 4 bytes -> float (LOD distance) | 4 bytes -> float (LOD distance) |
- |--> Read until FFFF? |--> Read these until FFFF?
- STRINGZ -> lod name | STRINGZ -> lod name |
- ========================================================== ======================================================
- """
- XMODEL1 = 'cod4/xmodel_character_russian_farmer'
- XMODEL2 = 'cod4/xmodel_com_crate01'
- import struct
- def current_pos(f):
- print("Current position: " + str(f.tell()) + " (d)")
- def read_null_terminated_string1(f):
- byte = f.read(1)
- string = ""
- while struct.unpack('B', byte)[0] != 0:
- string += byte
- byte = f.read(1)
- return string
- def read_null_terminated_string2(f):
- string = b''
- c = None
- while(c != b'\x00'):
- c = f.read(1)
- string += c
- string = string.decode('utf-8').rstrip('\x00')
- return string
- def read_xmodel(xmodel):
- print("Reading in: " + xmodel)
- with open(xmodel, 'rb') as f:
- current_pos(f)
- version = struct.unpack('H', f.read(2))[0]
- print("Version: " + str(version))
- f.read(25)
- read_null_terminated_string1(f)
- lods = []
- for i in range(4):
- some_int = struct.unpack('<I', f.read(4))
- lod_file_name = read_null_terminated_string2(f)
- if(lod_file_name != ""):
- lods.append({"name":lod_file_name})
- #print("lods: ")
- #print(lods)
- current_pos(f)
- f.read(4)
- current_pos(f)
- count = struct.unpack('<I', f.read(4))[0]
- print("count: " + str(count))
- for i in range(count):
- subcount = struct.unpack('<I', f.read(4))[0]
- print("subcount: " + str(subcount))
- current_pos(f)
- f.read((subcount * 48) + 36) # ???
- current_pos(f)
- # ===================== TESTING ===========================
- read_xmodel(XMODEL2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement