Пример #1
0
 /// <summary>
 /// Implements logic to update any relevant sample state.
 /// </summary>
 protected virtual void OnUpdate()
 {
     if (Freelook.Update(FrameDelta))
     {
         Device.SetTransform(TransformState.View, Freelook.View);
     }
     PhysicsContext.Update(FrameDelta);
 }
Пример #2
0
        protected virtual void OnResetDevice()
        {
            Fps.OnResetDevice();

            Matrix projection = Matrix.PerspectiveFovLH(FieldOfView, AspectRatio, NearPlane, FarPlane);

            Device.SetTransform(TransformState.Projection, projection);
            Device.SetTransform(TransformState.View, Freelook.View);

            Device.SetRenderState(RenderState.Ambient, Ambient);

            MeshFactory.OnResetDevice();
        }
Пример #3
0
        protected virtual void OnResetDevice()
        {
            Info.OnResetDevice();

            Matrix projection = Matrix.PerspectiveFovLH(FieldOfView, AspectRatio, NearPlane, FarPlane);

            Device.SetTransform(TransformState.Projection, projection);
            UpdateView();

            Device.SetRenderState(RenderState.Ambient, Ambient);

            Device.SetLight(0, light);
            Device.EnableLight(0, true);

            _meshFactory.OnResetDevice();
        }
Пример #4
0
        public override void UpdateView()
        {
            FreeLook freelook = Demo.Freelook;

            Device.SetTransform(TransformState.View, Matrix.LookAtLH(MathHelper.Convert(freelook.Eye), MathHelper.Convert(freelook.Target), MathHelper.Convert(freelook.Up)));
        }
Пример #5
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;
                }
            }
        }
Пример #6
0
        public Engine(EngineSetup setup = null)
        {
            XmlConfigurator.Configure();

            _loaded = false;
            _setup  = new EngineSetup();
            if (setup != null)
            {
                _setup = setup;
            }
            _gEngine = this;

            var d3d         = new Direct3D();
            var enumeration = new DeviceEnumeration(d3d);

            if (enumeration.ShowDialog() != DialogResult.OK)
            {
                ReleaseCom(d3d);
                return;
            }


            Window = new FpsForm {
                Name            = "WindowClass",
                Text            = _setup.Name,
                FormBorderStyle = enumeration.Windowed ? FormBorderStyle.FixedSingle : FormBorderStyle.None,
                Size            = new Size(800, 600)
            };

            var pp = new PresentParameters {
                BackBufferWidth              = enumeration.SelectedDisplayMode.Width,
                BackBufferHeight             = enumeration.SelectedDisplayMode.Height,
                BackBufferFormat             = enumeration.SelectedDisplayMode.Format,
                BackBufferCount              = _setup.TotalBackBuffers,
                SwapEffect                   = SwapEffect.Discard,
                DeviceWindowHandle           = Window.Handle,
                Windowed                     = enumeration.Windowed,
                EnableAutoDepthStencil       = true,
                AutoDepthStencilFormat       = Format.D24S8,
                FullScreenRefreshRateInHertz = enumeration.SelectedDisplayMode.RefreshRate,
                PresentationInterval         = enumeration.VSync ? PresentInterval.Default :  PresentInterval.Immediate,
                Multisample                  = MultisampleType.None,
                MultisampleQuality           = 0,
                PresentFlags                 = PresentFlags.None
            };

            enumeration.Dispose();

            _device = new Device(d3d, 0, DeviceType.Hardware, Window.Handle, CreateFlags.MixedVertexProcessing, pp);

            ReleaseCom(d3d);

            _device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Anisotropic);
            _device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Anisotropic);
            _device.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.Linear);

            var proj = Matrix.PerspectiveFovLH(
                (float)(Math.PI / 4),
                (float)pp.BackBufferWidth / pp.BackBufferHeight,
                0.1f / _setup.Scale, 1000.0f / _setup.Scale
                );

            _device.SetTransform(TransformState.Projection, proj);
            _displayMode = new SlimDX.Direct3D9.DisplayMode {
                Width       = pp.BackBufferWidth,
                Height      = pp.BackBufferHeight,
                RefreshRate = pp.FullScreenRefreshRateInHertz,
                Format      = pp.BackBufferFormat
            };
            _currentBackBuffer = 0;

            _sprite = new Sprite(_device);


            Window.Show();
            Window.Activate();
            _states      = new List <State>();
            CurrentState = null;

            ScriptManager = new ResourceManager <Script>();

            Input = new Input(Window);

            if (_setup.StateSetup != null)
            {
                _setup.StateSetup();
            }

            _loaded  = true;
            _running = true;
        }
Пример #7
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);
        }
Пример #8
0
        public Engine(EngineSetup setup = null)
        {
            XmlConfigurator.Configure();

            _loaded = false;
            _setup = new EngineSetup();
            if (setup != null) {
                _setup = setup;
            }
            _gEngine = this;

            var d3d = new Direct3D();
            var enumeration = new DeviceEnumeration(d3d);
            if (enumeration.ShowDialog() != DialogResult.OK) {
                ReleaseCom(d3d);
                return;
            }

            Window = new FpsForm {
                Name = "WindowClass",
                Text = _setup.Name,
                FormBorderStyle = enumeration.Windowed ? FormBorderStyle.FixedSingle : FormBorderStyle.None,
                Size = new Size(800, 600)
            };

            var pp = new PresentParameters {
                BackBufferWidth = enumeration.SelectedDisplayMode.Width,
                BackBufferHeight = enumeration.SelectedDisplayMode.Height,
                BackBufferFormat = enumeration.SelectedDisplayMode.Format,
                BackBufferCount = _setup.TotalBackBuffers,
                SwapEffect = SwapEffect.Discard,
                DeviceWindowHandle = Window.Handle,
                Windowed =  enumeration.Windowed,
                EnableAutoDepthStencil =  true,
                AutoDepthStencilFormat = Format.D24S8,
                FullScreenRefreshRateInHertz = enumeration.SelectedDisplayMode.RefreshRate,
                PresentationInterval = enumeration.VSync ? PresentInterval.Default :  PresentInterval.Immediate,
                Multisample = MultisampleType.None,
                MultisampleQuality = 0,
                PresentFlags = PresentFlags.None

            };
            enumeration.Dispose();

            _device = new Device(d3d, 0, DeviceType.Hardware, Window.Handle, CreateFlags.MixedVertexProcessing, pp);

            ReleaseCom(d3d);

            _device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Anisotropic);
            _device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Anisotropic);
            _device.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.Linear);

            var proj = Matrix.PerspectiveFovLH(
                (float) (Math.PI/4),
                (float)pp.BackBufferWidth/pp.BackBufferHeight,
                0.1f/_setup.Scale, 1000.0f/_setup.Scale
            );
            _device.SetTransform(TransformState.Projection, proj);
            _displayMode = new SlimDX.Direct3D9.DisplayMode {
                Width = pp.BackBufferWidth,
                Height = pp.BackBufferHeight,
                RefreshRate = pp.FullScreenRefreshRateInHertz,
                Format = pp.BackBufferFormat
            };
            _currentBackBuffer = 0;

            _sprite = new Sprite(_device);

            Window.Show();
            Window.Activate();
            _states = new List<State>();
            CurrentState = null;

            ScriptManager = new ResourceManager<Script>();

            Input = new Input(Window);

            if (_setup.StateSetup != null) {
                _setup.StateSetup();
            }

            _loaded = true;
            _running = true;
        }