예제 #1
0
        public bool LoadFromString(string content, string resourceName)
        {
#if UNITY_EDITOR
            Parser.DslToken      tokens = new Parser.DslToken(content);
            Parser.DslError      error  = new Parser.DslError(tokens);
            Parser.RuntimeAction action = new Parser.RuntimeAction(mScriptableDatas);
            action.onGetLastToken      = () => { return(tokens.getLastToken()); };
            action.onGetLastLineNumber = () => { return(tokens.getLastLineNumber()); };
            Parser.DslParser.parse(action, tokens, error, 0);
            if (error.HasError)
            {
                foreach (ScriptableDataInfo data in mScriptableDatas)
                {
                    data.Clear();
                }
            }
            else
            {
                foreach (ScriptableDataInfo data in mScriptableDatas)
                {
                    data.SetResourceName(resourceName);
                }
            }
            return(!error.HasError);
#else
            return(false);
#endif
        }
예제 #2
0
        public bool LoadFromString(string content, string resourceName)
        {
#if FULL_VERSION
            Parser.DslToken      tokens = new Parser.DslToken(content);
            Parser.DslError      error  = new Parser.DslError(tokens);
            Parser.RuntimeAction action = new Parser.RuntimeAction(mScriptableDatas);
            action.onGetLastToken      = () => { return(tokens.getLastToken()); };
            action.onGetLastLineNumber = () => { return(tokens.getLastLineNumber()); };
            Parser.DslParser.parse(action, tokens, error, 0);
            if (error.HasError)
            {
                for (int i = 0; i < mScriptableDatas.Count; i++)
                {
                    mScriptableDatas[i].Clear();
                }

                /*
                 *    foreach(ScriptableDataInfo data in mScriptableDatas) {
                 *        data.Clear();
                 *    }*/
            }
            else
            {
                for (int i = 0; i < mScriptableDatas.Count; i++)
                {
                    mScriptableDatas[i].SetResourceName(resourceName);
                }

                /*
                 * foreach (ScriptableDataInfo data in mScriptableDatas) {
                 *        data.SetResourceName(resourceName);
                 *    }*/
            }
            return(!error.HasError);
#else
            return(false);
#endif
        }
예제 #3
0
 public void LoadObfuscatedCode(string code, Dictionary <string, string> decodeTable)
 {
     Parser.RuntimeAction action = new Parser.RuntimeAction(mScriptableDatas);
     Parser.ObfuscationAction.parse(code, action, s => Decode(s, decodeTable));
 }
예제 #4
0
        internal static void parse(string obfuscatedCode, RuntimeAction action, DecodeStringDelegation decode)
        {
            if (string.IsNullOrEmpty(obfuscatedCode))
            {
                return;
            }
            int split = obfuscatedCode.IndexOf('|');

            if (split <= 0)
            {
                return;
            }

            TokenTempStore tokenStore = new TokenTempStore();

            if (null != decode)
            {
                tokenStore.onDecodeString = decode;
            }
            action.onGetLastToken = tokenStore.getLastToken;

            string code = obfuscatedCode.Substring(0, split);

            string[] ids     = obfuscatedCode.Substring(split + 1).Split('`');
            int      idIndex = 0;

            for (int i = 0; i < code.Length; i += 2)
            {
                string t = code.Substring(i, 2);
                byte   c = byte.Parse(t);
                ScriptableDataCodeEnum cc = (ScriptableDataCodeEnum)c;
                switch (cc)
                {
                case ScriptableDataCodeEnum.CODE_PUSH_ID:
                    tokenStore.setLastToken(nextToken(ids, ref idIndex));
                    action.pushId();
                    break;

                case ScriptableDataCodeEnum.CODE_PUSH_NUM:
                    tokenStore.setLastToken(nextToken(ids, ref idIndex));
                    action.pushNum();
                    break;

                case ScriptableDataCodeEnum.CODE_PUSH_STR:
                    tokenStore.setLastToken(nextToken(ids, ref idIndex));
                    action.pushStr();
                    break;

                case ScriptableDataCodeEnum.CODE_PUSH_TRUE:
                    action.pushTrue();
                    break;

                case ScriptableDataCodeEnum.CODE_PUSH_FALSE:
                    action.pushFalse();
                    break;

                case ScriptableDataCodeEnum.CODE_MARK_PERIOD_PARENTHESIS_PARAM:
                    action.markPeriodParenthesisParam();
                    break;

                case ScriptableDataCodeEnum.CODE_MARK_PERIOD_BRACKET_PARAM:
                    action.markPeriodBracketParam();
                    break;

                case ScriptableDataCodeEnum.CODE_MARK_PERIOD_BRACE_PARAM:
                    action.markPeriodBraceParam();
                    break;

                case ScriptableDataCodeEnum.CODE_SET_MEMBER_ID:
                    action.setMemberId();
                    break;

                case ScriptableDataCodeEnum.CODE_MARK_PERIOD_PARAM:
                    action.markPeriodParam();
                    break;

                case ScriptableDataCodeEnum.CODE_MARK_BRACKET_PARAM:
                    action.markBracketParam();
                    break;

                case ScriptableDataCodeEnum.CODE_BUILD_HIGHORDER_FUNCTION:
                    action.buildHighOrderFunction();
                    break;

                case ScriptableDataCodeEnum.CODE_MARK_PARENTHESIS_PARAM:
                    action.markParenthesisParam();
                    break;

                case ScriptableDataCodeEnum.CODE_MARK_HAVE_STATEMENT:
                    action.markHaveStatement();
                    break;

                case ScriptableDataCodeEnum.CODE_SET_FUNCTION_ID:
                    action.setFunctionId();
                    break;

                case ScriptableDataCodeEnum.CODE_BEGIN_FUNCTION:
                    action.beginFunction();
                    break;

                case ScriptableDataCodeEnum.CODE_END_FUNCTION:
                    action.endFunction();
                    break;

                case ScriptableDataCodeEnum.CODE_BEGIN_STATEMENT:
                    action.beginStatement();
                    break;

                case ScriptableDataCodeEnum.CODE_END_STATEMENT:
                    action.endStatement();
                    break;

                case ScriptableDataCodeEnum.CODE_BUILD_OPERATOR:
                    action.buildOperator();
                    break;

                case ScriptableDataCodeEnum.CODE_BUILD_FIRST_TERNARY_OPERATOR:
                    action.buildFirstTernaryOperator();
                    break;

                case ScriptableDataCodeEnum.CODE_BUILD_SECOND_TERNARY_OPERATOR:
                    action.buildSecondTernaryOperator();
                    break;
                }
            }
        }