Beispiel #1
0
        private DomainDefinition DetectVersion()
        {
            Record brcTES = this.Records.OfType <Record>().FirstOrDefault(x => x.Name.StartsWith("TES"));

            if (brcTES == null)
            {
                throw new ApplicationException("Plugin lacks a valid TES4 record. Cannot continue.");
            }
            var hdr = brcTES.SubRecords.FirstOrDefault(x => x.Name == "HEDR");

            if (hdr == null)
            {
                throw new ApplicationException("Plugin lacks a valid HEDR subrecord. Cannot continue.");
            }
            var version = hdr.GetValue <float>(0);

            return(DomainDefinition.DetectDefinitionFromVersion(brcTES.Name, version));
        }
Beispiel #2
0
        private DomainDefinition DetectVersion(BinaryReader br, string fileName)
        {
            // Quick check for master esm.  Skyrim.esm uses same as fallout. so harder to detect
            if (!string.IsNullOrEmpty(fileName))
            {
                foreach (var domain in DomainDefinition.AllDomains().Where(domain =>
                                                                           string.Compare(domain.Master, Path.GetFileName(fileName), StringComparison.InvariantCultureIgnoreCase) == 0))
                {
                    if (!domain.Loaded)
                    {
                        DomainDefinition.Load(domain.Name);
                    }
                    return(domain);
                }
            }

            var tes = ReadRecName(br);

            if (tes == "TES3")
            {
                return(DomainDefinition.Load("Morrowind")); // hardcoded?
            }
            if (tes != "TES4")
            {
                throw new Exception("File is not a valid TES4 plugin (Missing TES4 record)");
            }
            // Check for file version by checking the position of the HEDR field in the file. (ie. how big are the record header.)
            br.BaseStream.Position = 20;
            var s = ReadRecName(br);

            if (s == "HEDR")
            {
                return(DomainDefinition.Load("Oblivion")); // hardcoded?
            }
            s = ReadRecName(br);
            if (s != "HEDR")
            {
                throw new Exception("File is not a valid TES4 plugin (Missing HEDR subrecord in the TES4 record)");
            }
            var recsize = br.ReadUInt16();
            var version = br.ReadSingle();

            return(DomainDefinition.DetectDefinitionFromVersion(tes, version));
        }