Exemple #1
0
        /// <summary>
        /// Ctor
        ///
        /// From here we have to decide if this "GameObject" starts from the next object link at 0x08 or if it's an initial object to which we start at 0x10
        /// Initial objects are objects at the start of the active and tagged objects.
        /// </summary>
        /// <param name="objectAddress"></param>
        /// <param name="memory"></param>
        /// <param name="useNextObjectLink"></param>
        public GameObjectBase(long objectAddress, bool useNextObjectLink, bool isActiveObject, bool isBaseNetworkableObject)
        {
            _useNextAddress = useNextObjectLink;
            InitialAddress  = objectAddress;
            var t = objectAddress.ToString("X");

            _isActiveObject = isActiveObject;
            _rotationMatrix = new SharpDX.Mathematics.Interop.RawMatrix();
            _layer          = 0;
            _tag            = null;

            _name              = "";
            _positionVector    = new Vector3();
            _playerNameUnicode = "";
            _networkablePtr    = IntPtr.Zero;
            _playerFlagsPtr    = IntPtr.Zero;
            _position          = IntPtr.Zero;
            _rotation          = IntPtr.Zero;
            _steamId           = 0;
            _lifeState         = 0;

            var objectPtr = new IntPtr(objectAddress);

            _isNetworkableObject = isBaseNetworkableObject;

            /* Read the memory at 0x08 and sets the "NextObjectAddress" which is used if this is an object using the next object link */
            if (_useNextAddress)
            {
                var gameObjectValue = KeeperOf.Memory.ReadLong(IntPtr.Add(objectPtr, LastObjectBase.NextObjectLink));
                _nextObjectAddress = gameObjectValue;

                /* Now initializing the pointers here, once, instead of creating a new one everytime a mem call was used */
                _nextObjectAddressPtr = new IntPtr(gameObjectValue);

                _objectAddressPtr = IntPtr.Zero;
            }
            else if (_isNetworkableObject)
            {
                var gameObjectValue = KeeperOf.Memory.ReadLong(IntPtr.Add(objectPtr, LastObjectBase.GameObject));
                _objectAddressPtr = new IntPtr(gameObjectValue);

                /* Since this is a struct, we have to do something here */
                var nextGameObjectValue = KeeperOf.Memory.ReadLong(IntPtr.Add(objectPtr, LastObjectBase.NextObjectLink));
                _nextObjectAddressPtr = new IntPtr(nextGameObjectValue);
                _nextObjectAddress    = nextGameObjectValue;
            }
            else
            {
                var gameObjectValue     = KeeperOf.Memory.ReadLong(IntPtr.Add(objectPtr, LastObjectBase.GameObject));
                var nextGameObjectValue = KeeperOf.Memory.ReadLong(IntPtr.Add(objectPtr, LastObjectBase.NextObjectLink));

                /* Now initializing the pointers here, once, instead of creating a new one everytime a mem call was used */
                _objectAddressPtr     = new IntPtr(gameObjectValue);
                _nextObjectAddressPtr = new IntPtr(nextGameObjectValue);
                _nextObjectAddress    = nextGameObjectValue;
            }
        }
Exemple #2
0
        public DUIMatrix4x4(float M11, float M12, float M13, float M14, float M21, float M22, float M23, float M24, float M31, float M32, float M33, float M34, float M41, float M42, float M43, float M44)
        {
            dxMmatrix4x4     = new SharpDX.Mathematics.Interop.RawMatrix();
            dxMmatrix4x4.M11 = M11;
            dxMmatrix4x4.M12 = M12;
            dxMmatrix4x4.M13 = M13;
            dxMmatrix4x4.M14 = M14;

            dxMmatrix4x4.M21 = M21;
            dxMmatrix4x4.M22 = M22;
            dxMmatrix4x4.M23 = M23;
            dxMmatrix4x4.M24 = M24;

            dxMmatrix4x4.M31 = M31;
            dxMmatrix4x4.M32 = M32;
            dxMmatrix4x4.M33 = M33;
            dxMmatrix4x4.M34 = M34;

            dxMmatrix4x4.M41 = M41;
            dxMmatrix4x4.M42 = M42;
            dxMmatrix4x4.M43 = M43;
            dxMmatrix4x4.M44 = M44;
        }
Exemple #3
0
        public DUIMatrix4x4(float[] values)
        {
            dxMmatrix4x4     = new SharpDX.Mathematics.Interop.RawMatrix();
            dxMmatrix4x4.M11 = values[0];
            dxMmatrix4x4.M12 = values[1];
            dxMmatrix4x4.M13 = values[2];
            dxMmatrix4x4.M14 = values[3];

            dxMmatrix4x4.M21 = values[4];
            dxMmatrix4x4.M22 = values[5];
            dxMmatrix4x4.M23 = values[6];
            dxMmatrix4x4.M24 = values[7];

            dxMmatrix4x4.M31 = values[8];
            dxMmatrix4x4.M32 = values[9];
            dxMmatrix4x4.M33 = values[10];
            dxMmatrix4x4.M34 = values[11];

            dxMmatrix4x4.M41 = values[12];
            dxMmatrix4x4.M42 = values[13];
            dxMmatrix4x4.M43 = values[14];
            dxMmatrix4x4.M44 = values[15];
        }
Exemple #4
0
        public DUIMatrix4x4()
        {
            dxMmatrix4x4     = new SharpDX.Mathematics.Interop.RawMatrix();
            dxMmatrix4x4.M11 = 1;
            dxMmatrix4x4.M12 = 0;
            dxMmatrix4x4.M13 = 0;
            dxMmatrix4x4.M14 = 0;

            dxMmatrix4x4.M21 = 0;
            dxMmatrix4x4.M22 = 1;
            dxMmatrix4x4.M23 = 0;
            dxMmatrix4x4.M24 = 0;

            dxMmatrix4x4.M31 = 0;
            dxMmatrix4x4.M32 = 0;
            dxMmatrix4x4.M33 = 1;
            dxMmatrix4x4.M34 = 0;

            dxMmatrix4x4.M41 = 0;
            dxMmatrix4x4.M42 = 0;
            dxMmatrix4x4.M43 = 0;
            dxMmatrix4x4.M44 = 1;
        }
        public override void SetTextureMatrix(int stage, Matrix4 xform)
        {
            // the matrix we'll apply after conv. to D3D format
            var newMat = xform;

            // cache this since it's used often
            var autoTexCoordType = this._texStageDesc[stage].AutoTexCoordType;

            // if a vertex program is bound, we mustn't set texture transforms
            if (vertexProgramBound)
            {
                _setTextureStageState(stage, D3D9.TextureStage.TextureTransformFlags, (int)TextureTransform.Disable);
                return;
            }

            if (autoTexCoordType == TexCoordCalcMethod.EnvironmentMap)
            {
                if ((this._deviceManager.ActiveDevice.D3D9DeviceCaps.VertexProcessingCaps &
                     D3D9.VertexProcessingCaps.TexGenSphereMap) ==
                    D3D9.VertexProcessingCaps.TexGenSphereMap)
                {
                    // inverts the texture for a spheremap
                    var matEnvMap = Matrix4.Identity;
                    // set env_map values
                    matEnvMap.m11 = -1.0f;
                    // concatenate
                    newMat = newMat * matEnvMap;
                }
                else
                {
                    /* If envmap is applied, but device doesn't support spheremap,
                     * then we have to use texture transform to make the camera space normal
                     * reference the envmap properly. This isn't exactly the same as spheremap
                     * (it looks nasty on flat areas because the camera space normals are the same)
                     * but it's the best approximation we have in the absence of a proper spheremap */

                    // concatenate with the xform
                    newMat = newMat * Matrix4.ClipSpace2DToImageSpace;
                }
            }

            // If this is a cubic reflection, we need to modify using the view matrix
            if (autoTexCoordType == TexCoordCalcMethod.EnvironmentMapReflection)
            {
                // Get transposed 3x3, ie since D3D is transposed just copy
                // We want to transpose since that will invert an orthonormal matrix ie rotation
                var viewTransposed = Matrix4.Identity;
                viewTransposed.m00 = this._viewMatrix.m00;
                viewTransposed.m01 = this._viewMatrix.m10;
                viewTransposed.m02 = this._viewMatrix.m20;
                viewTransposed.m03 = 0.0f;

                viewTransposed.m10 = this._viewMatrix.m01;
                viewTransposed.m11 = this._viewMatrix.m11;
                viewTransposed.m12 = this._viewMatrix.m21;
                viewTransposed.m13 = 0.0f;

                viewTransposed.m20 = this._viewMatrix.m02;
                viewTransposed.m21 = this._viewMatrix.m12;
                viewTransposed.m22 = this._viewMatrix.m22;
                viewTransposed.m23 = 0.0f;

                viewTransposed.m30 = 0;
                viewTransposed.m31 = 0;
                viewTransposed.m32 = 0;
                viewTransposed.m33 = 1.0f;

                // concatenate
                newMat = newMat * viewTransposed;
            }

            if (autoTexCoordType == TexCoordCalcMethod.ProjectiveTexture)
            {
                // Derive camera space to projector space transform
                // To do this, we need to undo the camera view matrix, then
                // apply the projector view & projection matrices
                newMat = this._viewMatrix.Inverse();

                if (texProjRelative)
                {
                    Matrix4 viewMatrix;
                    this._texStageDesc[stage].Frustum.CalcViewMatrixRelative(texProjRelativeOrigin, out viewMatrix);
                    newMat = viewMatrix * newMat;
                }
                else
                {
                    newMat = this._texStageDesc[stage].Frustum.ViewMatrix * newMat;
                }
                newMat = this._texStageDesc[stage].Frustum.ProjectionMatrix * newMat;
                newMat = Matrix4.ClipSpace2DToImageSpace * newMat;
                newMat = xform * newMat;
            }

            // need this if texture is a cube map, to invert D3D's z coord
            if (autoTexCoordType != TexCoordCalcMethod.None && autoTexCoordType != TexCoordCalcMethod.ProjectiveTexture)
            {
                newMat.m20 = -newMat.m20;
                newMat.m21 = -newMat.m21;
                newMat.m22 = -newMat.m22;
                newMat.m23 = -newMat.m23;
            }

            // convert our matrix to D3D format
            DX.Mathematics.Interop.RawMatrix d3dMat = D3D9Helper.MakeD3DMatrix(newMat);

            // set the matrix if it is not the identity
            if (!D3D9Helper.IsIdentity(d3dMat))
            {
                //It's seems D3D automatically add a texture coordinate with value 1,
                //and fill up the remaining texture coordinates with 0 for the input
                //texture coordinates before pass to texture coordinate transformation.

                //NOTE: It's difference with D3DDECLTYPE enumerated type expand in
                //DirectX SDK documentation!

                //So we should prepare the texcoord transform, make the transformation
                //just like standardized vector expand, thus, fill w with value 1 and
                //others with 0.
                if (autoTexCoordType == TexCoordCalcMethod.None)
                {
                    //FIXME: The actually input texture coordinate dimensions should
                    //be determine by texture coordinate vertex element. Now, just trust
                    //user supplied texture type matchs texture coordinate vertex element.
                    if (this._texStageDesc[stage].TexType == D3D9TextureType.Normal)
                    {
                        /* It's 2D input texture coordinate:
                         *
                         * texcoord in vertex buffer     D3D expanded to     We are adjusted to
                         * -->                           -->
                         * (u, v)                        (u, v, 1, 0)        (u, v, 0, 1)
                         */
                        Utility.Swap(ref d3dMat.M31, ref d3dMat.M41);
                        Utility.Swap(ref d3dMat.M32, ref d3dMat.M42);
                        Utility.Swap(ref d3dMat.M33, ref d3dMat.M43);
                        Utility.Swap(ref d3dMat.M34, ref d3dMat.M44);
                    }
                }
                //else
                //{
                //    // All texgen generate 3D input texture coordinates.
                //}

                // tell D3D the dimension of tex. coord
                var texCoordDim = TextureTransform.Count2;

                if (autoTexCoordType == TexCoordCalcMethod.ProjectiveTexture)
                {
                    //We want texcoords (u, v, w, q) always get divided by q, but D3D
                    //projected texcoords is divided by the last element (in the case of
                    //2D texcoord, is w). So we tweak the transform matrix, transform the
                    //texcoords with w and q swapped: (u, v, q, w), and then D3D will
                    //divide u, v by q. The w and q just ignored as it wasn't used by
                    //rasterizer.

                    switch (this._texStageDesc[stage].TexType)
                    {
                    case D3D9TextureType.Normal:
                        Utility.Swap(ref d3dMat.M13, ref d3dMat.M14);
                        Utility.Swap(ref d3dMat.M23, ref d3dMat.M24);
                        Utility.Swap(ref d3dMat.M33, ref d3dMat.M34);
                        Utility.Swap(ref d3dMat.M43, ref d3dMat.M44);

                        texCoordDim = TextureTransform.Projected | TextureTransform.Count3;
                        break;

                    case D3D9TextureType.Cube:
                    case D3D9TextureType.Volume:
                        // Yes, we support 3D projective texture.
                        texCoordDim = TextureTransform.Projected | TextureTransform.Count4;
                        break;
                    }
                }
                else
                {
                    switch (this._texStageDesc[stage].TexType)
                    {
                    case D3D9TextureType.Normal:
                        texCoordDim = TextureTransform.Count2;
                        break;

                    case D3D9TextureType.Cube:
                    case D3D9TextureType.Volume:
                        texCoordDim = TextureTransform.Count3;
                        break;
                    }
                }

                // note: int values of D3D.TextureTransform correspond directly with tex dimension, so direct conversion is possible
                // i.e. Count1 = 1, Count2 = 2, etc
                _setTextureStageState(stage, D3D9.TextureStage.TextureTransformFlags, (int)texCoordDim);

                // set the manually calculated texture matrix
                var d3DTransType = (D3D9.TransformState)((int)(D3D9.TransformState.Texture0) + stage);
                ActiveD3D9Device.SetTransform(d3DTransType, d3dMat);
            }
            else
            {
                // disable texture transformation
                _setTextureStageState(stage, D3D9.TextureStage.TextureTransformFlags, (int)TextureTransform.Disable);

                // Needless to sets texture transform here, it's never used at all
            }
        }
Exemple #6
0
		// Method to marshal from native to managed struct
        internal unsafe void __MarshalFrom(ref __Native @ref)
        {            
            this.Name = ( @ref.Name == IntPtr.Zero )?null:Marshal.PtrToStringAnsi(@ref.Name);
            this.TransformationMatrix = @ref.TransformationMatrix;
            this.PMeshContainer = @ref.PMeshContainer;
            this.PFrameSibling = @ref.PFrameSibling;
            this.PFrameFirstChild = @ref.PFrameFirstChild;
        }
Exemple #7
0
        /// <summary>	
        /// <p>Retrieves a matrix describing a transformation state.</p>	
        /// </summary>	
        /// <param name="state"><dd>  <p>Device state variable that is being modified. This parameter can be any member of the <strong><see cref="SharpDX.Direct3D9.TransformState"/></strong> enumerated type, or the <strong>D3DTS_WORLDMATRIX</strong> macro. </p> </dd></param>	
        /// <returns><dd>  <p>Pointer to a  <strong><see cref="SharpDX.Mathematics.Interop.RawMatrix"/></strong> structure, describing the returned transformation state. </p> </dd></returns>	
        /// <remarks>	
        /// <p>This method will not return device state for a device that is created using <see cref="SharpDX.Direct3D9.CreateFlags.PureDevice"/>. If you want to use this method, you must create your device with any of the other flag values in <see cref="SharpDX.Direct3D9.CreateFlags"/>. </p>	
        /// </remarks>	
        /// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='IDirect3DDevice9::GetTransform']/*"/>	
        /// <msdn-id>bb174414</msdn-id>	
        /// <unmanaged>HRESULT IDirect3DDevice9::GetTransform([In] D3DTRANSFORMSTATETYPE State,[Out] D3DMATRIX* pMatrix)</unmanaged>	
        /// <unmanaged-short>IDirect3DDevice9::GetTransform</unmanaged-short>	
        public SharpDX.Mathematics.Interop.RawMatrix GetTransform(SharpDX.Direct3D9.TransformState state) {
            unsafe {
                SharpDX.Mathematics.Interop.RawMatrix matrixRef;
                matrixRef = new SharpDX.Mathematics.Interop.RawMatrix();
                SharpDX.Result __result__;
                __result__= 
				SharpDX.Direct3D9.LocalInterop.Calliint(_nativePointer, unchecked((int)state), &matrixRef,((void**)(*(void**)_nativePointer))[45]);		
                __result__.CheckError();
                return matrixRef;
            }
        }
Exemple #8
0
     /// <summary>	
     /// <p>Gets an array of references to transposed matrices.</p>	
     /// </summary>	
     /// <param name="hParameter"><dd>  <p>Unique identifier. See Handles (Direct3D 9).</p> </dd></param>	
     /// <param name="matrixOut"><dd>  <p>Array of references to transposed matrices. See <strong><see cref="SharpDX.Mathematics.Interop.RawMatrix"/></strong>.</p> </dd></param>	
     /// <param name="count"><dd>  <p>Number of matrices in the array.</p> </dd></param>	
     /// <returns><p>If the method succeeds, the return value is <see cref="SharpDX.Direct3D9.ResultCode.Success"/>. If the method fails, the return value can be <see cref="SharpDX.Direct3D9.ResultCode.InvalidCall"/>.</p></returns>	
     /// <remarks>	
     /// <p>A transposed matrix contains column-major data; that is, each vector is contained in a column.</p><p>If the destination matrices are larger than the source matrices, only the upper-left components of each destination matrix will be filled, and the remaining destination matrix components will be set to zero.</p>	
     /// </remarks>	
     /// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='ID3DXBaseEffect::GetMatrixTransposePointerArray']/*"/>	
     /// <msdn-id>bb205694</msdn-id>	
     /// <unmanaged>HRESULT ID3DXBaseEffect::GetMatrixTransposePointerArray([In] D3DXHANDLE hParameter,[Out] D3DXMATRIX** ppMatrix,[In] unsigned int Count)</unmanaged>	
     /// <unmanaged-short>ID3DXBaseEffect::GetMatrixTransposePointerArray</unmanaged-short>	
     public void GetMatrixTransposePointerArray(SharpDX.Direct3D9.EffectHandle hParameter, out SharpDX.Mathematics.Interop.RawMatrix matrixOut, int count) {
         unsafe {
             var hParameter_ = new SharpDX.Direct3D9.EffectHandle.__Native();
             SharpDX.Direct3D9.EffectHandle.__MarshalTo(ref hParameter, ref hParameter_);
             matrixOut = new SharpDX.Mathematics.Interop.RawMatrix();
             SharpDX.Result __result__;
             fixed (void* matrixOut_ = &matrixOut)
                 __result__= 
 				SharpDX.Direct3D9.LocalInterop.Calliint(_nativePointer, hParameter_, matrixOut_, count,((void**)(*(void**)_nativePointer))[49]);		
             SharpDX.Direct3D9.EffectHandle.__MarshalFree(ref hParameter, ref hParameter_);
             __result__.CheckError();
         }
     }
Exemple #9
0
     /// <summary>	
     /// <p>Gets a transposed matrix.</p>	
     /// </summary>	
     /// <param name="hParameter"><dd>  <p>Unique identifier. See Handles (Direct3D 9).</p> </dd></param>	
     /// <param name="matrixRef"><dd>  <p>Returns a transposed matrix. See <strong><see cref="SharpDX.Mathematics.Interop.RawMatrix"/></strong>.</p> </dd></param>	
     /// <returns><p>If the method succeeds, the return value is <see cref="SharpDX.Direct3D9.ResultCode.Success"/>. If the method fails, the return value can be <see cref="SharpDX.Direct3D9.ResultCode.InvalidCall"/>.</p></returns>	
     /// <remarks>	
     /// <p>A transposed matrix contains column-major data; that is, each vector is contained in a column.</p><p>If the destination matrix is larger than the source matrix, only the upper-left elements of the destination matrix will be filled, and the remaining destination matrix components will be set to zero.</p>	
     /// </remarks>	
     /// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='ID3DXBaseEffect::GetMatrixTranspose']/*"/>	
     /// <msdn-id>bb205692</msdn-id>	
     /// <unmanaged>HRESULT ID3DXBaseEffect::GetMatrixTranspose([In] D3DXHANDLE hParameter,[Out] D3DXMATRIX* pMatrix)</unmanaged>	
     /// <unmanaged-short>ID3DXBaseEffect::GetMatrixTranspose</unmanaged-short>	
     internal void GetMatrixTranspose(SharpDX.Direct3D9.EffectHandle hParameter, out SharpDX.Mathematics.Interop.RawMatrix matrixRef) {
         unsafe {
             var hParameter_ = new SharpDX.Direct3D9.EffectHandle.__Native();
             SharpDX.Direct3D9.EffectHandle.__MarshalTo(ref hParameter, ref hParameter_);
             matrixRef = new SharpDX.Mathematics.Interop.RawMatrix();
             SharpDX.Result __result__;
             fixed (void* matrixRef_ = &matrixRef)
                 __result__= 
 				SharpDX.Direct3D9.LocalInterop.Calliint(_nativePointer, hParameter_, matrixRef_,((void**)(*(void**)_nativePointer))[45]);		
             SharpDX.Direct3D9.EffectHandle.__MarshalFree(ref hParameter, ref hParameter_);
             __result__.CheckError();
         }
     }
Exemple #10
0
     /// <summary>	
     /// <p>Gets the sprite transform.</p>	
     /// </summary>	
     /// <param name="transformRef"><dd>  <p>Pointer to a <strong><see cref="SharpDX.Mathematics.Interop.RawMatrix"/></strong> that contains a transform of the sprite from the original world space.</p> </dd></param>	
     /// <returns><p>If the method succeeds, the return value is <see cref="SharpDX.Result.Ok"/>. If the method fails, the following value will be returned.<see cref="SharpDX.Direct3D9.ResultCode.InvalidCall"/></p></returns>	
     /// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='ID3DXSprite::GetTransform']/*"/>	
     /// <msdn-id>bb174255</msdn-id>	
     /// <unmanaged>HRESULT ID3DXSprite::GetTransform([Out] D3DXMATRIX* pTransform)</unmanaged>	
     /// <unmanaged-short>ID3DXSprite::GetTransform</unmanaged-short>	
     internal void GetTransform(out SharpDX.Mathematics.Interop.RawMatrix transformRef) {
         unsafe {
             transformRef = new SharpDX.Mathematics.Interop.RawMatrix();
             SharpDX.Result __result__;
             fixed (void* transformRef_ = &transformRef)
                 __result__= 
 				SharpDX.Direct3D9.LocalInterop.Calliint(_nativePointer, transformRef_,((void**)(*(void**)_nativePointer))[4]);		
             __result__.CheckError();
         }
     }