Пример #1
0
            public object MarshalNativeToManaged(IntPtr pNativeData)
            {
                if (pNativeData == IntPtr.Zero)
                {
                    return(null);
                }

                //NOTE: ikrimae: If it's an [in,out] paremeter, there may be some issues. Investigate later.
                //               Not needed now b/c D3DCompile funcs are only [in] for D3D_SHADER_MACRO

                var shaderMacroList = new List <D3D_SHADER_MACRO>();

                IntPtr pCurShaderMacro = pNativeData;

                while (true)
                {
                    D3D_SHADER_MACRO curShaderMacro = (D3D_SHADER_MACRO)Marshal.PtrToStructure(pCurShaderMacro, typeof(D3D_SHADER_MACRO));
                    shaderMacroList.Add(curShaderMacro);

                    if (curShaderMacro.Name == null && curShaderMacro.Definition == null)
                    {
                        pCurShaderMacro = IntPtr.Zero;
                        break;
                    }
                    //TODO: ikrimae: Should probably do an error check if someone doesn't pass a null terminated array.
                    //               Have to look at the D3D documentation to see if Name/Definition parameters can be null

                    pCurShaderMacro += D3D_SHADER_MACRO_BYTESIZE;
                }

                return(shaderMacroList.ToArray());
            }
Пример #2
0
        private unsafe static D3D_SHADER_MACRO[] ToAsciiDefines(ReadOnlySpan <ShaderDefine> defines)
        {
            var macros = new D3D_SHADER_MACRO[defines.Length];

            InitTlsMacroBuff();
            nuint asciiBuffOffset = 0;

            for (var i = 0; i < defines.Length; i++)
            {
                var define = defines[i];
                TlsMacroToPinnedAscii(define, ref asciiBuffOffset, out var pName, out var pDef);
                macros[i] = new D3D_SHADER_MACRO {
                    Name = (sbyte *)pName, Definition = (sbyte *)pDef
                };
            }

            return(macros);
        }
Пример #3
0
 //DX expects D3D_SHADER_MACRO[] to be null terminated
 private static D3D_SHADER_MACRO[] PrepareMacros(D3D_SHADER_MACRO[] macros)
 {
     if (macros == null)
     {
         return(null);
     }
     if (macros.Length == 0)
     {
         return(null);
     }
     if ((macros[macros.Length - 1].Name == null) && (macros[macros.Length - 1].Definition == null))
     {
         return(macros);
     }
     D3D_SHADER_MACRO[] destinationArray = new D3D_SHADER_MACRO[macros.Length + 1];
     Array.Copy(macros, destinationArray, macros.Length);
     destinationArray[macros.Length] = new D3D_SHADER_MACRO()
     {
         Name = null, Definition = null
     };
     return(destinationArray);
 }
            private IntPtr MarshalArrayWithAlloc(D3D_SHADER_MACRO[] shaderMacroArray)
            {
                int arrayByteSize = D3D_SHADER_MACRO_BYTESIZE * shaderMacroArray.Length;
                IntPtr pNativeShaderMacroArray = Marshal.AllocHGlobal(arrayByteSize);

                IntPtr pCurShaderMacro = pNativeShaderMacroArray;
                for (int i = 0; i < shaderMacroArray.Length; i++, pCurShaderMacro += (D3D_SHADER_MACRO_BYTESIZE))
                {
                    Marshal.StructureToPtr(shaderMacroArray[i], pCurShaderMacro, false);
                }

                return pNativeShaderMacroArray;
            }
 //DX expects D3D_SHADER_MACRO[] to be null terminated
 private static D3D_SHADER_MACRO[] PrepareMacros(D3D_SHADER_MACRO[] macros)
 {
     if (macros == null)
     {
         return null;
     }
     if (macros.Length == 0)
     {
         return null;
     }
     if ((macros[macros.Length - 1].Name == null) && (macros[macros.Length - 1].Definition == null))
     {
         return macros;
     }
     D3D_SHADER_MACRO[] destinationArray = new D3D_SHADER_MACRO[macros.Length + 1];
     Array.Copy(macros, destinationArray, macros.Length);
     destinationArray[macros.Length] = new D3D_SHADER_MACRO() { Name = null, Definition = null };
     return destinationArray;
 }
        static int D3DCompile_Hooked(IntPtr pSrcData,
                                     uint srcDataSize,
                                     String pSourceName,
                                     D3D_SHADER_MACRO[] pDefines,
                                     IntPtr pInclude,
                                     String pEntryPoint,
                                     String pTarget,
                                     uint flags1,
                                     uint flags2,
                                     out ID3DBlob ppCode,
                                     out ID3DBlob ppErrorMsgs)
        {
            try
            {
                Main This = (Main)HookRuntimeInfo.Callback;
                This.Interface.WriteConsole("D3DCompile_Hooked");
            }
            catch
            {
            }

            // call original API...
            return D3DCompile(pSrcData,
                              srcDataSize,
                              pSourceName,
                              pDefines,
                              pInclude,
                              pEntryPoint,
                              pTarget,
                              flags1,
                              flags2,
                              out ppCode,
                              out ppErrorMsgs);
        }
        static HRESULT D3DCompileFromFile_Hooked(String pFileName,
                                                 D3D_SHADER_MACRO[] pDefines,
                                                 IntPtr pInclude,
                                                 String pEntrypoint,
                                                 String pTarget,
                                                 uint Flags1,
                                                 uint Flags2,
                                                 out ID3DBlob ppCode,
                                                 out ID3DBlob ppErrorMsgs)
        {
            try
            {
                Main This = (Main)HookRuntimeInfo.Callback;
                This.Interface.WriteConsole("D3DCompileFromFile_Hooked");
                Console.WriteLine("D3DCompileFromFile_Hooked writing from client side");
            }
            catch
            {
            }

            return D3DCompileFromFile(pFileName,
                                      pDefines,
                                      pInclude,
                                      pEntrypoint,
                                      pTarget,
                                      Flags1,
                                      Flags2,
                                      out ppCode,
                                      out ppErrorMsgs);
        }