/// <summary>
        ///
        /// </summary>
        protected virtual void Idle()
        {
            SlimDX.Direct3D9.Device device = Device;

            device.BeginScene();

            // reset the depth buffer to 1.0 and the render target to black
            device.Clear(ClearFlags.Target | ClearFlags.ZBuffer,
                         new Color4(0, 0, 0), 1.0f, 0);

            // prepare for drawing sprites. We need transparency and z-order
            Sprite.Begin(SpriteFlags.AlphaBlend
                         | SpriteFlags.SortDepthBackToFront);

            OnRender(new RenderEventArgs(this, Device));

            System.Diagnostics.Debug.Assert(device != null);

            // aaaannnd.... done!
            Sprite.End();

            // painting done ...
            device.EndScene();

            // ... so show the result on screen
            device.Present();

            OnIdleEvent(new EventArgs());
        }
Example #2
0
        public bool RenderGauge()
        {
            try
            {
                if (device != null && !DX_reinit)
                {
                    Single brushAngle = (Int32)(m_BaseArcStart + (m_value - m_MinValue) * m_BaseArcSweep /
                                                (m_MaxValue - m_MinValue)) % 360;
                    Double needleAngle = brushAngle * Math.PI / 180;
                    verts1[0].X = (float)(Center.X + m_NeedleRadius / 4 * Math.Cos(needleAngle));
                    verts1[0].Y = (float)(Center.Y + m_NeedleRadius / 4 * Math.Sin(needleAngle));
                    verts1[1].X = (float)(Center.X + m_NeedleRadius * Math.Cos(needleAngle));
                    verts1[1].Y = (float)(Center.Y + m_NeedleRadius * Math.Sin(needleAngle));

                    device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black.ToArgb(), 0.0f, 0);
                    sprite.Begin(SpriteFlags.AlphaBlend);

                    if (BackgroundTexture != null)
                    {
                        sprite.Draw(BackgroundTexture, texture_size, (Color4)Color.White);
                    }

                    sprite.End();
                    //Begin the scene
                    device.BeginScene();
                    device.SetRenderState(RenderState.AlphaBlendEnable, true);
                    device.SetRenderState(RenderState.SourceBlend, SlimDX.Direct3D9.Blend.SourceAlpha);
                    device.SetRenderState(RenderState.DestinationBlend, SlimDX.Direct3D9.Blend.DestinationAlpha);
                    line.Draw(verts1, Color.Red);
                    device.EndScene();
                    device.Present();
                    return(true);
                }

                if (DX_reinit)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Debug.Write(ex.ToString());

                if (DX_reinit)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Example #3
0
        private void Render()
        {
            if (deviceLost)
            {
                // This should only become true if we're using D3D9, so we can assume the
                // D3D9 context is valid at this point.
                if (Device.TestCooperativeLevel() == global::SlimDX.Direct3D9.ResultCode.DeviceNotReset)
                {
                    Device.Reset(Context9.PresentParameters);
                    deviceLost = false;
                    OnResetDevice();
                }
                else
                {
                    Thread.Sleep(100);
                    return;
                }
            }

            try
            {
                Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.LightGray, 1.0f, 0);
                Device.BeginScene();

                foreach (CollisionObject colObj in Demo.World.CollisionObjectArray)
                {
                    if (colObj is SoftBody)
                    {
                        if (Demo.IsDebugDrawEnabled)
                        {
                            continue;
                        }

                        Device.Material = SoftBodyMaterial;
                        Device.SetTransform(TransformState.World, Matrix.Identity);
                        _meshFactory.RenderSoftBody(colObj as SoftBody);
                    }
                    else
                    {
                        if ("Ground".Equals(colObj.UserObject))
                        {
                            Device.Material = GroundMaterial;
                        }
                        else if (colObj.ActivationState == ActivationState.ActiveTag)
                        {
                            Device.Material = ActiveMaterial;
                        }
                        else
                        {
                            Device.Material = PassiveMaterial;
                        }
                        _meshFactory.Render(colObj);
                    }
                }

                if (Demo.IsDebugDrawEnabled)
                {
                    (Demo.World.DebugDrawer as PhysicsDebugDraw).DrawDebugWorld(Demo.World);
                }
                Info.OnRender(Demo.FramesPerSecond);

                Device.EndScene();
                Device.Present();
            }
            catch (global::SlimDX.Direct3D9.Direct3D9Exception e)
            {
                if (e.ResultCode == global::SlimDX.Direct3D9.ResultCode.DeviceLost)
                {
                    OnLostDevice();
                    deviceLost = true;
                }
                else
                {
                    throw;
                }
            }
        }
Example #4
0
        public void Run()
        {
            if (_loaded)
            {
                Window.Show();

                ViewerSetup viewer = new ViewerSetup();

                _lastTime = Stopwatch.GetTimestamp();
                while (_running)
                {
                    Application.DoEvents();
                    if (!_deactive)
                    {
                        long currentTime = Stopwatch.GetTimestamp();

                        long elapsed = (currentTime - _lastTime) / Stopwatch.Frequency;
                        _lastTime = currentTime;

                        Input.Update();

                        if (Input.GetKeyPress(Key.Escape))
                        {
                            Quit();
                        }

                        if (CurrentState != null)
                        {
                            CurrentState.RequestViewer(out viewer);
                        }
                        _stateChanged = false;
                        if (CurrentState != null)
                        {
                            CurrentState.Update(elapsed);
                        }
                        if (_stateChanged)
                        {
                            continue;
                        }
                        try {
                            _device.Clear(viewer.ClearFlags, Color.White, 1.0f, 0);
                        } catch (Direct3D9Exception dex) {
                        }
                        if (_device.BeginScene().IsSuccess)
                        {
                            if (CurrentState != null)
                            {
                                CurrentState.Render();
                            }
                            _device.EndScene();
                            _device.Present();
                            if (++_currentBackBuffer == _setup.TotalBackBuffers + 1)
                            {
                                _currentBackBuffer = 0;
                            }
                        }
                    }
                }
                Release();
                Application.Exit();
            }
        }
Example #5
0
        /// <summary>
        /// Sets the render states and draws the selected objects to scene.
        /// </summary>
        /// <param name="direct3DDevice">The direct 3D device pointer.</param>
        /// <returns><see cref="int"/></returns>
        public int EndSceneHook(IntPtr direct3DDevice)
        {
            // Do the first scan.
            if (!_opened)
            {
                _memory.OpenSF4Process();
                _memory.RunScan();

                _interface.WriteConsole("Street Fighter 4 Process hooked.");

                _opened = true;
            }

            if (_device == null)
            {
                _device = Device.FromPointer(direct3DDevice);

                _interface.WriteConsole(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\uiBackground.png");

                _background = Texture.FromFile(
                    _device,
                    Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\Resources\Images\uiBackground.png");

                _interface.WriteConsole("Device created.");

                // Attempting to scale the font.
                _fontSize = _device.Viewport.Height / 48;
                _interface.WriteConsole(string.Format("Font size set to {0}", _fontSize));

                _font = new Font(_device, new System.Drawing.Font("Consolas", _fontSize));
            }

            // The game calls endscene twice a frame. We only need to draw once.
            // We should just return as normal the other time.
            if (_endsceneSkip)
            {
                _endsceneSkip = false;
                return(_device.EndScene().Code);
            }

            _endsceneSkip = true;

            //// _device.SetRenderState(RenderState.Lighting, false);
            //// _device.SetRenderState(RenderState.SpecularEnable, false);

            _device.SetRenderState(RenderState.CullMode, Cull.None);
            _device.SetRenderState(RenderState.AlphaBlendEnable, true);
            _device.SetRenderState(RenderState.VertexBlend, VertexBlend.Disable);
            _device.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha);
            _device.SetRenderState(RenderState.DestinationBlend, Blend.InverseSourceAlpha);
            _device.SetRenderState(RenderState.BlendOperationAlpha, BlendOperation.Minimum);
            _device.SetRenderState(RenderState.FillMode, FillMode.Solid);
            _device.SetRenderState(RenderState.ColorWriteEnable, 0xF);
            _device.SetRenderState(RenderState.MultisampleAntialias, false);

            // Setting up the camera
            Vector3 eye = new Vector3 {
                X = _memory.GetCamX(), Y = _memory.GetCamY(), Z = _memory.GetCamZ()
            };
            Vector3 target = new Vector3 {
                X = _memory.GetCamXp(), Y = _memory.GetCamYp(), Z = _memory.GetCamZp()
            };

            float zoom = _memory.GetCamZoom();

            _device.SetRenderState(RenderState.Lighting, false); // We don't need light for this...
            _device.SetTransform(TransformState.View, Matrix.LookAtLH(eye, target, new Vector3(0, 1, 0)));

            // Fix this shit later!
            _device.SetTransform(
                TransformState.Projection,
                Matrix.PerspectiveLH(0.1f * 16 / 9 * zoom + 0.008f, 0.1f * zoom + 0.008f, 0.1F, 100.0F));

            _playerOneBoxes = _memory.ReadMemoryByteArrayWithBase(0x00688E6C, new int[] { 0x8, 0x2190 }, 25248);
            _playerTwoBoxes = _memory.ReadMemoryByteArrayWithBase(0x00688E6C, new int[] { 0xC, 0x2190 }, 25248);

            // Draw everything...
            if (_interface.DrawBasic1)
            {
                DrawHurtBoxes(_playerOneBoxes, _device);
            }

            if (_interface.DrawBasic2)
            {
                DrawHurtBoxes(_playerTwoBoxes, _device);
            }

            if (_interface.DrawPhysics1)
            {
                DrawPhysicsBoxes(_playerOneBoxes, _device);
            }

            if (_interface.DrawPhysics2)
            {
                DrawPhysicsBoxes(_playerTwoBoxes, _device);
            }

            if (_interface.DrawGrab1)
            {
                DrawThrowVulnerableBoxes(_playerOneBoxes, _device);
            }

            if (_interface.DrawGrab2)
            {
                DrawThrowVulnerableBoxes(_playerTwoBoxes, _device);
            }

            if (_interface.DrawHit1)
            {
                DrawHitbox(1, _device);
            }

            if (_interface.DrawHit2)
            {
                DrawHitbox(2, _device);
            }

            if (_interface.DrawGrab1)
            {
                DrawGrabBox(1, _device);
            }

            if (_interface.DrawGrab2)
            {
                DrawGrabBox(2, _device);
            }

            if (_interface.DrawProjectile1)
            {
                DrawProjectileBox(1, _device);
            }

            if (_interface.DrawProjectile2)
            {
                DrawProjectileBox(2, _device);
            }

            if (_interface.DrawProx1)
            {
                DrawProxBox(1, _device);
            }

            if (_interface.DrawProx2)
            {
                DrawProxBox(2, _device);
            }

            if (_interface.DrawInfo)
            {
                DrawInfo(_device);
            }

            _interface.FrameNumber = _memory.GetFrameCount();

            // This does not use the sprite we use for all the other text...
            _font.DrawString(null, "Frame Trapped Lab Active", 20, 20, _textColor);

            return(_device.EndScene().Code);
        }