public LgbModelEntry(IO.PackCollection packs, byte[] buffer, int offset)
        {
            this.Header = buffer.ToStructure <HeaderData>(offset);
            this.Name   = buffer.ReadString(offset + Header.NameOffset);

            ModelFilePath     = buffer.ReadString(offset + Header.ModelFileOffset);
            CollisionFilePath = buffer.ReadString(offset + Header.CollisionFileOffset);

            if (!string.IsNullOrWhiteSpace(ModelFilePath))
            {
                SaintCoinach.IO.File mdlFile;
                if (packs.TryGetFile(ModelFilePath, out mdlFile))
                {
                    this.Model = new TransformedModel(((Graphics.ModelFile)mdlFile).GetModelDefinition(), Header.Translation, Header.Rotation, Header.Scale);
                }
            }

            if (!string.IsNullOrWhiteSpace(CollisionFilePath))
            {
                try
                {
                    SaintCoinach.IO.File pcbFile;
                    if (packs.TryGetFile(CollisionFilePath, out pcbFile))
                    {
                        this.CollisionFile = new Pcb.PcbFile(pcbFile);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine($"{Name} at 0x{offset:X} PcbFile failure: {ex.Message}");
                }
            }
        }
Exemple #2
0
        public SgbGroup1CEntry(IO.PackCollection packs, byte[] buffer, int offset)
        {
            this.Header = buffer.ToStructure <HeaderData>(offset);
            this.Name   = buffer.ReadString(offset + Header.NameOffset + 9);

            string mdlFilePath = buffer.ReadString(offset + Header.ModelFileOffset + 9);

            if (!string.IsNullOrWhiteSpace(mdlFilePath))
            {
                SaintCoinach.IO.File file;
                if (mdlFilePath.Contains(".mdl"))
                {
                    if (packs.TryGetFile(mdlFilePath, out file))
                    {
                        this.Model = ((Graphics.ModelFile)file).GetModelDefinition().GetModel(ModelQuality.High);
                    }
                }
                else if (mdlFilePath.Contains(".sgb"))
                {
                    if (packs.TryGetFile(mdlFilePath, out file))
                    {
                        this.Gimmick = new Sgb.SgbFile(file);
                    }
                }
            }
        }
        internal MaterialDefinition(ModelDefinition definition, int index)
        {
            this.Definition = definition;
            this.Index      = index;
            _Packs          = definition.File.Pack.Collection;

            if (_Packs.FileExists(Name))
            {
                _DefaultPath       = Name;
                _VariantsAvailable = false;
                _StainedPathFormat = _PathFormat = null;
            }
            else
            {
                if (!TryExpand(Name, out _PathFormat, out _StainedPathFormat, out _VariantsAvailable))
                {
                    throw new NotSupportedException();
                }

                if (VariantsAvailable)
                {
                    _DefaultPath = string.Format(_PathFormat, 0);
                }
                else
                {
                    _DefaultPath = _PathFormat;
                }
            }
        }
Exemple #4
0
        public LgbEventObjectEntry(IO.PackCollection packs, byte[] buffer, int offset)
        {
            this.Header = buffer.ToStructure <HeaderData>(offset);
            this.Name   = buffer.ReadString(offset + Header.NameOffset);

            if (Collection == null)
            {
                LoadSheets(packs);
            }
            foreach (Ex.IDataRow row in EventObjectSheet)
            {
                if (row.Key == this.Header.EventObjectId)
                {
                    var sg = row.GetRaw(11);
                    foreach (Ex.IDataRow row2 in ExportedSgSheet)
                    {
                        if (row2.Key == (ushort)sg)
                        {
                            var path = ((SaintCoinach.Text.XivString)row2.GetRaw(0)).ToString();
                            if (!string.IsNullOrEmpty(path))
                            {
                                SaintCoinach.IO.File file;
                                if (packs.TryGetFile(path, out file))
                                {
                                    this.Gimmick = new Sgb.SgbFile(file);
                                }
                            }
                            break;
                        }
                    }
                    break;
                }
            }
        }
Exemple #5
0
        public LgbGimmickEntry(IO.PackCollection packs, byte[] buffer, int offset)
        {
            this.Header = buffer.ToStructure <HeaderData>(offset);
            byte[] Unknown = new byte[100];
            System.Buffer.BlockCopy(buffer, offset + System.Runtime.InteropServices.Marshal.SizeOf <HeaderData>(), Unknown, 0, 100);

            foreach (var c in Unknown)
            {
                if (c == 101)
                {
                    System.Diagnostics.Debugger.Break();
                }
            }
            this.Name = buffer.ReadString(offset + Header.NameOffset);

            var gimmickFilePath = buffer.ReadString(offset + Header.GimmickFileOffset);

            if (!string.IsNullOrWhiteSpace(gimmickFilePath))
            {
                SaintCoinach.IO.File file;
                if (packs.TryGetFile(gimmickFilePath, out file))
                {
                    this.Gimmick = new Sgb.SgbFile(file);
                }
            }
        }
        private Tuple <ModelDefinition, ImcVariant> GetMonsterModelDefinition()
        {
            const string ImcPathFormat   = "chara/monster/m{0:D4}/obj/body/b{1:D4}/b{1:D4}.imc";
            const string ModelPathFormat = "chara/monster/m{0:D4}/obj/body/b{1:D4}/model/m{0:D4}b{1:D4}.mdl";

            string imcPath = string.Format(ImcPathFormat, ModelKey, BaseKey);
            string mdlPath = string.Format(ModelPathFormat, ModelKey, BaseKey);

            IO.PackCollection packs = this.Sheet.Collection.PackCollection;

            if (!packs.TryGetFile(imcPath, out IO.File imcFileBase) || !packs.TryGetFile(mdlPath, out IO.File mdlFileBase) || !(mdlFileBase is ModelFile))
            {
                throw new InvalidOperationException($"Unable to find files for {this}.");
            }

            try {
                ModelDefinition model   = ((ModelFile)mdlFileBase).GetModelDefinition();
                ImcFile         imcFile = new ImcFile(imcFileBase);
                ImcVariant      variant = imcFile.GetVariant(Variant);

                return(Tuple.Create(model, variant));
            } catch (Exception ex) {
                throw new InvalidOperationException($"Unable to load model for {this}.", ex);
            }
        }
        private Image BuildImage(string size)
        {
            const string MapFileFormat = "ui/map/{0}/{1}{2}_{3}.tex";

            if (string.IsNullOrEmpty(Id))
            {
                return(null);
            }

            string fileName = Id.ToString().Replace("/", "");

            IO.PackCollection pack = Sheet.Collection.PackCollection;

            string filePath = string.Format(MapFileFormat, Id, fileName, string.Empty, size);

            if (!pack.TryGetFile(filePath, out IO.File file))
            {
                return(null);
            }

            ImageFile imageFile = new ImageFile(file.Pack, file.CommonHeader);

            string maskPath = string.Format(MapFileFormat, Id, fileName, "m", size);

            if (pack.TryGetFile(maskPath, out IO.File mask))
            {
                // Multiply the mask against the file.
                ImageFile maskFile = new ImageFile(mask.Pack, mask.CommonHeader);
                return(MultiplyBlend(imageFile, maskFile));
            }

            return(imageFile.GetImage());
        }
Exemple #8
0
        public SgbModelEntry(IO.PackCollection packs, byte[] buffer, int offset)
        {
            this.Header = buffer.ToStructure <HeaderData>(offset);
            this.Name   = buffer.ReadString(offset + Header.NameOffset);

            ModelFilePath     = buffer.ReadString(offset + Header.ModelFileOffset);
            CollisionFilePath = buffer.ReadString(offset + Header.CollisionFileOffset);

            if (!string.IsNullOrWhiteSpace(ModelFilePath))
            {
                SaintCoinach.IO.File mdlFile;
                if (packs.TryGetFile(ModelFilePath, out mdlFile))
                {
                    this.Model = new TransformedModel(((Graphics.ModelFile)mdlFile).GetModelDefinition(), Header.Translation, Header.Rotation, Header.Scale);
                }
            }
            if (!string.IsNullOrWhiteSpace(CollisionFilePath))
            {
                SaintCoinach.IO.File pcbFile;
                if (packs.TryGetFile(CollisionFilePath, out pcbFile))
                {
                    this.CollisionFile = new Pcb.PcbFile(pcbFile);
                }
            }
        }
Exemple #9
0
        /// <param name="levelPath">Not including bg/</param>
        public Territory(IO.PackCollection packs, string name, string levelPath)
        {
            this.Packs = packs;
            this.Name  = name;
            var i = levelPath.IndexOf("/level/");

            this.BasePath = "bg/" + levelPath.Substring(0, i + 1);

            Build();
        }
        public SgbVfxEntry(IO.PackCollection packs, byte[] buffer, int offset)
        {
            this.Header       = buffer.ToStructure <HeaderData>(offset);
            this.Name         = buffer.ReadString(offset + Header.NameOffset);
            this.AvfxFilePath = buffer.ReadString(offset + Header.AvfxFileOffset);

            if (!string.IsNullOrEmpty(AvfxFilePath))
            {
                this.AvfxFile = packs.GetFile(AvfxFilePath);
            }
        }
        public LgbGimmickEntry(IO.PackCollection packs, byte[] buffer, int offset)
        {
            this.Header = buffer.ToStructure <HeaderData>(offset);
            this.Name   = buffer.ReadString(offset + Header.NameOffset);

            var gimmickFilePath = buffer.ReadString(offset + Header.GimmickFileOffset);

            if (!string.IsNullOrWhiteSpace(gimmickFilePath))
            {
                var file = packs.GetFile(gimmickFilePath);
                this.Gimmick = new Sgb.SgbFile(file);
            }
        }
Exemple #12
0
        public LgbModelEntry(IO.PackCollection packs, byte[] buffer, int offset)
        {
            this.Header = buffer.ToStructure <HeaderData>(offset);
            this.Name   = buffer.ReadString(offset + Header.NameOffset);

            var mdlFilePath = buffer.ReadString(offset + Header.ModelFileOffset);

            if (!string.IsNullOrWhiteSpace(mdlFilePath))
            {
                SaintCoinach.Graphics.ModelFile mdlFile = (SaintCoinach.Graphics.ModelFile)packs.GetFile(mdlFilePath);
                this.Model = new TransformedModel(mdlFile.GetModelDefinition(), Header.Translation, Header.Rotation, Header.Scale);
            }
        }
Exemple #13
0
        private void Build()
        {
            byte[] buffer = File.GetData();

            int offset = 0;

            this.Header = buffer.ToStructure <MaterialHeader>(ref offset);

            int stringsStart = offset + (4 * (Header.TextureCount + Header.MapCount + Header.DataSetCount));

            string[]          texFileNames = ReadStrings(buffer, ref offset, stringsStart, Header.TextureCount);
            IO.PackCollection packs        = File.Pack.Collection;

            this.TexturesFiles = new Imaging.ImageFile[Header.TextureCount];
            for (int i = 0; i < Header.TextureCount; ++i)
            {
                string path = texFileNames[i];
                if (path == DummyTextureInMaterial)
                {
                    path = DummyTexturePath;
                }
                this.TexturesFiles[i] = (Imaging.ImageFile)packs.GetFile(path);
            }

            this.Maps     = ReadStrings(buffer, ref offset, stringsStart, Header.MapCount);
            this.DataSets = ReadStrings(buffer, ref offset, stringsStart, Header.DataSetCount);

            this.Shader = buffer.ReadString(stringsStart + Header.ShaderOffset);

            offset = stringsStart + Header.StringsSize;

            this.Unknown = new byte[Header.UnknownSize];
            Array.Copy(buffer, offset, this.Unknown, 0, Header.UnknownSize);
            offset += Header.UnknownSize;

            this.DataSetData = new byte[Header.DataSetSize];
            Array.Copy(buffer, offset, this.DataSetData, 0, Header.DataSetSize);
            offset += Header.DataSetSize;

            this.MetadataHeader = buffer.ToStructure <MaterialMetadataHeader>(ref offset);

            this.UnknownStructs1   = buffer.ToStructures <Unknowns.MaterialStruct1>(MetadataHeader.UnknownStruct1Count, ref offset);
            this.UnknownStructs2   = buffer.ToStructures <Unknowns.MaterialStruct2>(MetadataHeader.UnknownStruct2Count, ref offset);
            this.TextureParameters = buffer.ToStructures <MaterialTextureParameter>(MetadataHeader.ParameterMappingCount, ref offset);

            this.Data = new byte[MetadataHeader.DataSize];
            Array.Copy(buffer, offset, this.Data, 0, MetadataHeader.DataSize);
        }
        public SgbGimmickEntry(IO.PackCollection packs, byte[] buffer, int offset)
        {
            this.Header = buffer.ToStructure <HeaderData>(offset);
            this.Name   = buffer.ReadString(offset + Header.NameOffset);

            var sgbFileName = buffer.ReadString(offset + Header.GimmickFileOffset);

            if (!string.IsNullOrWhiteSpace(sgbFileName))
            {
                SaintCoinach.IO.File file;
                if (packs.TryGetFile(sgbFileName, out file))
                {
                    this.Gimmick = new SgbFile(file);
                }
            }
        }
        internal MaterialDefinition(ModelDefinition definition, int index)
        {
            this.Definition = definition;
            this.Index = index;
            _Packs = definition.File.Pack.Collection;

            if (_Packs.FileExists(Name)) {
                _DefaultPath = Name;
                _VariantsAvailable = false;
                _StainedPathFormat = _PathFormat = null;
            } else {
                if (!TryExpand(Name, out _PathFormat, out _StainedPathFormat, out _VariantsAvailable))
                    throw new NotSupportedException();

                if (VariantsAvailable)
                    _DefaultPath = string.Format(_PathFormat, 0);
                else
                    _DefaultPath = _PathFormat;
            }
        }
Exemple #16
0
 private void LoadSheets(IO.PackCollection packs)
 {
     Collection       = new Ex.ExCollection(packs);
     EventObjectSheet = Collection.GetSheet("EObj");
     ExportedSgSheet  = Collection.GetSheet("ExportedSG");
 }
Exemple #17
0
 public SgbLightEntry(IO.PackCollection packs, byte[] buffer, int offset)
 {
     this.Header = buffer.ToStructure <HeaderData>(offset);
 }
 public LgbVfxEntry(IO.PackCollection packs, byte[] buffer, int offset)
 {
     this.Header = buffer.ToStructure <HeaderData>(offset);
     this.Name   = buffer.ReadString(offset + Header.NameOffset);
 }