Beispiel #1
0
        /// <summary>
        /// 使用字符串和类型重建ParamData
        /// 重建value和bytes
        /// </summary>
        /// <param name="data"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static ParamData ToParamData(string data, DataType type)
        {
            ParamData param = new ParamData();

            byte[] dataBytes = null;
            switch (type)
            {
            case DataType.Byte:
            case DataType.Byte2:
            case DataType.Byte3:
            case DataType.Byte4:
                dataBytes = ScriptUtil.Hex2Byte(data);
                param     = new ParamData(type, dataBytes, dataBytes, data);
                break;

            case DataType.UInt16:
                var dataUint16 = Convert.ToUInt16(data);
                dataBytes = BitConverter.GetBytes(dataUint16);
                param     = new ParamData(type, dataUint16, dataBytes, data);
                break;

            case DataType.Int16:
                var dataInt16 = Convert.ToInt16(data);
                dataBytes = BitConverter.GetBytes(dataInt16);
                param     = new ParamData(type, dataInt16, dataBytes, data);
                break;

            case DataType.UInt32:
                var dataUint32 = Convert.ToUInt32(data);
                dataBytes = BitConverter.GetBytes(dataUint32);
                param     = new ParamData(type, dataUint32, dataBytes, data);
                break;

            case DataType.Position:
                dataBytes = BitConverter.GetBytes((UInt32)0);
                param     = new ParamData(type, (UInt32)0, dataBytes, data);
                break;

            case DataType.Int32:
                var dataInt32 = Convert.ToInt32(data);
                dataBytes = BitConverter.GetBytes(dataInt32);
                param     = new ParamData(type, dataInt32, dataBytes, data);
                break;

            case DataType.StringUnicode:
            case DataType.StringSJIS:
            case DataType.StringUTF8:
            case DataType.StringCustom:
            case DataType.LenStringUnicode:
            case DataType.LenStringSJIS:
            case DataType.LenStringUTF8:
            case DataType.LenStringCustom:
                dataBytes = ToEncodingBytes(data, type);
                param     = new ParamData(type, data, dataBytes, data);
                break;

            default:
                break;
            }
            return(param);
        }
Beispiel #2
0
        /// <summary>
        /// 可导入lua的加载,转成CodeLine
        /// </summary>
        /// <param name="codeStr"></param>
        public CodeLine(string codeStr)
        {
            List <string> tokens = new List <string>();
            string        token  = "";
            bool          isStr  = false;
            int           i      = 0;

            while (i < codeStr.Length)
            {
                if (codeStr[i] == '\"')
                {
                    isStr = !isStr;
                }
                if (!isStr &&
                    (codeStr[i] == '(' || codeStr[i] == '{' ||
                     codeStr[i] == ')' || codeStr[i] == '}' ||
                     codeStr[i] == ',' || codeStr[i] == ' '))
                {
                    token = token.Trim();
                    if (token != "")
                    {
                        tokens.Add(token);
                        token = "";
                    }
                    if (!(codeStr[i] == ',' || codeStr[i] == ' '))
                    {
                        tokens.Add(codeStr[i].ToString());
                    }
                }
                else
                {
                    token += codeStr[i];
                }
                i++;
            }
            token = token.Trim();
            if (token != "")
            {
                tokens.Add(token);
            }

            paramDatas = new List <ParamData>();
            bool   readParam = false;
            string tempStr   = "";

            i = 0;
            while (i < tokens.Count)
            {
                if (!readParam)
                {
                    if (tokens[i][0] == ':')
                    {
                        isLabel = true;
                        label   = tokens[i].Substring(2, tokens[i].Length - 4);
                        i++; // (
                    }
                    if (opcode == null)
                    {
                        opcode = tokens[i];
                    }
                    if (tokens[i] == "{")
                    {
                        i++; // {
                        CodeInfo      info  = new CodeInfo(0);
                        List <UInt16> datas = new List <UInt16>();
                        while (tokens[i] != "}")
                        {
                            datas.Add(Convert.ToUInt16(tokens[i++]));
                        }
                        info.count = datas.Count;
                        info.data  = datas.ToArray();
                        this.info  = info;
                        readParam  = true;
                        // i = }
                    }
                }
                else
                {
                    ParamData param = new ParamData();
                    if (tokens[i] == ")")
                    {
                        break;
                    }
                    else if (tokens[i] == "(")
                    {
                        i++;
                        DataType type = ScriptEntity.ToDataType(tokens[i++]);
                        i++;
                        if (tokens[i][0] == '\"')
                        {
                            tempStr = tokens[i].Substring(1, tokens[i].Length - 2).Replace(@"\n", "\n");;
                            param   = ScriptEntity.ToParamData(tempStr, type);
                            if (type == DataType.Position)
                            {
                                isPosition    = true;
                                param.valueOp = tempStr;
                            }
                        }
                        else
                        {
                            param = ScriptEntity.ToParamData(tokens[i], type);
                        }
                        // i = )
                    }
                    else if (tokens[i].Length >= 4 && tokens[i].Substring(0, 2) == "0x")
                    {
                        param = ScriptEntity.ToParamData(tokens[i], DataType.Byte2);
                    }
                    else
                    {
                        param = ScriptEntity.ToParamData(tokens[i], DataType.UInt16);
                    }

                    paramDatas.Add(param);
                }
                i++;
            }
        }