public DrawIndexedHook(DeviceContext deviceContext, DepthStencilState depthDisabledState, Shaders shaders)
        {
            _deviceContext      = deviceContext;
            _depthDisabledState = depthDisabledState;
            _shaders            = shaders;
            _modelsInScene      = new List <ModelInfo>();
            SavedModels         = new List <ModelInfo>();

            _drawIndexedHook = new FunctionHook <DrawIndexed>(
                VirtualTableAddress.GetVtableAddress(_deviceContext.NativePointer, (int)VirtualTableIndices.D3D11DeviceContext.DrawIndexed),
                new DrawIndexed(OnDrawIndexed),
                this);

            _drawIndexedHook.Activate();
        }
Beispiel #2
0
        public void Hook()
        {
            try
            {
                DeviceContext deviceContext = null;

                if (!InitializeSwapChain(out var swapChain))
                {
                    _server.Message("Failed to create swap chain");
                }
                else
                {
                    _server.Message("Swap chain created successfully!");
                }

                _server.Message("Hooking Present()...");
                using (var presentHook = new PresentHook(swapChain))
                {
                    presentHook.OnInitialized += (eDevice, eDeviceContext) =>
                    {
                        _device       = eDevice;
                        deviceContext = eDeviceContext;
                    };
                    while (!presentHook.Initialized)
                    {
                    }
                }

                lock (_lock)
                {
                    _shaders = new Shaders(_device);
                }

                using (_drawIndexedHook = new DrawIndexedHook(deviceContext, _device.CreateDepthStencilState(false, false), _shaders))
                {
                    _server.NotifyHookStarted();
                    _server.Message("Ready for input...");

                    while (true)
                    {
                        if (_drawIndexedHook.IsLoggerEnabled)
                        {
                            if (Input.GetKey(Keys.NumPad2))
                            {
                                _drawIndexedHook.ChangeModel(-1);
                            }
                            else if (Input.GetKey(Keys.NumPad5))
                            {
                                _drawIndexedHook.ChangeModel(1);
                            }

                            if (Input.GetKey(Keys.NumPad1))
                            {
                                _drawIndexedHook.ChangeSelectedByteWidth(-1);
                            }
                            else if (Input.GetKey(Keys.NumPad3))
                            {
                                _drawIndexedHook.ChangeSelectedByteWidth(1);
                            }

                            Thread.Sleep(100);
                        }

                        if (Input.GetKey(Keys.End))
                        {
                            _server.Message($"Logger enabled: {_drawIndexedHook.ToggleLogger()}");
                            Thread.Sleep(1000);
                        }
                        if (Input.GetKey(Keys.Insert))
                        {
                            var selectedModel = _drawIndexedHook.GetSelectedModel();

                            _server.RequestSaveModel(selectedModel);
                            Thread.Sleep(1000);
                        }

                        // Only render saved models - Immediate
                        _drawIndexedHook.RenderSavedModelsOnly(Input.GetKey(Keys.NumPad0));

                        _server.Ping();
                    }
                }
            }
            catch (RemotingException)
            {
                // Host application has exited
            }
            catch (Exception e)
            {
                _server.Message(e.ToString());
            }
        }