Battle_Script_Pro.Form1.HashOrgAddCommand C# (CSharp) Method

HashOrgAddCommand() private method

private HashOrgAddCommand ( List compiledHashOrg, int>.Dictionary compiledHashOrgLocations, Command c, bool compile, string info, int>.Dictionary lengths, int lineNumber, bool &newCompile ) : void
compiledHashOrg List
compiledHashOrgLocations int>.Dictionary
c Command
compile bool
info string
lengths int>.Dictionary
lineNumber int
newCompile bool
return void
        private void HashOrgAddCommand(List<byte> compiledHashOrg, Dictionary<string, int> compiledHashOrgLocations, Command c, bool compile, string[] info, Dictionary<string, int> lengths, int lineNumber, out bool newCompile)
        {
            newCompile = compile;
            if (c.HexID < 0x100)
            {
                compiledHashOrg.Add(Convert.ToByte(c.HexID));
            }
            else
            {
                compiledHashOrg.Add(Byte.Parse(ToDecimal(c.HexID.ToString("X4").Substring(0, 2))));
                compiledHashOrg.Add(Byte.Parse(ToDecimal(c.HexID.ToString("X4").Substring(2, 2))));
            }
            SQLiteConnection con = new SQLiteConnection("Data Source=" + System.Windows.Forms.Application.StartupPath + @"\Data\Commands.sqlite;Version=3;");
            con.Open();
            SQLiteCommand com = new SQLiteCommand("select * from endingcommands where id = " + c.HexID, con);
            SQLiteDataReader reader = com.ExecuteReader();
            if (reader.HasRows)
            {
                newCompile = false;
            }
            for (int i = 0; i < c.NumberOfParameters; i++)
            {
                if (c.HexID == 0x89 && i == 0)
                {
                    byte paramTwo;
                    if (info[2].ToUpper().Equals("TRUE"))
                    {
                        paramTwo = 0x40;
                    }
                    else if (info[2].ToUpper().Equals("FALSE"))
                    {
                        paramTwo = 0;
                    }
                    else
                    {
                        paramTwo = ParseByteParameter(info[2], lineNumber, 2).Byte;
                        if (paramTwo != 0x40)
                        {
                            paramTwo = 0;
                        }
                    }
                    byte byteOne = (byte)((int)ParseByteParameter(info[1], lineNumber, 1).Byte | (int)paramTwo);
                    compiledHashOrg.Add(byteOne);
                    i++;
                }
                else
                {
                    switch (c.ParameterLengths[i])
                    {
                        case 2:
                            {
                                ushort value = ParseHalfWordParameter(info[i + 1], 0, i).HalfWord;
                                for (int j = 0; j < 2; j++)
                                {
                                    compiledHashOrg.Add(Byte.Parse(ToDecimal("0x" + value.ToString("X4").Substring(value.ToString("X4").Length - ((j * 2) + 2), 2))));
                                }
                                break;
                            }
                        case 4:
                            {
                                if (info[i + 1].StartsWith("@"))
                                {
                                    int location3 = freeSpaceLocation;
                                    if (compiledHashOrgLocations.ContainsKey(info[i + 1]))
                                    {
                                        location3 = compiledHashOrgLocations[info[i + 1]];
                                    }
                                    else
                                    {
                                        foreach (string s in lengths.Keys)
                                        {
                                            if (!compiledHashOrgLocations.ContainsKey(s))
                                            {
                                                location3 = FindFreeSpace(lengths[s], location3, File.ReadAllBytes(selectedROMPath));
                                            }
                                            if (s.Equals(info[i + 1]))
                                            {
                                                break;
                                            }
                                            if (s.StartsWith("@"))
                                            {
                                                location3 += lengths[s];
                                            }
                                        }
                                    }
                                    location3 += 0x08000000;
                                    for (int j = 0; j < 4; j++)
                                    {
                                        compiledHashOrg.Add(Byte.Parse(ToDecimal("0x" + location3.ToString("X8").Substring(8 - ((j * 2) + 2), 2))));
                                    }
                                }
                                else
                                {
                                    uint value = ParseWordParameter(info[i + 1], 0, i, true).Word;
                                    for (int j = 0; j < 4; j++)
                                    {
                                        if (j == 3 && c.ParameterNames[i].ToUpper().Contains("ADDRESS") && (value.ToString("X8").Substring(8 - ((j * 2) + 2), 2).Equals("00") || value.ToString("X8").Substring(8 - ((j * 2) + 2), 2).Equals("01")))
                                        {
                                            compiledHashOrg.Add(Convert.ToByte(8 + Int32.Parse(value.ToString("X8").Substring(8 - ((j * 2) + 2), 2))));
                                        }
                                        else
                                        {
                                            compiledHashOrg.Add(Byte.Parse(ToDecimal("0x" + value.ToString("X8").Substring(8 - ((j * 2) + 2), 2))));
                                        }
                                    }
                                }
                                if (c.ParameterNames[i].Contains("Address"))
                                {
                                    if (c.HexID == 0x28)
                                    {
                                        newCompile = false;
                                    }
                                }
                                break;
                            }
                        default:
                            {
                                compiledHashOrg.Add(ParseByteParameter(info[i + 1], 0, i).Byte);
                                break;
                            }
                    }
                }
            }
        }
Form1