feat: 增加基础的游戏进程监听

This commit is contained in:
xkeyC
2025-11-20 00:27:20 +08:00
parent f6340337db
commit b65187d4f0
19 changed files with 1873 additions and 702 deletions

View File

@@ -69,7 +69,7 @@ class RustLib extends BaseEntrypoint<RustLibApi, RustLibApiImpl, RustLibWire> {
String get codegenVersion => '2.11.1';
@override
int get rustContentHash => -706588047;
int get rustContentHash => 1227557070;
static const kDefaultExternalLibraryLoaderConfig =
ExternalLibraryLoaderConfig(
@@ -95,6 +95,14 @@ abstract class RustLibApi extends BaseApi {
bool? withCustomDns,
});
Future<List<ProcessInfo>> crateApiWin32ApiGetProcessListByName({
required String processName,
});
Future<int> crateApiWin32ApiGetProcessPidByName({
required String processName,
});
Future<RsiLauncherAsarData> crateApiAsarApiGetRsiLauncherAsarData({
required String asarPath,
});
@@ -280,6 +288,66 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
],
);
@override
Future<List<ProcessInfo>> crateApiWin32ApiGetProcessListByName({
required String processName,
}) {
return handler.executeNormal(
NormalTask(
callFfi: (port_) {
var arg0 = cst_encode_String(processName);
return wire.wire__crate__api__win32_api__get_process_list_by_name(
port_,
arg0,
);
},
codec: DcoCodec(
decodeSuccessData: dco_decode_list_process_info,
decodeErrorData: dco_decode_AnyhowException,
),
constMeta: kCrateApiWin32ApiGetProcessListByNameConstMeta,
argValues: [processName],
apiImpl: this,
),
);
}
TaskConstMeta get kCrateApiWin32ApiGetProcessListByNameConstMeta =>
const TaskConstMeta(
debugName: "get_process_list_by_name",
argNames: ["processName"],
);
@override
Future<int> crateApiWin32ApiGetProcessPidByName({
required String processName,
}) {
return handler.executeNormal(
NormalTask(
callFfi: (port_) {
var arg0 = cst_encode_String(processName);
return wire.wire__crate__api__win32_api__get_process_pid_by_name(
port_,
arg0,
);
},
codec: DcoCodec(
decodeSuccessData: dco_decode_i_32,
decodeErrorData: dco_decode_AnyhowException,
),
constMeta: kCrateApiWin32ApiGetProcessPidByNameConstMeta,
argValues: [processName],
apiImpl: this,
),
);
}
TaskConstMeta get kCrateApiWin32ApiGetProcessPidByNameConstMeta =>
const TaskConstMeta(
debugName: "get_process_pid_by_name",
argNames: ["processName"],
);
@override
Future<RsiLauncherAsarData> crateApiAsarApiGetRsiLauncherAsarData({
required String asarPath,
@@ -722,6 +790,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
return raw as Uint8List;
}
@protected
List<ProcessInfo> dco_decode_list_process_info(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
return (raw as List<dynamic>).map(dco_decode_process_info).toList();
}
@protected
List<(String, String)> dco_decode_list_record_string_string(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
@@ -770,6 +844,19 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
return raw == null ? null : dco_decode_list_prim_u_8_strict(raw);
}
@protected
ProcessInfo dco_decode_process_info(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
final arr = raw as List<dynamic>;
if (arr.length != 3)
throw Exception('unexpected arr length: expect 3 but see ${arr.length}');
return ProcessInfo(
pid: dco_decode_u_32(arr[0]),
name: dco_decode_String(arr[1]),
path: dco_decode_String(arr[2]),
);
}
@protected
(String, String) dco_decode_record_string_string(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
@@ -949,6 +1036,18 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
return deserializer.buffer.getUint8List(len_);
}
@protected
List<ProcessInfo> sse_decode_list_process_info(SseDeserializer deserializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
var len_ = sse_decode_i_32(deserializer);
var ans_ = <ProcessInfo>[];
for (var idx_ = 0; idx_ < len_; ++idx_) {
ans_.add(sse_decode_process_info(deserializer));
}
return ans_;
}
@protected
List<(String, String)> sse_decode_list_record_string_string(
SseDeserializer deserializer,
@@ -1034,6 +1133,15 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
}
}
@protected
ProcessInfo sse_decode_process_info(SseDeserializer deserializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
var var_pid = sse_decode_u_32(deserializer);
var var_name = sse_decode_String(deserializer);
var var_path = sse_decode_String(deserializer);
return ProcessInfo(pid: var_pid, name: var_name, path: var_path);
}
@protected
(String, String) sse_decode_record_string_string(
SseDeserializer deserializer,
@@ -1295,6 +1403,18 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
serializer.buffer.putUint8List(self);
}
@protected
void sse_encode_list_process_info(
List<ProcessInfo> self,
SseSerializer serializer,
) {
// Codec=Sse (Serialization based), see doc to use other codecs
sse_encode_i_32(self.length, serializer);
for (final item in self) {
sse_encode_process_info(item, serializer);
}
}
@protected
void sse_encode_list_record_string_string(
List<(String, String)> self,
@@ -1378,6 +1498,14 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
}
}
@protected
void sse_encode_process_info(ProcessInfo self, SseSerializer serializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
sse_encode_u_32(self.pid, serializer);
sse_encode_String(self.name, serializer);
sse_encode_String(self.path, serializer);
}
@protected
void sse_encode_record_string_string(
(String, String) self,