/// <summary>
        /// In a derived class, implements logic to resize the buffer.
        /// During resize, the existing buffer contents need not be preserved.
        /// </summary>
        /// <param name="sizeInBytes">The new size, in bytes.</param>
        protected override void ResizeBuffer(int sizeInBytes)
        {
            if (buffer != null)
            {
                buffer.Dispose();
            }

            buffer = new D3D.VertexBuffer(
                device,
                sizeInBytes,
                D3D.Usage.Dynamic | D3D.Usage.WriteOnly,
                D3D.VertexFormat.None,
                D3D.Pool.Default
                );
        }
Exemple #2
0
        public SDX_VertexBuffer(SDX_Display display, VertexLayout layout, int vertexCount)
        {
            mDisplay = display;
            mCount   = vertexCount;

            mDeclaration = CreateVertexDeclaration(mDisplay.D3D_Device.Device, layout);
            Direct3D.VertexFormat mFormats = CreateVertexFormat(layout);

            mLayout = layout;

            mBuffer = new SlimDX.Direct3D9.VertexBuffer(
                mDisplay.D3D_Device.Device,
                vertexCount * layout.VertexSize,
                SlimDX.Direct3D9.Usage.WriteOnly,
                mFormats,
                Direct3D.Pool.Managed);
        }
Exemple #3
0
        private void Main_Load(object sender, EventArgs e)
        {
            HotKey = new Hotkey();
            HotKey.enable(this.Handle, Hotkey.Modifiers.None, Keys.Insert); // Delete //Insert
            HotKey.enable(this.Handle, Hotkey.Modifiers.Alt, Keys.F1);
            HotKey.enable(this.Handle, Hotkey.Modifiers.None, Keys.N);
            HotKey.enable(this.Handle, Hotkey.Modifiers.Alt, Keys.F3);
            HotKey.enable(this.Handle, Hotkey.Modifiers.Alt, Keys.F5);
            //HotKey.enable(base.Handle, Hotkey.Modifiers.None, Keys.CapsLock);
            //HotKey.enable(base.Handle, Hotkey.Modifiers.None, Keys.Q);

            Native.SetWindowLong(this.Handle, -20, (IntPtr)((Native.GetWindowLong(this.Handle, -20) ^ 0x80000) ^ 0x20));
            Native.SetLayeredWindowAttributes(this.Handle, 0, 0xff, 2);

            PresentParameters parameters = new SlimDX.Direct3D9.PresentParameters();
            parameters.Windowed = true;
            parameters.SwapEffect = SwapEffect.Discard;
            parameters.BackBufferFormat = Format.A8R8G8B8;
            parameters.BackBufferHeight = this.Height;
            parameters.BackBufferWidth = this.Width;
            parameters.PresentationInterval = PresentInterval.One;

            DXDevice = new SlimDX.Direct3D9.Device(new Direct3D(), 0, DeviceType.Hardware, this.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters[] { parameters });
            if (System.IO.File.Exists("map_large.png")) DXTextrureMapLarge = SlimDX.Direct3D9.Texture.FromFile(DXDevice, "map_large.png");
            if (System.IO.File.Exists("map.png")) DXTextrureMap = SlimDX.Direct3D9.Texture.FromFile(DXDevice, "map.png");
            if (System.IO.File.Exists("LagerMap.jpg")) DXTextureGameMap = SlimDX.Direct3D9.Texture.FromFile(DXDevice, "LagerMap.jpg");
            CircleVertices = new VertexBuffer(DXDevice, (circleComplexity + 2) * TexVertex.SizeBytes, Usage.WriteOnly, VertexFormat.None, Pool.Managed);
            DXSprite = new SlimDX.Direct3D9.Sprite(DXDevice);
            DXLine = new SlimDX.Direct3D9.Line(DXDevice);
            DXFont = new SlimDX.Direct3D9.Font(DXDevice, new System.Drawing.Font("NewRoman", 9f)); //NewRoman
            DXFontB = new SlimDX.Direct3D9.Font(DXDevice, new System.Drawing.Font("Tahoma", 12f)); //NewRoman

            if (this.GameMemory.Attach("H1Z1 PlayClient (Live)") == false) { Application.Exit(); return; }
            Thread dxThread = new Thread(new ThreadStart(DoProcess));
            dxThread.IsBackground = true;
            dxThread.Start();

            //Thread aimThread = new Thread(new ThreadStart(DoAiming));
            //aimThread.IsBackground = true;
            //aimThread.Start();
        }
 private void CreateNativeVertexBuffer()
 {
     nativeVertexBuffer = new VertexBufferD3D9(nativeDevice, maxNumberOfVertices * vertexSize,
                                               Usage.Dynamic, VertexFormatD3D9.None, Pool.Default);
 }
Exemple #5
0
        protected override void RenderBuffer()
        {
            if (!hasloaded)
            {

                internbuffer = new SlimDX.Direct3D9.VertexBuffer(engine.graphicsDevice, Vertex.getSize() * verts.Length, Usage.None, VertexFormat.None, Pool.Managed);
                List<Vertex> mtex = new List<Vertex>();
                for (int i = 0; i < verts.Length; i++)
                {
                    mtex.Add(new Vertex(verts[i], norms[i], texas[i]));
                }
                DataStream mstr = internbuffer.Lock(0, 0, LockFlags.None);
                mstr.WriteRange(mtex.ToArray());
                internbuffer.Unlock();
                List<VertexElement> elements = new List<VertexElement>();

                elements.Add(new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0));
                elements.Add(new VertexElement(0, sizeof(float)*3, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Normal, 0));
                elements.Add(new VertexElement(0, sizeof(float)*3+sizeof(float)*3, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0));
                elements.Add(VertexElement.VertexDeclarationEnd);

                    declaration = new VertexDeclaration(engine.graphicsDevice, elements.ToArray());

                hasloaded = true;

            }

                engine.graphicsDevice.VertexDeclaration = declaration;

                engine.graphicsDevice.SetStreamSource(0, internbuffer, 0, Vertex.getSize());

            engine.effect.Technique = engine.effect.GetTechnique("technique0");
            EffectHandle lightdirection = engine.effect.GetParameter(null, "LightDirection");
            EffectHandle lightenabled = engine.effect.GetParameter(null, "LightEnabled");
            engine.effect.SetValue<bool>(lightenabled, engine.LightingEnabled);
            engine.effect.SetValue<Vector3>(lightdirection, new Vector3(0, 1.4f, -2f));
            EffectHandle texhandle = engine.effect.GetParameter(null, "shaderTexture");
            engine.effect.SetTexture(texhandle, engine.texture);

               // Matrix mtrix = Matrix.Identity*Matrix.Translation(new Vector3(2,.5f,-9.4f))*Matrix.RotationY(rotation);
            Matrix worldrotation;
            bool mtr = false;
            if (!engine.rtarget)
            {
                worldrotation = Matrix.Transformation(new Vector3(), Quaternion.Identity, new Vector3(1, 1, 1), new Vector3(0, 0, 0), Quaternion.RotationMatrix(Matrix.RotationAxis(Vector3.UnitY,MathHelpers.DegreesToRadians(engine.worldRotation.Y))*Matrix.RotationAxis(Vector3.UnitX,MathHelpers.DegreesToRadians(engine.worldRotation.X))*Matrix.RotationAxis(Vector3.UnitZ, MathHelpers.DegreesToRadians(engine.worldRotation.Z))), new Vector3(0, 0, 0));//Matrix.RotationX(engine.worldRotation.X) * Matrix.RotationY(engine.worldRotation.Y) * Matrix.RotationZ(engine.worldRotation.Z);
            }
            else
            {

                    worldrotation = Matrix.Transformation(new Vector3(), Quaternion.Identity, new Vector3(1, 1, 1), new Vector3(0, 0, 0), Quaternion.RotationMatrix(Matrix.RotationAxis(Vector3.UnitY,MathHelpers.DegreesToRadians(RenderTargetChange.mchange.camrot.Y))*Matrix.RotationAxis(Vector3.UnitX, MathHelpers.DegreesToRadians(RenderTargetChange.mchange.camrot.X))*Matrix.RotationAxis(Vector3.UnitZ, MathHelpers.DegreesToRadians(RenderTargetChange.mchange.camrot.Z))), new Vector3(0, 0, 0));//Matrix.RotationX(engine.worldRotation.X) * Matrix.RotationY(engine.worldRotation.Y) * Matrix.RotationZ(engine.worldRotation.Z);
                    mtr = true;

            }

                Matrix worldmatrix = Matrix.LookAtLH(new Vector3(0, 0, 1), new Vector3(0, 0, 0), new Vector3(0, 1, 0));

            Matrix projectionmatrix = worldrotation*Matrix.PerspectiveFovLH(MathHelpers.DegreesToRadians(45), (float)engine.graphicsDevice.Viewport.Width / (float)engine.graphicsDevice.Viewport.Height, 1, 5000000);
            Matrix viewmatrix = Matrix.RotationX(rotation.X) * Matrix.RotationY(rotation.Y) * Matrix.RotationZ(rotation.Z);
             Matrix mtrix;
            if (!sta)
            {
                if (mtr)
                {
                    mtrix = viewmatrix * worldmatrix * Matrix.Translation(new Vector3(Position.X - RenderTargetChange.mchange.campos.X, Position.Y - RenderTargetChange.mchange.campos.Y, Position.Z - RenderTargetChange.mchange.campos.Z)) * projectionmatrix;
                }
                else
                {
                    mtrix = viewmatrix * worldmatrix * Matrix.Translation(new Vector3(Position.X - engine.cameraPosition.X, Position.Y - engine.cameraPosition.Y, Position.Z - engine.cameraPosition.Z)) * projectionmatrix;
                }
                }
            else
            {

                mtrix = viewmatrix * worldmatrix * Matrix.Translation(new Vector3(Position.X, Position.Y, Position.Z)) * projectionmatrix;
            }
            EffectHandle mathandle = engine.effect.GetParameter(null,"WorldViewProj");
            engine.effect.SetValue<Matrix>(mathandle, mtrix);
            if (!depthtest)
            {
                engine.graphicsDevice.SetRenderState(RenderState.ZEnable, ZBufferType.DontUseZBuffer);
            }
            engine.effect.Begin();
            engine.effect.BeginPass(0);
            if (engine.PMode == PrimitiveMode.TriangleList)
            {
                engine.graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, verts.Length / 3);
            }
            else
            {
                engine.graphicsDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, verts.Length);
            }
            engine.effect.EndPass();
            engine.effect.End();
            if (!depthtest)
            {
                engine.graphicsDevice.SetRenderState(RenderState.ZEnable, ZBufferType.UseZBuffer);
            }
        }