Esempio n. 1
0
        private void ot_importImage_Click(object sender, EventArgs e)
        {
            if (ot_info_RomAddress.Text.Contains("N/A") || ot_info_RomAddress.Text.Contains("null"))
            {
                MessageBox.Show("Importing over compressed MIO0 data is not currently supported in this version. You will need to use an extended ROM file.",
                                "Notice",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation,
                                MessageBoxDefaultButton.Button1);
                return;
            }
            string filename = LoadImage();

            if (filename != null)
            {
                Bitmap newImg =
                    new Bitmap(Image.FromFile(filename), new Size(ot_bitmap_preview.BackgroundImage.Width, ot_bitmap_preview.BackgroundImage.Height));
                byte format =
                    TextureFormats.ConvertStringToFormat(ot_info_Format.Text.Substring(ot_info_Format.Text.LastIndexOf(" ") + 1));
                byte[] data =
                    TextureFormats.encodeTexture(format, newImg);

                if (data != null)
                {
                    uint rom_offset =
                        uint.Parse(ot_info_RomAddress.Text.Substring(ot_info_RomAddress.Text.LastIndexOf(" ") + 1), System.Globalization.NumberStyles.HexNumber);
                    uint seg_offset =
                        uint.Parse(ot_info_SegAddress.Text.Substring(ot_info_SegAddress.Text.LastIndexOf(" ") + 1), System.Globalization.NumberStyles.HexNumber);
                    ROM.Instance.writeByteArray(rom_offset, data);
                    ROM.Instance.writeByteArrayToSegment(seg_offset, data);
                    Bitmap newImage = TextureFormats.decodeTexture(
                        format,
                        data,
                        ot_bitmap_preview.BackgroundImage.Width,
                        ot_bitmap_preview.BackgroundImage.Height,
                        null,
                        false
                        );
                    ot_bitmap_preview.BackgroundImage = newImage;
                    ReplaceButtonImage(ref ot_buttons[ot_list_index], newImage);
                    needToUpdateLevel = true;
                }
            }
        }
Esempio n. 2
0
        private List <RadioButtonWithInfo> parseOtherListJSON(JArray array, out string blockName)
        {
            ROM rom = ROM.Instance;

            blockName = "Unknown";
            List <RadioButtonWithInfo> list   = new List <RadioButtonWithInfo>();
            uint segmentAddressForLoadingData = 0;

            byte[][] tempSegments        = new byte[0x20][];
            uint[]   tempSegmentStarts   = new uint[0x20];
            bool[]   tempSegmentsAreMIO0 = new bool[0x20];

            foreach (JObject obj in array.Children())
            {
                if (obj["Block Name"] != null)
                {
                    blockName = obj["Block Name"].ToString();
                    segmentAddressForLoadingData = 0; // Reset for every new block
                }
                else if (obj["UseSegmentAddressesFromLevelScriptStartingFrom"] != null)
                {
                    segmentAddressForLoadingData = uint.Parse(obj["UseSegmentAddressesFromLevelScriptStartingFrom"].ToString(), NumberStyles.HexNumber);
                    for (int i = 0; i < 0x20; i++)
                    {
                        tempSegments[i]        = new byte[0]; // reset segments
                        tempSegmentsAreMIO0[i] = false;
                        tempSegmentStarts[i]   = 0;
                    }
                    tempSegments[0x00]        = rom.Bytes;
                    tempSegments[0x15]        = rom.cloneSegment(0x15, (byte)level.CurrentAreaID);
                    tempSegmentStarts[0x15]   = Globals.seg15_location[0];
                    tempSegments[0x02]        = rom.cloneSegment(0x02, (byte)level.CurrentAreaID);
                    tempSegmentStarts[0x02]   = Globals.seg02_location[0];
                    tempSegmentsAreMIO0[0x02] = !rom.Seg02_isFakeMIO0;
                    //Console.WriteLine("SegOff:0x{0}", segmentAddressForLoadingData.ToString("X8"));
                    parseLevelScriptTemporarlyForSegments(tempSegments, tempSegmentStarts, tempSegmentsAreMIO0, (byte)(segmentAddressForLoadingData >> 24), segmentAddressForLoadingData & 0xFFFFFF);
                }
                else
                {
                    if (checkForValidEntry(obj))
                    {
                        int    width    = int.Parse(obj["Width"].ToString());
                        int    height   = int.Parse(obj["Height"].ToString());
                        byte   format   = TextureFormats.ConvertStringToFormat(obj["Format"].ToString());
                        uint   dataSize = (uint)((TextureFormats.getNumberOfBitsForFormat(format) * width * height) / 8);
                        byte[] data;
                        if (obj["FromSegmentAddress"] != null)
                        {
                            uint segOffset = uint.Parse(obj["FromSegmentAddress"].ToString(), NumberStyles.HexNumber);
                            if (segmentAddressForLoadingData == 0)
                            {
                                data = rom.getDataFromSegmentAddress_safe(segOffset, dataSize, (byte)level.CurrentAreaID);
                            }
                            else
                            {
                                byte segment     = (byte)(segOffset >> 24);
                                uint segment_off = segOffset & 0x00FFFFFF;
                                data = rom.getSubArray_safe(tempSegments[segment], segment_off, dataSize);
                            }
                        }
                        else
                        {
                            if (rom.Type == ROM_Type.VANILLA && obj["ForExtendedROM"] != null)
                            {
                                string forExtendedROM = obj["ForExtendedROM"].ToString().ToLower();
                                if (forExtendedROM.Equals("true"))
                                {
                                    continue;
                                }
                            }
                            uint romOff = uint.Parse(obj["FromROMAddress"].ToString(), NumberStyles.HexNumber);
                            data = rom.getSubArray_safe(rom.Bytes, romOff, dataSize);
                        }
                        Bitmap   image = TextureFormats.decodeTexture(format, data, width, height, null, true);
                        string[] tags  = (string[])image.Tag;
                        Array.Resize(ref tags, tags.Length + 3);
                        uint segOff = 0;
                        if (obj["FromSegmentAddress"] != null)
                        {
                            segOff = uint.Parse(obj["FromSegmentAddress"].ToString(), NumberStyles.HexNumber);


                            if (segmentAddressForLoadingData == 0)
                            {
                                if (!rom.isSegmentMIO0((byte)(segOff >> 24), (byte)level.CurrentAreaID))
                                {
                                    tags[tags.Length - 3] = "ROM Address: " + rom.decodeSegmentAddress(segOff, (byte)level.CurrentAreaID).ToString("X");
                                }
                                else
                                {
                                    tags[tags.Length - 3] = "ROM Address: N/A";
                                }
                            }
                            else
                            {
                                byte seg_temp        = (byte)(segOff >> 24);
                                uint seg_temp_offset = segOff & 0x00FFFFFF;
                                if (tempSegmentsAreMIO0[seg_temp])
                                {
                                    tags[tags.Length - 3] = "ROM Address: N/A";
                                }
                                else
                                {
                                    tags[tags.Length - 3] = "ROM Address: " + (tempSegmentStarts[seg_temp] + seg_temp_offset).ToString("X");
                                }
                            }

                            tags[tags.Length - 2] = "Seg Addr: " + obj["FromSegmentAddress"];
                        }
                        else
                        {
                            tags[tags.Length - 3] = "ROM Address: " + obj["FromROMAddress"];
                            tags[tags.Length - 2] = "Seg Addr: N/A";
                        }
                        tags[tags.Length - 1] = "Name: " + obj["Name"];
                        image.Tag             = tags;

                        AddNewImage(ref list, image, segOff, ot_RadioButtonWithInfo_Click);

                        //Console.WriteLine("Added Other Image: " + obj["Name"]);
                    }
                    //Bitmap image = TextureFormats.decodeTexture();
                    //AddNewImage(ref list, level.ModelIDs[modelID].builder.TextureImages[i], address, ot_RadioButtonWithInfo_Click);
                }
                //Console.WriteLine(obj.ToString());
            }
            return(list);
        }
Esempio n. 3
0
        private void lt_importImage_Click(object sender, EventArgs e)
        {
            if (info_Format.Text.EndsWith("CI4") || info_Format.Text.EndsWith("CI8"))
            {
                MessageBox.Show("CI texture importing is not currently supported in this version.",
                                "Notice",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation,
                                MessageBoxDefaultButton.Button1);
                return;
            }
            if (info_Address.Text.Contains("N/A") || info_Address.Text.Contains("null"))
            {
                MessageBox.Show("Importing over compressed MIO0 data is not currently supported in this version. You will need to use an extended ROM file.",
                                "Notice",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation,
                                MessageBoxDefaultButton.Button1);
                return;
            }

            string filename = LoadImage();

            if (filename != null)
            {
                Bitmap newImg = new Bitmap(Image.FromFile(filename), new Size(info_bitmapImage.BackgroundImage.Width, info_bitmapImage.BackgroundImage.Height));
                byte   format = TextureFormats.ConvertStringToFormat(info_Format.Text.Substring(info_Format.Text.LastIndexOf(" ") + 1));
                byte[] data   = TextureFormats.encodeTexture(format, newImg);

                if (data != null)
                {
                    uint rom_offset = uint.Parse(info_Address.Text.Substring(info_Address.Text.LastIndexOf(" ") + 1), System.Globalization.NumberStyles.HexNumber);
                    uint seg_offset = uint.Parse(info_SegmentAddress.Text.Substring(info_SegmentAddress.Text.LastIndexOf(" ") + 1), System.Globalization.NumberStyles.HexNumber);
                    ROM.Instance.writeByteArray(rom_offset, data);
                    ROM.Instance.writeByteArrayToSegment(seg_offset, data);
                    Bitmap newImage = TextureFormats.decodeTexture(
                        format,
                        data,
                        info_bitmapImage.BackgroundImage.Width,
                        info_bitmapImage.BackgroundImage.Height,
                        null,
                        false
                        );
                    info_bitmapImage.BackgroundImage = newImage;

                    switch (lt_list_index)
                    {
                    case 0:
                        if (!ReplaceButtonImage(ref lt_levelButtons, newImage))
                        {
                            ReplaceButtonImage(ref lt_modelButtons, newImage);
                        }
                        break;

                    case 1:
                        ReplaceButtonImage(ref lt_levelButtons, newImage);
                        break;

                    case 2:
                        ReplaceButtonImage(ref lt_modelButtons, newImage);
                        break;

                    case 3:
                        ReplaceButtonImage(ref lt_objectButtons, newImage);
                        break;
                    }
                    needToUpdateLevel = true;
                }
            }
        }