dmclc
Version:
Dolphin Minecraft Launcher Core
55 lines (54 loc) • 1.54 kB
JavaScript
import { createHash } from "crypto";
import * as uuid from "uuid";
export class OfflineAccount {
data;
launcher;
constructor(data, launcher) {
this.data = data;
this.launcher = launcher;
}
getTokens() {
return [];
}
async getLaunchGameArgs() {
const map = new Map();
map.set("auth_access_token", "IT_WORKS");
map.set("auth_session", "IT_WORKS");
map.set("auth_player_name", this.data.name);
map.set("user_type", "mojang");
map.set("user_properties", "{}");
return map;
}
async prepareLaunch() {
// We don't need to do anything when use this method.
return true;
}
async getLaunchJVMArgs() {
return [];
}
async login() {
this.data.name = await this.launcher.askUserOne("accounts.offline.username");
this.data.uuid = genUUID("OfflinePlayer:".concat(this.data.name));
return true;
}
async check() {
return true;
}
getUUID() {
return this.data.uuid;
}
toString() {
return `${this.data.name} (${this.launcher.i18n("accounts.offline.name")})`;
}
}
function genUUID(name) {
const arr = [];
for (let i = 0, j = name.length; i < j; ++i) {
arr.push(name.charCodeAt(i));
}
let bytes = new Uint8Array(arr);
bytes = createHash("md5").update(bytes).digest();
bytes[6] = bytes[6] & 0x0f | 0x30;
bytes[8] = bytes[8] & 0x3f | 0x80;
return uuid.stringify(bytes).replaceAll("-", "");
}