Пример #1
0
 private byte[] WriteString(byte[] outScript, WS2String Entry)
 {
     if (Entry.String.Length > Entry.str.Length)
     {
         throw new Exception("String \"" + Entry.String + "\" Are too big.");
     }
     while (Entry.String.Length < Entry.str.Length)
     {
         Entry.String += @" ";
     }
     byte[] String = StringParse(Entry.Prefix + Entry.String + Entry.Sufix);
     outScript = InsertArray(outScript, String, Entry.Position);
     if (Entry.HaveActor)
     {
         outScript = WriteString(outScript, Entry.Actor);
     }
     return(outScript);
 }
Пример #2
0
        private WS2String GetString(int pos)
        {
            int length = 0;

            while (CuttedScript[pos + length] != 0x0)
            {
                length++;
            }
            byte[] str = new byte[length];
            for (int ind = 0; ind < length; ind++)
            {
                str[ind] = CuttedScript[pos + ind];
            }
            string _str = ByteParse(str);

            CuttedScript = CutRegion(CuttedScript, pos, length);
            WS2String ws2 = new WS2String();

            ws2.Position = pos;
            ws2.SetString(_str);
            return(ws2);
        }
Пример #3
0
        public WS2String[] Import()
        {
            CuttedScript = new byte[script.Length];
            script.CopyTo(CuttedScript, 0);
            WS2String[] Rst         = new WS2String[0];
            byte[]      TxtEntry    = StringParse("char\x0");
            byte[]      CharName    = StringParse("%LC");
            byte[]      NewCharName = StringParse("%LF");
            byte[]      ChoiceOP    = new byte[] { 0x00, 0xFF, 0x0F, 0x02 };//0xFF = any, the opcode is just 0x0F02
            WS2String   Actor       = null;
            bool        AskMerged   = true;

            for (int i = 0; i < CuttedScript.Length; i++)
            {
                if (Equals(CuttedScript, ChoiceOP, i))
                {
                    i += ChoiceOP.Length;
                    if (CuttedScript[i] == 0x00)
                    {
                        continue;
                    }

                    bool Continue = true;
                    while (i < CuttedScript.Length && Continue)
                    {
                        i += 2;
                        WS2String str = GetString(i);
                        i += 4;

                        while (CuttedScript[i] != 0x00)
                        {
                            i++;
                        }

                        if (CuttedScript[++i] == 0xFF)
                        {
                            Continue = false;
                        }

                        WS2String[] tmp = new WS2String[Rst.Length + 1];
                        Rst.CopyTo(tmp, 0);
                        tmp[Rst.Length] = str;
                        Rst             = tmp;
                    }
                }
                if (Equals(CuttedScript, CharName, i))
                {
                    i        += CharName.Length;
                    Actor     = GetString(i);
                    AskMerged = false;
                }
                if (Equals(CuttedScript, NewCharName, i))
                {
                    i        += NewCharName.Length;
                    Actor     = GetString(i);
                    AskMerged = false;
                }
                if (Equals(CuttedScript, TxtEntry, i))
                {
                    i += TxtEntry.Length;
                    WS2String str = GetString(i);
                    if (!AskMerged)
                    {
                        str.Actor     = Actor;
                        str.HaveActor = true;
                        AskMerged     = true;
                    }
                    WS2String[] tmp = new WS2String[Rst.Length + 1];
                    Rst.CopyTo(tmp, 0);
                    tmp[Rst.Length] = str;
                    Rst             = tmp;
                }
            }
            if (filter)
            {
                for (int i = 0; i < Rst.Length; i++)
                {
                    string str = Rst[i].String;
                    if (str.EndsWith("%K%P"))
                    {
                        Rst[i].SetString(str.Substring(0, str.Length - "%K%P".Length));
                        Rst[i].Sufix = "%K%P";
                    }
                    if (Rst[i].HaveActor)
                    {
                        if (Rst[i].Actor.String.StartsWith("%LC"))
                        {
                            Rst[i].Actor.Prefix = "%LC";
                            Rst[i].Actor.SetString(Rst[i].Actor.String.Substring(3, Rst[i].Actor.String.Length - 3));
                        }
                        if (Rst[i].Actor.String.StartsWith("%LF"))
                        {
                            Rst[i].Actor.Prefix = "%LF";
                            Rst[i].Actor.SetString(Rst[i].Actor.String.Substring(3, Rst[i].Actor.String.Length - 3));
                        }
                    }
                }
            }
            return(Rst);
        }