This commit is contained in:
Alessandro Autiero
2024-05-22 16:49:03 +02:00
parent 9f5590d41c
commit d478650e9b
20 changed files with 383 additions and 229 deletions

View File

@@ -16,7 +16,7 @@ class AuthenticatorController extends ServerController {
String get defaultHost => kDefaultAuthenticatorHost;
@override
String get defaultPort => kDefaultAuthenticatorPort.toString();
int get defaultPort => kDefaultAuthenticatorPort;
@override
Future<bool> get isPortFree => isAuthenticatorPortFree();
@@ -28,8 +28,8 @@ class AuthenticatorController extends ServerController {
RebootPageType get pageType => RebootPageType.authenticator;
@override
Future<int> startEmbeddedInternal() => startEmbeddedAuthenticator(detached.value);
Future<Win32Process> startEmbeddedInternal() => startEmbeddedAuthenticator(detached.value);
@override
Future<Uri?> pingServer(String host, String port) => pingAuthenticator(host, port);
Future<Uri?> pingServer(String host, int port) => pingAuthenticator(host, port);
}

View File

@@ -30,7 +30,7 @@ class HostingController extends GetxController {
description.addListener(() => _storage.write("description", description.text));
password = TextEditingController(text: _storage.read("password") ?? "");
password.addListener(() => _storage.write("password", password.text));
discoverable = RxBool(_storage.read("discoverable") ?? true);
discoverable = RxBool(_storage.read("discoverable") ?? false);
discoverable.listen((value) => _storage.write("discoverable", value));
headless = RxBool(_storage.read("headless") ?? true);
headless.listen((value) => _storage.write("headless", value));

View File

@@ -45,7 +45,7 @@ class MatchmakerController extends ServerController {
String get defaultHost => kDefaultMatchmakerHost;
@override
String get defaultPort => kDefaultMatchmakerPort.toString();
int get defaultPort => kDefaultMatchmakerPort;
@override
Future<bool> get isPortFree => isMatchmakerPortFree();
@@ -57,8 +57,8 @@ class MatchmakerController extends ServerController {
RebootPageType get pageType => RebootPageType.matchmaker;
@override
Future<int> startEmbeddedInternal() => startEmbeddedMatchmaker(detached.value);
Future<Win32Process> startEmbeddedInternal() => startEmbeddedMatchmaker(detached.value);
@override
Future<Uri?> pingServer(String host, String port) => pingMatchmaker(host, port);
Future<Uri?> pingServer(String host, int port) => pingMatchmaker(host, port);
}

View File

@@ -51,9 +51,9 @@ abstract class ServerController extends GetxController {
String get defaultHost;
String get defaultPort;
int get defaultPort;
Future<Uri?> pingServer(String host, String port);
Future<Uri?> pingServer(String host, int port);
Future<bool> get isPortFree;
@@ -64,17 +64,17 @@ abstract class ServerController extends GetxController {
Future<bool> freePort();
@protected
Future<int> startEmbeddedInternal();
Future<Win32Process> startEmbeddedInternal();
void reset() async {
type.value = ServerType.values.elementAt(0);
for (var type in ServerType.values) {
for (final type in ServerType.values) {
storage.write("${type.name}_host", null);
storage.write("${type.name}_port", null);
}
host.text = type.value != ServerType.remote ? defaultHost : "";
port.text = defaultPort;
port.text = defaultPort.toString();
detached.value = false;
}
@@ -85,48 +85,48 @@ abstract class ServerController extends GetxController {
}
String _readPort() =>
storage.read("${type.value.name}_port") ?? defaultPort;
storage.read("${type.value.name}_port") ?? defaultPort.toString();
Stream<ServerResult> start() async* {
if(started.value) {
return;
}
if(type() != ServerType.local) {
started.value = true;
yield ServerResult(ServerResultType.starting);
}else {
started.value = false;
if(port != defaultPort) {
yield ServerResult(ServerResultType.starting);
}
}
try {
var host = this.host.text.trim();
if (host.isEmpty) {
if(started.value) {
return;
}
final hostData = this.host.text.trim();
final portData = this.port.text.trim();
if(type() != ServerType.local) {
started.value = true;
yield ServerResult(ServerResultType.starting);
}else {
started.value = false;
if(portData != defaultPort) {
yield ServerResult(ServerResultType.starting);
}
}
if (hostData.isEmpty) {
yield ServerResult(ServerResultType.missingHostError);
started.value = false;
return;
}
var port = this.port.text.trim();
if (port.isEmpty) {
if (portData.isEmpty) {
yield ServerResult(ServerResultType.missingPortError);
started.value = false;
return;
}
var portNumber = int.tryParse(port);
final portNumber = int.tryParse(portData);
if (portNumber == null) {
yield ServerResult(ServerResultType.illegalPortError);
started.value = false;
return;
}
if ((type() != ServerType.local || port != defaultPort) && await isPortTaken) {
if ((type() != ServerType.local || portData != defaultPort) && await isPortTaken) {
yield ServerResult(ServerResultType.freeingPort);
var result = await freePort();
final result = await freePort();
yield ServerResult(result ? ServerResultType.freePortSuccess : ServerResultType.freePortError);
if(!result) {
started.value = false;
@@ -136,8 +136,15 @@ abstract class ServerController extends GetxController {
switch(type()){
case ServerType.embedded:
final pid = await startEmbeddedInternal();
watchProcess(pid).then((value) {
final process = await startEmbeddedInternal();
final processPid = process.pid;
if(processPid == null) {
yield ServerResult(ServerResultType.startError);
started.value = false;
return;
}
watchProcess(processPid).then((value) {
if(started()) {
started.value = false;
}
@@ -145,7 +152,7 @@ abstract class ServerController extends GetxController {
break;
case ServerType.remote:
yield ServerResult(ServerResultType.pingingRemote);
var uriResult = await pingServer(host, port);
final uriResult = await pingServer(hostData, portNumber);
if(uriResult == null) {
yield ServerResult(ServerResultType.pingError);
started.value = false;
@@ -155,7 +162,7 @@ abstract class ServerController extends GetxController {
remoteServer = await startRemoteAuthenticatorProxy(uriResult);
break;
case ServerType.local:
if(port != defaultPort) {
if(portData != defaultPort) {
localServer = await startRemoteAuthenticatorProxy(Uri.parse("http://$defaultHost:$port"));
}
@@ -163,7 +170,7 @@ abstract class ServerController extends GetxController {
}
yield ServerResult(ServerResultType.pingingLocal);
var uriResult = await pingServer(defaultHost, defaultPort);
final uriResult = await pingServer(defaultHost, defaultPort);
if(uriResult == null) {
yield ServerResult(ServerResultType.pingError);
remoteServer?.close(force: true);
@@ -195,7 +202,7 @@ abstract class ServerController extends GetxController {
try{
switch(type()){
case ServerType.embedded:
killProcessByPort(int.parse(defaultPort));
killProcessByPort(defaultPort);
break;
case ServerType.remote:
await remoteServer?.close(force: true);

View File

@@ -24,6 +24,7 @@ extension ServerControllerDialog on ServerController {
var stream = toggle();
var completer = Completer<bool>();
worker = stream.listen((event) {
print(event.type);
switch (event.type) {
case ServerResultType.starting:
showInfoBar(

View File

@@ -28,7 +28,7 @@ extension GameInstanceWatcher on GameInstance {
}
});
observerPid = await startBackgroundProcess(
final process = await startProcess(
executable: _executable,
args: [
hostingController.uuid,
@@ -36,8 +36,10 @@ extension GameInstanceWatcher on GameInstance {
launcherPid?.toString() ?? "-1",
eacPid?.toString() ?? "-1",
hosting.toString()
]
],
);
observerPid = process.pid;
}
bool get _nestedHosting {

View File

@@ -11,7 +11,7 @@ import 'package:reboot_launcher/src/util/translations.dart';
final UpdateController _updateController = Get.find<UpdateController>();
Future<void> downloadCriticalDllInteractive(String filePath) async {
try {
final fileName = path.basename(filePath);
final fileName = path.basename(filePath).toLowerCase();
if (fileName == "reboot.dll") {
_updateController.update(true);
return;

View File

@@ -51,11 +51,11 @@ class _LaunchButtonState extends State<LaunchButton> {
child: Obx(() => SizedBox(
height: 48,
child: Button(
onPressed: () => _operation = CancelableOperation.fromFuture(_start()),
child: Align(
alignment: Alignment.center,
child: Text(_hasStarted ? _stopMessage : _startMessage)
)
onPressed: () => _operation = CancelableOperation.fromFuture(_start()),
child: Align(
alignment: Alignment.center,
child: Text(_hasStarted ? _stopMessage : _startMessage)
)
),
)),
),
@@ -72,11 +72,11 @@ class _LaunchButtonState extends State<LaunchButton> {
Future<void> _start() async {
if (_hasStarted) {
_onStop(
reason: _StopReason.normal
reason: _StopReason.normal
);
return;
}
if(_operation != null) {
return;
}
@@ -149,7 +149,7 @@ class _LaunchButtonState extends State<LaunchButton> {
if(_hostingController.started()){
return null;
}
if(!_hostingController.automaticServer()) {
return null;
}
@@ -160,10 +160,12 @@ class _LaunchButtonState extends State<LaunchButton> {
}
Future<GameInstance?> _startGameProcesses(FortniteVersion version, bool host, GameInstance? linkedHosting) async {
final launcherProcess = await _createLauncherProcess(version);
final eacProcess = await _createEacProcess(version);
final launcherProcess = await _createPausedProcess(version.launcherExecutable);
print("Created launcher process");
final eacProcess = await _createPausedProcess(version.eacExecutable);
print("Created eac process");
final executable = await version.executable;
final gameProcess = await _createGameProcess(executable!.path, host);
final gameProcess = await _createGameProcess(executable!, host);
if(gameProcess == null) {
return null;
}
@@ -187,7 +189,7 @@ class _LaunchButtonState extends State<LaunchButton> {
return instance;
}
Future<int?> _createGameProcess(String gamePath, bool host) async {
Future<int?> _createGameProcess(File executable, bool host) async {
if(!_hasStarted) {
return null;
}
@@ -199,38 +201,32 @@ class _LaunchButtonState extends State<LaunchButton> {
_hostingController.headless.value,
_gameController.customLaunchArgs.text
);
final gameProcess = await Process.start(
gamePath,
gameArgs
final gameProcess = await startProcess(
executable: executable,
args: gameArgs,
window: false
);
gameProcess
..exitCode.then((_) => _onStop(reason: _StopReason.exitCode))
..outLines.forEach((line) => _onGameOutput(line, host, false))
..errLines.forEach((line) => _onGameOutput(line, host, true));
gameProcess.stdOutput.listen((line) => _onGameOutput(line, host, false));
gameProcess.errorOutput.listen((line) => _onGameOutput(line, host, true));
watchProcess(gameProcess.pid).then((_) => _onStop(reason: _StopReason.exitCode));
return gameProcess.pid;
}
Future<int?> _createLauncherProcess(FortniteVersion version) async {
final launcherFile = version.launcher;
if (launcherFile == null) {
Future<int?> _createPausedProcess(File? file) async {
if (file == null) {
return null;
}
final launcherProcess = await Process.start(launcherFile.path, []);
final pid = launcherProcess.pid;
suspend(pid);
return pid;
}
Future<int?> _createEacProcess(FortniteVersion version) async {
final eacFile = version.eacExecutable;
if (eacFile == null) {
return null;
}
final eacProcess = await Process.start(eacFile.path, []);
final pid = eacProcess.pid;
final process = await startProcess(
executable: file,
args: [],
window: false,
output: false
);
print("Started process: ${process.pid}");
final pid = process.pid;
suspend(pid);
print("Suspended");
return pid;
}
@@ -473,7 +469,7 @@ class _LaunchButtonState extends State<LaunchButton> {
return _settingsController.memoryLeakDll.text;
}
}
Future<File?> _getDllFileOrStop(_Injectable injectable, bool host) async {
final path = _getDllPath(injectable);
final file = File(path);

12
gui/lib/test.dart Normal file
View File

@@ -0,0 +1,12 @@
import 'dart:io';
import 'package:reboot_common/common.dart';
void main() async {
final process = await startProcess(
executable: File("C:\\FortniteBuilds\\Fortnite 4.2\\Fortnite 4.2\\Fortnite1\\FortniteGame\\Binaries\\Win64\\FortniteClient-Win64-Shipping-Reboot.exe"),
args: "-epicapp=Fortnite -epicenv=Prod -epiclocale=en-us -epicportal -skippatchcheck -nobe -fromfl=eac -fltoken=3db3ba5dcbd2e16703f3978d -caldera=eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2NvdW50X2lkIjoiYmU5ZGE1YzJmYmVhNDQwN2IyZjQwZWJhYWQ4NTlhZDQiLCJnZW5lcmF0ZWQiOjE2Mzg3MTcyNzgsImNhbGRlcmFHdWlkIjoiMzgxMGI4NjMtMmE2NS00NDU3LTliNTgtNGRhYjNiNDgyYTg2IiwiYWNQcm92aWRlciI6IkVhc3lBbnRpQ2hlYXQiLCJub3RlcyI6IiIsImZhbGxiYWNrIjpmYWxzZX0.VAWQB67RTxhiWOxx7DBjnzDnXyyEnX7OljJm-j2d88G_WgwQ9wrE6lwMEHZHjBd1ISJdUO1UVUqkfLdU5nofBQ -AUTH_LOGIN=Player698@projectreboot.dev -AUTH_PASSWORD=Rebooted -AUTH_TYPE=epic -nullrhi -nosplash -nosound".split(" ")
);
process.stdOutput.listen((event) => stdout.writeln(event));
process.errorOutput.listen((event) => stdout.writeln(event));
}