Exemple #1
0
        private void inputTb_TextChanged(object sender, EventArgs e)
        {
            outputTb.Clear();
            List <Token> tokens;

            try
            {
                tokens = Tokenizer.Tokenize(inputTb.Text);
            }
            catch (FormatException ex)
            {
                outputTb.Text = ex.Message;
                return;
            }

            try
            {
                MemberTypeTable.ClearUserTypes();
                var structs = Generator.Generate(tokens);
                foreach (var s in structs)
                {
                    outputTb.AppendText(s.ToString());
                    outputTb.AppendText("\r\n");
                }
            }
            catch (Exception ex)
            {
                outputTb.Text = ex.Message;
            }
        }
Exemple #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            inputTb.Font       = new Font(FontFamily.GenericMonospace, 12);
            inputTb.AcceptsTab = true;
            outputTb.Font      = new Font(FontFamily.GenericMonospace, 12);

            MemberTypeTable.AddBuiltinType("char", 1);
            MemberTypeTable.AddBuiltinType("__int8", 1);
            MemberTypeTable.AddBuiltinType("__int16", 2);
            MemberTypeTable.AddBuiltinType("__int32", 4);
            MemberTypeTable.AddBuiltinType("__int64", 8);

            MemberTypeTable.AddBuiltinType("float", 4);
            MemberTypeTable.AddBuiltinType("double", 8);

            MemberTypeTable.AddBuiltinType("D3DXVECTOR2", 2 * MemberTypeTable.GetMemberTypeSize("float"));
            MemberTypeTable.AddBuiltinType("D3DXVECTOR3", 3 * MemberTypeTable.GetMemberTypeSize("float"));
            MemberTypeTable.AddBuiltinType("D3DXMATRIX", 4 * 4 * MemberTypeTable.GetMemberTypeSize("float"));

            MemberTypeTable.AliasBuiltinType("int8", "__int8");
            MemberTypeTable.AliasBuiltinType("int16", "__int16");
            MemberTypeTable.AliasBuiltinType("int32", "__int32");
            MemberTypeTable.AliasBuiltinType("int64", "__int64");

            MemberTypeTable.AliasBuiltinType("BYTE", "__int8");
            MemberTypeTable.AliasBuiltinType("WORD", "__int16");
            MemberTypeTable.AliasBuiltinType("DWORD", "__int32");
            MemberTypeTable.AliasBuiltinType("QWORD", "__int64");

            const string example =
                @"struct Player {
    int32 Health : 0x10;
    int32 Mana : 0x14;
    D3DXVECTOR3 Position1 : 0x150;
    D3DXVECTOR3 Position2;
};
";

            inputTb.Text = example;
        }
Exemple #3
0
        public static List <Struct> Generate(List <Token> tokens)
        {
            var structs = new List <Struct>();

            try
            {
                int i = 0;
                while (i < tokens.Count)
                {
                    var s = ParseToken(tokens, ref i);
                    if (s != null)
                    {
                        structs.Add(s);
                        MemberTypeTable.AddUserType(s);
                    }
                }
            }
            catch (IndexOutOfRangeException)
            {
                // BAD SHIT HAPPENED!
            }
            return(structs);
        }
Exemple #4
0
        public static Member CreatePointerRelative(string typeName, string name, int lineNum, int numStars)
        {
            var type = MemberTypeTable.GetMemberType(typeName);

            return(CreatePointerRelative(type, name, lineNum, numStars));
        }
Exemple #5
0
        public static Member CreateArray(string typeName, string name, int lineNum, int offset, int numStars, int numElements)
        {
            var type = MemberTypeTable.GetMemberType(typeName);

            return(CreateArray(type, name, lineNum, offset, numStars, numElements));
        }
Exemple #6
0
        public static Member CreateValue(string typeName, string name, int lineNum, int offset)
        {
            var type = MemberTypeTable.GetMemberType(typeName);

            return(CreateValue(type, name, lineNum, offset));
        }