feat: RSILauncherEnhance

This commit is contained in:
2024-05-01 13:48:37 +08:00
parent 5d0c3f5fd4
commit f6907f233a
18 changed files with 1230 additions and 12 deletions

View File

@ -22,4 +22,5 @@ anyhow = "1.0"
win32job = "2"
scopeguard = "1.2"
notify-rust = "4"
windows = { version = "0.56.0", features = ["Win32_UI_WindowsAndMessaging"] }
windows = { version = "0.56.0", features = ["Win32_UI_WindowsAndMessaging"] }
asar = "0.3.0"

52
rust/src/api/asar_api.rs Normal file
View File

@ -0,0 +1,52 @@
use std::fs::File;
use asar::{AsarReader, AsarWriter};
use tokio::fs;
pub struct RsiLauncherAsarData {
pub asar_path: String,
pub main_js_path: String,
pub main_js_content: Vec<u8>,
}
impl RsiLauncherAsarData {
pub async fn write_main_js(&self, content: Vec<u8>) -> anyhow::Result<()> {
let mut asar_writer = AsarWriter::new();
let asar_mem_file = fs::read(self.asar_path.clone()).await?;
let asar = AsarReader::new(&asar_mem_file, None)?;
asar.files().iter().for_each(|v| {
let (path, file) = v;
let path_string = path.clone().into_os_string().into_string().unwrap();
if path_string == self.main_js_path {
asar_writer.write_file(path, &content, true).unwrap();
} else {
asar_writer.write_file(path, file.data(), true).unwrap();
}
});
// rm old asar
fs::remove_file(&self.asar_path).await?;
// write new asar
asar_writer.finalize(File::create(&self.asar_path)?)?;
Ok(())
}
}
pub async fn get_rsi_launcher_asar_data(asar_path: &str) -> anyhow::Result<RsiLauncherAsarData> {
let asar_mem_file = fs::read(asar_path).await?;
let asar = AsarReader::new(&asar_mem_file, None)?;
let mut main_js_path = String::from("");
let mut main_js_content: Vec<u8> = Vec::new();
asar.files().iter().for_each(|v| {
let (path, file) = v;
let path_string = path.clone().into_os_string().into_string().unwrap();
if path_string.starts_with("app\\static\\js\\main.") && path_string.ends_with(".js") {
main_js_path = path_string;
main_js_content = file.data().to_vec();
}
});
Ok(RsiLauncherAsarData {
asar_path: asar_path.to_string(),
main_js_path,
main_js_content,
})
}

View File

@ -4,3 +4,4 @@
pub mod http_api;
pub mod rs_process;
pub mod win32_api;
pub mod asar_api;

View File

@ -57,6 +57,13 @@ impl CstDecode<String> for *mut wire_cst_list_prim_u_8_strict {
String::from_utf8(vec).unwrap()
}
}
impl CstDecode<crate::api::asar_api::RsiLauncherAsarData> for *mut wire_cst_rsi_launcher_asar_data {
// Codec=Cst (C-struct based), see doc to use other codecs
fn cst_decode(self) -> crate::api::asar_api::RsiLauncherAsarData {
let wrap = unsafe { flutter_rust_bridge::for_generated::box_from_leak_ptr(self) };
CstDecode::<crate::api::asar_api::RsiLauncherAsarData>::cst_decode(*wrap).into()
}
}
impl CstDecode<u64> for *mut u64 {
// Codec=Cst (C-struct based), see doc to use other codecs
fn cst_decode(self) -> u64 {
@ -73,6 +80,15 @@ impl CstDecode<Vec<String>> for *mut wire_cst_list_String {
vec.into_iter().map(CstDecode::cst_decode).collect()
}
}
impl CstDecode<Vec<u8>> for *mut wire_cst_list_prim_u_8_loose {
// Codec=Cst (C-struct based), see doc to use other codecs
fn cst_decode(self) -> Vec<u8> {
unsafe {
let wrap = flutter_rust_bridge::for_generated::box_from_leak_ptr(self);
flutter_rust_bridge::for_generated::vec_from_leak_ptr(wrap.ptr, wrap.len)
}
}
}
impl CstDecode<Vec<u8>> for *mut wire_cst_list_prim_u_8_strict {
// Codec=Cst (C-struct based), see doc to use other codecs
fn cst_decode(self) -> Vec<u8> {
@ -108,6 +124,16 @@ impl CstDecode<crate::api::rs_process::RsProcessStreamData> for wire_cst_rs_proc
}
}
}
impl CstDecode<crate::api::asar_api::RsiLauncherAsarData> for wire_cst_rsi_launcher_asar_data {
// Codec=Cst (C-struct based), see doc to use other codecs
fn cst_decode(self) -> crate::api::asar_api::RsiLauncherAsarData {
crate::api::asar_api::RsiLauncherAsarData {
asar_path: self.asar_path.cst_decode(),
main_js_path: self.main_js_path.cst_decode(),
main_js_content: self.main_js_content.cst_decode(),
}
}
}
impl CstDecode<crate::http_package::RustHttpResponse> for wire_cst_rust_http_response {
// Codec=Cst (C-struct based), see doc to use other codecs
fn cst_decode(self) -> crate::http_package::RustHttpResponse {
@ -149,6 +175,20 @@ impl Default for wire_cst_rs_process_stream_data {
Self::new_with_null_ptr()
}
}
impl NewWithNullPtr for wire_cst_rsi_launcher_asar_data {
fn new_with_null_ptr() -> Self {
Self {
asar_path: core::ptr::null_mut(),
main_js_path: core::ptr::null_mut(),
main_js_content: core::ptr::null_mut(),
}
}
}
impl Default for wire_cst_rsi_launcher_asar_data {
fn default() -> Self {
Self::new_with_null_ptr()
}
}
impl NewWithNullPtr for wire_cst_rust_http_response {
fn new_with_null_ptr() -> Self {
Self {
@ -168,6 +208,23 @@ impl Default for wire_cst_rust_http_response {
}
}
#[no_mangle]
pub extern "C" fn frbgen_starcitizen_doctor_wire_get_rsi_launcher_asar_data(
port_: i64,
asar_path: *mut wire_cst_list_prim_u_8_strict,
) {
wire_get_rsi_launcher_asar_data_impl(port_, asar_path)
}
#[no_mangle]
pub extern "C" fn frbgen_starcitizen_doctor_wire_rsi_launcher_asar_data_write_main_js(
port_: i64,
that: *mut wire_cst_rsi_launcher_asar_data,
content: *mut wire_cst_list_prim_u_8_loose,
) {
wire_rsi_launcher_asar_data_write_main_js_impl(port_, that, content)
}
#[no_mangle]
pub extern "C" fn frbgen_starcitizen_doctor_wire_dns_lookup_ips(
port_: i64,
@ -243,6 +300,14 @@ pub extern "C" fn frbgen_starcitizen_doctor_wire_set_foreground_window(
wire_set_foreground_window_impl(port_, window_name)
}
#[no_mangle]
pub extern "C" fn frbgen_starcitizen_doctor_cst_new_box_autoadd_rsi_launcher_asar_data(
) -> *mut wire_cst_rsi_launcher_asar_data {
flutter_rust_bridge::for_generated::new_leak_box_ptr(
wire_cst_rsi_launcher_asar_data::new_with_null_ptr(),
)
}
#[no_mangle]
pub extern "C" fn frbgen_starcitizen_doctor_cst_new_box_autoadd_u_64(value: u64) -> *mut u64 {
flutter_rust_bridge::for_generated::new_leak_box_ptr(value)
@ -262,6 +327,17 @@ pub extern "C" fn frbgen_starcitizen_doctor_cst_new_list_String(
flutter_rust_bridge::for_generated::new_leak_box_ptr(wrap)
}
#[no_mangle]
pub extern "C" fn frbgen_starcitizen_doctor_cst_new_list_prim_u_8_loose(
len: i32,
) -> *mut wire_cst_list_prim_u_8_loose {
let ans = wire_cst_list_prim_u_8_loose {
ptr: flutter_rust_bridge::for_generated::new_leak_vec_ptr(Default::default(), len),
len,
};
flutter_rust_bridge::for_generated::new_leak_box_ptr(ans)
}
#[no_mangle]
pub extern "C" fn frbgen_starcitizen_doctor_cst_new_list_prim_u_8_strict(
len: i32,
@ -295,6 +371,12 @@ pub struct wire_cst_list_String {
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct wire_cst_list_prim_u_8_loose {
ptr: *mut u8,
len: i32,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct wire_cst_list_prim_u_8_strict {
ptr: *mut u8,
len: i32,
@ -320,6 +402,13 @@ pub struct wire_cst_rs_process_stream_data {
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct wire_cst_rsi_launcher_asar_data {
asar_path: *mut wire_cst_list_prim_u_8_strict,
main_js_path: *mut wire_cst_list_prim_u_8_strict,
main_js_content: *mut wire_cst_list_prim_u_8_strict,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct wire_cst_rust_http_response {
status_code: u16,
headers: *mut wire_cst_list_record_string_string,

View File

@ -31,7 +31,7 @@ flutter_rust_bridge::frb_generated_boilerplate!(
default_rust_auto_opaque = RustAutoOpaqueNom,
);
pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_VERSION: &str = "2.0.0-dev.32";
pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_CONTENT_HASH: i32 = 1453545208;
pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_CONTENT_HASH: i32 = 1832496273;
// Section: executor
@ -39,6 +39,58 @@ flutter_rust_bridge::frb_generated_default_handler!();
// Section: wire_funcs
fn wire_get_rsi_launcher_asar_data_impl(
port_: flutter_rust_bridge::for_generated::MessagePort,
asar_path: impl CstDecode<String>,
) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap_async::<flutter_rust_bridge::for_generated::DcoCodec, _, _, _>(
flutter_rust_bridge::for_generated::TaskInfo {
debug_name: "get_rsi_launcher_asar_data",
port: Some(port_),
mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal,
},
move || {
let api_asar_path = asar_path.cst_decode();
move |context| async move {
transform_result_dco(
(move || async move {
crate::api::asar_api::get_rsi_launcher_asar_data(&api_asar_path).await
})()
.await,
)
}
},
)
}
fn wire_rsi_launcher_asar_data_write_main_js_impl(
port_: flutter_rust_bridge::for_generated::MessagePort,
that: impl CstDecode<crate::api::asar_api::RsiLauncherAsarData>,
content: impl CstDecode<Vec<u8>>,
) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap_async::<flutter_rust_bridge::for_generated::DcoCodec, _, _, _>(
flutter_rust_bridge::for_generated::TaskInfo {
debug_name: "rsi_launcher_asar_data_write_main_js",
port: Some(port_),
mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal,
},
move || {
let api_that = that.cst_decode();
let api_content = content.cst_decode();
move |context| async move {
transform_result_dco(
(move || async move {
crate::api::asar_api::RsiLauncherAsarData::write_main_js(
&api_that,
api_content,
)
.await
})()
.await,
)
}
},
)
}
fn wire_dns_lookup_ips_impl(
port_: flutter_rust_bridge::for_generated::MessagePort,
host: impl CstDecode<String>,
@ -544,6 +596,20 @@ impl SseDecode for crate::api::rs_process::RsProcessStreamDataType {
}
}
impl SseDecode for crate::api::asar_api::RsiLauncherAsarData {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
let mut var_asarPath = <String>::sse_decode(deserializer);
let mut var_mainJsPath = <String>::sse_decode(deserializer);
let mut var_mainJsContent = <Vec<u8>>::sse_decode(deserializer);
return crate::api::asar_api::RsiLauncherAsarData {
asar_path: var_asarPath,
main_js_path: var_mainJsPath,
main_js_content: var_mainJsContent,
};
}
}
impl SseDecode for crate::http_package::RustHttpResponse {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
@ -721,6 +787,28 @@ impl flutter_rust_bridge::IntoIntoDart<crate::api::rs_process::RsProcessStreamDa
}
}
// Codec=Dco (DartCObject based), see doc to use other codecs
impl flutter_rust_bridge::IntoDart for crate::api::asar_api::RsiLauncherAsarData {
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
[
self.asar_path.into_into_dart().into_dart(),
self.main_js_path.into_into_dart().into_dart(),
self.main_js_content.into_into_dart().into_dart(),
]
.into_dart()
}
}
impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive
for crate::api::asar_api::RsiLauncherAsarData
{
}
impl flutter_rust_bridge::IntoIntoDart<crate::api::asar_api::RsiLauncherAsarData>
for crate::api::asar_api::RsiLauncherAsarData
{
fn into_into_dart(self) -> crate::api::asar_api::RsiLauncherAsarData {
self
}
}
// Codec=Dco (DartCObject based), see doc to use other codecs
impl flutter_rust_bridge::IntoDart for crate::http_package::RustHttpResponse {
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
[
@ -941,6 +1029,15 @@ impl SseEncode for crate::api::rs_process::RsProcessStreamDataType {
}
}
impl SseEncode for crate::api::asar_api::RsiLauncherAsarData {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
<String>::sse_encode(self.asar_path, serializer);
<String>::sse_encode(self.main_js_path, serializer);
<Vec<u8>>::sse_encode(self.main_js_content, serializer);
}
}
impl SseEncode for crate::http_package::RustHttpResponse {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {