private TES4Record[] TryGetRecordsByEDIDFollowNAMEAndLookUpSCRIIfNeeded(string edid, bool followName, out string?scriptEDID)
        {
            scriptEDID = null;
            TES4Record?record = TryGetRecordByEDIDAndFollowNAME(edid, followName);

            if (record == null)
            {
                return(new TES4Record[] { });
            }
            TES4RecordType recordType = record.RecordType;

            if (recordType == TES4RecordType.SCPT)
            {
                //Resolve the reference
                TES4Record[] recordsBySCRI = GetRecordsBySCRI(record.FormID);
                if (recordsBySCRI.Any())
                {
                    return(recordsBySCRI);
                }
            }
            else
            {
                Nullable <int> scri = record.TryGetSubrecordAsFormID("SCRI");
                if (scri != null)
                {
                    scriptEDID = GetEDIDByFormID(scri.Value);
                }
            }
            return(new TES4Record[] { record });
        }
        private TES4Record?TryGetRecordByEDIDAndFollowNAME(string edid, bool followName, bool throwException)
        {
            TES4Record?record = TryGetRecordByEDIDInTES4Collection(edid);

            if (record == null)
            {
                if (throwException)
                {
                    throw new ConversionException("Cannot resolve script type by searching its base form edid - no record found, " + edid);
                }
                return(null);
            }
            TES4RecordType recordType = record.RecordType;

            if (followName && (recordType == TES4RecordType.REFR || recordType == TES4RecordType.ACRE || recordType == TES4RecordType.ACHR))
            {
                //Resolve the reference
                int baseFormid = record.GetSubrecordAsFormID("NAME");
                record = GetRecordByFormID(baseFormid);
            }
            return(record);
        }
Example #3
0
        /*
         * @todo REFACTOR, it"s really ugly!
         * @throws ConversionException
         */
        public ITES5Type ResolveScriptTypeByItsAttachedName(string attachedName)
        {
            string    attachedNameLower = attachedName.ToLower();
            ITES5Type value;

            if (this.attachedNameCache.TryGetValue(attachedNameLower, out value))
            {
                return(value);
            }
            TES4LoadedRecord attachedNameRecord = FindInTES4Collection(attachedName, false);

            if (attachedNameRecord == null)
            {
                throw new ConversionException("Cannot resolve script type by searching its base form edid - no record found, " + attachedName);
            }
            TES4RecordType attachedNameRecordType = attachedNameRecord.RecordType;

            if (attachedNameRecordType == TES4RecordType.REFR || attachedNameRecordType == TES4RecordType.ACRE || attachedNameRecordType == TES4RecordType.ACHR)
            {
                //Resolve the reference
                Nullable <int> baseFormid = attachedNameRecord.GetSubrecordAsFormid("NAME");
                attachedNameRecord = esm.FindByFormid(baseFormid.Value);
            }

            Nullable <int> scriptFormid = attachedNameRecord.GetSubrecordAsFormid("SCRI");

            if (scriptFormid == null)
            {
                throw new ConversionException("Cannot resolve script type for " + attachedName + " - Asked base record has no script bound.");
            }

            TES4LoadedRecord scriptRecord = esm.FindByFormid(scriptFormid.Value);
            ITES5Type        customType   = TES5TypeFactory.MemberByValue(scriptRecord.GetSubrecordTrim("EDID"));

            this.attachedNameCache.Add(attachedNameLower, customType);
            return(customType);
        }
 private static void WriteWithIndexes(TES4Collection collection, string buildTargetsPath, string scriptFolderName, string scriptNamePrefix, TES4RecordType recordType)
 {
     Write(collection, buildTargetsPath, scriptFolderName, recordType, (record, directory) =>
     {
         foreach (var subrecord in record.GetSubrecordsWithStageIndexAndLogIndex("SCTX"))
         {
             string sctx = subrecord.Item1.Value.ToStringTrim();
             Write(directory, scriptNamePrefix, record, true, subrecord.Item2, false, sctx);
         }
     });
 }
        private static void Write(TES4Collection collection, string buildTargetsPath, string scriptFolderName, string scriptNamePrefix, bool includeFormID, StageIndexAndLogIndex?stageIndexAndLogIndex, bool allowFixScriptName, TES4RecordType recordType)
        {
            Write(collection, buildTargetsPath, scriptFolderName, recordType, (record, directory) =>
            {
                string[] sctxs = record.GetSubrecordsStrings("SCTX").ToArray();
                if (sctxs.Any())
                {
                    if (sctxs.Length > 1)
                    {
                        throw new InvalidOperationException(nameof(sctxs) + ".Length > 1");
                    }
#if !NEWBT
                    if (recordType == TES4RecordType.SCPT && !ShouldWriteScript(record.GetEditorID()))
                    {
                        return;
                    }
#endif
                    Write(directory, scriptNamePrefix, record, includeFormID, stageIndexAndLogIndex, allowFixScriptName, TES4Record.ReplaceSCTXSpecialCharacters(sctxs[0]));
                }
            });
        }
        private static void Write(TES4Collection collection, string buildTargetsPath, string scriptFolderName, TES4RecordType recordType, Action <TES4Record, string> writeRecord)
        {
            string directory = buildTargetsPath + scriptFolderName + Path.DirectorySeparatorChar + "Source" + Path.DirectorySeparatorChar;

            Directory.CreateDirectory(directory);
            var records =
                recordType == TES4RecordType.INFO ? collection.Where(r => r.RecordType == recordType) :
                collection.GetGrupRecords(recordType);

            foreach (TES4Record record in records)
            {
                writeRecord(record, directory);
            }
        }
        public static ITES5Type Map(TES4RecordType type)
        {
            string propertyType;

            switch (type.Name)
            {
            case "AACT":
            {
                propertyType = "Action";
                break;
            }

            case "ACTI":
            {
                propertyType = "Activator";
                break;
            }

            case "ACHR":
            case "ACRE":
            case "NPC_":
            {
                propertyType = "Actor";
                break;
            }

            case "AMMO":
            {
                propertyType = "Ammo";
                break;
            }

            case "APPA":
            {
                propertyType = "Apparatus";
                break;
            }

            case "CREA":
            {
                propertyType = "Actor";
                break;
            }

            case "CLMT":
            {
                propertyType = "Climate";
                break;
            }

            case "CLOT":
            case "ARMO":
            {
                propertyType = "Armor";
                break;
            }

            case "ASTP":
            {
                propertyType = "AssociationType";
                break;
            }

            case "BOOK":
            {
                propertyType = "Book";
                break;
            }

            case "CELL":
            {
                propertyType = "Cell";
                break;
            }

            case "CLAS":
            {
                propertyType = "Class";
                break;
            }

            case "COBJ":
            {
                propertyType = "ConstructibleObject";
                break;
            }

            case "CONT":
            {
                propertyType = "Container";
                break;
            }

            case "DOOR":
            {
                propertyType = "Door";
                break;
            }

            case "EFSH":
            {
                propertyType = "EffectShader";
                break;
            }

            case "ENCH":
            {
                propertyType = "Enchantment";
                break;
            }

            case "ECNZ":
            {
                propertyType = "EncounterZone";
                break;
            }

            case "EXPL":
            {
                propertyType = "Explosion";
                break;
            }

            case "FACT":
            {
                propertyType = "Faction";
                break;
            }

            case "FLOR":
            {
                propertyType = "Flora";
                break;
            }

            case "FLST":
            {
                propertyType = "FormList";
                break;
            }

            case "FURN":
            {
                propertyType = "Furniture";
                break;
            }

            case "GLOB":
            {
                propertyType = "GlobalVariable";
                break;
            }

            case "HAZD":
            {
                propertyType = "Hazard";
                break;
            }

            case "IMAD":
            {
                propertyType = "ImageSpaceModifier";
                break;
            }

            case "IPDS":
            {
                propertyType = "ImpactDataSet";
                break;
            }

            case "INGR":
            {
                propertyType = "Ingredient";
                break;
            }

            case "KEYM":
            {
                propertyType = "Key";
                break;
            }

            case "KYWD":
            {
                propertyType = "Keyword";
                break;
            }

            case "LVLN":
            {
                propertyType = "LeveledActor";
                break;
            }

            case "LVLI":
            {
                propertyType = "LeveledItem";
                break;
            }

            case "LVSP":
            {
                propertyType = "LeveledSpell";
                break;
            }

            case "LIGH":
            {
                propertyType = "Light";
                break;
            }

            case "LCTN":
            {
                propertyType = "Location";
                break;
            }

            case "LCRT":
            {
                propertyType = "LocationRefType";
                break;
            }

            case "MGEF":
            {
                propertyType = "MagicEffect";
                break;
            }

            case "MATH":
            {
                propertyType = "Math";
                break;
            }

            case "MESG":
            {
                propertyType = "Message";
                break;
            }

            case "MISC":
            {
                propertyType = "MiscObject";
                break;
            }

            case "MUSC":
            {
                propertyType = "MusicType";
                break;
            }

            case "REFR":
            {
                propertyType = "ObjectReference";
                break;
            }

            case "OTFT":
            {
                propertyType = "Outfit";
                break;
            }

            case "PACK":
            {
                propertyType = "Package";
                break;
            }

            case "PERK":
            {
                propertyType = "Perk";
                break;
            }

            case "ALCH":
            {
                propertyType = "Potion";
                break;
            }

            case "PROJ":
            {
                propertyType = "Projectile";
                break;
            }

            case "QUST":
            {
                propertyType = "Quest";
                break;
            }

            case "RACE":
            {
                propertyType = "Race";
                break;
            }

            case "SCEN":
            {
                propertyType = "Scene";
                break;
            }

            case "SCRL":
            {
                propertyType = "Scroll";
                break;
            }

            case "SHOU":
            {
                propertyType = "Shout";
                break;
            }

            case "SLGM":
            {
                propertyType = "SoulGem";
                break;
            }

            case "SOUN":
            {
                propertyType = "Sound";
                break;
            }

            case "SNCT":
            {
                propertyType = "SoundCategory";
                break;
            }

            case "SPEL":
            {
                propertyType = "Spell";
                break;
            }

            case "STAT":
            {
                propertyType = "Static";
                break;
            }

            case "TACT":
            {
                propertyType = "TalkingActivator";
                break;
            }

            case "DIAL":
            {
                propertyType = "Topic";
                break;
            }

            case "INFO":
            {
                propertyType = "TopicInfo";
                break;
            }

            case "RFCT":
            {
                propertyType = "VisualEffect";
                break;
            }

            case "VTYP":
            {
                propertyType = "VoiceType";
                break;
            }

            case "WEAP":
            {
                propertyType = "Weapon";
                break;
            }

            case "WTHR":
            {
                propertyType = "Weather";
                break;
            }

            case "WOOP":
            {
                propertyType = "WordOfPower";
                break;
            }

            case "WRLD":
            {
                propertyType = "WorldSpace";
                break;
            }

            default:
            {
                throw new ConversionException("Unknown " + type.Name + " formid reference.");
            }
            }

            return(TES5TypeFactory.MemberByValue(propertyType));
        }
Example #8
0
 public static TES5BasicType GetTES5BasicType(TES4RecordType recordType)
 {
     //For information about record types:  https://en.uesp.net/wiki/Tes4Mod:Mod_File_Format
     if (recordType == TES4RecordType.ACHR)
     {
         return(TES5BasicType.T_ACTOR);
     }                                                                       //Placed NPC_
     if (recordType == TES4RecordType.ACRE)
     {
         return(TES5BasicType.T_ACTOR);
     }                                                                       //Placed CREA
     if (recordType == TES4RecordType.ACTI)
     {
         return(TES5BasicType.T_ACTIVATOR);
     }
     if (recordType == TES4RecordType.ALCH)
     {
         return(TES5BasicType.T_POTION);
     }
     if (recordType == TES4RecordType.APPA)
     {
         return(TES5BasicType.T_APPARATUS);
     }
     if (recordType == TES4RecordType.AMMO)
     {
         return(TES5BasicType.T_AMMO);
     }
     if (recordType == TES4RecordType.ARMO)
     {
         return(TES5BasicType.T_ARMOR);
     }
     if (recordType == TES4RecordType.BOOK)
     {
         return(TES5BasicType.T_BOOK);
     }
     if (recordType == TES4RecordType.CELL)
     {
         return(TES5BasicType.T_CELL);
     }
     if (recordType == TES4RecordType.CLAS)
     {
         return(TES5BasicType.T_CLASS);
     }
     if (recordType == TES4RecordType.CLOT)
     {
         return(TES5BasicType.T_ARMOR);
     }
     if (recordType == TES4RecordType.CREA)
     {
         return(TES5BasicType.T_ACTORBASE);
     }
     if (recordType == TES4RecordType.CONT)
     {
         return(TES5BasicType.T_CONTAINER);
     }
     if (recordType == TES4RecordType.CSTY)
     {
         return(TES5BasicType.T_COMBATSTYLE);
     }
     if (recordType == TES4RecordType.DIAL)
     {
         return(TES5BasicType.T_TOPIC);
     }
     if (recordType == TES4RecordType.DOOR)
     {
         return(TES5BasicType.T_DOOR);
     }
     if (recordType == TES4RecordType.EFSH)
     {
         return(TES5BasicType.T_EFFECTSHADER);
     }
     if (recordType == TES4RecordType.FACT)
     {
         return(TES5BasicType.T_FACTION);
     }
     if (recordType == TES4RecordType.FLOR)
     {
         return(TES5BasicType.T_FLORA);
     }
     if (recordType == TES4RecordType.FURN)
     {
         return(TES5BasicType.T_FURNITURE);
     }
     if (recordType == TES4RecordType.GLOB)
     {
         return(TES5BasicType.T_GLOBALVARIABLE);
     }
     if (recordType == TES4RecordType.INGR)
     {
         return(TES5BasicType.T_INGREDIENT);
     }
     if (recordType == TES4RecordType.KEYM)
     {
         return(TES5BasicType.T_KEY);
     }
     if (recordType == TES4RecordType.LIGH)
     {
         return(TES5BasicType.T_LIGHT);
     }
     if (recordType == TES4RecordType.LVLC)
     {
         return(TES5BasicType.T_LEVELEDACTOR);
     }
     if (recordType == TES4RecordType.LVLI)
     {
         return(TES5BasicType.T_LEVELEDITEM);
     }
     if (recordType == TES4RecordType.MGEF)
     {
         return(TES5BasicType.T_MAGICEFFECT);
     }
     if (recordType == TES4RecordType.MISC)
     {
         return(TES5BasicType.T_MISCOBJECT);
     }
     if (recordType == TES4RecordType.NPC_)
     {
         return(TES5BasicType.T_ACTORBASE);
     }
     if (recordType == TES4RecordType.TREE)
     {
         return(TES5BasicType.T_FORM);
     }                                                                      //Skyrim doesn't have a Tree type.
     if (recordType == TES4RecordType.PACK)
     {
         return(TES5BasicType.T_PACKAGE);
     }
     if (recordType == TES4RecordType.QUST)
     {
         return(TES5BasicType.T_QUEST);
     }
     if (recordType == TES4RecordType.RACE)
     {
         return(TES5BasicType.T_RACE);
     }
     if (recordType == TES4RecordType.REFR)
     {
         return(TES5BasicType.T_OBJECTREFERENCE);
     }
     if (recordType == TES4RecordType.SCPT)
     {
         return(TES5BasicType.T_FORM);
     }                                                                      //WTM:  Note:  Apparently only used by TrapHungerStatue05SCRIPT.timer
     if (recordType == TES4RecordType.SLGM)
     {
         return(TES5BasicType.T_SOULGEM);
     }
     if (recordType == TES4RecordType.SOUN)
     {
         return(TES5BasicType.T_SOUND);
     }
     if (recordType == TES4RecordType.SPEL)
     {
         return(TES5BasicType.T_SPELL);
     }
     if (recordType == TES4RecordType.STAT)
     {
         return(TES5BasicType.T_STATIC);
     }
     if (recordType == TES4RecordType.WTHR)
     {
         return(TES5BasicType.T_WEATHER);
     }
     if (recordType == TES4RecordType.WEAP)
     {
         return(TES5BasicType.T_WEAPON);
     }
     if (recordType == TES4RecordType.WRLD)
     {
         return(TES5BasicType.T_WORLDSPACE);
     }
     throw new ArgumentException(nameof(recordType) + " " + recordType.Name + " could not be converted to a " + nameof(TES5BasicType) + ".", nameof(recordType));
 }