Esempio n. 1
0
        public ObjectTableEntry(ROMHandler rom, int ofs, bool isrel, ushort number = 0)
        {
            ROM              = rom;
            Offset           = ofs;
            IsOffsetRelative = isrel;

            StartAddress = Endian.SwapUInt32(BitConverter.ToUInt32(IsOffsetRelative ? rom.CodeData : rom.Data, ofs));
            EndAddress   = Endian.SwapUInt32(BitConverter.ToUInt32(IsOffsetRelative ? rom.CodeData : rom.Data, ofs + 4));

            IsValid =
                ((StartAddress > rom.Code.VStart) &&
                 (StartAddress < rom.Size) && (EndAddress < rom.Size) &&
                 ((StartAddress & 0xF) == 0) && ((EndAddress & 0xF) == 0) &&
                 (EndAddress > StartAddress));

            IsEmpty = (StartAddress == 0 && EndAddress == 0);

            Name = "N/A";

            if (IsValid == true && IsEmpty == false)
            {
                if ((Name = (ROM.XMLObjectNames.Names[number] as string)) == null)
                {
                    DMA = rom.Files.Find(x => x.PStart == StartAddress);
                    if (DMA != null)
                    {
                        Name = DMA.Name;
                    }
                    else
                    {
                        Name = string.Format("S{0:X}_E{1:X}", StartAddress, EndAddress);
                    }
                }
            }
        }
Esempio n. 2
0
        private void FindSceneTable()
        {
            Scenes = new List <ISceneTableEntry>();

            if (IsMajora || !HasZ64TablesHack)
            {
                int increment = (IsMajora ? 16 : 20);

                DMATableEntry dma = Files.OrderBy(x => x.VStart).FirstOrDefault(x => x.FileType == DMATableEntry.FileTypes.Scene);

                for (int i = CodeData.Length - (increment * 2); i > 0; i -= 4)
                {
                    ISceneTableEntry entry = !IsMajora ? new SceneTableEntryOcarina(this, i, true) : (ISceneTableEntry) new SceneTableEntryMajora(this, i, true);
                    if (entry.GetSceneStartAddress() == dma.VStart && entry.GetSceneEndAddress() == dma.VEnd)
                    {
                        SceneTableAddress = i;
                        break;
                    }
                }

                if (SceneTableAddress != -1)
                {
                    for (int i = SceneTableAddress, j = 0; i < CodeData.Length - (16 * 16); i += increment)
                    {
                        ISceneTableEntry scn1 = !IsMajora ? new SceneTableEntryOcarina(this, i, true) : (ISceneTableEntry) new SceneTableEntryMajora(this, i, true);

                        if (!scn1.IsValid() && !scn1.IsAllZero())
                        {
                            break;
                        }

                        scn1.SetNumber((ushort)j);
                        if (!scn1.IsAllZero())
                        {
                            Scenes.Add(scn1);
                        }
                        j++;
                    }
                }
            }
            else
            {
                SceneTableAddress = Endian.SwapInt32(BitConverter.ToInt32(Data, Z64TablesAdrOffset));
                int cnt = Endian.SwapInt32(BitConverter.ToInt32(Data, Z64TablesAdrOffset + 4));
                for (int i = 0; i < cnt; i++)
                {
                    Scenes.Add(new SceneTableEntryOcarina(this, SceneTableAddress + (i * 20), false));
                }
            }

            SceneNameACStrings = new AutoCompleteStringCollection();
            foreach (ISceneTableEntry ste in Scenes)
            {
                ste.ReadScene();
                SceneNameACStrings.Add(ste.GetName());
            }
        }
Esempio n. 3
0
        public SceneTableEntryOcarina(ROMHandler rom, int ofs, bool isrel)
        {
            ROM   = rom;
            inROM = true;

            Offset           = ofs;
            IsOffsetRelative = isrel;

            sceneStartAddress = Endian.SwapUInt32(BitConverter.ToUInt32(IsOffsetRelative ? rom.CodeData : rom.Data, ofs));
            sceneEndAddress   = Endian.SwapUInt32(BitConverter.ToUInt32(IsOffsetRelative ? rom.CodeData : rom.Data, ofs + 4));

            LabelStartAddress = Endian.SwapUInt32(BitConverter.ToUInt32(IsOffsetRelative ? rom.CodeData : rom.Data, ofs + 8));
            LabelEndAddress   = Endian.SwapUInt32(BitConverter.ToUInt32(IsOffsetRelative ? rom.CodeData : rom.Data, ofs + 12));
            Unknown1          = (IsOffsetRelative ? rom.CodeData : rom.Data)[ofs + 16];
            ConfigurationNo   = (IsOffsetRelative ? rom.CodeData : rom.Data)[ofs + 17];
            Unknown3          = (IsOffsetRelative ? rom.CodeData : rom.Data)[ofs + 18];
            Unknown4          = (IsOffsetRelative ? rom.CodeData : rom.Data)[ofs + 19];

            if (IsValid() && !IsAllZero())
            {
                DMATableEntry dma = rom.Files.Find(x => x.PStart == sceneStartAddress);
                if (dma != null)
                {
                    dmaFilename = dma.Name;
                }

                if ((Name = ROM.XMLSceneNames.Names[sceneStartAddress] as string) == null)
                {
                    isNameExternal = false;

                    if (dma != null)
                    {
                        Name = dmaFilename;
                    }
                    else
                    {
                        Name = string.Format("S{0:X}_L{1:X}", sceneStartAddress, LabelStartAddress);
                    }
                }
                else
                {
                    isNameExternal = true;
                }

                data = new byte[sceneEndAddress - sceneStartAddress];
                Array.Copy(ROM.Data, sceneStartAddress, data, 0, sceneEndAddress - sceneStartAddress);
            }
        }
Esempio n. 4
0
        private void ReadDMATable()
        {
            Files = new List <DMATableEntry>();

            int idx = 0;

            while (true)
            {
                if (DMATableAddress + (idx * 0x10) > Data.Length)
                {
                    throw new ROMHandlerException("Went out of range while reading DMA table.");
                }
                DMATableEntry ndma = new DMATableEntry(this, idx);
                if (ndma.VStart == 0 && ndma.VEnd == 0 && ndma.PStart == 0)
                {
                    break;
                }
                Files.Add(ndma);
                idx++;
            }
        }
Esempio n. 5
0
        public ActorTableEntry(ROMHandler rom, int ofs, bool isrel)
        {
            ROM              = rom;
            Offset           = ofs;
            IsOffsetRelative = isrel;

            StartAddress        = Endian.SwapUInt32(BitConverter.ToUInt32(IsOffsetRelative ? rom.CodeData : rom.Data, ofs));
            EndAddress          = Endian.SwapUInt32(BitConverter.ToUInt32(IsOffsetRelative ? rom.CodeData : rom.Data, ofs + 4));
            RAMStartAddress     = Endian.SwapUInt32(BitConverter.ToUInt32(IsOffsetRelative ? rom.CodeData : rom.Data, ofs + 8));
            RAMEndAddress       = Endian.SwapUInt32(BitConverter.ToUInt32(IsOffsetRelative ? rom.CodeData : rom.Data, ofs + 12));
            Unknown1            = Endian.SwapUInt32(BitConverter.ToUInt32(IsOffsetRelative ? rom.CodeData : rom.Data, ofs + 16));
            ActorInfoRAMAddress = Endian.SwapUInt32(BitConverter.ToUInt32(IsOffsetRelative ? rom.CodeData : rom.Data, ofs + 20));
            ActorNameRAMAddress = Endian.SwapUInt32(BitConverter.ToUInt32(IsOffsetRelative ? rom.CodeData : rom.Data, ofs + 24));
            Unknown2            = Endian.SwapUInt32(BitConverter.ToUInt32(IsOffsetRelative ? rom.CodeData : rom.Data, ofs + 28));

            IsValid =
                (ActorInfoRAMAddress >> 24 == 0x80) &&
                (((ActorNameRAMAddress >> 24 == 0x80) && (ActorNameRAMAddress - ROMHandler.CodeRAMAddress) < rom.CodeData.Length) || (ActorNameRAMAddress == 0));

            IsIncomplete = (StartAddress == 0 && EndAddress == 0 && RAMStartAddress == 0 && RAMEndAddress == 0);

            IsComplete =
                (StartAddress > rom.Code.VStart && StartAddress < rom.Size) &&
                (EndAddress > StartAddress && EndAddress > rom.Code.VStart && EndAddress < rom.Size) &&
                (RAMStartAddress >> 24 == 0x80) &&
                (RAMEndAddress > RAMStartAddress && RAMEndAddress >> 24 == 0x80) &&
                (ActorInfoRAMAddress >> 24 == 0x80) &&
                (((ActorNameRAMAddress >> 24 == 0x80) && (ActorNameRAMAddress - ROMHandler.CodeRAMAddress) < rom.CodeData.Length) || (ActorNameRAMAddress == 0));

            IsEmpty = (StartAddress == 0 && EndAddress == 0 && RAMStartAddress == 0 && RAMEndAddress == 0 && Unknown1 == 0 && ActorInfoRAMAddress == 0 && ActorNameRAMAddress == 0 && Unknown2 == 0);

            Name = Filename = "N/A";

            if (IsValid == true && IsEmpty == false)
            {
                if (ActorNameRAMAddress != 0)
                {
                    string tmp = string.Empty;
                    ROMHandler.GetTerminatedString(rom.CodeData, (int)(ActorNameRAMAddress - ROMHandler.CodeRAMAddress), out tmp);
                    Name = tmp;
                }
                else
                {
                    Name = string.Format("RAM Start 0x{0:X}", RAMStartAddress);
                }

                if (RAMStartAddress != 0 && RAMEndAddress != 0)
                {
                    DMATableEntry dma = rom.Files.Find(x => x.PStart == StartAddress);
                    if (dma != null)
                    {
                        Filename = dma.Name;

                        byte[] tmp = new byte[dma.VEnd - dma.VStart];
                        Array.Copy(rom.Data, dma.PStart, tmp, 0, dma.VEnd - dma.VStart);

                        uint infoadr = (ActorInfoRAMAddress - RAMStartAddress);
                        if (infoadr >= tmp.Length)
                        {
                            return;
                        }

                        ActorNumber  = Endian.SwapUInt16(BitConverter.ToUInt16(tmp, (int)infoadr));
                        ActorType    = tmp[infoadr + 2];
                        ObjectNumber = Endian.SwapUInt16(BitConverter.ToUInt16(tmp, (int)infoadr + 8));
                    }
                    else
                    {
                        Filename = Name;
                    }
                }
            }
        }
Esempio n. 6
0
        private void ReadDMATable()
        {
            Files = new List<DMATableEntry>();

            int idx = 0;
            while (true)
            {
                if (DMATableAddress + (idx * 0x10) > Data.Length) throw new ROMHandlerException("Went out of range while reading DMA table.");
                DMATableEntry ndma = new DMATableEntry(this, idx);
                if (ndma.VStart == 0 && ndma.VEnd == 0 && ndma.PStart == 0) break;
                Files.Add(ndma);
                idx++;
            }
        }