Exemple #1
0
        public string GetEventWrites()
        {
            StringBuilder eventBuilder = new StringBuilder();

            foreach (Location location in Locations)
            {
                location.WriteLocationEvent(eventBuilder);
            }

            foreach (EventDefine define in LogicParser.GetEventDefines())
            {
                define.WriteDefineString(eventBuilder);
            }

            byte[] seedValues = new byte[4];
            seedValues[0] = (byte)((Seed >> 00) & 0xFF);
            seedValues[1] = (byte)((Seed >> 08) & 0xFF);
            seedValues[2] = (byte)((Seed >> 16) & 0xFF);
            seedValues[3] = (byte)((Seed >> 24) & 0xFF);

            eventBuilder.AppendLine("#define seedHashed 0x" + StringUtil.AsStringHex8((int)PatchUtil.Crc32(seedValues, 4)));
            eventBuilder.AppendLine("#define settingHash 0x" + StringUtil.AsStringHex8((int)GetSettingHash()));

            return(eventBuilder.ToString());
        }
Exemple #2
0
        public void SaveFile(SaveFile save, int fileNumber)
        {
            uint checksum = CalculateChecksum(fileNumber);

            writer.WriteBytes(save.data, 0x80 + (fileNumber * 0x500));

            uint newchecksum = CalculateChecksum(fileNumber);

            Console.WriteLine("old checksum {0}", StringUtil.AsStringHex8((int)checksum));
            Console.WriteLine("new checksum {0}", StringUtil.AsStringHex8((int)newchecksum));

            writer.WriteUInt16((ushort)((newchecksum & 0xFFFF0000) >> 16), 0x30 + (fileNumber * 0x10));
            writer.WriteUInt16((ushort)(newchecksum & 0xFFFF));

            writer.Flush();

            byte[] dataToWrite = new byte[saveData.Length];

            Array.Copy(saveData, dataToWrite, saveData.Length);


            // Flip data back for output write, but don't touch current data
            for (int block = 0; block < dataToWrite.Length;)
            {
                Array.Reverse(dataToWrite, block, 8);
                block += 8;
            }

            if (dataToWrite == saveData)
            {
                Console.WriteLine("Same!");
            }

            File.WriteAllBytes(path, dataToWrite);
        }
Exemple #3
0
        public List <Location> ParseLocations(string[] lines, Random rng)
        {
            List <Location> outList = new List <Location>();

            foreach (string locationLine in lines)
            {
                // Spaces are ignored, and everything after a # is a comment
                string locationString = locationLine.Split('#')[0].Trim();

                // Empty lines or locations are ignored
                if (string.IsNullOrWhiteSpace(locationString))
                {
                    continue;
                }

                if (!SubParser.ShouldIgnoreLines())
                {
                    // Replace defines between `
                    // Probably a more efficient way to do it, but eh
                    if (locationString.IndexOf("`") != -1)
                    {
                        locationString = locationString.Replace("`RAND_INT`", StringUtil.AsStringHex8(rng.Next()));

                        locationString = SubParser.ReplaceDefines(locationString);
                    }

                    if (locationString[0] == '!')
                    {
                        // Parse the string as a directive, ignoring preparsed directives
                        if (!SubParser.ParseOnLoad(locationString))
                        {
                            SubParser.ParseDirective(locationString);
                        }
                    }
                    else
                    {
                        // Remove spaces as they're ignored in locations
                        locationString = locationString.Replace(" ", "");

                        Location newLocation = GetLocation(locationString);
                        outList.Add(newLocation);
                    }
                }
                else
                {
                    // Only parse directives to check for conditionals
                    if (locationString[0] == '!')
                    {
                        SubParser.ParseDirective(locationString);
                    }
                }
            }

            return(outList);
        }
Exemple #4
0
        private void LoadRom()
        {
            OpenFileDialog ofd = new OpenFileDialog
            {
                Filter = "GBA ROMs|*.gba|All Files|*.*",
                Title  = "Select TMC ROM"
            };

            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            try
            {
                ROM_ = new ROM(ofd.FileName);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            if (ROM.Instance.version.Equals(RegionVersion.None))
            {
                MessageBox.Show("Invalid TMC ROM. Please Open a valid ROM.", "Incorrect ROM", MessageBoxButtons.OK);
                statusText.Text = "Unable to determine ROM.";
                ROM_            = null;
                return;
            }

            if (!shuffler.RomCrcValid(ROM_))
            {
                Console.WriteLine(StringUtil.AsStringHex8((int)PatchUtil.Crc32(ROM_.romData, ROM_.romData.Length)));
                MessageBox.Show("ROM does not match the expected CRC for the logic file", "Incorrect ROM", MessageBoxButtons.OK);
                statusText.Text = "ROM not valid";
                ROM_            = null;
                return;
            }
        }
Exemple #5
0
        private void Randomize_Click(object sender, EventArgs e)
        {
            if (ROM_ == null)
            {
                LoadRom();

                if (ROM_ == null)
                {
                    return;
                }
            }


            if (shuffler == null)
            {
                return;
            }

            try
            {
                // If the seed is valid, load locations from the logic and randomize their contents
                if (int.TryParse(seedField.Text, out int seed))
                {
                    // Make sure the RNG is set to the seed, so the seed can be regenerated
                    shuffler.SetSeed(seed);

                    if (customLogicCheckBox.Checked)
                    {
                        shuffler.LoadLocations(customLogicPath.Text);
                    }
                    else
                    {
                        shuffler.LoadLocations();
                    }


                    shuffler.RandomizeLocations();
                }
                else
                {
                    MessageBox.Show("The seed value is not valid!\nMake sure it's not too large and only contains numeric characters.");
                    return;
                }

                // Mark that a seed has been generated so seed-specific options can be used
                Randomized = true;

                if (!mainTabs.TabPages.Contains(generatedTab))
                {
                    // Change the tab to the seed output tab
                    mainTabs.TabPages.Add(generatedTab);
                }

                mainTabs.SelectedTab = generatedTab;

                // Show ROM information on seed page
                generatedSeedValue.Text  = seed.ToString();
                generatedLogicLabel.Text = shuffler.GetLogicIdentifier();

                settingHashValue.Text = StringUtil.AsStringHex8((int)shuffler.GetSettingHash());
                gimmickHashValue.Text = StringUtil.AsStringHex8((int)shuffler.GetGimmickHash());

                statusText.Text = $"Successfully randomzied seed {seed}";
            }
            catch (ShuffleException error)
            {
                MessageBox.Show(error.Message);
                statusText.Text = $"Error randomizing seed: {error.Message}";
            }
        }
Exemple #6
0
 public string GetOptionsIdentifier()
 {
     return(StringUtil.AsStringHex8((int)GetSettingHash()) + "-" + StringUtil.AsStringHex8((int)GetGimmickHash()));
 }