spigot/CraftBukkit-Patches/0098-Allow-Reading-Old-Large-Chunks.patch
2020-11-03 07:00:00 +11:00

46 lines
2.1 KiB
Diff

From ca92c9762a83b7a0b093eb7f43817ec7e0f45617 Mon Sep 17 00:00:00 2001
From: md_5 <git@md-5.net>
Date: Tue, 19 Feb 2019 22:30:00 +1100
Subject: [PATCH] Allow Reading Old Large Chunks
The size of chunks in the region format is overdetermined. In particular their size on disk is indicated by both a sector count in the header, and actual size in the body.
If their size would overflow the header field (>= 255 sectors), it can just be read directly from the body instead.
This code/concept was adapted from MinecraftForge.
diff --git a/src/main/java/net/minecraft/server/RegionFile.java b/src/main/java/net/minecraft/server/RegionFile.java
index 831636803..49387e812 100644
--- a/src/main/java/net/minecraft/server/RegionFile.java
+++ b/src/main/java/net/minecraft/server/RegionFile.java
@@ -74,6 +74,14 @@ public class RegionFile implements AutoCloseable {
if (l != 0) {
int i1 = b(l);
int j1 = a(l);
+ // Spigot start
+ if (j1 == 255) {
+ // We're maxed out, so we need to read the proper length from the section
+ ByteBuffer realLen = ByteBuffer.allocate(4);
+ this.dataFile.read(realLen, i1 * 4096);
+ j1 = (realLen.getInt(0) + 4) / 4096 + 1;
+ }
+ // Spigot end
if (i1 < 2) {
RegionFile.LOGGER.warn("Region file {} has invalid sector at index: {}; sector {} overlaps with header", java_nio_file_path, k, i1);
@@ -109,6 +117,13 @@ public class RegionFile implements AutoCloseable {
} else {
int j = b(i);
int k = a(i);
+ // Spigot start
+ if (k == 255) {
+ ByteBuffer realLen = ByteBuffer.allocate(4);
+ this.dataFile.read(realLen, j * 4096);
+ k = (realLen.getInt(0) + 4) / 4096 + 1;
+ }
+ // Spigot end
int l = k * 4096;
ByteBuffer bytebuffer = ByteBuffer.allocate(l);
--
2.25.1