illwieckz

quick & dirty navcon parser

Sep 12th, 2021 (edited)
955
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.44 KB | None | 0 0
  1. #! /usr/bin/env python3
  2. #-*- coding: UTF-8 -*-
  3.  
  4. ### Legal
  5. #
  6. # Author:  Thomas DEBESSE <dev@illwieckz.net>
  7. # License: CC0 1.0
  8. #
  9.  
  10. import struct
  11. import sys
  12.  
  13. size_unsigned_char = 1
  14. size_unsigned_short = 2
  15. size_unsigned_int = 4
  16. size_int = 4
  17. size_float = 4
  18.  
  19. for file_name in sys.argv[1:]:
  20.     print("# file: " + file_name)
  21.  
  22.     file_blob = open(file_name, "rb")
  23.  
  24.     header_version = struct.unpack('<i', file_blob.read(size_int))[0]
  25.     print("# header_version: " + str(header_version))
  26.  
  27.     con_count = struct.unpack('<i', file_blob.read(size_int))[0]
  28.     print("# con_count: " + str(con_count))
  29.  
  30.     print("# format: x1 z1 y1 x2 z2 y2 rad flags areas dirs userids")
  31.  
  32.     con_list = [{} for i in range(0, con_count)]
  33.  
  34.     for i in range(0, con_count):
  35.         verts_bytes = file_blob.read(6 * size_float)
  36.         verts_floats = struct.unpack('ffffff', verts_bytes)
  37.         con_list[i]["verts"] = verts_floats
  38.  
  39.     for i in range(0, con_count):
  40.         rad_bytes = file_blob.read(size_float)
  41.         rad_float = struct.unpack('f', rad_bytes)[0]
  42.         con_list[i]["rad"] = rad_float
  43.  
  44.     for i in range(0, con_count):
  45.         flags_bytes = file_blob.read(size_unsigned_short)
  46.         flags_unsigned_short = struct.unpack("H", flags_bytes)[0]
  47.         con_list[i]["flags"] = flags_unsigned_short
  48.  
  49.     for i in range(0, con_count):
  50.         areas_bytes = file_blob.read(size_unsigned_char)
  51.         areas_unsigned_char = struct.unpack("B", areas_bytes)[0]
  52.         con_list[i]["areas"] = areas_unsigned_char
  53.  
  54.     for i in range(0, con_count):
  55.         dirs_bytes = file_blob.read(size_unsigned_char)
  56.         dirs_unsigned_char = struct.unpack("B", dirs_bytes)[0]
  57.         con_list[i]["dirs"] = dirs_unsigned_char
  58.  
  59.     for i in range(0, con_count):
  60.         userids_bytes = file_blob.read(size_unsigned_int)
  61.         userids_unsigned_int = struct.unpack("I", userids_bytes)[0]
  62.         con_list[i]["userids"] = userids_unsigned_int
  63.  
  64.     file_blob.close()
  65.  
  66.     for con in con_list:
  67.         for key in con.keys():
  68.             if key == "verts":
  69.                 for i in con[key]:
  70.                     print(i, end=' ')
  71.  
  72.             else:
  73.                 end = ' '
  74.                 if key == "userids":
  75.                     end='\n'
  76.  
  77.                 print(con[key], end=end)
  78.  
  79.     print()
  80.  
  81. """
  82. # file: /home/illwieckz/.local/share/unvanquished/game/maps/chasm-level0.navcon
  83. # header_version: 2
  84. # con_count: 2
  85. # format: x1 z1 y1 x2 z2 y2 rad flags areas dirs userids
  86. -1623.585205078125 226.0 1772.6363525390625 -1665.3758544921875 76.25360107421875 1898.5557861328125 50.0 1 63 0 0
  87. -1219.1612548828125 250.0 2232.142578125 -1232.4483642578125 142.98577880859375 2318.962646484375 50.0 1 63 1 0
  88. """
Add Comment
Please, Sign In to add comment