Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
thorsummoner
ttt_terrorcon
Commits
8c167c02
Commit
8c167c02
authored
Sep 18, 2021
by
dylan grafmyre
Browse files
pyvmf bsp header parser
parent
c16f9b67
Changes
4
Hide whitespace changes
Inline
Side-by-side
pyvmf/bsp.py
0 → 100644
View file @
8c167c02
import
sys
import
struct
lump_t
=
struct
.
Struct
(
'iii4c'
)
class
Lump
:
size
=
lump_t
.
size
def
__init__
(
self
,
bin_
):
tup
=
lump_t
.
unpack
(
bin_
)
self
.
fileofs
,
self
.
filelen
,
self
.
version
=
tup
[:
3
]
self
.
fourcc
=
tup
[
3
:]
@
property
def
fourcc_b
(
self
):
return
b
''
.
join
(
self
.
fourcc
)
def
__repr__
(
self
):
if
any
((
self
.
fileofs
,
self
.
filelen
,
self
.
version
,
any
(
i
!=
b
'
\x00
'
for
i
in
self
.
fourcc
[
0
]))):
return
'<{s.__class__.__name__}{version}{ofs}{len}{fourcc}>'
.
format
(
s
=
self
,
version
=
(
'.v{}'
.
format
(
self
.
version
)
if
self
.
version
else
''
),
ofs
=
(
' ofs:{}'
.
format
(
self
.
fileofs
)
if
self
.
fileofs
else
''
),
len
=
(
' len:{}'
.
format
(
self
.
filelen
)
if
self
.
filelen
else
''
),
fourcc
=
(
' fourcc:{}'
.
format
(
self
.
fourcc_b
)
if
any
(
i
!=
b
'
\x00
'
for
i
in
self
.
fourcc
)
else
''
),
)
return
'<{s.__class__.__name__} null>'
.
format
(
s
=
self
)
@
classmethod
def
iter_unpack
(
cls
,
bins
):
i
=
0
bins_len
=
len
(
bins
)
while
i
<
bins_len
:
yield
cls
(
bins
[
0
:
lump_t
.
size
])
i
+=
lump_t
.
size
class
Dheader
:
# little-endian "VBSP" 0x50534256
# define IDBSPHEADER (('P'<<24)+('S'<<16)+('B'<<8)+'V')
VBSP
=
((
ord
(
'P'
)
<<
24
)
+
(
ord
(
'S'
)
<<
16
)
+
(
ord
(
'B'
)
<<
8
)
+
ord
(
'V'
))
def
__init__
(
self
,
file_
):
self
.
ident
,
self
.
version
=
struct
.
unpack
(
'ii'
,
file_
.
read
(
8
))
if
self
.
ident
!=
self
.
VBSP
:
raise
TypeError
(
'file is missing VBSP identifier'
)
self
.
lumps
=
list
(
Lump
.
iter_unpack
(
file_
.
read
(
Lump
.
size
*
64
)))
self
.
map_revision
,
=
struct
.
unpack
(
'i'
,
file_
.
read
(
4
))
def
__repr__
(
self
):
return
'<{s.__class__.__name__} VBSP lumps:64 rev:{s.map_revision}>'
.
format
(
s
=
self
)
with
open
(
sys
.
argv
[
1
],
'rb'
)
as
fh
:
bsp
=
Dheader
(
fh
)
print
(
bsp
)
#print(bsp.lumps)
pyvmf/cfg.py
View file @
8c167c02
...
...
@@ -6,7 +6,7 @@ import io
import
pyvmf.objects
import
pyvmf.objects
as
o
import
pyvmf.re
as
r
import
pyvmf.re
_
as
r
import
pyvmf.exceptions
as
e
CFG_TOKENS
=
{
...
...
pyvmf/re.py
→
pyvmf/re
_
.py
View file @
8c167c02
File moved
pyvmf/vmf.py
View file @
8c167c02
...
...
@@ -6,7 +6,7 @@ import io
import
pyvmf.objects
import
pyvmf.objects
as
o
import
pyvmf.re
as
r
import
pyvmf.re
_
as
r
import
pyvmf.exceptions
as
e
VMF_TOKENS
=
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment