コード例 #1
0
    }                             // Dummy for R2R images.

    /* Initialize Mod Loader (DLL_PROCESS_ATTACH) */

    /// <summary>
    /// Initializes the mod loader.
    /// Returns the port on the local machine (but that wouldn't probably be used).
    /// </summary>
    public static unsafe int Initialize(IntPtr argument, int argSize)
    {
        _reloadedMappedFile = new ReloadedMappedFile(_process.Id);
        SetupLoader((EntryPointParameters *)argument);
        _reloadedMappedFile.SetInitialized(true);
        return(0); // Server is no longer part of mod loader, return 0 port.
    }
コード例 #2
0
    public static int GetPort(int pid)
    {
        if (!ReloadedMappedFile.Exists(pid))
        {
            throw new FileNotFoundException("Reloaded is not loaded into target process. No Memory Mapped File Exists.");
        }

        using var mappedFile = new ReloadedMappedFile(pid);
        return(mappedFile.GetState().Port);
    }
コード例 #3
0
    /// <summary>
    /// Injects the Reloaded bootstrapper into an active process.
    /// </summary>
    /// <exception cref="ArgumentException">DLL Injection failed, likely due to bad DLL or application.</exception>
    public void Inject()
    {
        long handle = _injector.Inject(GetBootstrapperPath(_process));

        if (handle == 0)
        {
            throw new ArgumentException(Resources.ErrorDllInjectionFailed.Get());
        }

        try
        {
            // Wait until mod loader loads.
            // If debugging, ignore timeout.
            bool WhileCondition()
            {
                if (CheckRemoteDebuggerPresent(_process.Handle, out var isDebuggerPresent))
                {
                    return(isDebuggerPresent);
                }

                return(false);
            }

            ActionWrappers.TryGetValueWhile(() =>
            {
                // Exit if application crashes while loading Reloaded.
                if (_process.HasExited)
                {
                    return(0);
                }

                if (!ReloadedMappedFile.Exists(_process.Id))
                {
                    throw new Exception("Reloaded isn't yet loaded.");
                }

                using var file = new ReloadedMappedFile(_process.Id);
                if (!file.GetState().IsInitialized)
                {
                    throw new Exception("Reloaded is loaded but not fully initalized.");
                }

                return(0);
            }, WhileCondition, _modLoaderSetupTimeout, _modLoaderSetupSleepTime);
        }
        catch (Exception e)
        {
            ActionWrappers.ExecuteWithApplicationDispatcherAsync(() =>
            {
                Errors.HandleException(new Exception(Resources.ErrorFailedToObtainPort.Get(), e));
            });
        };
    }
コード例 #4
0
 public static void WriteServerPort(int processId, int port)
 {
     using var file = new ReloadedMappedFile(processId);
     file.SetPort(port);
 }