Пример #1
0
        public static void SaveShaderInstance(string path, ulong guid, string name, teShaderInstance instance, teShaderCode shaderCode)
        {
            if (name == null)
            {
                name = teResourceGUID.AsString(guid);
            }
            string instanceDirectory = Path.Combine(path, shaderCode.Header.ShaderType.ToString(), name);

            IO.WriteFile(guid, instanceDirectory);
            IO.WriteFile(instance.Header.ShaderCode, instanceDirectory);

            //using (Stream file = File.OpenWrite(Path.Combine(instanceDirectory, IO.GetFileName(instance.Header.ShaderCode)))) {
            //    file.SetLength(0);
            //    file.Write(shaderCode.Data, 0, shaderCode.Header.DataSize);
            //}

            using (StreamWriter writer =
                       new StreamWriter(Path.Combine(instanceDirectory, IO.GetFileName(instance.Header.ShaderCode)) + ".meta")) {
                writer.WriteLine($"{shaderCode.Header.ShaderType}");
                writer.WriteLine("{texture \"hash\"} : {shader input index}");
                if (instance.ShaderResources == null)
                {
                    return;
                }
                foreach (teShaderInstance.ShaderResourceDefinition textureInputDefinition in instance.ShaderResources)
                {
                    writer.WriteLine($"{textureInputDefinition.NameHash:X8} : {textureInputDefinition.Register}");
                }
            }
        }
Пример #2
0
        public void GetSoundbanks(ICLIFlags toolFlags)
        {
            const string container = "ShaderHashes";

            string basePath;

            if (toolFlags is ExtractFlags flags)
            {
                basePath = flags.OutputPath;
            }
            else
            {
                throw new Exception("no output path");
            }

            HashSet <uint> hashes = new HashSet <uint>();

            foreach (ulong guid in TrackedFiles[0x86])
            {
                teShaderInstance instance = new teShaderInstance(OpenFile(guid));
                //teShaderCode shaderCode = new teShaderCode(OpenFile(instance.Header.ShaderCode));

                //if (shaderCode.Header.ShaderType != Enums.teSHADER_TYPE.PIXEL) continue;
                //if (shaderCode.Header.ShaderType != Enums.teSHADER_TYPE.VERTEX) continue;
                //if (shaderCode.Header.ShaderType != Enums.teSHADER_TYPE.COMPUTE) continue;

                if (instance.ShaderResources != null)
                {
                    foreach (teShaderInstance.ShaderResourceDefinition inputDefinition in instance.ShaderResources)
                    {
                        hashes.Add(inputDefinition.NameHash);
                    }
                }

                if (instance.BufferParts != null)
                {
                    foreach (teShaderInstance.BufferPart[] bufferParts in instance.BufferParts)
                    {
                        foreach (teShaderInstance.BufferPart part in bufferParts)
                        {
                            hashes.Add(part.Hash);
                        }
                    }
                }
            }

            string path = Path.Combine(basePath, container, "hashes.txt");

            CreateDirectoryFromFile(path);
            using (StreamWriter writer = new StreamWriter(path)) {
                foreach (uint hash in hashes.OrderBy(x => x))
                {
                    writer.WriteLine($"{hash:X8}");
                }
            }
        }
Пример #3
0
 public static void SaveShaderInstance(string path, ulong guid, string name)
 {
     using (Stream stream = IO.OpenFile(guid)) {
         if (stream == null)
         {
             return;
         }
         teShaderInstance instance = new teShaderInstance(stream);
         using (Stream stream2 = IO.OpenFile(instance.Header.ShaderCode)) {
             if (stream2 == null)
             {
                 return;
             }
             teShaderCode shaderCode = new teShaderCode(stream2);
             SaveShaderInstance(path, guid, name, instance, shaderCode);
         }
     }
 }
Пример #4
0
        public void SaveShaderGroup(teShaderGroup shaderGroup, string path)
        {
            int i = 0;

            foreach (ulong shaderGroupInstance in shaderGroup.Instances)
            {
                teShaderInstance instance   = new teShaderInstance(IO.OpenFile(shaderGroupInstance));
                teShaderCode     shaderCode = new teShaderCode(IO.OpenFile(instance.Header.ShaderCode));

                string name = null;
                if (shaderGroup.Hashes != null && shaderGroup.Hashes[i] != 0)
                {
                    name = shaderGroup.Hashes[i].ToString("X8");
                }

                SaveShaderInstance(path, shaderGroupInstance, name, instance, shaderCode);
                i++;
            }
        }
Пример #5
0
        public void SaveCompute(string path)
        {
            Dictionary <ulong, int> bufferOccr = new Dictionary <ulong, int>();

            foreach (ulong guid in TrackedFiles[0x86])
            {
                teShaderInstance instance = new teShaderInstance(IO.OpenFile(guid));
                //teShaderCode shaderCode = new teShaderCode(IO.OpenFile(instance.Header.ShaderCode));

                if (instance.BufferHeaders == null)
                {
                    continue;
                }
                foreach (teShaderInstance.BufferHeader bufferHeader in instance.BufferHeaders)
                {
                    if (!bufferOccr.ContainsKey(bufferHeader.Hash))
                    {
                        bufferOccr[bufferHeader.Hash] = 0;
                    }

                    bufferOccr[bufferHeader.Hash]++;
                }

                //if (shaderCode.Header.ShaderType == Enums.teSHADER_TYPE.COMPUTE) {
                //    SaveShaderInstance(path, guid, instance, shaderCode);
                //}
            }

            int i = 0;

            foreach (KeyValuePair <ulong, int> buffer in bufferOccr.OrderByDescending(x => x.Value))
            {
                Console.Out.WriteLine($"{buffer.Key:X16}: {buffer.Value}");
                i++;

                //if (i == 10) {
                //    break;
                //}
            }
        }