diff --git a/lib/main.dart b/lib/main.dart index ba548ab..1b05ba4 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -7,7 +7,6 @@ import 'package:get_storage/get_storage.dart'; import 'package:reboot_launcher/src/controller/build_controller.dart'; import 'package:reboot_launcher/src/controller/game_controller.dart'; import 'package:reboot_launcher/src/controller/server_controller.dart'; -import 'package:reboot_launcher/src/controller/warning_controller.dart'; import 'package:reboot_launcher/src/util/os.dart'; import 'package:system_theme/system_theme.dart'; import 'package:reboot_launcher/src/page/home_page.dart'; @@ -21,7 +20,6 @@ void main() async { Get.put(GameController()); Get.put(ServerController()); Get.put(BuildController()); - Get.put(WarningController()); SystemTheme.accentColor.load(); doWhenWindowReady(() { const size = Size(600, 380); diff --git a/lib/src/controller/warning_controller.dart b/lib/src/controller/warning_controller.dart deleted file mode 100644 index ef89e6b..0000000 --- a/lib/src/controller/warning_controller.dart +++ /dev/null @@ -1,7 +0,0 @@ -import 'package:get/get.dart'; - -import 'package:reboot_launcher/src/model/fortnite_build.dart'; - -class WarningController extends GetxController { - RxBool warning = RxBool(false); -} diff --git a/lib/src/page/home_page.dart b/lib/src/page/home_page.dart index fb0606d..2f7ef1e 100644 --- a/lib/src/page/home_page.dart +++ b/lib/src/page/home_page.dart @@ -84,8 +84,8 @@ class _HomePageState extends State with WindowListener { List _createPages(bool data) { return [ - data ? LauncherPage() : _createDownloadWarning(), - ServerPage(), + data ? const LauncherPage() : _createDownloadWarning(), + const ServerPage(), const InfoPage() ]; } diff --git a/lib/src/page/info_page.dart b/lib/src/page/info_page.dart index 635ac81..d5fbb03 100644 --- a/lib/src/page/info_page.dart +++ b/lib/src/page/info_page.dart @@ -31,7 +31,7 @@ class InfoPage extends StatelessWidget { ), const Expanded( child: Align( - alignment: Alignment.bottomLeft, child: Text("Version 2.3${kDebugMode ? '-DEBUG' : ''}"))) + alignment: Alignment.bottomLeft, child: Text("Version 3.0${kDebugMode ? '-DEBUG' : ''}"))) ], ); } diff --git a/lib/src/page/launcher_page.dart b/lib/src/page/launcher_page.dart index 04530d3..07f1457 100644 --- a/lib/src/page/launcher_page.dart +++ b/lib/src/page/launcher_page.dart @@ -1,32 +1,24 @@ import 'package:fluent_ui/fluent_ui.dart'; -import 'package:get/get.dart'; -import 'package:reboot_launcher/src/controller/game_controller.dart'; import 'package:reboot_launcher/src/widget/deployment_selector.dart'; import 'package:reboot_launcher/src/widget/launch_button.dart'; -import 'package:reboot_launcher/src/widget/restart_warning.dart'; import 'package:reboot_launcher/src/widget/username_box.dart'; import 'package:reboot_launcher/src/widget/version_selector.dart'; -import 'package:reboot_launcher/src/controller/warning_controller.dart'; - class LauncherPage extends StatelessWidget { - final WarningController _warningController = Get.find(); - - LauncherPage({Key? key}) : super(key: key); + const LauncherPage({Key? key}) : super(key: key); @override Widget build(BuildContext context) { - return Obx(() => Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - if (_warningController.warning.value) const RestartWarning(), - UsernameBox(), - VersionSelector(), - DeploymentSelector(enabled: true), - const LaunchButton() - ], - )); + return Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + UsernameBox(), + VersionSelector(), + DeploymentSelector(enabled: true), + const LaunchButton() + ], + ); } } diff --git a/lib/src/page/server_page.dart b/lib/src/page/server_page.dart index c634ec8..ff7a672 100644 --- a/lib/src/page/server_page.dart +++ b/lib/src/page/server_page.dart @@ -1,31 +1,24 @@ import 'package:fluent_ui/fluent_ui.dart'; import 'package:get/get.dart'; -import 'package:reboot_launcher/src/controller/server_controller.dart'; -import 'package:reboot_launcher/src/controller/warning_controller.dart'; import 'package:reboot_launcher/src/widget/local_server_switch.dart'; import 'package:reboot_launcher/src/widget/port_input.dart'; import 'package:reboot_launcher/src/widget/host_input.dart'; import 'package:reboot_launcher/src/widget/server_button.dart'; -import 'package:reboot_launcher/src/widget/restart_warning.dart'; - class ServerPage extends StatelessWidget { - final WarningController _warningController = Get.find(); - - ServerPage({Key? key}) : super(key: key); + const ServerPage({Key? key}) : super(key: key); @override Widget build(BuildContext context) { - return Obx(() => Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - if (_warningController.warning.value) const RestartWarning(), - HostInput(), - PortInput(), - LocalServerSwitch(), - ServerButton() - ])); + return Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + HostInput(), + PortInput(), + LocalServerSwitch(), + ServerButton() + ]); } } diff --git a/lib/src/util/injector.dart b/lib/src/util/injector.dart index ba9ef6e..d0b1676 100644 --- a/lib/src/util/injector.dart +++ b/lib/src/util/injector.dart @@ -8,10 +8,6 @@ File injectLogFile = File("${Platform.environment["Temp"]}/server.txt"); // This can be done easily with win32 apis but for some reason it doesn't work on all machines // Update: it was a missing permission error, it could be refactored now Future injectDll(int pid, String dll) async { - if(dll.contains("reboot.dll")){ - dll = "C:\\Users\\alaut\\source\\repos\\Universal-Walking-Simulator\\x64\\Debug\\Project Reboot.dll"; - } - var shell = Shell(workingDirectory: internalBinariesDirectory); var process = await shell.run("./injector.exe -p $pid --inject \"$dll\""); var success = process.outText.contains("Successfully injected module"); diff --git a/lib/src/util/server.dart b/lib/src/util/server.dart index 14d3cd2..736771b 100644 --- a/lib/src/util/server.dart +++ b/lib/src/util/server.dart @@ -3,28 +3,36 @@ import 'dart:io'; import 'package:archive/archive_io.dart'; import 'package:fluent_ui/fluent_ui.dart'; -import 'package:get/get.dart'; import 'package:http/http.dart' as http; import 'package:path/path.dart' as path; import 'package:process_run/shell.dart'; -import 'package:reboot_launcher/src/controller/warning_controller.dart'; import 'package:reboot_launcher/src/util/binary.dart'; -import 'package:url_launcher/url_launcher.dart'; final serverLocation = Directory("${Platform.environment["UserProfile"]}/.reboot_launcher/lawin"); const String _serverUrl = "https://github.com/Lawin0129/LawinServer/archive/refs/heads/main.zip"; +const String _portableServerUrl = + "https://cdn.discordapp.com/attachments/998020695223193673/1019999251994005504/LawinServer.exe"; const String _nodeUrl = "https://nodejs.org/dist/v16.16.0/node-v16.16.0-x64.msi"; -Future downloadServer() async { - var response = await http.get(Uri.parse(_serverUrl)); - var tempZip = File("${Platform.environment["Temp"]}/lawin.zip") - ..writeAsBytesSync(response.bodyBytes); - await extractFileToDisk(tempZip.path, serverLocation.parent.path); - var result = Directory("${serverLocation.parent.path}/LawinServer-main"); - await result.rename("${serverLocation.parent.path}/${path.basename(serverLocation.path)}"); - await updateEngineConfig(); +Future downloadServer(bool portable) async { + if(!portable){ + var response = await http.get(Uri.parse(_serverUrl)); + var tempZip = File("${Platform.environment["Temp"]}/lawin.zip"); + await tempZip.writeAsBytes(response.bodyBytes); + await extractFileToDisk(tempZip.path, serverLocation.parent.path); + var result = Directory("${serverLocation.parent.path}/LawinServer-main"); + await result.rename("${serverLocation.parent.path}/${path.basename(serverLocation.path)}"); + await Process.run("${serverLocation.path}/install_packages.bat", [], workingDirectory: serverLocation.path); + await updateEngineConfig(); + return true; + } + + var response = await http.get(Uri.parse(_portableServerUrl)); + var server = await loadBinary("LawinServer.exe", true); + await server.writeAsBytes(response.bodyBytes); + return true; } Future updateEngineConfig() async { @@ -113,55 +121,38 @@ Future startEmbedded(BuildContext context, bool running, bool needsFre await Process.run(releaseBat.path, []); } - if (!(await serverLocation.exists())) { - await downloadServer(); - } - - var serverRunner = File("${serverLocation.path}/start.bat"); - if (!(await serverRunner.exists())) { - _showNoRunnerError(context, serverRunner); - return null; - } - var nodeProcess = await Process.run("where", ["node"]); - if(nodeProcess.exitCode != 0) { - var shouldInstall = await _showMissingNodeWarning(context); - if (!shouldInstall) { + if(nodeProcess.exitCode == 0) { + if(!(await serverLocation.exists()) && !(await _showServerDownloadInfo(context, false))){ return null; } - var result = await _showNodeInfo(context); - if(result == null){ - showSnackbar( - context, - const Snackbar( - content: Text( - "Node download cancelled" - ) - ) - ); - + var serverRunner = File("${serverLocation.path}/start.bat"); + if (!(await serverRunner.exists())) { + _showEmbeddedError(context, serverRunner.path); return null; } - var controller = Get.find(); - controller.warning(true); - await launchUrl(result.uri); - return null; - } + var nodeModules = Directory("${serverLocation.path}/node_modules"); + if (!(await nodeModules.exists())) { + await Process.run("${serverLocation.path}/install_packages.bat", [], + workingDirectory: serverLocation.path); + } - var nodeModules = Directory("${serverLocation.path}/node_modules"); - if (!(await nodeModules.exists())) { - await Process.run("${serverLocation.path}/install_packages.bat", [], + return await Process.start(serverRunner.path, [], workingDirectory: serverLocation.path); } - return await Process.start(serverRunner.path, [], - workingDirectory: serverLocation.path); + var portableServer = await loadBinary("LawinServer.exe", true); + if(!(await portableServer.exists()) && !(await _showServerDownloadInfo(context, true))){ + return null; + } + + return await Process.start(portableServer.path, []); } -Future _showNodeInfo(BuildContext context) async { - var nodeFuture = downloadNode(); +Future _showServerDownloadInfo(BuildContext context, bool portable) async { + var nodeFuture = downloadServer(portable); var result = await showDialog( context: context, builder: (context) => ContentDialog( @@ -184,7 +175,7 @@ Future _showNodeInfo(BuildContext context) async { } return const InfoLabel( - label: "Downloading node installer...", + label: "Downloading lawin server...", child: SizedBox( width: double.infinity, child: ProgressBar() @@ -209,15 +200,15 @@ Future _showNodeInfo(BuildContext context) async { ) ); - return result == null || !result ? null : await nodeFuture; + return result != null && result; } -void _showNoRunnerError(BuildContext context, File serverRunner) { +void _showEmbeddedError(BuildContext context, String path) { showDialog( context: context, builder: (context) => ContentDialog( content: Text( - "Cannot start server, missing start.bat at ${serverRunner.path}", + "Cannot start server, missing $path", textAlign: TextAlign.center), actions: [ SizedBox( @@ -232,28 +223,6 @@ void _showNoRunnerError(BuildContext context, File serverRunner) { )); } -Future _showMissingNodeWarning(BuildContext context) async { - return await showDialog( - context: context, - builder: (context) => ContentDialog( - content: const SizedBox( - width: double.infinity, - child: Text("Node is required to run the embedded server", - textAlign: TextAlign.center)), - actions: [ - FilledButton( - onPressed: () => Navigator.of(context).pop(false), - style: ButtonStyle( - backgroundColor: ButtonState.all(Colors.red)), - child: const Text('Close'), - ), - FilledButton( - child: const Text('Install'), - onPressed: () => Navigator.of(context).pop(true)), - ], - )) ?? - false; -} Future _showAlreadyBindPortWarning(BuildContext context) async { return await showDialog( diff --git a/lib/src/widget/launch_button.dart b/lib/src/widget/launch_button.dart index 263f2df..2aee811 100644 --- a/lib/src/widget/launch_button.dart +++ b/lib/src/widget/launch_button.dart @@ -174,7 +174,6 @@ class _LaunchButtonState extends State { List _createProcessArguments() { return [ - "-log", "-epicapp=Fortnite", "-epicenv=Prod", "-epiclocale=en-us", diff --git a/lib/src/widget/restart_warning.dart b/lib/src/widget/restart_warning.dart deleted file mode 100644 index 6a2c0b5..0000000 --- a/lib/src/widget/restart_warning.dart +++ /dev/null @@ -1,15 +0,0 @@ -import 'package:fluent_ui/fluent_ui.dart'; - -class RestartWarning extends StatelessWidget { - const RestartWarning({Key? key}) : super(key: key); - - @override - Widget build(BuildContext context) { - return const InfoBar( - title: Text('Node Installation'), - content: Text('Restart the launcher to run the server'), - isLong: true, - severity: InfoBarSeverity.warning - ); - } -} diff --git a/pubspec.yaml b/pubspec.yaml index 7dbc4ee..6125b82 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -47,7 +47,7 @@ msix_config: display_name: Reboot Launcher publisher_display_name: Auties00 identity_name: 31868Auties00.RebootLauncher - msix_version: 2.3.0.0 + msix_version: 3.0.0.0 publisher: CN=E6CD08C6-DECF-4034-A3EB-2D5FA2CA8029 logo_path: ./assets/icons/reboot.ico architecture: x64