Example #1
0
 public MintVariable(string name, string type, uint flags, MintClass parentClass)
 {
     ParentClass = parentClass;
     SetName(name);
     Type  = type;
     Flags = flags;
 }
Example #2
0
        public MintVariable(EndianBinaryReader reader, MintClass parentClass)
        {
            ParentClass = parentClass;

            uint nameOffs = reader.ReadUInt32();

            byte[] hash     = reader.ReadBytes(4);
            uint   typeOffs = reader.ReadUInt32();
            uint   flags    = reader.ReadUInt32();

            reader.BaseStream.Seek(nameOffs, SeekOrigin.Begin);
            string name = Encoding.UTF8.GetString(reader.ReadBytes(reader.ReadInt32()));

            reader.BaseStream.Seek(typeOffs, SeekOrigin.Begin);
            string type = Encoding.UTF8.GetString(reader.ReadBytes(reader.ReadInt32()));

            Name  = name;
            Hash  = hash;
            Type  = type;
            Flags = flags;
        }
Example #3
0
        public MintScript(string[] text, byte[] version)
        {
            string scriptDeclare = text[0];

            if (!scriptDeclare.StartsWith("script "))
            {
                MessageBox.Show("Error: Invalid Mint Script file.", "Mint Workshop", MessageBoxButtons.OK);
                return;
            }

            XData   = new XData(Endianness.Little, new byte[] { 2, 0 });
            Version = version;
            Name    = scriptDeclare.Substring(7);
            SData   = new List <byte>();
            XRef    = new List <byte[]>();
            Classes = new List <MintClass>();

            Regex classRegex = new Regex("\\b(class)\\b");
            Regex varRegex   = new Regex("\\b(var)\\b");
            Regex funcRegex  = new Regex("(\\(.*\\))");

            for (int l = 0; l < text.Length; l++)
            {
                string line = text[l].TrimStart(trimChars);
                if (line.StartsWith("//"))
                {
                    continue;
                }
                if (classRegex.IsMatch(line))
                {
                    string[]  classDeclaration = line.Split(' ');
                    int       classWord        = classDeclaration.ToList().IndexOf("class");
                    MintClass newClass         = new MintClass(classDeclaration[classWord + 1], 0, this);
                    for (int i = 0; i < classWord; i++)
                    {
                        if (classDeclaration[i].StartsWith("flag"))
                        {
                            newClass.Flags |= uint.Parse(classDeclaration[i].Substring(4), NumberStyles.HexNumber);
                        }
                        else if (FlagLabels.ClassFlags.ContainsValue(classDeclaration[i]))
                        {
                            newClass.Flags |= FlagLabels.ClassFlags.Keys.ToArray()[FlagLabels.ClassFlags.Values.ToList().IndexOf(classDeclaration[i])];
                        }
                        else
                        {
                            throw new Exception($"Unknown Class flag name \"{classDeclaration[i]}\"");
                        }
                    }

                    for (int cl = l; cl < text.Length; cl++)
                    {
                        string classLine = text[cl].TrimStart(trimChars);
                        if (classLine.StartsWith("//"))
                        {
                            continue;
                        }
                        if (varRegex.IsMatch(classLine))
                        {
                            string[]     varDeclaration = classLine.Split(' ');
                            int          varWord        = varDeclaration.ToList().IndexOf("var");
                            MintVariable newVar         = new MintVariable(varDeclaration[varWord + 2], varDeclaration[varWord + 1], 0, newClass);
                            for (int i = 0; i < varWord; i++)
                            {
                                if (varDeclaration[i].StartsWith("flag"))
                                {
                                    newVar.Flags |= uint.Parse(varDeclaration[i].Substring(4), NumberStyles.HexNumber);
                                }
                                else if (FlagLabels.VariableFlags.ContainsValue(varDeclaration[i]))
                                {
                                    newVar.Flags |= FlagLabels.VariableFlags.Keys.ToArray()[FlagLabels.VariableFlags.Values.ToList().IndexOf(varDeclaration[i])];
                                }
                                else
                                {
                                    throw new Exception($"Unknown Variable flag name \"{varDeclaration[i]}\"");
                                }
                            }
                            newClass.Variables.Add(newVar);
                        }
                        else if (funcRegex.IsMatch(classLine))
                        {
                            string[] funcDeclaration = classLine.Split(' ');
                            string   name            = "";
                            uint     funcFlags       = 0;
                            for (int i = 0; i < funcDeclaration.Length; i++)
                            {
                                if (funcDeclaration[i].StartsWith("flag"))
                                {
                                    funcFlags |= uint.Parse(funcDeclaration[i].Substring(4), NumberStyles.HexNumber);
                                }
                                else if (FlagLabels.FunctionFlags.ContainsValue(funcDeclaration[i]))
                                {
                                    funcFlags |= FlagLabels.FunctionFlags.Keys.ToArray()[FlagLabels.FunctionFlags.Values.ToList().IndexOf(funcDeclaration[i])];
                                }
                                else
                                {
                                    name = string.Join(" ", funcDeclaration.Skip(i));
                                    break;
                                }
                            }

                            MintFunction  newFunc      = new MintFunction(name, funcFlags, newClass);
                            List <string> instructions = new List <string>();
                            for (int fl = cl + 2; fl < text.Length; fl++)
                            {
                                string funcLine = text[fl].TrimStart(trimChars);
                                if (funcLine.StartsWith("//"))
                                {
                                    continue;
                                }
                                if (funcLine.StartsWith("}"))
                                {
                                    cl = fl;
                                    break;
                                }
                                instructions.Add(funcLine);
                            }
                            newFunc.Assemble(instructions.ToArray());
                            newFunc.DetectArguments();
                            newFunc.DetectRegisters();

                            newClass.Functions.Add(newFunc);
                        }
                        else if (classLine.StartsWith("const "))
                        {
                            string[] constDeclaration = classLine.Split(' ');
                            uint     value;
                            if (constDeclaration[3].StartsWith("0x"))
                            {
                                value = uint.Parse(constDeclaration[3].Substring(2), NumberStyles.HexNumber);
                            }
                            else
                            {
                                value = uint.Parse(constDeclaration[3]);
                            }

                            newClass.Constants.Add(new MintClass.MintConstant(constDeclaration[1], value));
                        }
                        else if (classLine.StartsWith("unkvalue "))
                        {
                            string[] unkDeclaration = classLine.Split(' ');
                            newClass.UnknownList.Add(uint.Parse(unkDeclaration[1]));
                        }
                        else if (classLine.StartsWith("unk2value "))
                        {
                            string[] unkDeclaration = classLine.Split(' ');
                            newClass.Unknown2List.Add(uint.Parse(unkDeclaration[1]));
                        }
                        else if (classLine.StartsWith("}"))
                        {
                            l = cl;
                            break;
                        }
                    }

                    Classes.Add(newClass);
                }
            }
        }