Beispiel #1
0
        public void Run()
        {
            string[] scripts = this.buildTargets.GetScriptsToCompile(this.scriptName);
            //BuildSourceFilesCollection partitionedScripts = this.buildTargets.GetSourceFiles(scripts);
            TES5GlobalVariables globalVariables = this.esmAnalyzer.GlobalVariables;

            foreach (var buildTarget in this.buildTargets)
            {
                Dictionary <string, TES5GlobalScope> scriptsScopes = new Dictionary <string, TES5GlobalScope>();
                foreach (var buildScript in scripts)
                {
                    string scriptName = Path.GetFileNameWithoutExtension(buildScript);
                    string sourcePath = buildTarget.GetSourceFromPath(scriptName);
                    //string outputPath = buildTarget.GetTranspileToPath(scriptName);
                    TES5GlobalScope globalScope = buildTarget.BuildScope(sourcePath, globalVariables);
                    scriptsScopes.Add(scriptName, globalScope);
                }

                TES5MultipleScriptsScope multipleScriptsScope = new TES5MultipleScriptsScope(scriptsScopes.Values, globalVariables);
                foreach (var buildScript in scripts)
                {
                    string          scriptName  = Path.GetFileNameWithoutExtension(buildScript);
                    string          sourcePath  = buildTarget.GetSourceFromPath(scriptName);
                    string          outputPath  = buildTarget.GetTranspileToPath(scriptName);
                    TES5GlobalScope globalScope = buildTarget.BuildScope(sourcePath, globalVariables);
                    buildTarget.Transpile(sourcePath, outputPath, globalScope, multipleScriptsScope);
                }
            }
        }
        public static void GenerateINFOAddTopicScripts(ESMAnalyzer esmAnalyzer, BuildTracker buildTracker, IBuildTarget tifBuildTarget)
        {
            TES5TypeInferencer    typeInferencer    = new TES5TypeInferencer(esmAnalyzer);
            TES5ObjectCallFactory objectCallFactory = new TES5ObjectCallFactory(typeInferencer);
            TES4TopicsToTES5GlobalVariableFinder globalVariableFinder = new TES4TopicsToTES5GlobalVariableFinder();
            TES5GlobalVariables globalVariables = esmAnalyzer.GlobalVariables;
            var builtTIFs = buildTracker.GetBuiltScripts(BuildTargetFactory.TIFName);

            foreach (TES4Record infoRecord in esmAnalyzer.GetRecords().Where(r => r.RecordType == TES4RecordType.INFO))
            {
                TES4SubrecordData[] names = infoRecord.GetSubrecords("NAME").ToArray();
                if (names.Any())
                {
                    string                fragment0Name     = TES5FragmentFactory.GetFragmentName(0);
                    string                nameTES5FormIDHex = (infoRecord.FormID + 0x01000000).ToString("x8");
                    string                scriptName        = TES5ReferenceFactory.tif_Prefix + "_" + nameTES5FormIDHex;
                    TES5Script?           infoTIF           = builtTIFs.Where(s => s.Key == scriptName).Select(s => s.Value.Script).FirstOrDefault();
                    TES5FunctionCodeBlock fragment0;
                    if (infoTIF != null)
                    {
                        fragment0 = infoTIF.BlockList.Blocks.OfType <TES5FunctionCodeBlock>().Where(b => b.BlockName == fragment0Name).First();
                    }
                    else
                    {
                        TES5ScriptHeader  scriptHeader  = TES5ScriptHeaderFactory.GetFromCacheOrConstructByBasicType(scriptName, TES5BasicType.T_TOPICINFO, TES5TypeFactory.TES4_Prefix, true);
                        TES5GlobalScope   globalScope   = new TES5GlobalScope(scriptHeader);
                        TES5FunctionScope functionScope = new TES5FunctionScope(fragment0Name);
                        functionScope.AddParameter(new TES5SignatureParameter("akSpeakerRef", TES5BasicType.T_OBJECTREFERENCE, true));
                        TES5LocalScope localScope = new TES5LocalScope(functionScope);
                        TES5CodeScope  codeScope  = TES5CodeScopeFactory.CreateCodeScope(localScope);
                        fragment0 = new TES5FunctionCodeBlock(functionScope, codeScope, TES5VoidType.Instance, false, true);
                        TES5BlockList blockList = new TES5BlockList()
                        {
                            fragment0
                        };
                        infoTIF = new TES5Script(globalScope, blockList, true);
                        string     outputPath = tifBuildTarget.GetTranspileToPath(scriptName);
                        TES5Target target     = new TES5Target(infoTIF, outputPath);
                        buildTracker.RegisterBuiltScript(tifBuildTarget, target);
                    }
                    foreach (TES4SubrecordData name in names)
                    {
                        int                 formID                   = infoRecord.ExpandBytesIntoFormID(name);
                        TES4Record          addedTopic               = esmAnalyzer.GetRecordByFormID(formID);
                        Tuple <int, string>?globalVariable           = globalVariableFinder.GetGlobalVariableNullable(addedTopic.FormID);
                        string              globalVariableEditorID   = globalVariable != null ? globalVariable.Item2 : globalVariableFinder.GetGlobalVariableEditorID(addedTopic.GetEditorID());
                        Nullable <int>      globalVariableTES5FormID = globalVariable != null ? globalVariable.Item1 : (Nullable <int>)null;
                        TES5Property        topicAddedProperty       = TES5PropertyFactory.ConstructWithTES5FormID(globalVariableEditorID, TES5BasicType.T_GLOBALVARIABLE, globalVariableEditorID, globalVariableTES5FormID);
                        infoTIF.GlobalScope.AddPropertyIfNotExists(topicAddedProperty);
                        TES5Reference topicAddedReference = TES5ReferenceFactory.CreateReferenceToVariableOrProperty(topicAddedProperty);
                        fragment0.AddChunk(objectCallFactory.CreateObjectCall(topicAddedReference, "SetValueInt", new TES5ObjectCallArguments()
                        {
                            new TES5Integer(1)
                        }));
                    }
                }
            }
        }
        public TES5GlobalScope Build(string scriptPath, TES5GlobalVariables globalVariables)
        {
            TES4Script                  parsedScript = this.standaloneParsingService.ParseOrGetFromCache(scriptPath);
            TES5ScriptHeader            scriptHeader = this.CreateHeader(parsedScript);
            TES4VariableDeclarationList?variableList = parsedScript.VariableDeclarationList;
            TES5GlobalScope             globalScope  = new TES5GlobalScope(scriptHeader);

            if (variableList != null)
            {
                propertyFactory.CreateAndAddProperties(variableList, globalScope, globalVariables);
            }
            return(globalScope);
        }
Beispiel #4
0
        public TES5GlobalScope Build(string sourcePath, TES5GlobalVariables globalVariables)
        {
            string scriptName = Path.GetFileNameWithoutExtension(sourcePath);
            TES4VariableDeclarationList variableList = fragmentsReferencesBuilder.BuildVariableDeclarationList(sourcePath, scriptName, fragmentType);
            //Create the header.
            TES5ScriptHeader scriptHeader = TES5ScriptHeaderFactory.GetFromCacheOrConstructByBasicType(scriptName, scriptType, scriptNamePrefix, true);
            TES5GlobalScope  globalScope  = new TES5GlobalScope(scriptHeader);

            if (variableList != null)
            {
                propertyFactory.CreateAndAddProperties(variableList, globalScope, globalVariables);
            }
            return(globalScope);
        }
Beispiel #5
0
        public TES5GlobalScope Build(string sourcePath, TES5GlobalVariables globalVariables)
        {
            string scriptName     = Path.GetFileNameWithoutExtension(sourcePath);
            string referencesPath = Path.Combine(Path.GetDirectoryName(sourcePath), scriptName + ".references");
            //Create the header.
            TES5ScriptHeader            scriptHeader = new TES5ScriptHeader(scriptName, TES5BasicType.T_QUEST, "", true);
            TES5GlobalScope             globalScope  = new TES5GlobalScope(scriptHeader);
            TES4VariableDeclarationList variableList = FragmentsReferencesBuilder.buildVariableDeclarationList(referencesPath);

            if (variableList != null)
            {
                TES5PropertiesFactory.CreateProperties(variableList, globalScope, globalVariables);
            }
            return(globalScope);
        }
Beispiel #6
0
        private TES5Property CreateProperty(TES4VariableDeclaration variable, TES5GlobalVariables globalVariables)
        {
            string   variableName = variable.VariableName;
            TES4Type variableType = variable.VariableType;

            if (variableType == TES4Type.T_FLOAT)
            {
                return(ConstructWithoutFormID(variableName, TES5BasicType.T_FLOAT, null));
            }
            if (variableType == TES4Type.T_INT || variableType == TES4Type.T_SHORT || variableType == TES4Type.T_LONG)
            {
                return(ConstructWithoutFormID(variableName, TES5BasicType.T_INT, null));
            }
            if (variableType == TES4Type.T_REF)
            {
                return(CreatePropertyFromReference(variable, globalVariables));
            }
            throw new ConversionException("Unknown variable declaration type.");
        }
        /*
         * @throws ConversionException
         */
        public static void CreateProperties(TES4VariableDeclarationList variableList, TES5GlobalScope globalScope, TES5GlobalVariables globalVariables)
        {
            Dictionary <string, TES4VariableDeclaration> alreadyDefinedVariables = new Dictionary <string, TES4VariableDeclaration>();

            foreach (TES4VariableDeclaration variable in variableList.getVariableList())
            {
                string   variableName      = variable.VariableName;
                string   variableNameLower = variableName.ToLower();
                TES4Type variableType      = variable.VariableType;
                TES4VariableDeclaration alreadyDefinedVariable;
                if (alreadyDefinedVariables.TryGetValue(variableNameLower, out alreadyDefinedVariable))
                {
                    if (variableType == alreadyDefinedVariable.VariableType)
                    {
                        continue; //Same variable defined twice, smack the original script developer and fallthrough silently.
                    }
                    throw new ConversionException("Double definition of variable named " + variableName + " with different types ( " + alreadyDefinedVariables[variableNameLower].VariableType.Name + " and " + variable.VariableType.Name + " )");
                }

                TES5Property property;
                if (variableType == TES4Type.T_FLOAT)
                {
                    property = new TES5Property(variable.VariableName, TES5BasicType.T_FLOAT, null);
                }
                else if (variableType == TES4Type.T_INT || variableType == TES4Type.T_SHORT || variableType == TES4Type.T_LONG)
                {
                    property = new TES5Property(variable.VariableName, TES5BasicType.T_INT, null);
                }
                else if (variableType == TES4Type.T_REF)
                {
                    property = CreatePropertyFromReference(variable, globalVariables);
                }
                else
                {
                    throw new ConversionException("Unknown variable declaration type.");
                }

                globalScope.AddProperty(property);
                alreadyDefinedVariables.Add(variableNameLower, variable);
            }
        }
        /*
         * Create an pre-defined property from a ref VariableDeclaration
         */
        private static TES5Property CreatePropertyFromReference(TES4VariableDeclaration declaration, TES5GlobalVariables globalVariables)
        {
            string variableName = declaration.VariableName;

            if (globalVariables.ContainsName(variableName))
            {
                return(new TES5Property(variableName, TES5BasicType.T_GLOBALVARIABLE, variableName));
            }
            else
            {
                return(new TES5Property(variableName, TES5BasicType.T_FORM, variableName));
            }
        }
 public TES5GlobalScope BuildScope(string sourcePath, TES5GlobalVariables globalVariables)
 {
     return(this.buildScopeCommand.Build(sourcePath, globalVariables));
 }
Beispiel #10
0
        public void RunTask(StreamWriter errorLog, ProgressWriter progressWriter)
        {
            foreach (var buildChunk in this.buildPlan)
            {
                Dictionary <string, TES5GlobalScope> scriptsScopes = new Dictionary <string, TES5GlobalScope>();
                TES5GlobalVariables globalVariables = this.esmAnalyzer.GlobalVariables;

                /*
                 * First, build the scripts global scopes
                 */
                foreach (var kvp in buildChunk)
                {
                    var         buildTargetName = kvp.Key;
                    var         buildScripts    = kvp.Value;
                    BuildTarget buildTarget     = this.GetBuildTarget(buildTargetName);
                    foreach (var buildScript in buildScripts)
                    {
                        string scriptName = Path.GetFileNameWithoutExtension(buildScript);
                        string sourcePath = buildTarget.GetSourceFromPath(scriptName);
                        scriptsScopes.Add(scriptName, buildTarget.BuildScope(sourcePath, globalVariables));
                    }
                }

                //Add the static global scopes which are added by complimenting scripts..
                List <TES5GlobalScope> staticGlobalScopes = TES5StaticGlobalScopesFactory.CreateGlobalScopes();
                //WTM:  Change:  In the PHP, scriptsScopes is used as a dictionary above but as a list below.  I have added the "GlobalScope"+n key to ameliorate this.
                int globalScopeIndex = 0;
                foreach (var staticGlobalScope in staticGlobalScopes)
                {
                    scriptsScopes.Add("GlobalScope" + globalScopeIndex.ToString(), staticGlobalScope);
                    globalScopeIndex++;
                }

                TES5MultipleScriptsScope multipleScriptsScope = new TES5MultipleScriptsScope(scriptsScopes.Values, globalVariables);
                //Dictionary<string, TES5Target> convertedScripts = new Dictionary<string, TES5Target>();
                foreach (var kvp in buildChunk)
                {
                    var buildTargetName = kvp.Key;
                    var buildScripts    = kvp.Value;
                    foreach (var buildScript in buildScripts)
                    {
                        BuildTarget     buildTarget = this.GetBuildTarget(buildTargetName);
                        string          scriptName  = Path.GetFileNameWithoutExtension(buildScript);
                        TES5GlobalScope globalScope = scriptsScopes[scriptName];
                        string          sourcePath  = buildTarget.GetSourceFromPath(scriptName);
                        string          outputPath  = buildTarget.GetTranspileToPath(scriptName);
                        TES5Target      convertedScript;
                        try
                        {
                            convertedScript = buildTarget.Transpile(sourcePath, outputPath, globalScope, multipleScriptsScope);
                        }
                        catch (EOFOnlyException) { continue; }//Ignore files that are only whitespace or comments.
#if !DEBUG || LOG_EXCEPTIONS
                        catch (ConversionException ex) when(ex.Expected)
                        {
                            errorLog.Write(scriptName + " (" + sourcePath + ")" + Environment.NewLine + ex.GetType().FullName + Environment.NewLine + ex.Message + Environment.NewLine + Environment.NewLine);
                            continue;
                        }
#endif
                        this.buildTracker.RegisterBuiltScript(buildTarget, convertedScript);
                        //convertedScripts.Add(buildScript, convertedScript);
                        progressWriter.IncrementAndWrite();
                    }
                }

                /*foreach (var kvp2 in convertedScripts)
                 * {
                 *  var originalScriptName = kvp2.Key;
                 *  Console.WriteLine("Script Complete:  " + originalScriptName);
                 * }*/
            }
        }
 public TES5MultipleScriptsScope(IEnumerable <TES5GlobalScope> globalScopes, TES5GlobalVariables globalVariables)
 {
     this.globalScopes    = globalScopes.ToDictionary(x => x.ScriptHeader.OriginalScriptName.ToLower(), x => x);
     this.globalVariables = globalVariables;
 }
Beispiel #12
0
 public TES5GlobalScope Build(string sourcePath, TES5GlobalVariables globalVariables)
 {
     // TODO: Implement Build() method.
     throw new NotImplementedException();
 }
Beispiel #13
0
        public ESMAnalyzer(string dataFile = DataDirectory.TES4GameFileName)
        {
            if (esm == null)
            {
                TES4Collection collection = new TES4Collection(DataDirectory.GetESMDirectoryPath());
                collection.Add(dataFile);
                //NOTE - SCRI record load scheme is a copypasta, as in, i didnt check which records do actually might have SCRI
                //Doesnt really matter for other purposes than cleaniness
                TES4FileLoadScheme fileScheme = new TES4FileLoadScheme();
                TES4GrupLoadScheme grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.GMST, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.GMST, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.GLOB, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.GLOB, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.CLAS, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.CLAS, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.FACT, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.FACT, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.HAIR, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.HAIR, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.EYES, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.EYES, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.RACE, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.RACE, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.SOUN, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.SOUN, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.SKIL, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.SKIL, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.MGEF, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.MGEF, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.SCPT, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI", "SCHR" }));
                fileScheme.add(TES4RecordType.SCPT, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.LTEX, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.LTEX, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.ENCH, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.ENCH, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.SPEL, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.SPEL, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.BSGN, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.BSGN, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.ACTI, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.ACTI, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.APPA, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.APPA, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.ARMO, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.ARMO, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.BOOK, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.BOOK, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.CLOT, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.CLOT, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.CONT, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.CONT, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.DOOR, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.DOOR, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.INGR, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.INGR, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.LIGH, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.LIGH, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.MISC, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.MISC, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.STAT, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.STAT, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.GRAS, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.GRAS, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.TREE, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.TREE, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.FLOR, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.FLOR, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.FURN, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.FURN, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.WEAP, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.WEAP, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.AMMO, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.AMMO, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.NPC_, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.NPC_, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.CREA, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.CREA, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.LVLC, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.LVLC, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.SLGM, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.SLGM, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.KEYM, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.KEYM, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.ALCH, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.ALCH, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.SBSP, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.SBSP, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.SGST, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.SGST, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.LVLI, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.LVLI, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.WTHR, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.WTHR, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.CLMT, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.CLMT, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.REGN, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.REGN, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.CELL, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI", "FULL" }));//WTM:  Change:  Added "Full" for use from GetInCellFactory.cs.
                grupScheme.Add(TES4RecordType.REFR, new TES4RecordLoadScheme(new string[] { "EDID", "NAME" }));
                grupScheme.Add(TES4RecordType.ACHR, new TES4RecordLoadScheme(new string[] { "EDID", "NAME" }));
                grupScheme.Add(TES4RecordType.ACRE, new TES4RecordLoadScheme(new string[] { "EDID", "NAME" }));
                fileScheme.add(TES4RecordType.CELL, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.WRLD, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                grupScheme.Add(TES4RecordType.CELL, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                grupScheme.Add(TES4RecordType.REFR, new TES4RecordLoadScheme(new string[] { "EDID", "NAME" }));
                grupScheme.Add(TES4RecordType.ACHR, new TES4RecordLoadScheme(new string[] { "EDID", "NAME" }));
                grupScheme.Add(TES4RecordType.ACRE, new TES4RecordLoadScheme(new string[] { "EDID", "NAME" }));
                fileScheme.add(TES4RecordType.WRLD, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.DIAL, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.DIAL, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.QUST, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.QUST, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.IDLE, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.IDLE, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.PACK, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.PACK, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.CSTY, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.CSTY, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.LSCR, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.LSCR, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.LVSP, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.LVSP, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.ANIO, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.ANIO, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.WATR, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.WATR, grupScheme);
                grupScheme = new TES4GrupLoadScheme();
                grupScheme.Add(TES4RecordType.EFSH, new TES4RecordLoadScheme(new string[] { "EDID", "SCRI" }));
                fileScheme.add(TES4RecordType.EFSH, grupScheme);
                collection.Load(fileScheme);
                esm = collection;
            }

            if (this.scriptTypes == null)
            {
                this.scriptTypes = new Dictionary <string, ITES5Type>();
                List <TES4Grup> scpts = esm.GetGrup(TES4RecordType.SCPT);
                foreach (ITES4Record scpt in scpts.SelectMany(s => s.Select(r => r)))
                {
                    string schr = scpt.GetSubrecordString("SCHR");
                    string edid = scpt.GetSubrecordTrimLower("EDID");
                    if (string.IsNullOrWhiteSpace(schr) || string.IsNullOrWhiteSpace(edid))
                    {
                        continue;
                    }

                    TES5BasicType scriptType;
                    if (edid == "dark09skeletonsuicidescript" || edid == "xpebroccabossscript")//WTM:  Change:  Added special condition
                    {
                        scriptType = TES5BasicType.T_ACTOR;
                    }
                    else
                    {
                        bool isQuest             = ((int)schr.Substring(16, 1)[0]) != 0;
                        bool isActiveMagicEffect = ((int)schr.Substring(17, 1)[0]) != 0;
                        if (isQuest)
                        {
                            scriptType = TES5BasicType.T_QUEST;
                        }
                        else if (isActiveMagicEffect)
                        {
                            scriptType = TES5BasicType.T_ACTIVEMAGICEFFECT;
                        }
                        else
                        {
                            scriptType = TES5BasicType.T_OBJECTREFERENCE;
                        }
                    }

                    this.scriptTypes.Add(edid, scriptType);
                }
            }

            if (this.GlobalVariables == null)
            {
                List <TES4Grup>           globals     = esm.GetGrup(TES4RecordType.GLOB);
                List <TES5GlobalVariable> globalArray = new List <TES5GlobalVariable>();
                foreach (ITES4Record global in globals.SelectMany(g => g.Select(r => r)))
                {
                    string edid = global.GetSubrecordTrim("EDID");
                    if (string.IsNullOrWhiteSpace(edid))
                    {
                        continue;
                    }

                    globalArray.Add(new TES5GlobalVariable(edid));
                }

                /*
                 * Hacky - add infamy into the globals array
                 * Probably we should extract this from this class and put this into other place
                 */
                globalArray.Add(new TES5GlobalVariable("Infamy"));
                this.GlobalVariables = new TES5GlobalVariables(globalArray);
            }

            if (instance == null)
            {
                instance = this;
            }
        }
Beispiel #14
0
        /*
         * Create an pre-defined property from a ref VariableDeclaration
         */
        private TES5Property CreatePropertyFromReference(TES4VariableDeclaration declaration, TES5GlobalVariables globalVariables)
        {
            string         variableName = declaration.VariableName;
            Nullable <int> tes4FormID   = null;
            ITES5Type      type;

            if (globalVariables.ContainsName(variableName))
            {
                type = TES5BasicType.T_GLOBALVARIABLE;
            }
            else
            {
                tes4FormID = declaration.FormID;
                if (declaration.TES5Type != null)
                {
                    type = declaration.TES5Type;
                }
                else
                {
                    if (declaration.VariableType != TES4Type.T_REF)
                    {
                        throw new ConversionException("Unknown type:  " + declaration.VariableType.Name + " " + declaration.VariableType.Name);
                    }
                    ITES5Type?esmType = esmAnalyzer.GetTypeByEDIDWithFollow(variableName, false); //This seems to return null always, which makes sense since declaration.TES5Type is null.
                    type = esmType != null ? esmType : TES5BasicType.T_FORM;
                }
            }
            return(ConstructWithTES4FormID(variableName, type, variableName, tes4FormID));
        }
Beispiel #15
0
        /*
         * @throws ConversionException
         */
        public void CreateAndAddProperties(TES4VariableDeclarationList variableList, TES5GlobalScope globalScope, TES5GlobalVariables globalVariables)
        {
            Dictionary <string, TES4VariableDeclaration> alreadyDefinedVariables = new Dictionary <string, TES4VariableDeclaration>();

            foreach (TES4VariableDeclaration variable in variableList.VariableList)
            {
                string   variableName      = variable.VariableName;
                string   variableNameLower = variableName.ToLower();
                TES4Type variableType      = variable.VariableType;
                TES4VariableDeclaration?alreadyDefinedVariable;
                if (alreadyDefinedVariables.TryGetValue(variableNameLower, out alreadyDefinedVariable))
                {
                    if (variableType == alreadyDefinedVariable.VariableType)
                    {
                        continue; //Same variable defined twice, smack the original script developer and fallthrough silently.
                    }
                    throw GetDuplicatePropertyException(variableName, alreadyDefinedVariable.VariableType.Name, variable.VariableType.Name);
                }

                CreateAndAddProperty(variable, globalScope, globalVariables);
                alreadyDefinedVariables.Add(variableNameLower, variable);
            }
        }
Beispiel #16
0
        public TES5Property CreateAndAddProperty(TES4VariableDeclaration variable, TES5GlobalScope globalScope, TES5GlobalVariables globalVariables)
        {
            TES5Property property = CreateProperty(variable, globalVariables);
            TES5Property?existingPropertyWithDifferentType = globalScope.Properties.Where(p => p.Name.Equals(property.Name, StringComparison.OrdinalIgnoreCase) && p.TES5DeclaredType != property.TES5DeclaredType).FirstOrDefault();

            if (existingPropertyWithDifferentType != null)
            {
                throw GetDuplicatePropertyException(existingPropertyWithDifferentType.Name, existingPropertyWithDifferentType.TES5DeclaredType.OriginalName, property.TES5DeclaredType.OriginalName);
            }
            globalScope.AddProperty(property);
            return(property);
        }