// ---- METHODS ------------------------------------------------------------------------------------------------ void IResData.Load(BfshaFileLoader loader) { position = (uint)loader.Position; loader.CheckSignature(_signature); int pos = loader.ReadInt32(); int SectionCount = loader.ReadInt32(); loader.Seek(4); //Padding }
// ---- PROPERTIES --------------------------------------------------------------------------------------------- // ---- METHODS ------------------------------------------------------------------------------------------------ void IResData.Load(BfshaFileLoader loader) { Name = loader.LoadString(); Index = loader.ReadInt32(); Offset = loader.ReadUInt16(); BlockIndex = loader.ReadByte(); byte padding = loader.ReadByte(); }
// ---- METHODS (INTERNAL) ------------------------------------------------------------------------------------- void IResData.Load(BfshaFileLoader loader) { // Read the header. uint signature = loader.ReadUInt32(); //Always 0x00000000 int numNodes = loader.ReadInt32(); // Excludes root node. int i = 0; // Read the nodes including the root node. List <Node> nodes = new List <Node>(); for (; numNodes >= 0; numNodes--) { nodes.Add(ReadNode(loader)); i++; } _nodes = nodes; }
void IResData.Load(BfshaFileLoader loader) { Name = loader.LoadString(); long staticOptionArrayOffset = loader.ReadOffset(); StaticOptionDict = loader.LoadDict(); long dynamicOptionArrayOffset = loader.ReadOffset(); DynamiOptionDict = loader.LoadDict(); long attribArrayOffset = loader.ReadOffset(); AttributeDict = loader.LoadDict(); long samplerArrayOffset = loader.ReadOffset(); SamplersDict = loader.LoadDict(); if (loader.BfshaFile.VersionMinor >= 8) { loader.ReadInt64(); loader.ReadInt64(); } long uniformBlockArrayOffset = loader.ReadOffset(); UniformBlockDict = loader.LoadDict(); long uniformArrayOffset = loader.ReadOffset(); if (loader.BfshaFile.VersionMinor >= 7) { loader.ReadInt64(); loader.ReadInt64(); loader.ReadInt64(); } long shaderProgramArrayOffset = loader.ReadOffset(); long tableOffset = loader.ReadOffset(); long shaderArchiveOffset = loader.ReadOffset(); long shaderInfoOffset = loader.ReadOffset(); long shaderFileOffset = loader.ReadOffset(); loader.ReadUInt64(); if (loader.BfshaFile.VersionMinor >= 7) { //padding loader.ReadInt64(); loader.ReadInt64(); } loader.ReadUInt64(); loader.ReadUInt64(); uint uniformCount = loader.ReadUInt32(); if (loader.BfshaFile.VersionMinor <= 7) { loader.ReadUInt32(); } int defaultProgramIndex = loader.ReadInt32(); ushort staticOptionCount = loader.ReadUInt16(); ushort dynamicOptionCount = loader.ReadUInt16(); ushort shaderProgramCount = loader.ReadUInt16(); byte staticKeyLength = loader.ReadByte(); byte dynamicKeyLength = loader.ReadByte(); byte attribCount = loader.ReadByte(); byte samplerCount = loader.ReadByte(); if (loader.BfshaFile.VersionMinor >= 8) { byte imageCount = loader.ReadByte(); } byte uniformBlockCount = loader.ReadByte(); loader.ReadBytes(5); if (loader.BfshaFile.VersionMinor >= 7) { loader.ReadBytes(6); } System.Console.WriteLine($"shaderFileOffset " + shaderFileOffset); System.Console.WriteLine($"Sampler " + samplerCount); System.Console.WriteLine($"attribCount " + attribCount); System.Console.WriteLine($"dynamicOptionCount " + dynamicOptionCount); System.Console.WriteLine($"staticOptionArrayOffset " + staticOptionArrayOffset); System.Console.WriteLine($"staticOptionCount " + staticOptionCount); if (loader.BfshaFile.VersionMinor >= 8) { loader.ReadBytes(7); } if (loader.BfshaFile.VersionMinor < 7) { loader.ReadBytes(4); } System.Console.WriteLine($"end pos " + loader.Position); int BnshSize = 0; if (shaderFileOffset != 0) { //Go into the bnsh file and get the file size using (loader.TemporarySeek(shaderFileOffset + 0x1C, System.IO.SeekOrigin.Begin)) { BnshSize = (int)loader.ReadUInt32(); } } byte[] BinaryShaderData = loader.LoadCustom(() => loader.ReadBytes(BnshSize), shaderFileOffset); BnshFile = new BnshFile(new System.IO.MemoryStream(BinaryShaderData)); StaticOptions = loader.LoadList <ShaderOption>(staticOptionCount, staticOptionArrayOffset); DynamiOptions = loader.LoadList <ShaderOption>(dynamicOptionCount, dynamicOptionArrayOffset); Attributes = loader.LoadList <Attribute>(attribCount, attribArrayOffset); Samplers = loader.LoadList <Sampler>(samplerCount, samplerArrayOffset); UniformBlocks = loader.LoadList <UniformBlock>(uniformBlockCount, uniformBlockArrayOffset); UniformVars = loader.LoadList <UniformVar>((int)uniformCount, uniformArrayOffset); }
// ---- METHODS ------------------------------------------------------------------------------------------------ void IResData.Load(BfshaFileLoader loader) { long FrameArrayOffset = loader.ReadOffset(); long KeyArrayOffset = loader.ReadOffset(); _flags = loader.ReadUInt16(); ushort numKey = loader.ReadUInt16(); AnimDataOffset = loader.ReadUInt32(); StartFrame = loader.ReadSingle(); EndFrame = loader.ReadSingle(); Scale = loader.ReadSingle(); Offset = loader.ReadSingle(); Delta = loader.ReadSingle(); int padding = loader.ReadInt32(); Frames = loader.LoadCustom(() => { switch (FrameType) { case AnimCurveFrameType.Single: return(loader.ReadSingles(numKey)); case AnimCurveFrameType.Decimal10x5: float[] dec10x5Frames = new float[numKey]; for (int i = 0; i < numKey; i++) { dec10x5Frames[i] = (float)loader.ReadDecimal10x5(); } return(dec10x5Frames); case AnimCurveFrameType.Byte: float[] byteFrames = new float[numKey]; for (int i = 0; i < numKey; i++) { byteFrames[i] = loader.ReadByte(); } return(byteFrames); default: throw new ResException($"Invalid {nameof(FrameType)}."); } }, FrameArrayOffset); Keys = loader.LoadCustom(() => { int elementsPerKey = ElementsPerKey; float[,] keys = new float[numKey, elementsPerKey]; switch (KeyType) { case AnimCurveKeyType.Single: for (int i = 0; i < numKey; i++) { for (int j = 0; j < elementsPerKey; j++) { keys[i, j] = loader.ReadSingle(); } } break; case AnimCurveKeyType.Int16: for (int i = 0; i < numKey; i++) { for (int j = 0; j < elementsPerKey; j++) { keys[i, j] = loader.ReadInt16(); } } break; case AnimCurveKeyType.SByte: for (int i = 0; i < numKey; i++) { for (int j = 0; j < elementsPerKey; j++) { keys[i, j] = loader.ReadSByte(); } } break; default: throw new ResException($"Invalid {nameof(KeyType)}."); } return(keys); }, KeyArrayOffset); }
// ---- METHODS ------------------------------------------------------------------------------------------------ void IResData.Load(BfshaFileLoader loader) { ShaderInputDictionary = loader.LoadDict(); ShaderOutputDictionary = loader.LoadDict(); ShaderSamplerDictionary = loader.LoadDict(); ShaderConstantsDictionary = loader.LoadDict(); ShaderUnknownDictionary = loader.LoadDict(); Unknown1 = loader.ReadInt32(); Unknown2 = loader.ReadInt32(); Unknown3 = loader.ReadInt32(); Unknown4 = loader.ReadInt32(); Unknown5 = loader.ReadInt32(); Unknown6 = loader.ReadInt32(); Unknown7 = loader.ReadInt32(); Unknown8 = loader.ReadInt32(); Unknown9 = loader.ReadInt32(); Unknown10 = loader.ReadInt32(); Unknown11 = loader.ReadInt32(); loader.ReadInt64(); //padding foreach (var key in ShaderInputDictionary) { Console.WriteLine($"Input: {key}"); } foreach (var key in ShaderOutputDictionary) { Console.WriteLine($"Output: {key}"); } foreach (var key in ShaderSamplerDictionary) { Console.WriteLine($"Sampler: {key}"); } foreach (var key in ShaderConstantsDictionary) { Console.WriteLine($"Constant: {key}"); } foreach (var key in ShaderUnknownDictionary) { Console.WriteLine($"Unknown: {key}"); } }