Example #1
0
        public void ProcessLines(string[] lines)
        {
            Tool.GetKey(true, true);
            int i = 0;

            try
            {
                for (i = 0; i < lines.Length; i++)
                {
                    ProcessLine(lines[i]);
                }
                ApplySchedule();
            }
            catch (Exception e)
            {
                StringBuilder sb = new StringBuilder(150);
                sb.Append("Error! ");
                if (i < lines.Length)
                {
                    sb.Append(string.Format("line #{0}:\t'{1}'", i, lines[i]));
                }
                sb.Append(e.Message);
                sb.Append("\n");
                sb.Append(e.StackTrace);
                sb.Append("\n\nOperation aborted at this point. Data not applied.");
                StringInputDlg.ShowError(sb.ToString());
            }
        }
Example #2
0
        private void replaceStringToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string searchStr  = StringInputDlg.GetString("Enter Search String", "");
            string replaceStr = StringInputDlg.GetString("Enter String to replace it with", "");

            if (replaceStr.Length > searchStr.Length)
            {
                MessageBox.Show("Error, cannot replace a string with a longer string");
                return;
            }
            while (replaceStr.Length < searchStr.Length)
            {
                replaceStr = replaceStr + " ";
            }

            List <long> locs = StaticUtils.FindStringInFile(searchStr, SaveFile, 0, SaveFile.Length);

            for (int i = 0; i < locs.Count; i++)
            {
                int stringLoc = (int)locs[i];
                for (int j = 0; j < replaceStr.Length; j++)
                {
                    Tool.SetByte(stringLoc, (byte)replaceStr[j]);
                    Tool.SetByte(stringLoc + 1, 0);
                    stringLoc += 2;
                }
            }
        }
Example #3
0
 public static string GetString(string title, string message, string initialText)
 {
     StringInputDlg sid = new StringInputDlg(title, message, initialText);
     sid.ShowDialog();
     string ret = sid.getResult();
     sid.Dispose();
     return ret;
 }
Example #4
0
        public static string GetString(string title, string message, string initialText)
        {
            StringInputDlg sid = new StringInputDlg(title, message, initialText);

            sid.ShowDialog();
            string ret = sid.getResult();

            sid.Dispose();
            return(ret);
        }
Example #5
0
        private void getCoachItem_Click(object sender, EventArgs e)
        {
            string number = StringInputDlg.GetString("Enter Coach number", "(0-31", "0");

            try
            {
                int num = Int32.Parse(number);
                if (num > -1 && num < 32)
                {
                    Tool.CoachKey        = Tool.CoachKeyAll;
                    mResultsTextBox.Text = String.Format("#coach:{0}\n{1}\n{2}", num, Tool.CoachKeyAll, Tool.GetCoachData(num));
                }
            }
            catch {
            }
        }
Example #6
0
        private void autoUpdateYearsProToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string        baseYear    = StringInputDlg.GetString("Base year:", "Enter the year for the season", "2004");
            string        teamsString = StringInputDlg.GetString("Teams:", "Enter the teams you wish to update (seperated by comma), blank for all teams", "");
            List <string> teams       = new List <string>(teamsString.Split(new char[] { ',' }));

            if (teamsString == "" || teams.Count < 1)
            {
                teams = new List <string>(GamesaveTool.Teams);
                teams.Add("FreeAgents");
                teams.Add("DraftClass");
            }

            if (!String.IsNullOrEmpty(baseYear))
            {
                int year = 0;
                Int32.TryParse(baseYear, out year);
                Tool.AutoUpdateYearsProFromYear(year, teams.ToArray());
            }
        }
Example #7
0
        /// <summary>
        /// Prompts the user for a string to search for
        /// </summary>
        /// <returns>true if the search string was set</returns>
        public bool SetSearchString()
        {
            bool ret = false;

            if (this.SelectionLength > 0)
            {
                SearchString = this.Text.Substring(this.SelectionStart, this.SelectionLength);
            }
            string result = StringInputDlg.GetString(
                "Enter Search String",
                "Please enter text (or a regex) to search for.",
                SearchString);

            if (!result.Equals(""))
            {
                SearchString = result;
                ret          = true;
            }
            return(ret);
        }
Example #8
0
        private void getCoachBytesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string number = StringInputDlg.GetString("Enter Coach number", "(0-31", "0");

            try
            {
                int num = Int32.Parse(number);
                if (num > 31)
                {
                    StringBuilder sb = new StringBuilder(5000);
                    for (int t = 0; t < 32; t++)
                    {
                        byte[] data = Tool.GetCoachBytes(t);
                        sb.Append(String.Format("Coach {0:d2}:", t));
                        sb.Append("0x");
                        for (int i = 0; i < data.Length; i++)
                        {
                            sb.Append(String.Format("{0:x2}", data[i]));
                        }
                        sb.Append("\n");
                    }
                    mResultsTextBox.Text = sb.ToString();
                }
                else if (num > -1 && num < 32)
                {
                    byte[]        data = Tool.GetCoachBytes(num);
                    StringBuilder sb   = new StringBuilder(data.Length * 2 + 4);
                    sb.Append("0x");
                    for (int i = 0; i < data.Length; i++)
                    {
                        sb.Append(String.Format("{0:x2}", data[i]));
                    }
                    mResultsTextBox.Text = num + ": Coach Bytes\n" + sb.ToString();
                }
            }
            catch
            {
            }
        }
Example #9
0
        private void ApplySet(string line)
        {
            if (simpleSetRegex == null)
            {
                simpleSetRegex = new Regex("SET\\s*\\(\\s*(0x[0-9a-fA-F]+)\\s*,\\s*(0x[0-9a-fA-F]+)\\s*\\)");
            }

            if (simpleSetRegex.Match(line) != Match.Empty)
            {
                ApplySimpleSet(line);
            }
            else if (line.IndexOf("PromptUser", StringComparison.OrdinalIgnoreCase) > -1)
            {
                string simpleSetLine = StringInputDlg.PromptForSetUserInput(line);
                if (!string.IsNullOrEmpty(simpleSetLine))
                {
                    ApplySet(simpleSetLine);
                }
            }
            else
            {
                StaticUtils.AddError(string.Format("ERROR with line \"{0}\"", line));
            }
        }
Example #10
0
        /// <summary>
        /// Prompt the user for input for a 'set' command
        /// </summary>
        /// <param name="input">The input string to operate on</param>
        /// <returns>empty string on cancel, 'SET' string when successful.</returns>
        public static string PromptForSetUserInput(string input)
        {
            string retVal = "";
            string msg = GetPromptUserMesage(input);
            string location = GetSetLocation(input);

            while (retVal == "")
            {
                StringBuilder rangeMsg = new StringBuilder(25);
                String userInputValue = "";
                int min = 0;
                int max = 0;
                //SET(0x2224B, {32TeamNES,28TeamNES PromptUser:Msg="Enter desired quarter length":int(1-15)} )
                //SET(0x2224B, {32TeamNES,28TeamNES PromptUser:Msg="Enter desired quarter length":int(0x1-0x15)} )
                //SET(0x2224B, {32TeamNES,28TeamNES PromptUser:Msg="Enter name of...":string(len=8)} ) maybe not this one.
                if (input.IndexOf("int", StringComparison.OrdinalIgnoreCase) > -1 &&
                    (GetHexRange(ref min, ref max, input, rangeMsg) || GetDecimalRange(ref min, ref max, input, rangeMsg)))
                {
                    string rangeMessage = rangeMsg.ToString();
                    NumberStyles style = rangeMessage.IndexOf('x') > 0 ? NumberStyles.HexNumber : NumberStyles.Integer;
                    string initialText = style == NumberStyles.HexNumber ? "0x" : "";
                    StringInputDlg dlg = new StringInputDlg(msg, rangeMessage, initialText);
                    int userVal = Int32.MinValue;

                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        userInputValue = dlg.getResult();
                        if (userInputValue.StartsWith("0x"))
                            userInputValue = userInputValue.Substring(2);

                        try
                        {
                            userVal = Int32.Parse(userInputValue, style);
                            if (userVal < min || userVal > max)
                            {
                                userVal = Int32.MinValue;
                                throw new Exception("Invalid input.");
                            }
                        }
                        catch (Exception )
                        {
                            ShowError(string.Format(
                                "Error with '{0}'. Value '{1}' is invalid for range {2}",
                                msg, userInputValue, rangeMessage));
                        }
                        if (userVal > Int32.MinValue)
                        {
                            retVal = string.Format("SET({0}, 0x{1:x})", location, userVal);
                        }
                    }
                    else
                    {
                        retVal = " "; // trigger us to leave the loop
                    }
                    dlg.Dispose();
                }
                else
                {
                    ShowError("ERROR applying line: " + input);
                    retVal = null;
                }
            }
            return retVal;
        }
Example #11
0
        /// <summary>
        /// Prompt the user for input for a 'set' command
        /// </summary>
        /// <param name="input">The input string to operate on</param>
        /// <returns>empty string on cancel, 'SET' string when successful.</returns>
        public static string PromptForSetUserInput(string input)
        {
            string retVal   = "";
            string msg      = GetPromptUserMesage(input);
            string location = GetSetLocation(input);

            while (retVal == "")
            {
                StringBuilder rangeMsg       = new StringBuilder(25);
                String        userInputValue = "";
                int           min            = 0;
                int           max            = 0;
                //SET(0x2224B, {32TeamNES,28TeamNES PromptUser:Msg="Enter desired quarter length":int(1-15)} )
                //SET(0x2224B, {32TeamNES,28TeamNES PromptUser:Msg="Enter desired quarter length":int(0x1-0x15)} )
                //SET(0x2224B, {32TeamNES,28TeamNES PromptUser:Msg="Enter name of...":string(len=8)} ) maybe not this one.
                if (input.IndexOf("int", StringComparison.OrdinalIgnoreCase) > -1 &&
                    (GetHexRange(ref min, ref max, input, rangeMsg) || GetDecimalRange(ref min, ref max, input, rangeMsg)))
                {
                    string         rangeMessage = rangeMsg.ToString();
                    NumberStyles   style        = rangeMessage.IndexOf('x') > 0 ? NumberStyles.HexNumber : NumberStyles.Integer;
                    string         initialText  = style == NumberStyles.HexNumber ? "0x" : "";
                    StringInputDlg dlg          = new StringInputDlg(msg, rangeMessage, initialText);
                    int            userVal      = Int32.MinValue;

                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        userInputValue = dlg.getResult();
                        if (userInputValue.StartsWith("0x"))
                        {
                            userInputValue = userInputValue.Substring(2);
                        }

                        try
                        {
                            userVal = Int32.Parse(userInputValue, style);
                            if (userVal < min || userVal > max)
                            {
                                userVal = Int32.MinValue;
                                throw new Exception("Invalid input.");
                            }
                        }
                        catch (Exception)
                        {
                            ShowError(string.Format(
                                          "Error with '{0}'. Value '{1}' is invalid for range {2}",
                                          msg, userInputValue, rangeMessage));
                        }
                        if (userVal > Int32.MinValue)
                        {
                            retVal = string.Format("SET({0}, 0x{1:x})", location, userVal);
                        }
                    }
                    else
                    {
                        retVal = " "; // trigger us to leave the loop
                    }
                    dlg.Dispose();
                }
                else
                {
                    ShowError("ERROR applying line: " + input);
                    retVal = null;
                }
            }
            return(retVal);
        }