Beispiel #1
0
        private void ReadBuffer(byte[] oneBuffer)
        {
            List <CharaModelHeaders> cmh = new List <CharaModelHeaders>();
            int lastMsPosition           = 0;

            using (MemoryStream ms = new MemoryStream(oneBuffer))
                using (BinaryReader br = new BinaryReader(ms))
                {
                    uint nModels = br.ReadUInt32();
                    for (int i = 0; i < nModels; i++)
                    {
                        CharaModelHeaders localCmh = new CharaModelHeaders
                        {
                            offset    = br.ReadUInt32() + 4,
                            size      = br.ReadUInt32(),
                            size2     = br.ReadUInt32(),
                            flagDWORD = br.ReadUInt32()
                        };
                        bool bIgnorePadding = false;
                        bool bMainChara     = false;
                        if (localCmh.flagDWORD >> 24 == 0xD0) //main character file
                        {
                            localCmh.timOffset       = new uint[0];
                            localCmh.modelDataOffset = 0xFFFFFFFF;
                            ms.Seek(4, SeekOrigin.Current);
                            bMainChara = true;
                        }
                        else if (localCmh.flagDWORD >> 24 == 0xa0) //unknown- object without texture/ placeholder?
                        {
                            localCmh.timOffset       = new uint[0];
                            localCmh.modelDataOffset = 0xFFFFFFFF;
                            ms.Seek(8, SeekOrigin.Current);
                            bIgnorePadding = true;
                        }
                        else
                        {
                            List <uint> timOffsets    = new List <uint>();
                            uint        flagTimOffset = localCmh.flagDWORD & 0x00FFFFFF;

                            timOffsets.Add(localCmh.flagDWORD << 8);
                            uint localTimOffset;
                            while ((localTimOffset = br.ReadUInt32()) != 0xFFFFFFFF)
                            {
                                timOffsets.Add(localTimOffset & 0x00FFFFFF);
                            }
                            localCmh.timOffset       = timOffsets.ToArray();
                            localCmh.modelDataOffset = br.ReadUInt32();
                        }
                        localCmh.modelName = br.ReadChars(8);
                        localCmh.padding   = br.ReadUInt32();
                        if (localCmh.padding != 0xEEEEEEEE && !bIgnorePadding) //null models for placeholders are 2 not eeeeeeee
                        {
                            throw new Exception("Chara one- padding was not 0xEEEEEEEE- check code for ReadBuffer in FieldCharaOne");
                        }

                        if (localCmh.modelDataOffset != 0xFFFFFFFF)
                        {
                            lastMsPosition = (int)ms.Position;
                            ms.Seek(localCmh.offset + localCmh.modelDataOffset, SeekOrigin.Begin);
                            localCmh.mch = new Debug_MCH(ms, br, Debug_MCH.mchMode.FieldNPC, 3f);
                            //ms.Seek(localCmh.offset + 4, SeekOrigin.Begin);
                            List <Texture2D> texList = new List <Texture2D>();
                            for (int n = 0; n < localCmh.timOffset.Length; n++)
                            {
                                if (localCmh.timOffset[n] > 0x10000000)
                                {
                                    localCmh.timOffset[n] = localCmh.timOffset[n] & 0x00FFFFFF;
                                }
                                TIM2 localTim = new TIM2(br, localCmh.offset + localCmh.timOffset[n]);
                                texList.Add(localTim.GetTexture());
                            }
                            localCmh.textures = texList.ToArray();
                            ms.Seek(lastMsPosition, SeekOrigin.Begin);
                        }
                        else if (bMainChara)
                        {
                            lastMsPosition = (int)ms.Position;
                            //this is main chara, so please grab data from main_chr.fs
                            int getRefId = int.Parse(new string(localCmh.modelName).Substring(1, 3));
                            var chara    = FieldMainCharaOne.MainFieldCharacters.Where(x => x.id == getRefId).First();
                            localCmh.modelDataOffset = 1;
                            localCmh.mch             = chara.mch;
                            localCmh.textures        = chara.textures;
                            ms.Seek(localCmh.offset, SeekOrigin.Begin);
                            localCmh.mch.MergeAnimations(ms, br);
                            ms.Seek(lastMsPosition, SeekOrigin.Begin);
                        }

                        cmh.Add(localCmh);
                    }
                }
            fieldModels = cmh.ToArray();
        }
Beispiel #2
0
        private void ReadBuffer(byte[] oneBuffer)
        {
            var cmh = new List <CharaModelHeaders>();

            using (var ms = new MemoryStream(oneBuffer))
                using (var br = new BinaryReader(ms))
                {
                    var nModels = br.ReadUInt32();
                    for (var i = 0; i < nModels; i++)
                    {
                        var localCmh = new CharaModelHeaders
                        {
                            Offset    = br.ReadUInt32() + 4,
                            Size      = br.ReadUInt32(),
                            Size2     = br.ReadUInt32(),
                            FlagDword = br.ReadUInt32()
                        };
                        var bIgnorePadding = false;
                        var bMainChara     = false;
                        if (localCmh.FlagDword >> 24 == 0xD0) //main character file
                        {
                            localCmh.TIMOffset       = new uint[0];
                            localCmh.ModelDataOffset = 0xFFFFFFFF;
                            ms.Seek(4, SeekOrigin.Current);
                            bMainChara = true;
                        }
                        else if (localCmh.FlagDword >> 24 == 0xa0) //unknown- object without texture/ placeholder?
                        {
                            localCmh.TIMOffset       = new uint[0];
                            localCmh.ModelDataOffset = 0xFFFFFFFF;
                            ms.Seek(8, SeekOrigin.Current);
                            bIgnorePadding = true;
                        }
                        else
                        {
                            var timOffsets = new List <uint>();
                            // ReSharper disable once UnusedVariable
                            var flagTimOffset = localCmh.FlagDword & 0x00FFFFFF;

                            timOffsets.Add(localCmh.FlagDword << 8);
                            uint localTimOffset;
                            while ((localTimOffset = br.ReadUInt32()) != 0xFFFFFFFF)
                            {
                                timOffsets.Add(localTimOffset & 0x00FFFFFF);
                            }
                            localCmh.TIMOffset       = timOffsets.ToArray();
                            localCmh.ModelDataOffset = br.ReadUInt32();
                        }
                        localCmh.ModelName = br.ReadChars(8);
                        localCmh.Padding   = br.ReadUInt32();
                        if (localCmh.Padding != 0xEEEEEEEE && !bIgnorePadding) //null models for placeholders are 2 not eeeeeeee
                        {
                            throw new Exception("Chara one- padding was not 0xEEEEEEEE- check code for ReadBuffer in FieldCharaOne");
                        }

                        int lastMsPosition;
                        if (localCmh.ModelDataOffset != 0xFFFFFFFF)
                        {
                            lastMsPosition = (int)ms.Position;
                            ms.Seek(localCmh.Offset + localCmh.ModelDataOffset, SeekOrigin.Begin);
                            localCmh.MCH = new Debug_MCH(ms, br, Debug_MCH.mchMode.FieldNPC, 3f);
                            //ms.Seek(localCmh.offset + 4, SeekOrigin.Begin);
                            var texList = new List <Texture2D>();
                            for (var n = 0; n < localCmh.TIMOffset.Length; n++)
                            {
                                if (localCmh.TIMOffset[n] > 0x10000000)
                                {
                                    localCmh.TIMOffset[n] = localCmh.TIMOffset[n] & 0x00FFFFFF;
                                }
                                var localTim = new TIM2(br, localCmh.Offset + localCmh.TIMOffset[n]);
                                texList.Add(localTim.GetTexture());
                            }
                            localCmh.Textures = texList.ToArray();
                            ms.Seek(lastMsPosition, SeekOrigin.Begin);
                        }
                        else if (bMainChara)
                        {
                            lastMsPosition = (int)ms.Position;
                            //this is main chara, so please grab data from main_chr.fs
                            var getRefId = int.Parse(new string(localCmh.ModelName).Substring(1, 3));
                            var chara    = FieldMainCharaOne.MainFieldCharacters.First(x => x.ID == getRefId);
                            localCmh.ModelDataOffset = 1;
                            localCmh.MCH             = chara.MCH;
                            localCmh.Textures        = chara.Textures;
                            ms.Seek(localCmh.Offset, SeekOrigin.Begin);
                            localCmh.MCH.MergeAnimations(ms, br);
                            ms.Seek(lastMsPosition, SeekOrigin.Begin);
                        }

                        cmh.Add(localCmh);
                    }
                }
            FieldModels = cmh.ToArray();
        }