localization

This commit is contained in:
zhushenwudi 2024-12-31 11:20:24 +08:00
parent 8f81d1fa44
commit 6c3bd958e4
4 changed files with 64 additions and 30 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.idea

View File

@ -1,20 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="https://rawcdn.githack.com/Stuk/jszip/master/dist/jszip.js"></script>
<script src="jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.0.0/crypto-js.min.js"></script>
<script src="loader.js"></script>
</head>
<body>
<h3>Patch sif file in the browser</h3>
<h3>SIF1服务器修补程序</h3>
<br>
<fieldset>
<legend>Select input file:</legend>
<p>If no file is selected, it will be downloaded automatically (recommended).</p>
<input type="file" id="sifgamefile">
<br><br>
Server URL: <input id="serverurl" type="text" value="http://localhost:51376" autocomplete="off"><br><br>
服务器 URL<input id="serverurl" type="text" value="https://sif.zhushenwudi.top" autocomplete="off"><br><br>
<input type="radio" id="apk" name="format" value="apk" onchange="clickstuff(event)" checked><label for="apk">Android</label>
<input type="radio" id="ipa" name="format" value="ipa" onchange="clickstuff(event)"><label for="ipa">iOS</label>
<div id="patches">
@ -23,7 +20,7 @@
</div>
</fieldset>
<br><br><br>
<button onclick="load(event)">Patch</button>
<button onclick="load(event)">开始修补</button>
<script>
function clickstuff(e) {
if (document.getElementById("apk").checked) {
@ -47,7 +44,7 @@
patches[i].checked = patch.ios ? document.getElementById(patch.id + "-ios").checked : false;
}
}
init_honoka(document.getElementById("sifgamefile").files[0], android, document.getElementById("serverurl").value, patches);
init_honoka(android, document.getElementById("serverurl").value, patches);
}
(async () => {
patches = JSON.parse(await (await fetch("patches.json")).text());

13
jszip.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -3,20 +3,43 @@ function update_status(status) {
document.getElementById("status").innerText = status;
}
async function patch(file, android, newDomain, patches) {
async function downloadFile(url) {
const response = await fetch(url);
const contentLength = response.headers.get('Content-Length');
const total = parseInt(contentLength, 10);
let loaded = 0;
const reader = response.body.getReader();
const chunks = [];
while (true) {
const { done, value } = await reader.read();
if (done) break;
chunks.push(value);
loaded += value.length;
// 计算并显示下载进度
const progress = (loaded / total) * 100;
update_status(`下载中... ${progress.toFixed(2)}%`);
}
// 将所有块合并为一个 Blob
return new Blob(chunks);
}
async function patch(android, newDomain, patches) {
if (newDomain.endsWith("/")) newDomain = newDomain.slice(0, -1);
if (!file) {
console.log("downloading");
update_status("Downloading...");
file = await (await fetch("https://ethanthesleepy.one/public/lovelive/sif/lovelive-community." + (android ? "apk" : "ipa"))).blob();
update_status("下载中...");
let file = await downloadFile("https://file.zhushenwudi.top/pd/1/SIF_CLIENT/lovelive-community." + (android ? "apk" : "ipa"));
console.log("downloaded");
}
console.log("loaded");
update_status("Opening file");
update_status("解压客户端...");
const zip = new JSZip();
await zip.loadAsync(file);
update_status("Getting current config");
update_status("获取当前配置...");
let basePath = android ? "" : "Payload/LoveLive.app/";
let server_file;
@ -51,21 +74,21 @@ async function patch(file, android, newDomain, patches) {
//console.log(server_file);
FS.writeFile("/server_info.json", new Uint8Array(server_file));
update_status("Decrypting");
update_status("解密中...");
Module.callMain(["server_info.json"]);
update_status("Patching domain");
update_status("修补地址中...");
const data = FS.readFile("/server_info.json", {encoding: 'utf8'});
const currentData = JSON.parse(data);
const currentDomain = currentData.domain;
const newData = data.split(currentDomain).join(newDomain);
FS.writeFile("/server_info.json", newData);
update_status("Encrypting");
update_status("加密中...");
Module.callMain(["-e", "-j", "server_info.json"]);
const new_server_info = FS.readFile("/server_info.json");
let type;
let ext;
update_status("Applying changes");
update_status("打包中...");
if (android) {
let server_info = await zip.file("assets/AppAssets.zip").async("arraybuffer");
const zip2 = new JSZip();
@ -94,11 +117,11 @@ async function patch(file, android, newDomain, patches) {
ext = "ipa";
}
let finalized = await zip.generateAsync({type: "uint8array"});
update_status("Finalizing");
update_status("请选择下载成果物");
const downloadUrl = URL.createObjectURL(new Blob([finalized], {type: type}));
const b = document.createElement("a");
b.href = URL.createObjectURL(new Blob([new_server_info], {type: "application/json"}))
b.innerText = "Download patched server_info.json (you probably dont need this)";
b.innerText = "修补文件server_info.json你可能不需要这个";
b.download = "server_info.json";
document.body.appendChild(b);
@ -107,26 +130,26 @@ async function patch(file, android, newDomain, patches) {
const a = document.createElement("a");
a.href = downloadUrl;
a.innerText = "Download";
a.innerText = "下载客户端";
a.download = "lovelive-patched."+ext;
document.body.appendChild(a);
update_status("Done!");
update_status("完成!");
if (android) {
const p = document.createElement("p");
p.innerHTML = "Package is not signed. Using <a href=\"https://github.com/patrickfav/uber-apk-signer/releases\">uber-apk-signer</a>, sign it with the command `java -jar uber-apk-signer-<version>.jar -a lovelive.apk`.";
p.innerHTML = "修补的安装包未签名,可以使用 <a href=\"https://github.com/patrickfav/uber-apk-signer/releases\">uber-apk-signer</a>, 使用如下命令 `java -jar uber-apk-signer-<version>.jar -a lovelive.apk` 进行签名.";
document.body.appendChild(p);
}
}
function init_honoka(file, android, newDomain, patches) {
function init_honoka(android, newDomain, patches) {
window.Module = {
noInitialRun: true,
onRuntimeInitialized: async function() {
try {
await patch(file, android, newDomain, patches);
await patch(android, newDomain, patches);
} catch(e) {
console.warn(e);
document.getElementById("status").innerText = "It didnt work. Are your files/options invalid?";
document.getElementById("status").innerText = "失败。您的文件/选项无效吗?";
}
},
arguments: [],