add java client source
This commit is contained in:
commit
c7a15fdc7d
98 files changed
+80145
No files matched your search
@@ -0,0 +1,90 @@
|
||||
"""Build the small JNI binding table from the official 1.21.1 client mapping."""
|
||||
import hashlib
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
MAPPING_SHA1 = "2244b6f072256667bcd9a73df124d6c58de77992"
|
||||
PRIMITIVES = dict(zip("void boolean byte char short int long float double".split(), "VZBCSIJFD"))
|
||||
|
||||
|
||||
def descriptor(type_name, classes):
|
||||
dimensions = 0
|
||||
while type_name.endswith("[]"):
|
||||
dimensions += 1
|
||||
type_name = type_name[:-2]
|
||||
if type_name in PRIMITIVES:
|
||||
return "[" * dimensions + PRIMITIVES[type_name]
|
||||
return "[" * dimensions + "L" + classes.get(type_name, type_name).replace(".", "/") + ";"
|
||||
|
||||
|
||||
def read_mapping(raw):
|
||||
classes, members = {}, {}
|
||||
owner = None
|
||||
for line in raw.decode("utf-8").splitlines():
|
||||
if not line or line.startswith("#") or " -> " not in line:
|
||||
continue
|
||||
left, right = line.strip().rsplit(" -> ", 1)
|
||||
if not line[0].isspace():
|
||||
owner = left
|
||||
classes[left] = right.removesuffix(":")
|
||||
members[left] = {}
|
||||
continue
|
||||
match = re.fullmatch(r"(?:\d+:\d+:)?(\S+) (\S+?)(?::\d+(?::\d+)?)?", left)
|
||||
if match:
|
||||
result, member = match.groups()
|
||||
members[owner].setdefault(member, set()).add((result, right))
|
||||
return classes, members
|
||||
|
||||
|
||||
def main(mapping_path, spec_path, output_path):
|
||||
raw = Path(mapping_path).read_bytes()
|
||||
if hashlib.sha1(raw).hexdigest() != MAPPING_SHA1:
|
||||
raise ValueError("expected the unmodified Mojang Java 1.21.1 client mappings")
|
||||
classes, members = read_mapping(raw)
|
||||
aliases, rows = {}, []
|
||||
for line in Path(spec_path).read_text().splitlines():
|
||||
if not line.strip() or line.startswith("#"):
|
||||
continue
|
||||
kind, alias, owner, *entry = line.split()
|
||||
if kind == "class":
|
||||
aliases[alias] = owner
|
||||
rows.append((alias, "Class", owner, classes.get(owner, owner), "", "", "", ""))
|
||||
continue
|
||||
owner = aliases[owner]
|
||||
if kind == "ctor":
|
||||
member = "<init>" + entry[0]
|
||||
result, obfuscated = "void", "<init>"
|
||||
else:
|
||||
member = entry[0]
|
||||
variants = members[owner].get(member, ())
|
||||
if len(entry) == 2:
|
||||
variants = [variant for variant in variants if variant[0] == entry[1]]
|
||||
if len(variants) != 1:
|
||||
raise ValueError(f"{alias}: expected one declaration of {owner}.{member}, found {variants}")
|
||||
result, obfuscated = next(iter(variants))
|
||||
name, separator, arguments = member.partition("(")
|
||||
signatures = []
|
||||
for class_map in ({}, classes):
|
||||
signature = descriptor(result, class_map)
|
||||
if separator:
|
||||
arguments_list = arguments.removesuffix(")").split(",") if arguments != ")" else []
|
||||
signature = "(" + "".join(descriptor(arg, class_map) for arg in arguments_list) + ")" + signature
|
||||
signatures.append(signature)
|
||||
rows.append((alias, "Constructor" if kind == "ctor" else kind.title(), owner,
|
||||
classes.get(owner, owner), name, obfuscated, *signatures))
|
||||
body = ["// Generated from Mojang Java 1.21.1 mappings.", "#pragma once",
|
||||
"enum class Kind { Class, Field, Staticfield, Method, Staticmethod, Constructor };",
|
||||
"enum Binding {"]
|
||||
body.extend(f" {row[0]}," for row in rows)
|
||||
body.extend([" BindingCount", "};",
|
||||
"struct Declaration { Kind kind; const char* owner[2]; const char* name[2]; const char* signature[2]; };",
|
||||
"inline constexpr Declaration declarations[] = {"])
|
||||
for _, kind, named_owner, obf_owner, named, obf, named_sig, obf_sig in rows:
|
||||
body.append(f' {{Kind::{kind}, {{"{named_owner}", "{obf_owner}"}}, {{"{named}", "{obf}"}}, {{"{named_sig}", "{obf_sig}"}}}},')
|
||||
body.extend(["};", ""])
|
||||
Path(output_path).write_text("\n".join(body), encoding="utf-8")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(*sys.argv[1:])
|
||||
@@ -0,0 +1,13 @@
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$root = Split-Path -Parent $PSScriptRoot
|
||||
$deps = Join-Path $root 'build/deps'
|
||||
New-Item -ItemType Directory -Path $deps -Force | Out-Null
|
||||
$version = (Invoke-RestMethod 'https://piston-meta.mojang.com/mc/game/version_manifest_v2.json').versions |
|
||||
Where-Object id -eq '1.21.1' | Select-Object -First 1
|
||||
if (-not $version) { throw 'Mojang did not list Java 1.21.1.' }
|
||||
$mappings = (Invoke-RestMethod $version.url).downloads.client_mappings
|
||||
$file = Join-Path $deps 'client.txt'
|
||||
Invoke-WebRequest $mappings.url -OutFile $file
|
||||
if ((Get-FileHash -LiteralPath $file -Algorithm SHA1).Hash -ne '2244b6f072256667bcd9a73df124d6c58de77992') {
|
||||
throw 'The downloaded mappings did not match Mojang Java 1.21.1.'
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
"""Stage Bedrock views with Java platform adapters. Rendering stays upstream."""
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
|
||||
def replace(text, old, new):
|
||||
if text.count(old) != 1:
|
||||
raise ValueError(f"Bedrock UI adapter expected one occurrence of {old!r}")
|
||||
return text.replace(old, new)
|
||||
|
||||
|
||||
def region(text, start, end, content):
|
||||
left = text.index(start)
|
||||
right = text.index(end, left)
|
||||
return text[:left] + content + text[right:]
|
||||
|
||||
|
||||
def generate(src, out):
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
for name, location in {
|
||||
"clickgui": "gui", "account_screen": "gui", "startup_intro": "gui", "music_player": "modules"
|
||||
}.items():
|
||||
content = (src / location / f"{name}.h").read_text(encoding="utf-8")
|
||||
if name == "clickgui":
|
||||
content = region(content, "#include \"imgui.h\"", "inline std::string key_name", '#include "ui_bridge.h"\n\n')
|
||||
content = replace(content, "const bool menu_down = is_key_down(k_menu_key);", "const bool menu_down = false;")
|
||||
content = replace(content, "const bool esc_down = is_key_down(VK_ESCAPE);", "const bool esc_down = false;")
|
||||
content = replace(content, " void draw_backdrop() {", """ bool editing_hud() const { return editing_hud_; }
|
||||
bool binding() const { return any_binding(); }
|
||||
void escape() {
|
||||
if (editing_hud_) editing_hud_ = false;
|
||||
else close();
|
||||
}
|
||||
void draw_backdrop() {""")
|
||||
content = replace(content, "if (is_key_down(vk)) {\n m.set_toggle_key",
|
||||
"if (java_ui_binding_key(vk)) {\n m.set_toggle_key")
|
||||
content = replace(content, "if (is_key_down(vk)) {\n // Keep",
|
||||
"if (java_ui_binding_key(vk)) {\n // Keep")
|
||||
content = replace(content, "for (auto& s:m.settings()) if (!s.hidden) draw_setting(s,inner_w);",
|
||||
"for (auto& s:m.settings()) if (!s.hidden) draw_setting(s,inner_w);\n java_ui_module_extra(m,inner_w);")
|
||||
elif name == "account_screen":
|
||||
content = region(content, "#include", "namespace account_ui", '#include "ui_bridge.h"\n\n')
|
||||
content = content.replace("licensing::client()", "java_ui_account_service()")
|
||||
content = content.replace("licensing::config_path()", "java_ui_account_path()")
|
||||
content = content.replace("licensing::saved_login::load(saved)", "licensing::saved_login::load(saved, java_ui_credential())")
|
||||
content = content.replace("licensing::saved_login::forget()", "licensing::saved_login::forget(java_ui_credential())")
|
||||
content = replace(content, 'L"http://127.0.0.1:8787/api",value', 'winrt::to_hstring(address).c_str(),value')
|
||||
elif name == "startup_intro":
|
||||
content = region(content, "#include <d3d11.h>", "namespace startup_intro", '#include "ui_bridge.h"\n\n')
|
||||
content = replace(content, "Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> texture;", "java_ui_texture texture;")
|
||||
content = replace(content, "void initialize_texture(ID3D11Device* device)", "void initialize_texture()")
|
||||
content = replace(content, "if(!device || texture)return;", "if(texture)return;")
|
||||
content = region(content, " D3D11_TEXTURE2D_DESC desc", " struct playback",
|
||||
" texture.upload(128,128,pixels.data());\n }\n\n")
|
||||
content = replace(content, "reinterpret_cast<ImTextureID>(texture.Get())", "ImTextureID(texture.Get())")
|
||||
elif name == "music_player":
|
||||
content = region(content, "#include", "class music_player", '#include "ui_bridge.h"\n#include "modules/text_hud.h"\n\n')
|
||||
content = replace(content, "Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> image_;", "java_ui_texture image_;")
|
||||
content = replace(content, "!art || !media_art::device || ", "!art || ")
|
||||
content = region(content, " D3D11_TEXTURE2D_DESC desc", " }\n};",
|
||||
" image_.upload(art->width,art->height,art->rgba.data());\n")
|
||||
content = replace(content, " float text_font_size() const", " void release_texture() { image_.Reset(); }\n float text_font_size() const")
|
||||
(out / f"bedrock_{name}.h").write_text(content, encoding="utf-8")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
generate(*(Path(arg) for arg in sys.argv[1:]))
|
||||
Reference in new issue
Block a user