Exemple #1
0
 internal ResFileLoader(IResData resData, ResFile resFile, Stream stream, bool leaveOpen = false)
     : base(stream, Encoding.ASCII, leaveOpen)
 {
     ResFile        = resFile;
     _dataMap       = new Dictionary <uint, IResData>();
     ImportableFile = resData;
 }
 internal ResFileSaver(IResData resData, ResFile resFile, Stream stream, bool leaveOpen)
     : base(stream, Encoding.ASCII, leaveOpen)
 {
     ByteOrder      = ByteOrder.BigEndian;
     ExportableData = resData;
     ResFile        = resFile;
 }
 static internal void ExportSection(string fileName, IResData resData, ResFile resFile)
 {
     if (resFile.IsPlatformSwitch)
     {
         using (var saver = new Switch.Core.ResFileSwitchSaver(resData, resFile, fileName)) {
             saver.ExportSection();
         }
     }
     else
     {
         using (var saver = new WiiU.Core.ResFileWiiUSaver(resData, resFile, fileName)) {
             saver.ExportSection();
         }
     }
 }
 internal void Save(IResData resData, int index = -1)
 {
     if (resData == null)
     {
         Write(0);
         return;
     }
     if (TryGetItemEntry(resData, ItemEntryType.ResData, out ItemEntry entry))
     {
         entry.Offsets.Add((uint)Position);
         entry.Index = index;
     }
     else
     {
         _savedItems.Add(new ItemEntry(resData, ItemEntryType.ResData, (uint)Position, index: index));
     }
     Write(UInt32.MaxValue);
 }
        // ---- METHODS (INTERNAL) -------------------------------------------------------------------------------------

        internal void ImportSection(IResData vertexBuffer = null)
        {
            ReadImportedFileHeader();

            if (ImportableFile is Shape)
            {
                uint ShapeOffset        = ReadUInt32();
                uint VertexBufferOffset = ReadUInt32();

                Seek(ShapeOffset, SeekOrigin.Begin);
                ((IResData)ImportableFile).Load(this);

                Seek(VertexBufferOffset, SeekOrigin.Begin);
                ((IResData)vertexBuffer).Load(this);
            }
            else
            {
                ((IResData)ImportableFile).Load(this);
            }
        }
Exemple #6
0
        static internal void ImportSection(Stream stream, IResData resData, ResFile resFile)
        {
            bool platformSwitch = false;

            using (var reader = new BinaryDataReader(stream, true)) {
                reader.Seek(24, SeekOrigin.Begin);
                platformSwitch = reader.ReadUInt32() != 0;
            }

            if (platformSwitch)
            {
                using (var reader = new Switch.Core.ResFileSwitchLoader(resData, resFile, stream)) {
                    reader.ImportSection();
                }
            }
            else
            {
                using (var reader = new WiiU.Core.ResFileWiiULoader(resData, resFile, stream)) {
                    reader.ImportSection();
                }
            }
        }
 internal ResFileWiiULoader(IResData resData, ResFile resFile, Stream stream, bool leaveOpen = false)
     : base(resData, resFile, stream, leaveOpen)
 {
     ByteOrder = ByteOrder.BigEndian;
 }
Exemple #8
0
        public FMDL(ref EndianBinaryReader reader)
        {
            mMagic = reader.ReadString(4);

            if (mMagic != "FMDL")
            {
                throw new Exception("Invalid FMDL header.");
            }

            mHeaderLength   = reader.ReadUInt32();
            mHeaderLength64 = reader.ReadUInt64();
            mNameOffset     = reader.ReadInt64();

            mEndOfStringTable = reader.ReadUInt64();
            mSkeletonOffset   = reader.ReadUInt64();
            mVertArrayOffset  = reader.ReadUInt64();
            mShapeOffset      = reader.ReadUInt64();
            mShapeDict        = reader.ReadUInt64();
            mMaterialOffset   = reader.ReadUInt64();
            mMaterialDict     = reader.ReadUInt64();
            mUserDataOffset   = reader.ReadUInt64();

            reader.ReadBytes(0x10);

            mVertArrayCount = reader.ReadUInt16();
            mShapeCount     = reader.ReadUInt16();
            mMatCount       = reader.ReadUInt16();
            mUserDataCount  = reader.ReadUInt16();
            mNumVerts       = reader.ReadUInt32();
            reader.ReadUInt32();

            mName = reader.ReadStringFromOffset(mNameOffset);

            mResData = new IResData
            {
                unk          = reader.ReadUInt32(),
                size         = reader.ReadUInt32(),
                bufferOffset = reader.ReadInt64()
            };

            reader.ReadBytes(0x10);

            mModelDict = new ModelDict
            {
                size      = reader.ReadUInt32(),
                nodeCount = reader.ReadUInt32(),

                nodes = new List <DictNode>()
            };

            for (int i = 0; i < mModelDict.nodeCount + 1; i++)
            {
                DictNode node = new DictNode
                {
                    key        = reader.ReadUInt32(),
                    leftIndex  = reader.ReadUInt16(),
                    rightIndex = reader.ReadUInt16(),
                    nameOffset = reader.ReadInt64()
                };

                node.name = reader.ReadStringFromOffset(node.nameOffset);

                mModelDict.nodes.Add(node);
            }
        }
 internal ResFileWiiUSaver(IResData resData, ResFile resFile, string fileName)
     : base(resData, resFile, fileName)
 {
 }
 internal ResFileSaver(IResData resData, ResFile resFile, string fileName)
     : this(resData, resFile, new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.Read), false)
 {
 }
 internal ResFileSwitchLoader(IResData resData, ResFile resFile, Stream stream, bool leaveOpen = false)
     : base(resData, resFile, stream, leaveOpen)
 {
     ByteOrder = ByteOrder.LittleEndian;
     IsSwitch  = true;
 }
Exemple #12
0
        // ---- METHODS (INTERNAL) -------------------------------------------------------------------------------------

        static internal void ImportSection(string fileName, IResData resData, ResFile resFile)
        {
            ImportSection(new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read), resData, resFile);
        }
Exemple #13
0
 internal ResFileLoader(IResData resData, ResFile resFile, string fileName)
     : this(resData, resFile, new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
 {
 }
 internal ResFileSwitchLoader(IResData resData, ResFile resFile, string fileName)
     : base(resData, resFile, fileName)
 {
     ByteOrder = ByteOrder.LittleEndian;
     IsSwitch  = true;
 }
 internal ResFileWiiULoader(IResData resData, ResFile resFile, string fileName)
     : base(resData, resFile, fileName)
 {
     ByteOrder = ByteOrder.BigEndian;
 }
 internal void WriteSection(IResData resData)
 {
     resData.Save(this);
 }
        internal void ExportSection(IResData VertexBuffer = null)
        {
            if (ExportableData is Model)
            {
                WriteHeader("fresSUB", "FMDL\0\0\0\0");
                ((IResData)ExportableData).Save(this);
            }
            else if (ExportableData is Skeleton)
            {
                WriteHeader("fresSUB", "FSKL\0\0\0\0");
                ((IResData)ExportableData).Save(this);
            }
            else if (ExportableData is Bone)
            {
                WriteHeader("fmdlSUB", "FSKL\0\0\0\0");
                WriteSignature("BONE");
                ((IResData)ExportableData).Save(this);
            }
            else if (ExportableData is Material)
            {
                WriteHeader("fmdlSUB", "FMAT\0\0\0\0");
                ((IResData)ExportableData).Save(this);
            }
            else if (ExportableData is Shape)
            {
                WriteHeader("fmdlSUB", "FSHP\0\0\0\0");

                long ShapeOffPos = Position;
                Write(0);
                long VertexBufferOffPos = Position;
                Write(0);

                var offset = Position;
                using (TemporarySeek(ShapeOffPos, SeekOrigin.Begin))
                {
                    Write(offset);
                }
                ((IResData)ExportableData).Save(this);

                offset = Position;
                using (TemporarySeek(VertexBufferOffPos, SeekOrigin.Begin))
                {
                    Write(offset);
                }
                ((IResData)VertexBuffer).Save(this);
            }
            else if (ExportableData is SkeletalAnim)
            {
                WriteHeader("fresSUB", "FSKA\0\0\0\0");
                ((IResData)ExportableData).Save(this);
            }
            else if (ExportableData is TexPatternAnim)
            {
                WriteHeader("fresSUB", "FTXP\0\0\0\0");
                ((IResData)ExportableData).Save(this);
            }
            else if (ExportableData is SceneAnim)
            {
                WriteHeader("fresSUB", "FSCN\0\0\0\0");
                ((IResData)ExportableData).Save(this);
            }
            else if (ExportableData is CameraAnim)
            {
                WriteHeader("fresSUB", "FSCNFCAM");
                ((IResData)ExportableData).Save(this);
            }
            else if (ExportableData is LightAnim)
            {
                WriteHeader("fresSUB", "FSCNFLIT");
                ((IResData)ExportableData).Save(this);
            }
            else if (ExportableData is FogAnim)
            {
                WriteHeader("fresSUB", "FSCNFFOG");
                ((IResData)ExportableData).Save(this);
            }
            else if (ExportableData is Texture)
            {
                WriteHeader("fresSUB", "FTEX\0\0\0\0");
                ((IResData)ExportableData).Save(this);
            }
            else if (ExportableData is VisibilityAnim)
            {
                WriteHeader("fresSUB", "FVIS\0\0\0\0");
                ((IResData)ExportableData).Save(this);
            }

            WriteEndOfExportData();
        }