diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8c2dd28 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +out/ +.idea/ diff --git a/README.md b/README.md index 7fe998e..51f1393 100644 --- a/README.md +++ b/README.md @@ -1 +1,7 @@ -# RuntimeID-Fixer \ No newline at end of file +# WaterDog RuntimeID-Fixer +This plugin is should be used by PocketMine servers. It is created to remove block palette randomizing, what +can occur while using proxy. This should fix NukkitX -> PMMP transfers as well. +>Warning: It may not work on some pmmp forks! + +### Special Thanks +To SynapsePM Team. Plugin is discontinued build of SynapsePMs RuntimeID-Fix \ No newline at end of file diff --git a/plugin.yml b/plugin.yml new file mode 100644 index 0000000..62085fb --- /dev/null +++ b/plugin.yml @@ -0,0 +1,5 @@ +name: RuntimeID-Fixer +author: WaterdogTeam +api: 3.0.0 +main: waterdog\runtimeidfixer\RuntimeFixer +version: 1.2 diff --git a/src/waterdog/runtimeidfixer/RuntimeFixer.php b/src/waterdog/runtimeidfixer/RuntimeFixer.php new file mode 100644 index 0000000..9f34661 --- /dev/null +++ b/src/waterdog/runtimeidfixer/RuntimeFixer.php @@ -0,0 +1,114 @@ +init(); + } + + public function init() : void{ + try { + $tag = null; + $file = null; + try{ + $file = file_get_contents(self::NUKKIT_BLOCK_STATES, false, stream_context_create([ + "ssl" => [ + "verify_peer" => false, + "verify_peer_name" => false, + ] + ])); + + /** @var ListTag $tag */ + $tag = (new NetworkLittleEndianNBTStream())->read($file); + }catch(BinaryDataException $e){ + throw new RuntimeException("", 0, $e); + } + + $blockReflect = new \ReflectionClass(RuntimeBlockMapping::class); + + $legacyToRuntimeMap = $blockReflect->getProperty("legacyToRuntimeMap"); + $legacyToRuntimeMap->setAccessible(true); + + $runtimeToLegacyMap = $blockReflect->getProperty("runtimeToLegacyMap"); + $runtimeToLegacyMap->setAccessible(true); + + $bedrockKnownStates = $blockReflect->getProperty("bedrockKnownStates"); + $bedrockKnownStates->setAccessible(true); + + $registerMapping = $blockReflect->getMethod("registerMapping"); + $registerMapping->setAccessible(true); + + $randomizeTable = $blockReflect->getMethod("randomizeTable"); + $randomizeTable->setAccessible(true); + + + + /* Null values first*/ + $runtimeToLegacyMap->setValue([]); + $legacyToRuntimeMap->setValue([]); + $bedrockKnownStates->setValue($tag->getValue()); + + /** @var CompoundTag $state */ + $decompressed = []; + + $runtimeIdAllocator = 0; + $runtimeToLegacy = []; + $legacyToRuntime = []; + + foreach($tag->getAllValues() as $state){ + $runtimeId = $runtimeIdAllocator; + $runtimeIdAllocator++; + + $block = $state->getCompoundTag("block"); + $id = $state->getShort("id"); + $name = $block->getString("name"); + + $meta = [0]; + if ($state->hasTag("meta")){ + $meta = $state->getIntArray("meta"); + $state->removeTag("meta"); + } + + /* Save data cor feature references*/ + $decompressed[$runtimeId] = [ + "name" => $name, + "states" => $block->getCompoundTag("states"), + "data" => $meta[0], + "legacy_id" => $id + ]; + + $runtimeToLegacy[$runtimeId] = $id << 4 | $meta[0]; + foreach ($meta as $val){ + $legacyId = $id << 4 | $val; + $legacyToRuntime[$legacyId] = $runtimeId; + } + } + + //$bedrockKnownStates->setValue($decompressed); + $runtimeToLegacyMap->setValue($runtimeToLegacy); + $legacyToRuntimeMap->setValue($legacyToRuntime); + + $startGameReflect = new \ReflectionClass(StartGamePacket::class); + $blockTableCache = $startGameReflect->getProperty("blockTableCache"); + $blockTableCache->setAccessible(true); + $blockTableCache->setValue($file); + }catch (\ReflectionException $e) { + MainLogger::getLogger()->logException($e); + } + } + }