Пример #1
0
    //WARNING: returned string will be prefixed by seperator
    public static string ArgToString(ushort arg, string type)
    {
        string s          = type.Equals("Null") ? "" : " ";
        string strReplace = "";

        // special formatting
        switch (type)
        {
        case "WordID":
            if (arg == 0)
            {
                return("Null");
            }
            else if (arg == 1)
            {
                return("Empty");
            }
            else if (arg > word.Count)
            {
                goto default;
            }
            else
            {
                strReplace = word.Read(arg).Trim();
            }
            break;

        case "MessageID":
            string msg = message.Read(arg);
            strReplace = String.Format("`{0}`", msg);
            break;

        case "ScriptID":
            if (!printAll && !ReferredScript.ContainsKey((int)arg))
            {
                ReferredScript.Add((int)arg, false);
            }
            goto default;

        default:
            // variable-to-file expansion
            strReplace = ScriptEntryDescription.FormatArg(type, arg);
            break;
        }
        s += strReplace;

        return(s);
    }
Пример #2
0
    // Print the script at index until End (00) or Jump commands (02, 03) is reached.
    // return The index to the next line of script after the last one printed, or -1 if end of the script file is reached.
    public static int PrintScript(int index)
    {
        ScriptEntry entry;

        try
        {
            do
            {
                entry = script.Read(index);
                if (entry == null)
                {
                    throw new EndOfStreamException();
                }
                WriteDebug(traceSwitch.TraceInfo, "{0:x4}: ", index);
                index++;

                // display raw data
                WriteDebug(traceSwitch.TraceVerbose, "{0:x4} {1:x4} {2:x4} {3:x4}",
                           entry.command, entry.arg[0], entry.arg[1], entry.arg[2]);
                WriteDebug(traceSwitch.TraceVerbose, " ;");

                ScriptEntryDescription entryDesc = (ScriptEntryDescription)ScriptEntryDescription.SCRIPT_COMMAND[entry.command];
                if (entryDesc != null)
                {
                    string s = String.Format("{0}{1}{2}{3}",
                                             entryDesc.commandName,
                                             ArgToString(entry.arg[0], entryDesc.argType[0]),
                                             ArgToString(entry.arg[1], entryDesc.argType[1]),
                                             ArgToString(entry.arg[2], entryDesc.argType[2]));
                    Console.WriteLine(s);
                }
                else
                {
                    Console.WriteLine(entry);
                }
            } while (entry.command != 0 && (entry.command < 2 || entry.command > 3));
        }
        catch (EndOfStreamException)
        {
            return(-1);
        }

        return(index);
    }
Пример #3
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;
        }