@@ -23,6 +23,7 @@ template<BufferStreamPODType T>
2323	}
2424
2525	BufferStreamReadOnly stream{*data};
26+ 	stream.set_big_endian (bsp.isConsole ());
2627	std::vector<T> out;
2728	callback (bsp, stream, out);
2829	return  out;
@@ -104,6 +105,22 @@ void BSP::setMapRevision(uint32_t mapRevision) {
104105	this ->stagedMapRevision  = mapRevision;
105106}
106107
108+ bool  BSP::isL4D2 () const  {
109+ 	return  this ->l4d2 ;
110+ }
111+ 
112+ void  BSP::setL4D2 (bool  isL4D2) {
113+ 	this ->l4d2  = isL4D2;
114+ }
115+ 
116+ bool  BSP::isConsole () const  {
117+ 	return  this ->console ;
118+ }
119+ 
120+ void  BSP::setConsole (bool  isConsole) {
121+ 	this ->console  = isConsole;
122+ }
123+ 
107124bool  BSP::hasLump (BSPLump lumpIndex) const  {
108125	if  (this ->path .empty ()) {
109126		return  false ;
@@ -351,6 +368,7 @@ bool BSP::bake(std::string_view outputPath) {
351368
352369	std::vector<std::byte> out;
353370	BufferStream stream{out};
371+ 	stream.set_big_endian (this ->console );
354372
355373	stream << BSP_SIGNATURE << this ->stagedVersion ;
356374	if  (this ->stagedVersion  == 27 ) {
@@ -421,7 +439,7 @@ bool BSP::bake(std::string_view outputPath) {
421439
422440			const  auto  curPos = stream.tell ();
423441			stream.seek_u (lumpsHeaderOffset + (i * sizeof (Lump)));
424- 			if  (!this ->isL4D2 ) {
442+ 			if  (!this ->l4d2 ) {
425443				stream
426444					.write <uint32_t >(gameLumpOffset)
427445					.write <uint32_t >(curPos - gameLumpOffset)
@@ -442,7 +460,7 @@ bool BSP::bake(std::string_view outputPath) {
442460			const  auto & lumpPair = this ->stagedLumps .at (i);
443461			const  auto  curPos = stream.tell ();
444462			stream.seek_u (lumpsHeaderOffset + (i * sizeof (Lump)));
445- 			if  (!this ->isL4D2 ) {
463+ 			if  (!this ->l4d2 ) {
446464				stream
447465					.write <uint32_t >(curPos)
448466					.write <uint32_t >(lumpPair.second .size ())
@@ -466,7 +484,7 @@ bool BSP::bake(std::string_view outputPath) {
466484			stream.seek_u (lumpsHeaderOffset + (i * sizeof (Lump)));
467485
468486			auto & lump = this ->header .lumps [i];
469- 			if  (!this ->isL4D2 ) {
487+ 			if  (!this ->l4d2 ) {
470488				stream
471489					.write <uint32_t >(curPos)
472490					.write <uint32_t >(lump.length )
@@ -494,7 +512,7 @@ bool BSP::bake(std::string_view outputPath) {
494512		}
495513	}
496514
497- 	out.resize (stream.tell ());
515+ 	out.resize (stream.size ());
498516	if  (!fs::writeFileBuffer (outputPath.empty () ? this ->path  : std::string{outputPath}, out)) {
499517		return  false ;
500518	}
@@ -511,9 +529,12 @@ bool BSP::readHeader() {
511529	}
512530	reader.seek_in (0 );
513531
514- 	if  (reader.read <uint32_t >()  != BSP_SIGNATURE) {
532+ 	if  (auto  signature =  reader.read <uint32_t >(); signature  != BSP_SIGNATURE && signature != BSP_CONSOLE_SIGNATURE ) {
515533		//  File is not a BSP
516534		return  false ;
535+ 	} else  if  (signature == BSP_CONSOLE_SIGNATURE) {
536+ 		this ->console  = true ;
537+ 		reader.set_big_endian (true );
517538	}
518539	this ->header .version  = reader.read <uint32_t >();
519540
@@ -539,8 +560,8 @@ bool BSP::readHeader() {
539560				break ;
540561			}
541562		}
542- 		this ->isL4D2  = i == BSP_LUMP_COUNT;
543- 		if  (this ->isL4D2 ) {
563+ 		this ->l4d2  = i == BSP_LUMP_COUNT;
564+ 		if  (this ->l4d2 ) {
544565			//  Swap fields around
545566			for  (i = 0 ; i < BSP_LUMP_COUNT; i++) {
546567				std::swap (this ->header .lumps [i].offset , this ->header .lumps [i].version );
@@ -693,6 +714,7 @@ std::vector<BSPGameLump> BSP::parseGameLumps(bool decompress) const {
693714		return  lumps;
694715	}
695716	BufferStreamReadOnly stream{*gameLumpData};
717+ 	stream.set_big_endian (this ->console );
696718
697719	lumps.resize (stream.read <uint32_t >());
698720	for  (auto & lump : lumps) {
0 commit comments