コード例 #1
0
        public static Hashtable ReadScriptCommandDescription(string descFileName)
        {
            Hashtable    ht     = new Hashtable(200);
            StreamReader reader = new StreamReader(File.Open(descFileName, FileMode.Open));
            //TODO catch IOException

            Regex  r        = new Regex("^@(\\S+):(\\s*(\\S+))+");
            Regex  rComment = new Regex(";.*$");
            string s;

            while ((s = reader.ReadLine()) != null)
            {
                if (!s.Trim().StartsWith("@"))
                {
                    continue;
                }
                s = rComment.Replace(s, "");

                MatchCollection mc = r.Matches(s);
                foreach (Match m in mc)
                {
                    GroupCollection gc = m.Groups;
                    if (gc.Count < 4)
                    {
                        throw new Exception(String.Format("Error when parsing line: {0}", s));
                    }
                    ushort cmd = Convert.ToUInt16(gc[1].ToString(), 16);

                    // WARNING: later definitions overrides the prior, may change behavior to exception throwing
                    if (ht.ContainsKey(cmd))
                    {
                        ht.Remove(cmd);
                    }

                    CaptureCollection      cc        = gc[3].Captures;
                    ScriptEntryDescription entryDesc = new ScriptEntryDescription();
                    // TODO: catch FormatException
                    entryDesc.commandName = cc[0].ToString();
                    for (int i = 1; i < 4; i++)
                    {
                        if (i >= cc.Count)
                        {
                            entryDesc.argType[i - 1] = "Null";
                        }
                        else
                        {
                            string argType = cc[i].ToString();
                            entryDesc.argType[i - 1] = argType;
                        }
                    }
                    ht.Add(cmd, entryDesc);
                }
            }
            reader.Close();

            return(ht);
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            Script script = new Script("sss4.bin");

            for (int index = 0; index < 20; index++)
            {
                ScriptEntry            entry     = script.Read(0x966e + index);
                ScriptEntryDescription entryDesc = (ScriptEntryDescription)ScriptEntryDescription.SCRIPT_COMMAND[entry.command];
                if (entryDesc == null)
                {
                    Console.WriteLine(entry);
                }
                else
                {
                    Console.WriteLine(entryDesc);
                    string s = String.Format("{0}", entryDesc.commandName);
                    for (int i = 0; i < entry.arg.Length; i++)
                    {
                        s += " " + ScriptEntryDescription.FormatArg(entryDesc.argType[i], entry.arg[i]);
                    }
                    Console.WriteLine(s);
                }
            }
        }