Exemple #1
0
        public CommandList ApplyChanges()
        {
            // Don't bother selectively processing events, just clear and repopulate the whole thing.
            string[] lines = Lines.Where(x => !string.IsNullOrWhiteSpace(x) && !x.Contains("//")).Select(x => x.Trim()).ToArray();
            _list.Clear();

            UnknownCommand unkC = null;
            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i].StartsWith("0x"))
                {
                    if (unkC == null)
                        unkC = new UnknownCommand();
                    unkC.data.Add(Int32.Parse(lines[i].Substring(2, 8), System.Globalization.NumberStyles.HexNumber));
                    continue;
                }
                foreach (CommandInfo e in Runtime.commandDictionary)
                    if (lines[i].StartsWith(e.Name))
                    {
                        if (unkC != null)
                        {
                            _list.Add(unkC);
                            unkC = null;
                        }
                        string temp = lines[i].Substring(lines[i].IndexOf('(')).Trim(new char[] { '(', ')' });
                        List<string> Params = temp.Replace("0x", "").Split(',').ToList();
                        Command c = new Command(e);
                        for (int counter = 0; counter < e.ParamSpecifiers.Count; counter++)
                        {
                            // parameter - it's syntax keyword(s), and then parse.
                            if (e.ParamSyntax.Count > 0)
                                Params[counter] = Params[counter].Substring(Params[counter].IndexOf('=') + 1);

                            if (e.ParamSpecifiers[counter] == 0)
                                c.parameters.Add(Int32.Parse(Params[counter], System.Globalization.NumberStyles.HexNumber));
                            else if (e.ParamSpecifiers[counter] == 1)
                                c.parameters.Add(float.Parse(Params[counter]));
                            else if (e.ParamSpecifiers[counter] == 2)
                                c.parameters.Add(decimal.Parse(Params[counter]));
                        }
                        _list.Add(c);
                    }
            }
            CommandList = _list;
            return _list;
        }
Exemple #2
0
        private CommandList ParseEventList(uint CRC, int Offset)
        {
            CommandList _list = new CommandList(CRC, this);

            Command c;
            UnknownCommand unkC = null;

            VoidPtr addr = (_workingSource.Address + Offset);

            // Loop through Event List.
            while (Util.GetWordUnsafe(addr, Endian) != Runtime._endingCommand.Identifier)
            {
                // Try to get command definition
                uint ident = (uint)Util.GetWordUnsafe(addr, Endian);
                CommandInfo info = Runtime.commandDictionary.FirstOrDefault(e => e.Identifier == ident);

                // If a command definition exists, use that info to deserialize.
                if (info != null)
                {
                    // If previous commands were unknown, add them here.
                    if (unkC != null)
                    {
                        _list.Add(unkC);
                        unkC = null;
                    }

                    // Get command parameters and add the command to the event list.
                    c = new Command(info);
                    for (int i = 0; i < info.ParamSpecifiers.Count; i++)
                    {
                        switch (info.ParamSpecifiers[i])
                        {
                            case 0:
                                c.parameters.Add(Util.GetWordUnsafe(0x04 + (addr + (i * 4)), Endian));
                                break;
                            case 1:
                                c.parameters.Add(Util.GetFloatUnsafe(0x04 + (addr + (i * 4)), Endian));
                                break;
                            case 2:
                                c.parameters.Add((decimal)Util.GetWordUnsafe(0x04 + (addr + (i * 4)), Endian));
                                break;
                            default:
                                goto case 0;
                        }
                    }

                    _list.Add(c);
                    addr += c.CalcSize();
                }

                // If there is no command definition, this is unknown data.
                // Add the current word to the unk command and continue adding
                // until we hit a known command
                else
                {
                    if (unkC == null)
                        unkC = new UnknownCommand();
                    unkC.data.Add(Util.GetWordUnsafe(addr, Endian));
                    addr += 0x04;
                }
            }

            if (unkC != null)
                _list.Add(unkC);


            // If we hit a script_end command, add it to the the Event List and terminate looping.
            if (Util.GetWordUnsafe(addr, Endian) == Runtime._endingCommand.Identifier)
            {
                CommandInfo info = Runtime.commandDictionary.FirstOrDefault(e => e.Identifier == Runtime._endingCommand.Identifier);

                c = new Command(info);
                _list.Add(c);
            }

            _list.Initialize();
            return _list;
        }
Exemple #3
0
        private CommandList ParseEventList(uint CRC, int Offset)
        {
            CommandList _list = new CommandList(CRC, this);

            Command        c;
            UnknownCommand unkC = null;

            VoidPtr addr = (_workingSource.Address + Offset);

            // Loop through Event List.
            while (Util.GetWordUnsafe(addr, Endian) != Runtime._endingCommand.Identifier)
            {
                // Try to get command definition
                uint        ident = (uint)Util.GetWordUnsafe(addr, Endian);
                CommandInfo info  = Runtime.commandDictionary.FirstOrDefault(e => e.Identifier == ident);

                // If a command definition exists, use that info to deserialize.
                if (info != null)
                {
                    // If previous commands were unknown, add them here.
                    if (unkC != null)
                    {
                        _list.Add(unkC);
                        unkC = null;
                    }

                    // Get command parameters and add the command to the event list.
                    c = new Command(info);
                    for (int i = 0; i < info.ParamSpecifiers.Count; i++)
                    {
                        switch (info.ParamSpecifiers[i])
                        {
                        case 0:
                            c.parameters.Add(Util.GetWordUnsafe(0x04 + (addr + (i * 4)), Endian));
                            break;

                        case 1:
                            c.parameters.Add(Util.GetFloatUnsafe(0x04 + (addr + (i * 4)), Endian));
                            break;

                        case 2:
                            c.parameters.Add((decimal)Util.GetWordUnsafe(0x04 + (addr + (i * 4)), Endian));
                            break;

                        default:
                            goto case 0;
                        }
                    }

                    _list.Add(c);
                    addr += c.CalcSize();
                }

                // If there is no command definition, this is unknown data.
                // Add the current word to the unk command and continue adding
                // until we hit a known command
                else
                {
                    if (unkC == null)
                    {
                        unkC = new UnknownCommand();
                    }
                    unkC.data.Add(Util.GetWordUnsafe(addr, Endian));
                    addr += 0x04;
                }
            }

            if (unkC != null)
            {
                _list.Add(unkC);
            }


            // If we hit a script_end command, add it to the the Event List and terminate looping.
            if (Util.GetWordUnsafe(addr, Endian) == Runtime._endingCommand.Identifier)
            {
                CommandInfo info = Runtime.commandDictionary.FirstOrDefault(e => e.Identifier == Runtime._endingCommand.Identifier);

                c = new Command(info);
                _list.Add(c);
            }

            _list.Initialize();
            return(_list);
        }