Skip to content

Commit b82e086

Browse files
committed
Updates
1 parent 26d3475 commit b82e086

File tree

5 files changed

+110
-13
lines changed

5 files changed

+110
-13
lines changed

api2/index.php

Lines changed: 96 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
const debugOn = false;
4+
25
set_error_handler(function($n, $msg, $file, $line){
36
header("Content-Type: text/plain");
47
echo "Error: $msg at $file#$line";
@@ -7,7 +10,7 @@
710
});
811
if(isset($_FILES["phar"])){
912
$newApi = "2.0.0";
10-
if(isset($_REQUEST["api"])) $newApi = $_REQUEST["api"];
13+
if(isset($_REQUEST["diffapi"]) and $_REQUEST["diffapi"] === "on" and isset($_REQUEST["api"])) $newApi = $_REQUEST["api"];
1114
$path = $_FILES["phar"]["tmp_name"];
1215
$extended = $path . ".phar";
1316
move_uploaded_File($path, $extended);
@@ -29,7 +32,79 @@
2932
$yaml["api"][] = "2.0.0";
3033
$contents = yaml_emit($yaml);
3134
$phar->addFromString("plugin.yml", $contents);
35+
36+
if(debugOn) header("Content-Type: text/plain");
37+
38+
$replaceUse = ($_REQUEST["nbt-use"] ?? "off") === "on";
39+
$replaceFQN = ($_REQUEST["nbt-fqn"] ?? "off") === "on";
40+
$replaceNew = ($_REQUEST["nbt-new"] ?? "off") === "on";
41+
$replaceInstanceOf = ($_REQUEST["nbt-instanceof"] ?? "off") === "on";
42+
if($replaceUse or $replaceFQN or $replaceNew or $replaceInstanceOf){
43+
$refactorTable = [
44+
"ByteArray" => "ByteArrayTag",
45+
"Byte" => "ByteTag",
46+
"Compound" => "CompoundTag",
47+
"Double" => "DoubleTag",
48+
"End" => "EndTag",
49+
"Float" => "FloatTag",
50+
"IntArray" => "IntArrayTag",
51+
"Int" => "IntTag",
52+
"Enum" => "ListTag",
53+
"Long" => "LongTag",
54+
"Short" => "ShortTag",
55+
"String" => "StringTag"
56+
];
57+
foreach(new \RecursiveIteratorIterator($phar) as $localName => $file){
58+
$fn = $file->getFileName();
59+
$localName = substr($localName, 8 + strlen($extended));
60+
if(substr($fn, -4) === ".php"){
61+
$c = $o = file_get_contents($file->getPathName());
62+
if($replaceUse){
63+
$ns = "pocketmine\\nbt\\tag\\";
64+
$quotedNs = preg_quote($ns);
65+
$names = implode("|", array_map("preg_quote", array_keys($refactorTable)));
66+
$c = preg_replace_callback("/use[ \t\n\r]+$quotedNs($names)[ \t\n\r]*;/i", function($match) use($ns, $refactorTable){
67+
return "use $ns" . $refactorTable[$match[1]] . ";";
68+
}, $c);
69+
}
70+
if($replaceFQN){
71+
foreach($refactorTable as $from => $to){
72+
$from = "\\pocketmine\\nbt\\tag\\$from";
73+
$to = "\\pocketmine\\nbt\\tag\\$to";
74+
$c = str_replace($from, $to, $c);
75+
}
76+
}
77+
if($replaceNew){
78+
$ns = "pocketmine\\nbt\\tag\\";
79+
$quotedNs = preg_quote($ns);
80+
$names = implode("|", array_map("preg_quote", array_keys($refactorTable)));
81+
$c = preg_replace_callback("/new[ \t\n\r]+($names)[ \t\n\r]*([\(\);,])/i", function($match) use($ns, $refactorTable){
82+
return "new " . $refactorTable[$match[1]] . $match[2];
83+
}, $c);
84+
}
85+
if($replaceInstanceOf){
86+
$ns = "pocketmine\\nbt\\tag\\";
87+
$quotedNs = preg_quote($ns);
88+
$names = implode("|", array_map("preg_quote", array_keys($refactorTable)));
89+
$c = preg_replace_callback("/instanceof[ \t\n\r]+$quotedNs($names)/i", function($match) use($ns, $refactorTable){
90+
return "instanceof " . $refactorTable[$match[1]];
91+
}, $c);
92+
}
93+
if(debugOn){
94+
echo $localName, " ($fn):\n", $c, "\n\n";
95+
}
96+
if($c !== $o){
97+
$phar->addFromString($localName, $c);
98+
}
99+
}
100+
}
101+
}
102+
32103
$phar->stopBuffering();
104+
if(debugOn){
105+
echo base64_encode(file_get_contents($extended));
106+
die;
107+
}
33108
header("Content-Type: application/octet-stream");
34109
echo file_get_contents($extended);
35110
exit;
@@ -41,17 +116,31 @@
41116
</head>
42117
<body>
43118
<h1>API 2.0.0 injection</h1>
44-
<p>Before using this tool, please carefully read the following cautions:</p>
119+
<p>Before using this tool, please carefully read the following caution:</p>
45120
<ul>
46-
<li>This tool only <em>forces</em> the plugin to say that it supports API 2.0.0 (PHP 7 update). It will not fix the actual incompatibility issues.</li>
121+
<li>This tool only <em>forces</em> the plugin to say that it supports API 2.0.0 (PHP 7 update), and optionally, blindly replaces some specific backwards-incompatible changes in the phar. It will not fix the actual incompatibility issues.</li>
47122
<li>If errors happen after using phars downloaded from this page, unintsall it immediately.</li>
48-
<li>Click <button onclick='document.getElementById("upload").disabled = false;'>this button</button> if you have read the above.</li>
123+
<li>Click <span onclick='alert("Thanks for carefully reading the caution!"); document.getElementById("upload").disabled = false;'>these three words</span> if you have read the above.</li>
49124
</ul>
50125
<hr>
51126
<form action="updated.phar" method="post" enctype="multipart/form-data">
52-
<input type="file" name="phar"><br>
53-
No, I don't want API <code>2.0.0</code>. I want something else: <input type="text" name="api" value="2.0.0"><br>
54-
<input type="submit" id="upload" value="Inject" disabled>
127+
<p><input type="file" name="phar"></p>
128+
<ul>
129+
<li>
130+
<input type="checkbox" name="diffapi" onclick='document.getElementById("apiInput").disabled = false;'> No, I don't want API <code>2.0.0</code>.
131+
I want something else: <input id="apiInput" type="text" name="api" value="2.0.0" disabled>
132+
</li>
133+
<li>
134+
Replace the following usage of NBT tags:
135+
<ul>
136+
<li><input type="checkbox" name="nbt-use" checked> <code>use pocketmine\nbt\tag\****Tag</code></li>
137+
<li><input type="checkbox" name="nbt-fqn" checked> fully-qualified <code>\pocketmine\nbt\tag\****Tag</code></li>
138+
<li><input type="checkbox" name="nbt-new" checked> <code>new ****Tag</code></li>
139+
<li><input type="checkbox" name="nbt-instanceof" checked> <code>instanceof ****Tag</code></li>
140+
</ul>
141+
</li>
142+
</ul>
143+
<p><input type="submit" id="upload" value="Inject" disabled></p>
55144
</form>
56145
</body>
57146
</html>

pg

Submodule pg updated from 9ca2243 to f669c9d

phar.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
<html>
22
<head>
33
<title>Create phar</title>
4+
<script>
5+
function fillPmStub(){
6+
document.getElementById("stubInput").value = '<?= "<?php" ?> define("pocketmine\\\\PATH", "phar://". __FILE__ ."/"); require_once("phar://". __FILE__ ."/src/pocketmine/PocketMine.php"); __HALT_COMPILER();';
7+
}
8+
</script>
49
</head>
5-
<body><font face="Comic Sans MS">
10+
<body><font face="Helvetica">
611
<h1>Phar maker</h1>
712
<h3>How to use</h3>
813
<ol>
@@ -15,10 +20,11 @@
1520
<p><input type="file" name="file"></p>
1621
<p>Stub (Leave as default unless you know what it is):
1722
<?php
18-
echo "<input type=\"text\" name=\"stub\" value=\"";
23+
echo '<input type="text" name="stub" value="';
1924
echo '<?php __HALT_COMPILER();';
20-
echo "\" size=\"32\">";
25+
echo '" size="100" id="stubInput">';
2126
?>
27+
<button onclick="fillPmStub(); return false;">Use the PocketMine-MP.phar stub</button>
2228
</p>
2329
<p>Tune the plugin using the following methods: <br>
2430
<input type="checkbox" name="tune_top_namespace_optimization">

pocketmine-frame-left.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
</style>
2121
</head>
2222
<body>
23-
<font face="Comic Sans MS">
23+
<font face="Helvetica">
2424
<ul>
2525
<li><a href="/phar.php" target="content">Zip to Phar converter</a></li>
2626
<li><a href="/unphar.php" target="content">Phar to Zip converter</a></li>
@@ -29,6 +29,8 @@
2929
<li><a href="/varDump.php" target="content"><code>var_dump()</code> viewer (<code>xdebug</code>-style dumps are
3030
not supported yet)</a></li>
3131
<li><a href="/crashdump/" target="content">PocketMine Crash Dump parsing</a></li>
32+
<li><a href="/pmb/" target="content">PocketMine phar build archive</a></li>
33+
<li><a href="/api2/" target="content">Plugin API 2.0.0 Injector</a></li>
3234
<li><a href="#" class="disabled"><strong>[W.I.P.]</strong> Plugin Generator</a></li>
3335
</ul>
3436
<input type="button" value="Reload content frame" onclick="parent.content.location.reload()">

pocketmine-frame-up.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<html><head><title>PocketMine Plugin Making Tools</title></head>
2-
<body><font face="Comic Sans MS">
2+
<body><font face="Helvetica">
33
<font style="font-size: 24px; font-weight: bolder;">
44
<a name="title">PocketMine-MP Plugin Making Tools</a>
55
</font>

0 commit comments

Comments
 (0)