Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Alemiz112 committed Dec 13, 2019
1 parent 3f04284 commit b9aa799
Showing 5 changed files with 130 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
out/
.idea/
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# RuntimeID-Fixer
# 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
5 changes: 5 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: RuntimeID-Fixer
author: WaterdogTeam
api: 3.0.0
main: waterdog\runtimeidfixer\RuntimeFixer
version: 1.2
114 changes: 114 additions & 0 deletions src/waterdog/runtimeidfixer/RuntimeFixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php
namespace waterdog\runtimeidfixer;
use pocketmine\event\Listener;
use pocketmine\plugin\PluginBase;
use pocketmine\network\mcpe\protocol\types\RuntimeBlockMapping;
use pocketmine\utils\MainLogger;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\mcpe\protocol\StartGamePacket;

use pocketmine\nbt\NetworkLittleEndianNBTStream;
use pocketmine\nbt\tag\ListTag;
use pocketmine\utils\BinaryDataException;
use function file_get_contents;

class RuntimeFixer extends PluginBase implements Listener{

const NUKKIT_BLOCK_STATES = "https://raw.githubusercontent.com/NukkitX/Nukkit/master/src/main/resources/runtime_block_states.dat";
const NUKKIT_BLOCK_STATES_OLD = "https://raw.githubusercontent.com/NukkitX/Nukkit/74ff17b98733159e788cb2763ea40886124980fc/src/main/resources/runtime_block_states.dat";

public function onEnable () {
$this->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);
}
}
}

0 comments on commit b9aa799

Please sign in to comment.