Sfoglia il codice sorgente

Merge pull request #6221 from MichalZr6/fix_for_Awar_map

Fix buffered stream growth & decode river type from low 3 bits (compat for “A War” AB map)
Ivan Savenko 1 giorno fa
parent
commit
2aa2157145
2 ha cambiato i file con 7 aggiunte e 5 eliminazioni
  1. 2 2
      lib/filesystem/CCompressedStream.cpp
  2. 5 3
      lib/mapping/MapReaderH3M.cpp

+ 2 - 2
lib/filesystem/CCompressedStream.cpp

@@ -65,10 +65,10 @@ void CBufferedStream::ensureSize(si64 size)
 	while(static_cast<si64>(buffer.size()) < size && !endOfFileReached)
 	{
 		si64 initialSize = buffer.size();
-		si64 currentStep = std::min<si64>(size, buffer.size());
+		si64 need = size - buffer.size();
 		// to avoid large number of calls at start
 		// this is often used to load h3m map headers, most of which are ~300 bytes in size
-		vstd::amax(currentStep, 512);
+		si64 currentStep = std::min<si64>(need, std::max<si64>(initialSize, si64{512}));
 
 		buffer.resize(initialSize + currentStep);
 

+ 5 - 3
lib/mapping/MapReaderH3M.cpp

@@ -199,9 +199,11 @@ RoadId MapReaderH3M::readRoad()
 
 RiverId MapReaderH3M::readRiver()
 {
-	RiverId result(readInt8());
-	assert(result.getNum() <= features.riversCount);
-	return result;
+	const uint8_t raw = readInt8();
+	// Keep low 3 bits as river type (0..4); discard high-bit flags set by some editors (HotA ?)
+	const uint8_t type = raw & 0x07;
+	assert(type <= features.riversCount);
+	return RiverId(type);
 }
 
 PrimarySkill MapReaderH3M::readPrimary()