public static TES5ScriptDependencyGraph ReadGraph(this IEnumerable <IBuildTarget> buildTargets)
        {
            string graphPath       = buildTargets.GetFilePath();
            string serializedGraph = File.ReadAllText(graphPath);

            return(PHPFunction.Deserialize <TES5ScriptDependencyGraph>(serializedGraph));
        }
예제 #2
0
        public void Load(Stream file, TES4RecordLoadScheme scheme)
        {
            if (this.size == 0)
            {
                return;
            }

            byte[] fileData = file.Read(this.size);
            //Decompression
            if ((this.flags & 0x00040000) == 0x00040000)
            {
                //Skip the uncompressed data size
                this.size = PHPFunction.UnpackV(fileData.Take(4).ToArray());
                fileData  = PHPFunction.GZUncompress(fileData.Skip(4).ToArray());
            }

            int i = 0;

            while (i < this.size)
            {
                string subrecordType = TES4File.ISO_8859_1.Value.GetString(fileData, i, 4);
                int    subrecordSize = PHPFunction.UnpackV(fileData.Skip(i + 4).Take(2).ToArray());
                if (scheme.ShouldLoad(subrecordType))
                {
                    byte[] subrecordData = fileData.Skip(i + 6).Take(subrecordSize).ToArray();
                    this.subrecords.Add(new KeyValuePair <string, TES4SubrecordData>(subrecordType, new TES4SubrecordData(subrecordData)));
                }

                i += (subrecordSize + 6);
            }
        }
예제 #3
0
        public void WriteGraph(TES5ScriptDependencyGraph graph)
        {
            string graphPath       = GetFilePath();
            string serializedGraph = PHPFunction.Serialize(graph);

            Directory.CreateDirectory(Path.GetDirectoryName(graphPath));
            File.WriteAllText(graphPath, serializedGraph);
        }
 private static string GeneratePropertyName(TES5ScriptHeader header, TES5Property property)
 {
     return("col_" + property.GetPropertyNameWithoutSuffix() + "_" +
            PHPFunction.MD5(header.EscapedScriptName).Substring(0, 4)
            //WTM:  Note:  Instead of using an MD5 hash, I tried the below (where index was the property index within the script's TES5GlobalScope.
            //It worked, but I don't think the names matched up well with what GECK generates, so I've commented it for now.
            //header.EscapedScriptName + "_" + index
            );
 }
예제 #5
0
        /*
         * Add value to the trie
         *
         *  string The key
         *  mixed The value
         *  Overwrite existing value
         */
        public void Add(string str, TES4LoadedRecord value, bool overWrite = true)
        {
            if (str == "")
            {
                if (this.value == null || overWrite)
                {
                    this.value = value;
                }
                return;
            }
            foreach (var kvp in this.trie)
            {
                var    prefix       = kvp.Key;
                var    trie         = kvp.Value;
                int    prefixLength = prefix.Length;
                string head         = PHPFunction.Substr(str, prefixLength);
                int    headLength   = head.Length;
                bool   equals       = true;
                string equalPrefix  = "";
                for (int i = 0; i < prefixLength; ++i)
                { //Split
                    if (i >= headLength)
                    {
                        Trie equalTrie = new Trie(value);
                        this.trie.Add(equalPrefix, equalTrie);
                        equalTrie.trie.Add(prefix.Substring(i), trie);
                        this.trie.Remove(prefix);
                        return;
                    }
                    else if (prefix[i] != head[i])
                    {
                        if (i > 0)
                        {
                            Trie equalTrie = new Trie();
                            this.trie.Add(equalPrefix, equalTrie);
                            equalTrie.trie.Add(prefix.Substring(i), trie);
                            equalTrie.trie.Add(str.Substring(i), new Trie(value));
                            this.trie.Remove(prefix);
                            return;
                        }

                        equals = false;
                        break;
                    }

                    equalPrefix += head[i];
                }

                if (equals)
                {
                    trie.Add(str.Substring(prefixLength), value, overWrite);
                    return;
                }
            }
            this.trie.Add(str, new Trie(value));
        }
예제 #6
0
        private TES4LoadedRecord FetchTES4(FileStream stream)
        {
            byte[]           recordHeader = stream.Read(TES4LoadedRecord.RECORD_HEADER_SIZE);
            int              recordSize   = PHPFunction.UnpackV(recordHeader.Skip(4).Take(4).ToArray());//Throw away the first four bytes.
            int              recordFlags  = PHPFunction.UnpackV(recordHeader.Skip(8).Take(4).ToArray());
            int              recordFormid = PHPFunction.UnpackV(recordHeader.Skip(12).Take(4).ToArray());
            TES4LoadedRecord tes4record   = new TES4LoadedRecord(this, TES4RecordType.TES4, recordFormid, recordSize, recordFlags);

            tes4record.Load(stream, new TES4RecordLoadScheme(new string[] { "MAST" }));
            return(tes4record);
        }
예제 #7
0
 private static string GeneratePropertyName(TES5ScriptHeader header, TES5Property property)
 {
     if (property.AllowNameTransformation)
     {
         return("col_" + property.OriginalName + "_" + PHPFunction.MD5(header.EscapedScriptName).Substring(0, 4));
         //WTM:  Note:  Instead of using an MD5 hash, I tried the below (where index was the property index within the script's TES5GlobalScope).
         //"col_" + property.OriginalName + "_" + header.EscapedScriptName + "_" + index
         //It worked, but I don't think the names match with what GECKFrontend generates, so I've commented it for now.
     }
     return(property.OriginalName);
 }
예제 #8
0
        public IEnumerable <TES4Record> Load(TES4FileLoadScheme scheme)
        {
            Console.Write("Processing " + nameof(TES4File) + " Data...");
            Stopwatch stopwatch = Stopwatch.StartNew();

            using (FileStream contents = GetFile())
            {
                this.FetchTES4(contents);
                while (true)
                {
                    byte[] headerBytes = new byte[TES4Grup.GRUP_HEADER_SIZE];
                    int    read        = contents.Read(headerBytes);
                    if (read == 0)
                    {
                        break;
                    }
                    string headerString = ISO_8859_1.Value.GetString(headerBytes);
                    if (headerString.Substring(0, 4) != "GRUP")
                    {
                        throw new InvalidESFileException("Invalid GRUP magic, found " + headerString.Substring(0, 4));
                    }
                    contents.Seek(-TES4Grup.GRUP_HEADER_SIZE, SeekOrigin.Current);

                    int            grupSize = PHPFunction.UnpackV(headerBytes.Skip(4).Take(4).ToArray());
                    TES4RecordType grupType = TES4RecordType.First(headerString.Substring(8, 4));
                    if (scheme.ShouldLoad(grupType))
                    {
                        TES4GrupLoadScheme?rules = scheme.GetRulesFor(grupType);
                        if (rules == null)
                        {
                            throw new InvalidOperationException(nameof(rules) + " was null for " + nameof(grupType) + " " + grupType.Name + ".");
                        }
                        TES4Grup grup = new TES4Grup();
                        foreach (var loadedRecord in grup.Load(contents, this, rules, true))
                        {
                            yield return(loadedRecord);
                        }
                        if (grup.Type == null)
                        {
                            throw new InvalidOperationException(nameof(grup.Type) + " was null.");
                        }
                        this.grups.Add(grup.Type, grup);
                    }
                    else
                    {
                        contents.Seek(grupSize, SeekOrigin.Current);
                    }
                }
            }
            stopwatch.Stop();
            Console.WriteLine("\rProcessing " + nameof(TES4File) + " Complete (" + stopwatch.ElapsedMilliseconds + " ms)");
        }
        public static void WriteGraph(this IEnumerable <IBuildTarget> buildTargets, TES5ScriptDependencyGraph graph)
        {
            string graphPath       = buildTargets.GetFilePath();
            string serializedGraph = PHPFunction.Serialize(graph);
            string?graphDirectory  = Path.GetDirectoryName(graphPath);

            if (graphDirectory == null)
            {
                throw new NullableException(nameof(graphDirectory));
            }
            Directory.CreateDirectory(graphDirectory);
            File.WriteAllText(graphPath, serializedGraph);
        }
        public static string GetEscapedName(string name, string prefix, bool includePrefix)
        {
            string newName  = PHPFunction.MD5(name.ToLower());//Some names are normal, and others are lowercase.  ToLower() homogenizes them.
            string fullName = prefix + newName;

            if (fullName.Length > maxLength)
            {
                int newNameLength = newName.Length - (fullName.Length - maxLength);
                newName  = newName.Substring(0, newNameLength);
                fullName = prefix + newName;
            }
            return(includePrefix ? fullName : newName);
        }
예제 #11
0
        public ITES5ValueCodeChunk ConvertFunction(ITES5Referencer calledOn, TES4Function function, TES5CodeScope codeScope, TES5GlobalScope globalScope, TES5MultipleScriptsScope multipleScriptsScope)
        {
            TES4FunctionArguments functionArguments = function.Arguments;
            string arg0      = functionArguments.Pop(0).StringValue;
            string arg0Lower = arg0.ToLower();

            if (arg0Lower != "x" && arg0Lower != "y" && arg0Lower != "z")
            {
                throw new ConversionException("getPos can handle only X,Y,Z parameters.");
            }
            string functionName = "GetPosition" + PHPFunction.UCWords(arg0);

            return(this.objectCallFactory.CreateObjectCall(calledOn, functionName, multipleScriptsScope, this.objectCallArgumentsFactory.CreateArgumentList(functionArguments, codeScope, globalScope, multipleScriptsScope)));
        }
        public Nullable <int> GetSubrecordAsFormid(string type)
        {
            int value;

            if (this.dataAsFormidCache.TryGetValue(type, out value))
            {
                return(value);
            }
            byte[] subrecord = this.GetSubrecord(type);
            if (subrecord == null || subrecord.Length < 4)
            {
                return(null);
            }
            value = this.placedFile.Expand(PHPFunction.UnpackV(subrecord.Take(4).ToArray()));
            this.dataAsFormidCache.Add(type, value);
            return(value);
        }
        private static string GetUniqueBuildFingerprint(this IEnumerable <IBuildTarget> buildTargets)
        {
#if PHP_COMPAT
            string md5 = PHPFunction.MD5("randomseed");
            foreach (var key in this.buildTargets.Select(kvp => kvp.Key).OrderBy(k => k))
            {
                md5 = PHPFunction.MD5(md5 + key);
            }
            return(md5);
#else
            string fileName = string.Join("", buildTargets.Select(bt => bt.Name));
            foreach (char invalid in Path.GetInvalidFileNameChars())
            {
                fileName = fileName.Replace(invalid.ToString(), "");
            }
            return(fileName);
#endif
        }
        /*
         * @param memberByValue string Type to be created.
         * @param basicType TES5BasicType You might override the basic type for this custom type created.
         */
        public static ITES5Type MemberByValue(string memberByValue, ITES5Type basicType = null)
        {
            if (memberByValue == null)
            {
                throw new ArgumentNullException(nameof(memberByValue));
            }
            if (memberByValue == "void")
            {
                return(new TES5VoidType());
            }
            TES5BasicType tes5BasicType = TES5BasicType.GetFirstOrNull(PHPFunction.UCWords(memberByValue));

            if (tes5BasicType != null)
            {
                return(tes5BasicType);
            }
            //Ugly - todo: REFACTOR THIS TO NON-STATIC CLASS AND MOVE THIS TO DI
            if (basicType == null)
            {
                ESMAnalyzer analyzer = ESMAnalyzer._instance();
                basicType = analyzer.GetScriptType(memberByValue);
            }
            return(new TES5CustomType(memberByValue, TES4Prefix, basicType));
        }
        public override ITES5ValueCodeChunk ConvertFunction(ITES5Referencer calledOn, TES4Function function, TES5CodeScope codeScope, TES5GlobalScope globalScope, TES5MultipleScriptsScope multipleScriptsScope)
        {
            TES5LocalScope              localScope         = codeScope.LocalScope;
            TES4FunctionArguments       functionArguments  = function.Arguments;
            TES5ObjectCallArguments     convertedArguments = new TES5ObjectCallArguments();
            Dictionary <string, string> actorValueMap      = ActorValueMap.Map;
            ITES4StringValue            firstArg           = functionArguments[0];
            string firstArgString      = firstArg.StringValue;
            string firstArgStringLower = firstArgString.ToLower();

            switch (firstArgStringLower)
            {
            case "strength":
            case "intelligence":
            case "willpower":
            case "agility":
            case "endurance":
            case "personality":
            case "luck":
            {
                if (!TES5PlayerReference.EqualsPlayer(calledOn.Name))
                {
                    //We can"t convert those.. and shouldn"t be any, too.
                    throw new ConversionException("[" + TES4FunctionName + "] Cannot set attributes on non-player");
                }

                const string functionName = "SetValue";
                calledOn = this.referenceFactory.CreateReference(TES5ReferenceFactory.TES4Attr + PHPFunction.UCWords(firstArgStringLower), globalScope, multipleScriptsScope, localScope);
                ITES4StringValue secondArg = functionArguments[1];
                convertedArguments.Add(this.valueFactory.CreateValue(secondArg, codeScope, globalScope, multipleScriptsScope));
                return(CreateObjectCall(calledOn, functionName, multipleScriptsScope, convertedArguments));
            }

            case "speed":
            {
                const string     functionName = "ForceMovementSpeed";
                ITES4StringValue secondArg    = functionArguments[1];
                convertedArguments.Add(this.valueFactory.CreateValue(secondArg, codeScope, globalScope, multipleScriptsScope));
                return(CreateObjectCall(calledOn, functionName, multipleScriptsScope, convertedArguments));
            }

            case "fatigue":
            case "armorer":
            case "security":
            case "acrobatics":
            case "mercantile":
            case "mysticism":     //It doesn"t exist in Skyrim - defaulting to Illusion..
            case "blade":
            case "blunt":
            case "encumbrance":
            case "spellabsorbchance":
            case "resistfire":
            case "resistfrost":
            case "resistdisease":
            case "resistmagic":
            case "resistpoison":
            case "resistshock":
            {
                convertedArguments.Add(new TES5String(actorValueMap[firstArgStringLower]));
                ITES4StringValue secondArg = functionArguments[1];
                convertedArguments.Add(this.valueFactory.CreateValue(secondArg, codeScope, globalScope, multipleScriptsScope));
                return(CreateObjectCall(calledOn, TES5FunctionName, multipleScriptsScope, convertedArguments));
            }

            case "aggression":
            {
                ITES4StringValue     secondArg            = functionArguments[1];
                object               secondArgObject      = secondArg.Data;
                Nullable <int>       secondArgNullableInt = secondArgObject as Nullable <int>;
                AST.Value.ITES5Value convertedArgument2;
                if (secondArgNullableInt != null)
                {        //WTM:  Change:  This apparently went unnoticed in the PHP version.  The second argument is not always an integer.  Sometimes its a variable reference.
                    //But the value of the variable will not be properly scaled to the values below, so the converted script may operate incorrectly.
                    int   secondArgInt = secondArgNullableInt.Value;
                    float newValue;
                    if (secondArgInt == 0)
                    {
                        newValue = 0;
                    }
                    else if (secondArgInt > 0 && secondArgInt < 50)
                    {
                        newValue = 1;
                    }
                    else if (secondArgInt >= 50 && secondArgInt < 80)
                    {
                        newValue = 2;
                    }
                    else
                    {
                        newValue = 3;
                    }
                    convertedArgument2 = new TES5Float(newValue);
                }
                else
                {
                    convertedArgument2 = this.valueFactory.CreateValue(secondArg, codeScope, globalScope, multipleScriptsScope);
                }

                convertedArguments.Add(new TES5String(firstArgString));
                convertedArguments.Add(convertedArgument2);
                return(CreateObjectCall(calledOn, TES5FunctionName, multipleScriptsScope, convertedArguments));
            }

            case "confidence":
            {
                ITES4StringValue secondArg = functionArguments[1];
                int   secondArgData        = (int)secondArg.Data;
                float newValue;
                if (secondArgData == 0)
                {
                    newValue = 0;
                }
                else if (secondArgData > 0 && secondArgData < 30)
                {
                    newValue = 1;
                }
                else if (secondArgData >= 30 && secondArgData < 70)
                {
                    newValue = 2;
                }
                else if (secondArgData >= 70 && secondArgData < 99)
                {
                    newValue = 3;
                }
                else
                {
                    newValue = 4;
                }

                convertedArguments.Add(new TES5String(firstArgString));
                convertedArguments.Add(new TES5Float(newValue));
                return(CreateObjectCall(calledOn, TES5FunctionName, multipleScriptsScope, convertedArguments));
            }

            default:
            {
                convertedArguments.Add(new TES5String(firstArgString));
                ITES4StringValue secondArg = functionArguments[1];
                convertedArguments.Add(this.valueFactory.CreateValue(secondArg, codeScope, globalScope, multipleScriptsScope));
                return(CreateObjectCall(calledOn, TES5FunctionName, multipleScriptsScope, convertedArguments));
            }
            }
        }
예제 #16
0
 public int ExpandBytesIntoFormID(TES4SubrecordData subrecord)
 {
     return(this.placedFile.Expand(PHPFunction.UnpackV(subrecord.FirstFourBytes())));
 }
예제 #17
0
        /*
         * @throws InvalidESFileException
         */
        public IEnumerable <ITES4Record> Load(FileStream fileContents, TES4File file, TES4GrupLoadScheme scheme, bool isTopLevelGrup)
        {
            long startPosition = fileContents.Position;

            byte[] headerBytes  = fileContents.Read(GRUP_HEADER_SIZE);
            string headerString = TES4File.ISO_8859_1.Value.GetString(headerBytes);

            if (headerString.Substring(0, 4) != "GRUP")
            {
                throw new InvalidESFileException("Invalid GRUP magic, found " + headerString.Substring(0, 4));
            }

            this.Size = PHPFunction.UnpackV(headerBytes.Skip(4).Take(4).ToArray());
            if (isTopLevelGrup)
            {
                this.Type = TES4RecordType.First(headerString.Substring(8, 4));
            }

            long end = startPosition + this.Size;

            while (fileContents.Position < end)
            {
                //Ineffective lookahead, but oh well
                byte[] nextEntryTypeBytes = new byte[4];
                int    bytesRead          = fileContents.Read(nextEntryTypeBytes);
                if (bytesRead == 0)
                {
                    break;
                }
                fileContents.Seek(-4, SeekOrigin.Current);
                string nextEntryType = TES4File.ISO_8859_1.Value.GetString(nextEntryTypeBytes);
                switch (nextEntryType)
                {
                case "GRUP":
                {
                    TES4Grup nestedGrup = new TES4Grup();
                    foreach (var subrecord in nestedGrup.Load(fileContents, file, scheme, false))
                    {
                        yield return(subrecord);
                    }
                    break;
                }

                default:
                {
                    byte[]         recordHeaderBytes = fileContents.Read(TES4LoadedRecord.RECORD_HEADER_SIZE);
                    string         recordTypeString  = TES4File.ISO_8859_1.Value.GetString(recordHeaderBytes.Take(4).ToArray());
                    TES4RecordType recordType        = TES4RecordType.First(recordTypeString);
                    int            recordSize        = PHPFunction.UnpackV(recordHeaderBytes.Skip(4).Take(4).ToArray());
                    int            recordFlags       = PHPFunction.UnpackV(recordHeaderBytes.Skip(8).Take(4).ToArray());
                    int            recordFormid      = PHPFunction.UnpackV(recordHeaderBytes.Skip(12).Take(4).ToArray());
                    if (scheme.ShouldLoad(recordType))
                    {
                        TES4LoadedRecord record = new TES4LoadedRecord(file, recordType, recordFormid, recordSize, recordFlags);
                        record.Load(fileContents, scheme.GetRulesFor(recordType));
                        this.records.Add(record);
                        yield return(record);
                    }
                    else
                    {
                        fileContents.Seek(recordSize, SeekOrigin.Current);
                    }
                    break;
                }
                }
            }
        }
        public ITES5ValueCodeChunk ConvertFunction(ITES5Referencer calledOn, TES4Function function, TES5CodeScope codeScope, TES5GlobalScope globalScope, TES5MultipleScriptsScope multipleScriptsScope)
        {
            TES4FunctionArguments functionArguments = function.Arguments;
            TES5LocalScope        localScope        = codeScope.LocalScope;

            if (function.FunctionCall.FunctionName.Equals("modpcskill", StringComparison.OrdinalIgnoreCase))
            {
                /*
                 * MODPCSkill means we will need to call upon the player object
                 */
                calledOn = TES5ReferenceFactory.CreateReferenceToPlayer();
            }

            TES5ObjectCallArguments convertedArguments = new TES5ObjectCallArguments();
            var    actorValueMap       = ActorValueMap.Map;
            string firstArgString      = functionArguments[0].StringValue;
            string firstArgStringLower = firstArgString.ToLower();

            switch (firstArgStringLower)
            {
            case "strength":
            case "intelligence":
            case "willpower":
            case "agility":
            case "speed":
            case "endurance":
            case "personality":
            case "luck":
            {
                if (!TES5PlayerReference.EqualsPlayer(calledOn.Name))
                {
                    //We can"t convert those.. and shouldn"t be any, too.
                    throw new ConversionException(nameof(ModActorValueFactory) + ":  Cannot set attributes on non-player.  Name:  " + calledOn.Name + ", Argument:  " + firstArgString);
                }

                const string functionName     = "SetValue";
                string       tes4AttrFirstArg = TES5ReferenceFactory.TES4Attr + PHPFunction.UCWords(firstArgStringLower);

                /*
                 *  Switch out callee with the reference to attr
                 */
                ITES5Referencer  newCalledOn = this.referenceFactory.CreateReference(tes4AttrFirstArg, globalScope, multipleScriptsScope, localScope);
                ITES4StringValue secondArg   = functionArguments[1];
                ITES5Value       addedValue  = this.valueFactory.CreateValue(secondArg, codeScope, globalScope, multipleScriptsScope);
                convertedArguments.Add(TES5ExpressionFactory.CreateArithmeticExpression(addedValue, TES5ArithmeticExpressionOperator.OPERATOR_ADD, this.referenceFactory.CreateReadReference(tes4AttrFirstArg, globalScope, multipleScriptsScope, localScope)));
                return(this.objectCallFactory.CreateObjectCall(newCalledOn, functionName, multipleScriptsScope, convertedArguments));
            }

            case "fatigue":
            case "armorer":
            case "security":
            case "acrobatics":
            case "mercantile":
            case "mysticism":     //It doesn"t exist in Skyrim - defaulting to Illusion..
            case "blade":
            case "blunt":
            case "encumbrance":
            case "spellabsorbchance":
            case "resistfire":
            case "resistfrost":
            case "resistdisease":
            case "resistmagic":
            case "resistpoison":
            case "resistshock":
            {
                const string functionName = "ModActorValue";
                convertedArguments.Add(new TES5String(actorValueMap[firstArgStringLower]));
                ITES4StringValue secondArg = functionArguments[1];
                convertedArguments.Add(this.valueFactory.CreateValue(secondArg, codeScope, globalScope, multipleScriptsScope));
                return(this.objectCallFactory.CreateObjectCall(calledOn, functionName, multipleScriptsScope, convertedArguments));
            }

            case "aggression":
            {
                const string     functionName = "ModActorValue";
                ITES4StringValue secondArg    = functionArguments[1];
                int secondArgData             = (int)secondArg.Data;
                int newValue;
                if (secondArgData < -80)
                {
                    newValue = -3;
                }
                else if (secondArgData >= -80 && secondArgData < -50)
                {
                    newValue = -2;
                }
                else if (secondArgData >= -50 && secondArgData < 0)
                {
                    newValue = -1;
                }
                else
                if (secondArgData == 0)
                {
                    newValue = 0;
                }
                else if (secondArgData > 0 && secondArgData < 50)
                {
                    newValue = 1;
                }
                else if (secondArgData >= 50 && secondArgData < 80)
                {
                    newValue = 2;
                }
                else
                {
                    newValue = 3;
                }

                convertedArguments.Add(new TES5String(firstArgString));
                convertedArguments.Add(new TES5Float(newValue));
                return(this.objectCallFactory.CreateObjectCall(calledOn, functionName, multipleScriptsScope, convertedArguments));
            }

            case "confidence":
            {
                const string     functionName = "ModActorValue";
                ITES4StringValue secondArg    = functionArguments[1];
                int secondArgData             = (int)secondArg.Data;
                int newValue;
                if (secondArgData == -100)
                {
                    newValue = -4;
                }
                else if (secondArgData <= -70 && secondArgData > -100)
                {
                    newValue = -3;
                }
                else
                if (secondArgData <= -30 && secondArgData > -70)
                {
                    newValue = -2;
                }
                else
                if (secondArgData < 0 && secondArgData > -30)
                {
                    newValue = -1;
                }
                else
                if (secondArgData == 0)
                {
                    newValue = 0;
                }
                else if (secondArgData > 0 && secondArgData < 30)
                {
                    newValue = 1;
                }
                else
                if (secondArgData >= 30 && secondArgData < 70)
                {
                    newValue = 2;
                }
                else
                if (secondArgData >= 70 && secondArgData < 99)
                {
                    newValue = 3;
                }
                else
                {
                    newValue = 4;
                }

                convertedArguments.Add(new TES5String(firstArgString));
                convertedArguments.Add(new TES5Float(newValue));
                return(this.objectCallFactory.CreateObjectCall(calledOn, functionName, multipleScriptsScope, convertedArguments));
            }

            default:
            {
                const string functionName = "ModActorValue";
                convertedArguments.Add(new TES5String(firstArgString));
                ITES4StringValue secondArg = functionArguments[1];
                convertedArguments.Add(this.valueFactory.CreateValue(secondArg, codeScope, globalScope, multipleScriptsScope));
                return(this.objectCallFactory.CreateObjectCall(calledOn, functionName, multipleScriptsScope, convertedArguments));
            }
            }
        }
 public static string GetTES4AttrPlusName(string name)
 {
     return(TES4Attr + PHPFunction.UCWords(name));
 }
예제 #20
0
        public ITES5ValueCodeChunk ConvertFunction(ITES5Referencer calledOn, TES4Function function, TES5CodeScope codeScope, TES5GlobalScope globalScope, TES5MultipleScriptsScope multipleScriptsScope)
        {
            TES5LocalScope        localScope        = codeScope.LocalScope;
            const string          functionName      = "GetActorValue";
            TES4FunctionArguments functionArguments = function.Arguments;
            //@TODO - This should be fixed on expression-parsing level, with agression and confidence checks adjusted accordingly. There are no retail uses, so im not doing this for now ;)
            Dictionary <string, string> actorValueMap = ActorValueMap.Map;
            ITES4StringValue            firstArg      = functionArguments[0];
            string firstArgString      = firstArg.StringValue;
            string firstArgStringLower = firstArgString.ToLower();

            switch (firstArgStringLower)
            {
            case "strength":
            case "intelligence":
            case "willpower":
            case "agility":
            case "speed":
            case "endurance":
            case "personality":
            case "luck":
            {
                if (!TES5PlayerReference.EqualsPlayer(calledOn.Name))
                {
                    if (calledOn.TES5Type.NativeType == TES5BasicType.T_ACTOR)        //WTM:  Change:  I added this if branch.
                    {
                        TES5ObjectCallArguments convertedArguments = new TES5ObjectCallArguments()
                        {
                            new TES5String(firstArgString)
                        };
                        return(this.objectCallFactory.CreateObjectCall(calledOn, functionName, multipleScriptsScope, convertedArguments));
                    }
                    //We can"t convert those.. and shouldn"t be any, too.
                    throw new ConversionException(nameof(GetActorValueFactory) + ":  Cannot get attributes on non-player.  Name:  " + calledOn.Name + ", Argument:  " + firstArgString);
                }

                /*
                 *  Switch out callee with the reference to attr
                 */
                return(this.referenceFactory.CreateReadReference(TES5ReferenceFactory.TES4Attr + PHPFunction.UCWords(firstArgStringLower), globalScope, multipleScriptsScope, localScope));
            }

            case "fatigue":
            case "armorer":
            case "security":
            case "acrobatics":
            case "mercantile":
            case "mysticism":     //It doesn"t exist in Skyrim - defaulting to Illusion..
            case "blade":
            case "blunt":
            case "encumbrance":
            case "spellabsorbchance":
            case "resistfire":
            case "resistfrost":
            case "resistdisease":
            case "resistmagic":
            case "resistpoison":
            case "resistshock":
            {
                TES5ObjectCallArguments convertedArguments = new TES5ObjectCallArguments()
                {
                    new TES5String(actorValueMap[firstArgStringLower])
                };
                return(this.objectCallFactory.CreateObjectCall(calledOn, functionName, multipleScriptsScope, convertedArguments));
            }

            default:
            {
                TES5ObjectCallArguments convertedArguments = new TES5ObjectCallArguments()
                {
                    new TES5String(firstArgString)
                };
                return(this.objectCallFactory.CreateObjectCall(calledOn, functionName, multipleScriptsScope, convertedArguments));
            }
            }
        }
예제 #21
0
 private TES5ScriptDependencyGraph ReadGraph()
 {
     return(PHPFunction.Deserialize <TES5ScriptDependencyGraph>(File.ReadAllText(GetFilePath())));
 }