Ejemplo n.º 1
0
        public static ModelResourceNode Convert(LmMsgPck msg)
        {
            var aabb      = LmAABB.Unpack(msg);
            var boneTable = LmBoneTable.Unpack(msg);

            var i = 0u;
            var modelResourceNode = new ModelResourceNode();

            foreach (var boneInfo in boneTable.BoneInfos)
            {
                modelResourceNode.MeshBoneInformation.Bones.Add(new MeshBoneInformation.Bone(boneInfo.BoneName, boneInfo.LodBoneIdx, boneInfo.UniqueBoneIdx));
                // FIXME modelResourceNode.MeshBoneInformation.BoneLut.Add(boneInfo.UniqueBoneIdx, i);
                i++;
            }

            modelResourceNode.NodeTable = LmNodeTable.Unpack(msg);
            if (msg.Version >= 20141113)
            {
                var assetHash = (ulong)msg.Read();
                // TODO msg.UserData.GpuBuffer = msg.UserData.DependencyTable.Get(assetHash);
            }

            var meshContainerCount = (int)msg.Read();

            for (var _ = 0; _ < meshContainerCount; _++)
            {
                var meshContainer = MeshContainer.Convert(msg);
                modelResourceNode.MeshContainers.Add(meshContainer);
            }

            if (msg.Version >= 20140623)
            {
                var unknown = msg.ReadBool();
                modelResourceNode.Name = msg.ReadString();
            }

            if (msg.Version >= 20140722 && msg.Version < 20140929)
            {
                var hasPsdData  = msg.ReadBool();
                var psdDataHash = msg.ReadUint64();
            }

            if (msg.Version < 20140815)
            {
                return(modelResourceNode);
            }

            var gmdlPartsDatasCount = msg.ReadUint();

            for (var _ = 0; _ < gmdlPartsDatasCount; _++)
            {
                var gmdlPartsData = GmdlPartsData.Unpack(msg);
                modelResourceNode.GmdlPartsDatas.Add(gmdlPartsData);
            }

            return(modelResourceNode);
        }
Ejemplo n.º 2
0
        public bool Load(LmMsgPck msg, IDictionary <string, byte[]> dependencies)
        {
            this.Version = (uint)msg.Read();
            if (this.Version < 1)
            {
                DefaultPrintFunction.Write($"[LmGfxBin_V1]Version {this.Version}");
                return(false);
            }
            else if (this.Version > 20160705)
            {
                DefaultPrintFunction.Write($"[LmGfxBin_V1]Version {this.Version}");
            }
            else if (this.Version < 20150713)
            {
                DefaultPrintFunction.Write($"[LmGfxBin_V1]Version {this.Version}");
                return(false);
            }

            var dependencyRefCount = msg.ReadMapCount();

            for (var _ = 0; _ < dependencyRefCount; _++)
            {
                // TODO: This is actually Metadata, not Dependencies
                var dependencyRef = UnpackDependencyRef(msg);
                this.Dependencies.Add(dependencyRef);

                if (ulong.TryParse(dependencyRef.HashValue, out ulong parsedHash))
                {
                    // msg.UserData.DependencyTable.Put(parsedHash, dependencies[dependencyRef.Path]);
                }
            }

            // Next up is a repeat of all the hashes; skip them
            // ReadArrayCount is the problem fyi
            msg.UnpackArraySize(out int hashArrayCount);
            var hashes = new List <ulong>();

            for (var _ = 0; _ < hashArrayCount; _++)
            {
                var hash = msg.ReadUint64();
                hashes.Add(hash);
            }

            //msg.Skip(hashArrayCount * 9);

            return(true);
        }