Пример #1
0
        public static ProcessEntry[] EnumerateProcesses()
        {
            var processEntries = new List <ProcessEntry>();

            var processes = Process.GetProcesses();

            foreach (var process in processes)
            {
                try
                {
                    processEntries.Add(new ProcessEntry()
                    {
                        FullPath  = process.MainModule.FileName,
                        ImageName = process.ProcessName,
                        Id        = process.Id,
                        IsX64     = RemoteHooking.IsX64Process(process.Id),
                        Owner     = RemoteHooking.GetProcessIdentity(process.Id).Name
                    });
                }
                catch
                {
                    // Access will be denied to some processes even though we're running as a service
                    continue;
                }
            }

            return(processEntries.ToArray());
        }
Пример #2
0
        public static ProcessInfo[] EnumProcesses()
        {
            List <ProcessInfo> result = new List <ProcessInfo>();

            Process[] procList = Process.GetProcesses();

            for (int i = 0; i < procList.Length; i++)
            {
                Process proc = procList[i];

                try
                {
                    ProcessInfo info = new ProcessInfo();

                    info.FileName = proc.MainModule.FileName;
                    info.Id       = proc.Id;
                    info.Is64Bit  = RemoteHooking.IsX64Process(proc.Id);
                    info.User     = RemoteHooking.GetProcessIdentity(proc.Id).Name;

                    result.Add(info);
                }
                catch
                {
                }
            }

            return(result.ToArray());
        }
Пример #3
0
        public static ProcessInfo[] Enum()
        {
            List <ProcessInfo> Result = new List <ProcessInfo>();

            Process[] ProcList = Process.GetProcesses();

            for (int i = 0; i < ProcList.Length; i++)
            {
                Process Proc = ProcList[i];

                try
                {
                    ProcessInfo Info = new ProcessInfo();

                    Info.FileName = Proc.MainModule.FileName;
                    Info.Id       = Proc.Id;
                    Info.Is64Bit  = RemoteHooking.IsX64Process(Proc.Id);
                    Info.Identity = RemoteHooking.GetProcessIdentity(Proc.Id).Owner.ToString();

                    Result.Add(Info);
                }
                catch
                {
                }
            }

            return(Result.ToArray());
        }
Пример #4
0
        /// <summary>
        /// Inject a DLL to target
        /// </summary>
        /// <param name="assemblyFile">x86 DLL</param>
        /// <param name="assemblyFile64">x64 DLL, if your target is 64bit program</param>
        /// <returns></returns>
        public int Inject(string assemblyFile, string assemblyFile64 = null)
        {
            try
            {
                _interface.SleepInterval      = SleepInterval;
                _interface.IsBackgroundThread = IsBackgroundThread;
                if (RemoteHooking.IsX64Process(_pid))
                {
                    //Console.WriteLine("64bit program!");
                }
                RemoteHooking.Inject(_pid, assemblyFile, assemblyFile64, _channelName);

                RegisterEvents();
                return(_pid);
            }
            catch (Exception)
            {
                //FIXED: The Part Where He Kills You
                Eject();
                return(0);
            }
        }
        /// <summary>
        /// Called by EasyHook to begin any hooking etc in the target process
        /// </summary>
        /// <param name="InContext"></param>
        /// <param name="channelName"></param>
        /// <param name="strVersion">Direct3DVersion passed as a string so that GAC registration is not required</param>
        /// <param name="showOverlay">Whether or not to show an overlay</param>
        public void Run(
            RemoteHooking.IContext InContext,
            String channelName,
            String strVersion,
            bool showOverlay)
        {
            Direct3DVersion version = (Direct3DVersion)Enum.Parse(typeof(Direct3DVersion), strVersion);

            // NOTE: We are now already running within the target process
            try
            {
                _interface.OnDebugMessage(RemoteHooking.GetCurrentProcessId(), "DLL Injection succeeded");

                bool isX64Process = RemoteHooking.IsX64Process(RemoteHooking.GetCurrentProcessId());
                _interface.OnDebugMessage(RemoteHooking.GetCurrentProcessId(), "64-bit Process: " + isX64Process.ToString());

                if (version == Direct3DVersion.AutoDetect)
                {
                    // Attempt to determine the correct version based on loaded module.
                    // In most cases this will work fine, however it is perfectly ok for an application to use a D3D10 device along with D3D11 devices
                    // so the version might matched might not be the one you want to use
                    IntPtr d3D9Loaded    = IntPtr.Zero;
                    IntPtr d3D10Loaded   = IntPtr.Zero;
                    IntPtr d3D10_1Loaded = IntPtr.Zero;
                    IntPtr d3D11Loaded   = IntPtr.Zero;
                    IntPtr d3D11_1Loaded = IntPtr.Zero;

                    int delayTime  = 100;
                    int retryCount = 0;
                    while (d3D9Loaded == IntPtr.Zero && d3D10Loaded == IntPtr.Zero && d3D10_1Loaded == IntPtr.Zero && d3D11Loaded == IntPtr.Zero && d3D11_1Loaded == IntPtr.Zero)
                    {
                        retryCount++;
                        d3D9Loaded    = GetModuleHandle("d3d9.dll");
                        d3D10Loaded   = GetModuleHandle("d3d10.dll");
                        d3D10_1Loaded = GetModuleHandle("d3d10_1.dll");
                        d3D11Loaded   = GetModuleHandle("d3d11.dll");
                        d3D11_1Loaded = GetModuleHandle("d3d11_1.dll");
                        Thread.Sleep(delayTime);

                        if (retryCount * delayTime > 5000)
                        {
                            _interface.OnDebugMessage(RemoteHooking.GetCurrentProcessId(), "Unsupported Direct3DVersion, or Direct3D DLL not loaded within 5 seconds.");
                            return;
                        }
                    }

                    version = Direct3DVersion.Unknown;
                    if (d3D11_1Loaded != IntPtr.Zero)
                    {
                        _interface.OnDebugMessage(RemoteHooking.GetCurrentProcessId(), "Autodetect found Direct3D 11.1");
                        version = Direct3DVersion.Direct3D11_1;
                    }
                    else if (d3D11Loaded != IntPtr.Zero)
                    {
                        _interface.OnDebugMessage(RemoteHooking.GetCurrentProcessId(), "Autodetect found Direct3D 11");
                        version = Direct3DVersion.Direct3D11;
                    }
                    else if (d3D10_1Loaded != IntPtr.Zero)
                    {
                        _interface.OnDebugMessage(RemoteHooking.GetCurrentProcessId(), "Autodetect found Direct3D 10.1");
                        version = Direct3DVersion.Direct3D10_1;
                    }
                    else if (d3D10Loaded != IntPtr.Zero)
                    {
                        _interface.OnDebugMessage(RemoteHooking.GetCurrentProcessId(), "Autodetect found Direct3D 10");
                        version = Direct3DVersion.Direct3D10;
                    }
                    else if (d3D9Loaded != IntPtr.Zero)
                    {
                        _interface.OnDebugMessage(RemoteHooking.GetCurrentProcessId(), "Autodetect found Direct3D 9");
                        version = Direct3DVersion.Direct3D9;
                    }
                }

                switch (version)
                {
                case Direct3DVersion.Direct3D9:
                    _directXHook = new DXHookD3D9(_interface);
                    break;

                case Direct3DVersion.Direct3D10:
                    _directXHook = new DXHookD3D10(_interface);
                    break;

                case Direct3DVersion.Direct3D10_1:
                    _directXHook = new DXHookD3D10_1(_interface);
                    break;

                case Direct3DVersion.Direct3D11:
                    _directXHook = new DXHookD3D11(_interface);
                    break;

                default:
                    _interface.OnDebugMessage(RemoteHooking.GetCurrentProcessId(), "Unsupported Direct3DVersion");
                    break;
                }
                _directXHook.ShowOverlay = showOverlay;

                _directXHook.Hook();
            }
            catch (Exception e)
            {
                /*
                 *  We should notify our host process about this error...
                 */
                //_interface.ReportError(RemoteHooking.GetCurrentProcessId(), e);
                _interface.OnDebugMessage(RemoteHooking.GetCurrentProcessId(), "Exception during device creation and hooking: \r\n" + e.Message);
                while (_interface.Ping(RemoteHooking.GetCurrentProcessId()))
                {
                    Thread.Sleep(100);
                }

                return;
            }

            // Wait for host process termination...
            try
            {
                // When not using GAC there can be issues with remoting assemblies resolving correctly
                // this is a workaround that ensures that the current assembly is correctly associated
                AppDomain currentDomain = AppDomain.CurrentDomain;
                currentDomain.AssemblyResolve += (sender, args) =>
                {
                    return(this.GetType().Assembly.FullName == args.Name ? this.GetType().Assembly : null);
                };

                while (_interface.Ping(RemoteHooking.GetCurrentProcessId()))
                {
                    Thread.Sleep(10);

                    ScreenshotRequest request = _interface.GetScreenshotRequest(RemoteHooking.GetCurrentProcessId());

                    if (request != null)
                    {
                        _directXHook.Request = request;
                    }
                }
            }
            catch
            {
                // .NET Remoting will raise an exception if host is unreachable
            }
            finally
            {
                try
                {
                    _directXHook.Cleanup();
                }
                catch
                {
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Called by EasyHook to begin any hooking etc in the target process
        /// </summary>
        /// <param name="InContext"></param>
        /// <param name="InArg1"></param>
        public void Run(
            RemoteHooking.IContext InContext,
            String channelName,
            Direct3DVersion version,
            int VertexMode)
        {
            // NOTE: We are now already running within the target process
            try
            {
                _interface.OnDebugMessage(RemoteHooking.GetCurrentProcessId(), "DLL Injection succeeded");

                bool isX64Process = RemoteHooking.IsX64Process(RemoteHooking.GetCurrentProcessId());
                _interface.OnDebugMessage(RemoteHooking.GetCurrentProcessId(), "64-bit Process: " + isX64Process.ToString());

                switch (version)
                {
                case Direct3DVersion.Direct3D9:
                    _directXHook = new DXHookD3D9(_interface, VertexMode);
                    break;

                case Direct3DVersion.Direct3D10:
                    _directXHook = new DXHookD3D10(_interface);
                    break;

                //case Direct3DVersion.Direct3D10_1:
                //    _directXHook = new DXHookD3D10(_interface);
                //    break;
                case Direct3DVersion.Direct3D11:
                    _directXHook = new DXHookD3D11(_interface);
                    break;

                default:
                    _interface.OnDebugMessage(RemoteHooking.GetCurrentProcessId(), "Unsupported Direct3DVersion");
                    break;
                }

                _directXHook.Hook();
            }
            catch (Exception e)
            {
                /*
                 *  We should notify our host process about this error...
                 */
                _interface.ReportError(RemoteHooking.GetCurrentProcessId(), e);

                return;
            }

            // Wait for host process termination...
            try
            {
                while (_interface.Ping(RemoteHooking.GetCurrentProcessId()))
                {
                    Thread.Sleep(10);

                    ScreenshotRequest request = _interface.GetScreenshotRequest(RemoteHooking.GetCurrentProcessId());

                    if (request != null)
                    {
                        _directXHook.Request = request;
                    }
                }
            }
            catch
            {
                // .NET Remoting will raise an exception if host is unreachable
            }
            finally
            {
                try
                {
                    _directXHook.Cleanup();
                }
                catch
                {
                }
            }
        }
Пример #7
0
        private bool InitialiseDirectXHook(OverlayConfig config)
        {
            var version = config.Direct3DVersion;

            var loadedVersions = new List <Direct3DVersion>();

            var isX64Process = RemoteHooking.IsX64Process(RemoteHooking.GetCurrentProcessId());

            _interface.Message(MessageType.Information, "Remote process is a {0}-bit process.", isX64Process ? "64" : "32");

            try
            {
                if (version == Direct3DVersion.Unknown)
                {
                    // Attempt to determine the correct version based on loaded module.
                    // In most cases this will work fine, however it is perfectly ok for an application to use a D3D10 device along with D3D11 devices
                    // so the version might matched might not be the one you want to use
                    var d3D9Loaded   = IntPtr.Zero;
                    var d3D10Loaded  = IntPtr.Zero;
                    var d3D101Loaded = IntPtr.Zero;
                    var d3D11Loaded  = IntPtr.Zero;
                    var d3D111Loaded = IntPtr.Zero;

                    var delayTime  = 100;
                    var retryCount = 0;
                    while (d3D9Loaded == IntPtr.Zero && d3D10Loaded == IntPtr.Zero && d3D101Loaded == IntPtr.Zero && d3D11Loaded == IntPtr.Zero && d3D111Loaded == IntPtr.Zero)
                    {
                        retryCount++;
                        d3D9Loaded   = NativeMethods.GetModuleHandle("d3d9.dll");
                        d3D10Loaded  = NativeMethods.GetModuleHandle("d3d10.dll");
                        d3D101Loaded = NativeMethods.GetModuleHandle("d3d10_1.dll");
                        d3D11Loaded  = NativeMethods.GetModuleHandle("d3d11.dll");
                        d3D111Loaded = NativeMethods.GetModuleHandle("d3d11_1.dll");
                        Thread.Sleep(delayTime);

                        if (retryCount * delayTime > 5000)
                        {
                            _interface.Message(MessageType.Error, "Unsupported Direct3D version, or Direct3D DLL not loaded within 5 seconds.");
                            return(false);
                        }
                    }

                    version = Direct3DVersion.Direct3D9;
                    if (d3D9Loaded != IntPtr.Zero)
                    {
                        _interface.Message(MessageType.Debug, "Autodetect found Direct3D 9");
                        version = Direct3DVersion.Direct3D9;
                        loadedVersions.Add(version);
                    }
                }
                else
                {
                    // If not autodetect, assume specified version is loaded
                    loadedVersions.Add(version);
                }

                foreach (var dxVersion in loadedVersions)
                {
                    version = dxVersion;
                    switch (version)
                    {
                    case Direct3DVersion.Direct3D9:
                        _directXHook = new DxHookD3D9(_interface);
                        break;

                    default:
                        _interface.Message(MessageType.Error, "Unsupported Direct3D version: {0}", version);
                        return(false);
                    }

                    _directXHook.Config = config;
                    _directXHook.Hook();

                    _directXHooks.Add(_directXHook);
                }

                return(true);
            }
            catch (Exception e)
            {
                // Notify the host/server application about this error
                _interface.Message(MessageType.Error, "Error in InitialiseHook: {0}", e.ToString());
                return(false);
            }
        }
Пример #8
0
        /// <summary>
        /// Called by EasyHook to begin any hooking etc in the target process
        /// </summary>
        /// <param name="InContext"></param>
        /// <param name="InArg1"></param>
        public void Run(RemoteHooking.IContext InContext, String InArg1)
        {
            Interface.Write("Running in target.");
            int pid = RemoteHooking.GetCurrentProcessId();

            try
            {
                // NOTE: We are now already running within the target process

                // We want to hook each method of we are interested in
                IntPtr pGetControllerState         = IntPtr.Zero;
                IntPtr pGetControllerStateWithPose = IntPtr.Zero;
                IntPtr pPollNextEvent         = IntPtr.Zero;
                IntPtr pPollNextEventWithPose = IntPtr.Zero;

                // TODO: Find out version of openvr dll, which will determine the correct index of the function
                // ver = vr::IVRSystem_Version; returns string
                // string matching determines which enum to use

                if (RemoteHooking.IsX64Process(pid))
                {
                    /*
                     * EVRInitError error = EVRInitError.None;
                     * OpenVR.Init(ref error);
                     * if(error == EVRInitError.None)
                     * {
                     *  Func<in uint, VRControllerState_t, in uint, out bool> ptr = null;
                     *  ptr = OpenVR.System.GetControllerState;
                     * }
                     */

                    Interface.Write("64 bit process");
                    pGetControllerState         = GetIVRSystemFunctionAddress64((short)OpenVRFunctionIndex.GetControllerState, (int)OpenVRFunctionIndex.Count);
                    pGetControllerStateWithPose = GetIVRSystemFunctionAddress64((short)OpenVRFunctionIndex.GetControllerStateWithPose, (int)OpenVRFunctionIndex.Count);
                    pPollNextEvent         = GetIVRSystemFunctionAddress64((short)OpenVRFunctionIndex.PollNextEvent, (int)OpenVRFunctionIndex.Count);
                    pPollNextEventWithPose = GetIVRSystemFunctionAddress64((short)OpenVRFunctionIndex.PollNextEventWithPose, (int)OpenVRFunctionIndex.Count);
                }
                else
                {
                    Interface.Write("32 bit process");
                    pGetControllerState         = GetIVRSystemFunctionAddress32((short)OpenVRFunctionIndex.GetControllerState, (int)OpenVRFunctionIndex.Count);
                    pGetControllerStateWithPose = GetIVRSystemFunctionAddress32((short)OpenVRFunctionIndex.GetControllerStateWithPose, (int)OpenVRFunctionIndex.Count);
                    pPollNextEvent         = GetIVRSystemFunctionAddress32((short)OpenVRFunctionIndex.PollNextEvent, (int)OpenVRFunctionIndex.Count);
                    pPollNextEventWithPose = GetIVRSystemFunctionAddress32((short)OpenVRFunctionIndex.PollNextEventWithPose, (int)OpenVRFunctionIndex.Count);
                }

                if ((pGetControllerState == IntPtr.Zero && pGetControllerStateWithPose == IntPtr.Zero) ||
                    (pPollNextEvent == IntPtr.Zero || pPollNextEventWithPose == IntPtr.Zero))
                {
                    throw new VRNotInitializedException("No runtime installed, no HMD present, version mismatch, or other error.");
                }

                Interface.Write("GetControllerState function pointer: " + (pGetControllerState).ToString());
                Interface.Write("GetControllerStateWithPose function pointer: " + (pGetControllerStateWithPose).ToString());
                Interface.Write("PollNextEventEvent function pointer: " + (pPollNextEvent).ToString());
                Interface.Write("PollNextEventWithPose function pointer: " + (pPollNextEventWithPose).ToString());

                GetControllerStatePtr  = pGetControllerState;
                GetControllerStateHook = LocalHook.Create(
                    pGetControllerState,
                    new vr_GetControllerStateDelegate(GetControllerState_Hooked),
                    this);

                GetControllerStateWithPosePtr  = pGetControllerStateWithPose;
                GetControllerStateWithPoseHook = LocalHook.Create(
                    pGetControllerStateWithPose,
                    new vr_GetControllerStateWithPoseDelegate(GetControllerStateWithPose_Hooked),
                    this);

                PollNextEventPtr  = pPollNextEvent;
                PollNextEventHook = LocalHook.Create(
                    pPollNextEvent,
                    new vr_PollNextEventDelegate(PollNextEvent_Hooked),
                    this);

                PollNextEventWithPosePtr  = pPollNextEventWithPose;
                PollNextEventWithPoseHook = LocalHook.Create(
                    pPollNextEventWithPose,
                    new vr_PollNextEventWithPoseDelegate(PollNextEventWithPose_Hooked),
                    this);

                /*
                 * Don't forget that all hooks will start deactivated...
                 * The following ensures that all threads are intercepted:
                 * Note: you must do this for each hook.
                 */
                GetControllerStateHook.ThreadACL.SetExclusiveACL(new Int32[] { 0 });
                GetControllerStateWithPoseHook.ThreadACL.SetExclusiveACL(new Int32[] { 0 });
                PollNextEventHook.ThreadACL.SetExclusiveACL(new Int32[] { 0 });
                PollNextEventWithPoseHook.ThreadACL.SetExclusiveACL(new Int32[] { 0 });
            }
            catch (Exception e)
            {
                /*
                 *  We should notify our host process about this error...
                 */
                Interface.Write("Error: ");
                Interface.ReportError(pid, e);
                return;
            }

            Interface.Write("DLL installed");
            Interface.IsInstalled(pid);

            // Wait for host process termination...
            try
            {
                ChosenDeviceIndex = 0; // base station
                while (ChosenDeviceIndex == 0)
                {
                    if (!Interface.Installed)
                    {
                        Interface.Write("Need to uninstall hooks!");
                        break;
                    }

                    // wait until controller comes on?
                    if (RemoteHooking.IsX64Process(pid))
                    {
                        LeftHandIndex  = GetLeftHandIndex64();
                        RightHandIndex = GetRightHandIndex64();
                    }
                    else
                    {
                        LeftHandIndex  = GetLeftHandIndex32();
                        RightHandIndex = GetRightHandIndex32();
                    }
                    Interface.Write("Left hand " + LeftHandIndex);
                    Interface.Write("Right hand " + RightHandIndex);
                    ChosenDeviceIndex = Interface.Hand == PStrafeHand.Left ? LeftHandIndex : RightHandIndex;
                    Thread.Sleep(300);
                }

                while (true)
                {
                    Thread.Sleep(10);
                    if (!Interface.Installed)
                    {
                        break;
                    }
                    bool running = Interface.UserIsRunning;
                    if (running != UserRunning)
                    {
                        // look for interface changes (keybinding, user is running, etc)
                        RunButton         = Interface.RunButton;
                        ButtonType        = Interface.ButtonType;
                        ChosenDeviceIndex = Interface.Hand == PStrafeHand.Left ? LeftHandIndex : RightHandIndex;
                        UserRunning       = running;

                        // create event for vive controller
                        MyEvent = new ButtonEvent()
                        {
                            Queued      = true,
                            ShouldPress = ButtonType == PStrafeButtonType.Press,
                            ShouldTouch = true
                        };
                    }
                }
            }
            catch
            {
                // NET Remoting will raise an exception if host is unreachable
                Interface.ReportError(pid, new Exception("Host unreachable?"));
            }
            finally
            {
                // Note: this will probably not get called if the target application closes before the
                //       host application.
                Interface.Write("Remove and cleanup hooks");
                Cleanup();
            }
        }
Пример #9
0
        private bool InitialiseDirectXHook(CaptureConfig config)
        {
            var version = config.Direct3DVersion;

            var isX64Process = RemoteHooking.IsX64Process(RemoteHooking.GetCurrentProcessId());

            _interface.Message(MessageType.Information, "Remote process is a {0}-bit process.", isX64Process ? "64" : "32");

            try
            {
                if (version == Direct3DVersion.AutoDetect)
                {
                    // Attempt to determine the correct version based on loaded module.
                    // In most cases this will work fine, however it is perfectly ok for an application to use a D3D10 device along with D3D11 devices
                    // so the version might matched might not be the one you want to use
                    var d3D9Loaded    = IntPtr.Zero;
                    var d3D10Loaded   = IntPtr.Zero;
                    var d3D10_1Loaded = IntPtr.Zero;
                    var d3D11Loaded   = IntPtr.Zero;
                    var d3D11_1Loaded = IntPtr.Zero;

                    var delayTime  = 100;
                    var retryCount = 0;
                    while (d3D9Loaded == IntPtr.Zero &&
                           d3D10Loaded == IntPtr.Zero &&
                           d3D10_1Loaded == IntPtr.Zero &&
                           d3D11Loaded == IntPtr.Zero &&
                           d3D11_1Loaded == IntPtr.Zero)
                    {
                        retryCount++;
                        d3D9Loaded    = NativeMethods.GetModuleHandle("d3d9.dll");
                        d3D10Loaded   = NativeMethods.GetModuleHandle("d3d10.dll");
                        d3D10_1Loaded = NativeMethods.GetModuleHandle("d3d10_1.dll");
                        d3D11Loaded   = NativeMethods.GetModuleHandle("d3d11.dll");
                        d3D11_1Loaded = NativeMethods.GetModuleHandle("d3d11_1.dll");
                        Thread.Sleep(delayTime);

                        if (retryCount * delayTime > 5000)
                        {
                            _interface.Message(MessageType.Error, "Unsupported Direct3D version, or Direct3D DLL not loaded within 5 seconds.");
                            return(false);
                        }
                    }

                    version = Direct3DVersion.Unknown;
                    if (d3D11_1Loaded != IntPtr.Zero)
                    {
                        _interface.Message(MessageType.Debug, "Autodetect found Direct3D 11.1");
                        version = Direct3DVersion.Direct3D11_1;
                    }
                    else if (d3D11Loaded != IntPtr.Zero)
                    {
                        _interface.Message(MessageType.Debug, "Autodetect found Direct3D 11");
                        version = Direct3DVersion.Direct3D11;
                    }
                    else if (d3D10_1Loaded != IntPtr.Zero)
                    {
                        _interface.Message(MessageType.Debug, "Autodetect found Direct3D 10.1");
                        version = Direct3DVersion.Direct3D10_1;
                    }
                    else if (d3D10Loaded != IntPtr.Zero)
                    {
                        _interface.Message(MessageType.Debug, "Autodetect found Direct3D 10");
                        version = Direct3DVersion.Direct3D10;
                    }
                    else if (d3D9Loaded != IntPtr.Zero)
                    {
                        _interface.Message(MessageType.Debug, "Autodetect found Direct3D 9");
                        version = Direct3DVersion.Direct3D9;
                    }
                }

                switch (version)
                {
                case Direct3DVersion.Direct3D9:
                    _directXHook = new DXHookD3D9(_interface);
                    break;

                case Direct3DVersion.Direct3D9Simple:
                    _directXHook = new DXHookD3D9Simple(_interface);
                    break;     //case Direct3DVersion.Direct3D9Obs:

                case Direct3DVersion.Direct3D9SharedMem:
                    _directXHook = new DXHookD3D9SharedMem(_interface);
                    break;

                //case Direct3DVersion.Direct3D9Obs:
                //    _directXHook = new DXHookD3D9Obs(_interface);
                //    break;
                //case Direct3DVersion.Direct3D10:
                //    _directXHook = new DXHookD3D10(_interface);
                //    break;
                //case Direct3DVersion.Direct3D10_1:
                //    _directXHook = new DXHookD3D10_1(_interface);
                //    break;
                //case Direct3DVersion.Direct3D11:
                //    _directXHook = new DXHookD3D11(_interface);
                //    break;
                //case Direct3DVersion.Direct3D11_1:
                //    _directXHook = new DXHookD3D11_1(_interface);
                //    return;
                default:
                    _interface.Message(MessageType.Error, "Unsupported Direct3D version: {0}", version);
                    return(false);
                }

                _directXHook.Config = config;
                _directXHook.Hook();

                return(true);
            }
            catch (Exception e)
            {
                // Notify the host/server application about this error
                _interface.Message(MessageType.Error, "Error in InitialiseHook: {0}", e.ToString());
                return(false);
            }
        }