Ejemplo n.º 1
0
        public bool LoadFile(string path, ProcessManager processManager, ComboBox comboBox)
        {
            string[] cheats = File.ReadAllLines(path);

            if (cheats.Length < 2)
            {
                return(false);
            }

            string header = cheats[0];

            string[] header_items = header.Split('|');

            if (header_items.Length < CHEAT_CODE_HEADER_ELEMENT_COUNT)
            {
                return(false);
            }

            string[] version = (header_items[CHEAT_CODE_HEADER_VERSION]).Split('.');

            ulong major_version     = 0;
            ulong secondary_version = 0;

            ulong.TryParse(version[0], out major_version);
            if (version.Length > 1)
            {
                ulong.TryParse(version[1], out secondary_version);
            }

            if (major_version > CONSTANT.MAJOR_VERSION || secondary_version > CONSTANT.SECONDARY_VERSION)
            {
                return(false);
            }

            string process_name = header_items[CHEAT_CODE_HEADER_PROCESS_NAME];

            if (process_name != (string)comboBox.SelectedItem)
            {
                comboBox.SelectedItem = process_name;
            }

            if (process_name != (string)comboBox.SelectedItem)
            {
                MessageBox.Show("Invalid process or refresh processes first.");
                return(false);
            }

            string game_id  = "";
            string game_ver = "";

            if (header_items.Length > CHEAT_CODE_HEADER_PROCESS_ID)
            {
                game_id = header_items[CHEAT_CODE_HEADER_PROCESS_ID];
                game_id = game_id.Substring(3);
            }

            if (header_items.Length > CHEAT_CODE_HEADER_PROCESS_VER)
            {
                game_ver = header_items[CHEAT_CODE_HEADER_PROCESS_VER];
                game_ver = game_ver.Substring(4);
            }

            if (game_id != "" && game_ver != "")
            {
                GameInfo gameInfo = new GameInfo();
                if (gameInfo.GameID != game_id)
                {
                    if (MessageBox.Show("Your Game ID(" + gameInfo.GameID + ") is different with cheat file(" + game_id + "), still load?",
                                        "Invalid game ID", MessageBoxButtons.YesNo) != DialogResult.Yes)
                    {
                        return(false);
                    }
                }

                if (gameInfo.Version != game_ver)
                {
                    if (MessageBox.Show("Your game version(" + gameInfo.Version + ") is different with cheat file(" + game_ver + "), still load?",
                                        "Invalid game version", MessageBoxButtons.YesNo) != DialogResult.Yes)
                    {
                        return(false);
                    }
                }
            }

            for (int i = 1; i < cheats.Length; ++i)
            {
                string   cheat_tuple    = cheats[i];
                string[] cheat_elements = cheat_tuple.Split(new string[] { "|" }, StringSplitOptions.None);

                if (cheat_elements.Length == 0)
                {
                    continue;
                }

                if (cheat_elements[CHEAT_CODE_TYPE] == "data")
                {
                    DataCheat cheat = new DataCheat(processManager);
                    if (!cheat.Parse(cheat_elements))
                    {
                        MessageBox.Show("Invaid cheat code:" + cheat_tuple);
                        continue;
                    }

                    cheat_list.Add(cheat);
                }
                else if (cheat_elements[CHEAT_CODE_TYPE] == "simple pointer")
                {
                    SimplePointerCheat cheat = new SimplePointerCheat(processManager);
                    if (!cheat.Parse(cheat_elements))
                    {
                        continue;
                    }
                    cheat_list.Add(cheat);
                }
                else
                {
                    MessageBox.Show("Invaid cheat code:" + cheat_tuple);
                    continue;
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
        public bool LoadFile(string path, ProcessManager processManager, ComboBox comboBox, ICheatPlugin cheatPlugin)
        {
            string[] cheats = File.ReadAllLines(path);

            string process_name = "";
            string game_id      = "";
            string game_ver     = "";

            if (cheatPlugin != null)
            {
                bool ret = cheatPlugin.ParseGameInfo(cheats);
                process_name = cheatPlugin.process_name;

                game_id  = cheatPlugin.game_id;
                game_ver = cheatPlugin.game_ver;
            }
            else
            {
                if (cheats.Length < 2)
                {
                    return(false);
                }

                string   header       = cheats[0];
                string[] header_items = header.Split('|');

                if (header_items.Length < CHEAT_CODE_HEADER_ELEMENT_COUNT)
                {
                    return(false);
                }

                string[] version = (header_items[CHEAT_CODE_HEADER_VERSION]).Split('.');

                ulong major_version     = 0;
                ulong secondary_version = 0;

                ulong.TryParse(version[0], out major_version);
                if (version.Length > 1)
                {
                    ulong.TryParse(version[1], out secondary_version);
                }

                if (major_version > CONSTANT.MAJOR_VERSION || (major_version == CONSTANT.MAJOR_VERSION && secondary_version > CONSTANT.SECONDARY_VERSION))
                {
                    return(false);
                }

                process_name = header_items[CHEAT_CODE_HEADER_PROCESS_NAME];

                if (header_items.Length > CHEAT_CODE_HEADER_PROCESS_ID)
                {
                    game_id = header_items[CHEAT_CODE_HEADER_PROCESS_ID];
                    game_id = game_id.Substring(3);
                }

                if (header_items.Length > CHEAT_CODE_HEADER_PROCESS_VER)
                {
                    game_ver = header_items[CHEAT_CODE_HEADER_PROCESS_VER];
                    game_ver = game_ver.Substring(4);
                }
            }

            if (process_name != (string)comboBox.SelectedItem)
            {
                comboBox.SelectedItem = process_name;
            }

            if (process_name != (string)comboBox.SelectedItem && !IS_DEV)
            {
                MessageBox.Show("Invalid process or refresh processes first.");
                return(false);
            }

            if (game_id != "" && game_ver != "")
            {
                GameInfo gameInfo = new GameInfo();
                if (gameInfo.GameID != game_id && !IS_DEV)
                {
                    if (MessageBox.Show("Your Game ID(" + gameInfo.GameID + ") is different with cheat file(" + game_id + "), still load?",
                                        "Invalid game ID", MessageBoxButtons.YesNo) != DialogResult.Yes)
                    {
                        return(false);
                    }
                }

                if (gameInfo.Version != game_ver && !IS_DEV)
                {
                    if (MessageBox.Show("Your game version(" + gameInfo.Version + ") is different with cheat file(" + game_ver + "), still load?",
                                        "Invalid game version", MessageBoxButtons.YesNo) != DialogResult.Yes)
                    {
                        return(false);
                    }
                }
            }

            if (cheatPlugin != null)
            {
                bool ret = cheatPlugin.ParseCheats(processManager, cheats);
                return(ret);
            }

            for (int i = 1; i < cheats.Length; ++i)
            {
                string   cheat_tuple    = cheats[i];
                string[] cheat_elements = cheat_tuple.Split(new string[] { "|" }, StringSplitOptions.None);

                if (cheat_elements.Length == 0)
                {
                    continue;
                }

                Cheat cheat = null;
                switch (cheat_elements[CHEAT_CODE_TYPE])
                {
                case "data":
                    cheat = new DataCheat(processManager);
                    if (!cheat.Parse(cheat_elements))
                    {
                        MessageBox.Show("Invaid cheat code:" + cheat_tuple);
                        continue;
                    }
                    break;

                case "simple pointer":
                    cheat = new SimplePointerCheat(processManager);
                    if (!cheat.Parse(cheat_elements))
                    {
                        continue;
                    }
                    break;

                case "@batchcode":
                    cheat = new BatchCodeCheat(processManager);
                    if (!cheat.Parse(cheat_elements))
                    {
                        MessageBox.Show("Invaid @batchcode:" + cheat_tuple);
                        continue;
                    }
                    break;

                case "@cheatcode":
                    //cheat = new CheatCodeCheat(processManager);
                    //if (!cheat.Parse(cheat_elements))
                    //{
                    //    MessageBox.Show("Invaid @cheatcode:" + cheat_tuple);
                    //    continue;
                    //}
                    break;

                default:
                    MessageBox.Show("Invaid cheat code:" + cheat_tuple);
                    continue;
                }
                cheat_list.Add(cheat);

                /*if (cheat_elements[CHEAT_CODE_TYPE] == "data")
                 * {
                 *  DataCheat cheat = new DataCheat(processManager);
                 *  if (!cheat.Parse(cheat_elements))
                 *  {
                 *      MessageBox.Show("Invaid cheat code:" + cheat_tuple);
                 *      continue;
                 *  }
                 *
                 *  cheat_list.Add(cheat);
                 * }
                 * else if (cheat_elements[CHEAT_CODE_TYPE] == "simple pointer")
                 * {
                 *
                 *  SimplePointerCheat cheat = new SimplePointerCheat(processManager);
                 *  if (!cheat.Parse(cheat_elements))
                 *      continue;
                 *  cheat_list.Add(cheat);
                 * }
                 * else
                 * {
                 *  MessageBox.Show("Invaid cheat code:" + cheat_tuple);
                 *  continue;
                 * }*/
            }
            return(true);
        }