/// <summary> /// Sets up bindings for libReloaded Print functions for printing any errors which happen within /// libReloaded. /// </summary> private static void SetuplibReloadedBindings() { Bindings.PrintError += delegate(string message) { ConsoleFunctions.PrintMessageWithTime(message, ConsoleFunctions.PrintErrorMessage); }; Bindings.PrintWarning += delegate(string message) { ConsoleFunctions.PrintMessageWithTime(message, ConsoleFunctions.PrintWarningMessage); }; Bindings.PrintInfo += delegate(string message) { ConsoleFunctions.PrintMessageWithTime(message, ConsoleFunctions.PrintInfoMessage); }; Bindings.PrintText += delegate(string message) { ConsoleFunctions.PrintMessageWithTime(message, ConsoleFunctions.PrintMessage); }; }
/// <summary> /// Prints a message received from a client to the console/standard output. /// </summary> /// <param name="printMessageType">The message colour/type to print.</param> /// <param name="asciiMessage">The character array of ASCII bytes to parse back to string. (MessageStruct.Data)</param> /// <param name="socket">Sends a message back to signify that the message has successfully printed.</param> public static void Print(PrintMessageType printMessageType, byte[] asciiMessage, ReloadedSocket socket) { // Retrieve the message to print. string messageToPrint = Encoding.ASCII.GetString(asciiMessage); // Print to screen. switch (printMessageType) { case PrintMessageType.PrintText: ConsoleFunctions.PrintMessageWithTime(messageToPrint, ConsoleFunctions.PrintMessage); break; case PrintMessageType.PrintInfo: ConsoleFunctions.PrintMessageWithTime(messageToPrint, ConsoleFunctions.PrintInfoMessage); break; case PrintMessageType.PrintWarning: ConsoleFunctions.PrintMessageWithTime(messageToPrint, ConsoleFunctions.PrintWarningMessage); break; case PrintMessageType.PrintError: ConsoleFunctions.PrintMessageWithTime(messageToPrint, ConsoleFunctions.PrintErrorMessage); break; } }
/// <summary> /// Injects itself to the game depending on the individual method chosen either from the commandline or in the launcher. /// By default, Reloaded starts the game and injects immediately into suspended, otherwise if --attach is specified, Reloaded /// tries to hook itself into an already running game/application. /// </summary> /// <param name="arguments">A copy of the arguments passed into the application used for optionally rebooting in x64 mode.</param> private static void InjectByMethod(string[] arguments) { // Fast return if soft reboot (game process killed and restarted itself) if (_gameProcess != null) { return; } // Attach if specified by the user. if (_attachTargetName != null) { // Grab current already running game. _gameProcess = ReloadedProcess.GetProcessByName(_attachTargetName); // Check if gameProcess successfully returned. if (_gameProcess == null) { ConsoleFunctions.PrintMessageWithTime("Error: An active running game instance was not found.", ConsoleFunctions.PrintErrorMessage); Console.ReadLine(); Shutdown(null, null); } // Check if the current running architecture matched ~(32 bit), if not, restart as x64. if (!_gameProcess.CheckArchitectureMatch()) { RebootX64(arguments); } } // Otherwise start process suspended in Reloaded, hook it, exploit it and resume the intended way. else { _gameProcess = new ReloadedProcess($"{Path.Combine(_gameConfig.GameDirectory, _gameConfig.ExecutableLocation)}"); // The process handle is 0 if the process failed to initialize. if ((int)_gameProcess.ProcessHandle == 0) { // libReloaded will already print the error message. Console.ReadLine(); Shutdown(null, null); } // Check if the current running architecture matched ~(32 bit), if not, restart as x64. if (!_gameProcess.CheckArchitectureMatch()) { _gameProcess.KillProcess(); RebootX64(arguments); } } // Set binding for target process for memory IO Bindings.TargetProcess = _gameProcess; // Obtain the process start time. if (_gameProcess != null) { _processStartTime = _gameProcess.GetProcessFromReloadedProcess().StartTime; } }
/// <summary> /// Removes Zone Information from dynamic link libraries downloaded from the internet such /// that certain users of Microsoft Windows would not be denied loading of our own arbitrary code. /// </summary> /// <remarks> /// Only affects files downloaded via very specific certain outdated programs such as /// Internet Explorer /// </remarks> public static void UnblockDlls() { // Print Info Message about Unlocking DLLs ConsoleFunctions.PrintMessageWithTime("Removing Zone Identifiers from Files (DLL Unlocking)", ConsoleFunctions.PrintInfoMessage); // Search all DLLs under loader directories. // Normally I'd restrict this to mod directories, but the loader's own libraries might also be worth checking. string[] dllFiles = Directory.GetFiles(LoaderPaths.GetModLoaderDirectory(), "*.dll", SearchOption.AllDirectories); // Unblock new file. foreach (string dllFile in dllFiles) { FileUnblocker.Unblock(dllFile); } }
/// <summary> /// Displays a warning about how to use the mod loader. /// </summary> public static void DisplayWarning() { // Print ConsoleFunctions.PrintMessageWithTime("No game to launch has been specified.", ConsoleFunctions.PrintErrorMessage); ConsoleFunctions.PrintInfoMessage ( "\nCommand Line Reloaded Mod Loader Usage Instructions:\n" + "Reloaded-Loader.exe <Arguments>\n\n" + "Arguments List:\n" + $"{Strings.Common.LoaderSettingConfig} <GAME_CONFIGURATION_PATH> | Specifies the game configuration to run.\n" + $"{Strings.Common.LoaderSettingAttach} <EXECUTABLE_NAME> | Attaches to an already running game/executable.\n\n" + "Examples:\n" + $"Reloaded-Loader.exe {Strings.Common.LoaderSettingConfig} D:/Reloaded/Reloaded-Config/Games/Sonic-Heroes\n" + $"Reloaded-Loader.exe {Strings.Common.LoaderSettingConfig} D:/Reloaded/Reloaded-Config/Games/Sonic-Heroes {Strings.Common.LoaderSettingAttach} Tsonic_win_custom.exe\n\n" ); Console.ReadLine(); Environment.Exit(0); }
/// <summary> /// Retrieves the controller list from the mod loader library libReloaded and prints it to the screen. /// </summary> public static void PrintControllerOrder() { // Header ConsoleFunctions.PrintMessageWithTime("Displaying Connected Controller List", ConsoleFunctions.PrintInfoMessage); ConsoleFunctions.PrintMessageWithTime("Key: [Controller Port] [Controller Type] <Controller Name> (Disconnected?)", ConsoleFunctions.PrintInfoMessage); // Retrieve Controllers ControllerManager controllerManager = new ControllerManager(); // Print list of controllers. foreach (ControllerCommon.IController controller in controllerManager.Controllers) { // Is controller XInput or DInput string controllerName = "[" + controller.InputMappings.ControllerId.ToString("00") + "]"; // Get Controller Type if (controller.Remapper.DeviceType == Remapper.InputDeviceType.XInput) { controllerName += " [XInput] "; } else if (controller.Remapper.DeviceType == Remapper.InputDeviceType.DirectInput) { controllerName += " [DInput] "; } // Add controller name from remapper. controllerName += controller.Remapper.GetControllerName; // Check if disconnected. if (!controller.IsConnected()) { controllerName += " (Disconnected)"; } // Print controller to screen. ConsoleFunctions.PrintMessageWithTime(controllerName, ConsoleFunctions.PrintMessage); } }
/// <summary> /// Sets up the Reloaded Mod Loader Server. /// </summary> public static void SetupServer() { // Triggered on soft reboot, self killing and restarting games. if (ReloadedServer != null) { ConsoleFunctions.PrintMessageWithTime("Local Server Already Running!", ConsoleFunctions.PrintInfoMessage); return; } try { // Create new server instance. ReloadedServer = new Host(IPAddress.Loopback, ServerPort); // Start Server Internally ReloadedServer.StartServer(); // Redirect sent data towards certain method. ReloadedServer.ProcessBytesMethods += MessageHandler; // Print words of success ConsoleFunctions.PrintMessageWithTime("Local Server Successfully Started!", ConsoleFunctions.PrintInfoMessage); } // If the port is occupied, an exception will be thrown. // Try hosting the server on another port. catch (SocketException ex) { // Print Warning ConsoleFunctions.PrintMessageWithTime("Failed to create local host at port " + ServerPort + ". Attempting port " + (ServerPort + 1) + ".", ConsoleFunctions.PrintWarningMessage); ConsoleFunctions.PrintMessageWithTime("Original Message: " + ex.Message, ConsoleFunctions.PrintWarningMessage); // Increment the port number. ServerPort += 1; // Call self SetupServer(); } }