public static bool Convert(
     string oldConfigPath,
     string newConfigPath,
     string newVersion,
     bool isBuiltIn,
     bool useCustomName)
 {
     try
     {
         JObject jobject1 = JObject.Parse(File.ReadAllText(oldConfigPath));
         string  str;
         if (oldConfigPath == null)
         {
             str = (string)null;
         }
         else
         {
             str = ((IEnumerable <string>)oldConfigPath.Split('\\')).Last <string>();
         }
         str.Remove(str.Length - 4, 4);
         int?configVersion = ConfigConverter.GetConfigVersion(jobject1);
         int num1          = 13;
         if (configVersion.GetValueOrDefault() <= num1 & configVersion.HasValue)
         {
             JObject jobject2 = ConfigConverter.Convert(jobject1, newVersion, isBuiltIn, useCustomName);
             if (jobject2 != null)
             {
                 File.WriteAllText(newConfigPath, jobject2.ToString());
                 return(true);
             }
         }
         else
         {
             configVersion = ConfigConverter.GetConfigVersion(jobject1);
             int num2 = 16;
             if (configVersion.GetValueOrDefault() < num2 & configVersion.HasValue && Utils.CheckIfImagesArrayPresentInCfg(jobject1))
             {
                 JObject jobject2 = jobject1;
                 foreach (JObject scheme in (IEnumerable <JToken>)jobject1["ControlSchemes"])
                 {
                     scheme["Images"] = (JToken)ConfigConverter.ConvertImagesArrayForPV16(scheme);
                 }
                 jobject2["MetaData"][(object)"Comment"]       = (JToken)string.Format((IFormatProvider)CultureInfo.InvariantCulture, "Generated automatically from ver {0}", (object)(int)jobject2["MetaData"][(object)"ParserVersion"]);
                 jobject2["MetaData"][(object)"ParserVersion"] = (JToken)16;
                 if (jobject2 != null)
                 {
                     File.WriteAllText(newConfigPath, jobject2.ToString());
                     return(true);
                 }
             }
         }
         return(false);
     }
     catch (Exception ex)
     {
         Logger.Error(string.Format((IFormatProvider)CultureInfo.InvariantCulture, "Error while parsing config file {0}", (object)oldConfigPath), (object)ex.Message);
         return(false);
     }
 }
 public static int?GetConfigVersion(string config)
 {
     try
     {
         return(ConfigConverter.GetConfigVersion(JObject.Parse(File.ReadAllText(config))));
     }
     catch (Exception ex)
     {
         Logger.Error(string.Format((IFormatProvider)CultureInfo.InvariantCulture, "Error while parsing config file {0}", (object)config), (object)ex.Message);
         return(new int?());
     }
 }
 private static void UpdateTiltAndStatePrimitives(JObject primitive)
 {
     if ((primitive["Type"] == null || !string.Equals(primitive["Type"].ToString(), "State", StringComparison.OrdinalIgnoreCase)) && !string.Equals(primitive["Type"].ToString(), "Tilt", StringComparison.OrdinalIgnoreCase))
     {
         return;
     }
     primitive.Add("X", (JToken)ConfigConverter.GetLocationForPoint(ConfigConverter.mTiltCol, 2));
     primitive.Add("Y", (JToken)ConfigConverter.GetLocationForPoint(ConfigConverter.mTiltRow, 2));
     ++ConfigConverter.mTiltCol;
     if (ConfigConverter.mTiltCol == 2)
     {
         ++ConfigConverter.mTiltRow;
         ConfigConverter.mTiltRow %= 2;
     }
     ConfigConverter.mTiltCol %= 2;
 }
        private static void ConvertComboSequences(JObject primitive)
        {
            if (primitive["Type"] == null || !string.Equals(primitive["Type"].ToString(), "Combo", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }
            primitive.Add("X", (JToken)ConfigConverter.GetLocationForPoint(ConfigConverter.mScriptCol, 8));
            primitive.Add("Y", (JToken)ConfigConverter.GetLocationForPoint(ConfigConverter.mScriptRow, 8));
            ++ConfigConverter.mScriptCol;
            if (ConfigConverter.mScriptCol == 8)
            {
                ++ConfigConverter.mScriptRow;
                ConfigConverter.mScriptRow %= 8;
            }
            ConfigConverter.mScriptCol     %= 8;
            primitive["Type"]               = (JToken)"Script";
            primitive["$type"]              = (JToken)"Script, Bluestacks";
            primitive["IsVisibleInOverlay"] = (JToken)true;
            primitive["ShowOnOverlay"]      = (JToken)true;
            primitive.Add("Comment", primitive["Description"]);
            primitive["Description"].Parent.Remove();
            if (primitive["Events"] == null || !(primitive["Events"] is JArray jarray))
            {
                return;
            }
            JArray jarray1 = new JArray();
            int    num1    = 0;

            foreach (JToken jtoken in jarray)
            {
                int result1;
                if (int.TryParse(jtoken[(object)"Timestamp"].ToString(), out result1))
                {
                    int num2 = result1 - num1;
                    jarray1.Add((JToken)string.Format((IFormatProvider)CultureInfo.InvariantCulture, "wait {0}", (object)num2));
                    ConfigConverter.ComboEventType result2;
                    if (jtoken[(object)"EventType"] != null && EnumHelper.TryParse <ConfigConverter.ComboEventType>(jtoken[(object)"EventType"].ToString(), out result2))
                    {
                        switch (result2)
                        {
                        case ConfigConverter.ComboEventType.MouseDown:
                            jarray1.Add((JToken)string.Format((IFormatProvider)CultureInfo.InvariantCulture, "mouseDown {0} {1}", (object)jtoken[(object)"X"].ToString(), (object)jtoken[(object)"Y"].ToString()));
                            break;

                        case ConfigConverter.ComboEventType.MouseUp:
                            jarray1.Add((JToken)string.Format((IFormatProvider)CultureInfo.InvariantCulture, "mouseUp {0} {1}", (object)jtoken[(object)"X"].ToString(), (object)jtoken[(object)"Y"].ToString()));
                            break;

                        case ConfigConverter.ComboEventType.MouseMove:
                            jarray1.Add((JToken)string.Format((IFormatProvider)CultureInfo.InvariantCulture, "mouseMove {0} {1}", (object)jtoken[(object)"X"].ToString(), (object)jtoken[(object)"Y"].ToString()));
                            break;

                        case ConfigConverter.ComboEventType.MouseWheel:
                            jarray1.Add((JToken)string.Format((IFormatProvider)CultureInfo.InvariantCulture, "mouseWheel {0} {1} {2}", (object)jtoken[(object)"X"].ToString(), (object)jtoken[(object)"Y"].ToString(), (object)jtoken[(object)"Delta"].ToString()));
                            break;

                        case ConfigConverter.ComboEventType.KeyDown:
                            jarray1.Add((JToken)string.Format((IFormatProvider)CultureInfo.InvariantCulture, "keyDown {0}", (object)jtoken[(object)"KeyName"].ToString()));
                            break;

                        case ConfigConverter.ComboEventType.KeyUp:
                            jarray1.Add((JToken)string.Format((IFormatProvider)CultureInfo.InvariantCulture, "keyUp {0}", (object)jtoken[(object)"KeyName"].ToString()));
                            break;

                        case ConfigConverter.ComboEventType.IME:
                            string[] strArray = jtoken[(object)"Msg"].ToString().Split(' ');
                            string   a        = strArray[1].Split('=')[1];
                            if (!string.Equals(a, "0", StringComparison.OrdinalIgnoreCase))
                            {
                                jarray1.Add((JToken)string.Format((IFormatProvider)CultureInfo.InvariantCulture, "text backspace {0}", (object)a));
                            }
                            if (!string.IsNullOrEmpty(strArray[0].Split('_')[1]))
                            {
                                jarray1.Add((JToken)string.Format((IFormatProvider)CultureInfo.InvariantCulture, "text {0}", (object)strArray[0].Split('_')[1]));
                                break;
                            }
                            break;
                        }
                    }
                }
                num1 = result1;
            }
            primitive.Add("Commands", (JToken)jarray1);
            primitive["Events"].Parent.Remove();
        }
        public static JObject Convert(
            JObject oldConfigJson,
            string newVersion,
            bool isBuiltIn,
            bool useCustomName)
        {
            if (useCustomName)
            {
                ConfigConverter.DEFAULT_PROFILE_NAME = "Custom";
            }
            List <string> source1 = new List <string>();

            if (oldConfigJson?["Primitives"] is JArray jarray)
            {
                foreach (JToken jtoken1 in jarray)
                {
                    if (jtoken1[(object)"Tags"] is JArray jarray)
                    {
                        foreach (JToken jtoken2 in jarray)
                        {
                            source1.Add(jtoken2.ToString());
                        }
                    }
                }
            }
            List <string> list    = source1.Distinct <string>().ToList <string>();
            string        empty   = string.Empty;
            JArray        source2 = new JArray();

            if (!list.Any <string>())
            {
                source2.Add((JToken) new JObject()
                {
                    {
                        "Name",
                        (JToken)ConfigConverter.DEFAULT_PROFILE_NAME
                    },
                    {
                        "BuiltIn",
                        (JToken)isBuiltIn
                    },
                    {
                        "Selected",
                        (JToken)true
                    },
                    {
                        "IsBookMarked",
                        (JToken)false
                    },
                    {
                        "KeyboardLayout",
                        oldConfigJson["MetaData"][(object)"KeyboardLayout"]
                    },
                    {
                        "GameControls",
                        (JToken) new JArray()
                    },
                    {
                        "Images",
                        (JToken) new JArray()
                    }
                });
            }
            else
            {
                if (oldConfigJson["Schemes"] != null && oldConfigJson["Schemes"] is JArray source3 && source3.Any <JToken>())
                {
                    JToken jtoken = oldConfigJson["Schemes"].Where <JToken>((Func <JToken, bool>)(scheme => bool.Parse(scheme[(object)"Selected"].ToString()))).FirstOrDefault <JToken>();
                    if (jtoken != null && jtoken[(object)"Tag"] != null)
                    {
                        empty = jtoken[(object)"Tag"].ToString();
                    }
                }
                foreach (string str in list)
                {
                    source2.Add((JToken) new JObject()
                    {
                        {
                            "Name",
                            (JToken)str.ToString((IFormatProvider)CultureInfo.InvariantCulture)
                        },
                        {
                            "BuiltIn",
                            (JToken)isBuiltIn
                        },
                        {
                            "Selected",
                            (JToken)string.Equals(empty, str.ToString((IFormatProvider)CultureInfo.InvariantCulture), StringComparison.OrdinalIgnoreCase)
                        },
                        {
                            "IsBookMarked",
                            (JToken)false
                        },
                        {
                            "KeyboardLayout",
                            oldConfigJson["MetaData"][(object)"KeyboardLayout"]
                        },
                        {
                            "GameControls",
                            (JToken) new JArray()
                        },
                        {
                            "Images",
                            (JToken) new JArray()
                        }
                    });
                }
                if (string.IsNullOrEmpty(empty))
                {
                    source2[0][(object)"Selected"] = (JToken)true;
                }
            }
            foreach (JToken jtoken in (IEnumerable <JToken>)oldConfigJson["Primitives"])
            {
                if (jtoken.DeepClone() is JObject primitive)
                {
                    List <string> tags = new List <string>();
                    if (primitive["Tags"] != null)
                    {
                        primitive["Tags"].ToList <JToken>().ForEach((System.Action <JToken>)(x => tags.Add(x.ToString())));
                        primitive["Tags"].Parent.Remove();
                    }
                    ConfigConverter.ConvertComboSequences(primitive);
                    ConfigConverter.UpdateTiltAndStatePrimitives(primitive);
                    if (!tags.Any <string>())
                    {
                        ConfigConverter.AddPrimitiveToGameControls((IEnumerable <JToken>)source2, (JToken)primitive);
                    }
                    else
                    {
                        ConfigConverter.AddPrimitiveToGameControls(source2.ToList <JToken>().Where <JToken>((Func <JToken, bool>)(scheme => tags.Contains(scheme[(object)"Name"].ToString()))), (JToken)primitive);
                    }
                }
            }
            if (!string.IsNullOrEmpty(empty) && !list.Contains(empty))
            {
                source2.Add((JToken) new JObject()
                {
                    {
                        "Name",
                        (JToken)empty
                    },
                    {
                        "BuiltIn",
                        (JToken)isBuiltIn
                    },
                    {
                        "Selected",
                        (JToken)true
                    },
                    {
                        "IsBookMarked",
                        (JToken)false
                    },
                    {
                        "KeyboardLayout",
                        oldConfigJson["MetaData"][(object)"KeyboardLayout"]
                    },
                    {
                        "GameControls",
                        (JToken) new JArray()
                    },
                    {
                        "Images",
                        (JToken) new JArray()
                    }
                });
            }
            return(new JObject()
            {
                {
                    "MetaData",
                    (JToken)ConfigConverter.GetMetadata(oldConfigJson["MetaData"], newVersion)
                },
                {
                    "ControlSchemes",
                    (JToken)source2
                },
                {
                    "Strings",
                    oldConfigJson["Strings"].DeepClone()
                }
            });
        }