Script update: redirect in-game browser, support more versions of HSR

HSR 0.56 tested and supported now
Embedded browser is being redirected now, so you can use in-game register window to create an account.
This commit is contained in:
xeon 2024-01-21 12:35:18 +00:00
parent 6a491658aa
commit cafcbffcdd

View file

@ -5,26 +5,64 @@ function main(stage, parameters) {
return; return;
} }
const SystemDll = Il2cppApiWrap.GetImageByName("System.dll"); // Redirect http requests
const UnityWebRequestSetUrlPtr = Helpers.FindMethodImpl("UnityEngine.UnityWebRequestModule.dll", "UnityEngine.Networking", "UnityWebRequest", "set_url", 1);
const UriCtorPtr = Helpers.FindMethodImpl("System.dll", "System", "Uri", ".ctor", 1);
const SystemUriClass = Il2cppApiWrap.GetClassByName(SystemDll, "System", "Uri"); console.log("Found UnityWebRequest::set_url at " + UnityWebRequestSetUrlPtr);
const SystemUriCtor = Il2cppApiWrap.GetClassMethodByName(SystemUriClass, ".ctor", 1); console.log("Found Uri::ctor at " + UriCtorPtr);
console.log("Found System.Uri.ctor(System.String) at " + SystemUriCtor.readPointer()); RedirectCallback.targetHost = parameters.redirectHost;
Interceptor.attach(UnityWebRequestSetUrlPtr, RedirectCallback);
Interceptor.attach(UriCtorPtr, RedirectCallback);
Interceptor.attach(SystemUriCtor.readPointer(), { console.log("Attached successfully, will redirect all requests to: " + parameters.redirectHost);
onEnter(args) {
var requestUrl = args[1].readCSharpString(); // Hook ZFGameBrowser to redirect in-game WebView
if (requestUrl.startsWith("http://") || requestUrl.startsWith("https://")) { const BrowserLoadURL = Helpers.FindMethodImpl("ZFBrowser.dll", "ZenFulcrum.EmbeddedBrowser", "Browser", "LoadURL", 2);
if (BrowserLoadURL) {
Interceptor.attach(BrowserLoadURL, {
onEnter(args) {
var requestUrl = args[1].readCSharpString();
var prefix = requestUrl.split('/', 3).join('/'); var prefix = requestUrl.split('/', 3).join('/');
args[1] = Il2cppApiWrap.AllocateString(requestUrl.replace(prefix, parameters.redirectHost)); args[1] = Il2cppApiWrap.AllocateString(requestUrl.replace(prefix, parameters.redirectHost));
console.log("redirected: " + args[1].readCSharpString()); console.log("EmbeddedBrowser redirected: " + args[1].readCSharpString());
} }
} });
});
console.log("Attached successfully, will redirect all requests to: " + parameters.redirectHost); console.log("Successfully hooked EmbeddedBrowser");
}
}
const RedirectCallback = {
onEnter(args) {
var requestUrl = args[1].readCSharpString();
if (requestUrl.startsWith("http://") || requestUrl.startsWith("https://")) {
if (requestUrl.includes(RedirectCallback.targetHost)) return; // already redirected
var prefix = requestUrl.split('/', 3).join('/');
args[1] = Il2cppApiWrap.AllocateString(requestUrl.replace(prefix, RedirectCallback.targetHost));
console.log("redirected: " + args[1].readCSharpString());
}
}
};
const Helpers = {
FindMethodImpl(moduleName, namespace, className, methodName, argCount) {
const module = Il2cppApiWrap.GetImageByName(moduleName);
if (module.equals(ptr(0))) return null;
const il2cppClass = Il2cppApiWrap.GetClassByName(module, namespace, className);
if (il2cppClass.equals(ptr(0))) return null;
const il2cppMethod = Il2cppApiWrap.GetClassMethodByName(il2cppClass, methodName, argCount);
if (il2cppMethod.equals(ptr(0))) return null;
return il2cppMethod.readPointer();
}
} }
const Il2cppApiWrap = { const Il2cppApiWrap = {