Beispiel #1
0
        /// <summary>
        /// Returns a reference to a decompressed file
        /// </summary>
        /// <param name="record">The DMA address used to reference the file</param>
        /// <returns></returns>
        protected RomFile GetFile(FileRecord record)
        {
            MemoryStream ms;

            byte[] data;
            byte[] decompressedData;

            if (record.VirtualAddress == CachedFileAddress)
            {
                ms = new MemoryStream(CachedFile);
                return(new RomFile(record, ms, Version));
            }

            using (FileStream fs = new FileStream(RomLocation, FileMode.Open, FileAccess.Read))
            {
                data        = new byte[record.DataAddress.Size];
                fs.Position = record.DataAddress.Start;
                fs.Read(data, 0, record.DataAddress.Size);

                if (record.IsCompressed)
                {
                    ms = new MemoryStream(data);
                    decompressedData = Yaz.Decode(ms, record.DataAddress.Size);
                }
                else
                {
                    decompressedData = data;
                }
            }
            CachedFile        = decompressedData;
            ms                = new MemoryStream(decompressedData);
            CachedFileAddress = record.VirtualAddress;
            return(new RomFile(record, ms, Version));
        }
Beispiel #2
0
        protected FileAddress GetFileByRomTable(FileRefTable refTable, int index)
        {
            string       table = refTable.StartKey;
            int          size = refTable.RecSize;
            int          offset = refTable.FileStartOff;
            int          recordAddr, startAddr, endAddr;
            RomFileToken token = ORom.FileList.invalid;

            if (Version.Game == Game.OcarinaOfTime)
            {
                token = ORom.FileList.code;
            }
            if (Version.Game == Game.MajorasMask)
            {
                token = MRom.FileList.code;
            }

            recordAddr = Addresser.GetRom(token, Version, table);
            startAddr  = recordAddr + (index * size) + offset;
            startAddr  = ReadInt32(startAddr);
            endAddr    = recordAddr + (index * size) + refTable.FileEndOff;
            endAddr    = ReadInt32(endAddr);
            FileAddress result = new FileAddress();

            try
            {
                result = GetVRomAddress(startAddr);
            }
            catch
            {
                result = new FileAddress(startAddr, endAddr);
            }

            return(result);
        }
Beispiel #3
0
 public FOut(FileRecord rec)
 {
     Source      = rec.VRom;
     SourceIndex = 0; //rec.Index;
     Target      = new FileAddress();
     TargetIndex = -1;
 }
Beispiel #4
0
 public JSectionInfo(string name, int subsection, bool isCode, FileAddress ram)
 {
     Name       = name;
     Subsection = subsection;
     IsCode     = isCode;
     Ram        = ram;
 }
Beispiel #5
0
        //static int Room_Alloc_Table { get { return SpectrumVariables.Room_Allocation_Table; } }
        //public N64PtrRange Ram { get; }
        //public FileAddress VRom { get; set; }

        //public RamRoom(Ptr ptr)
        //{
        //    Ram = new N64PtrRange(
        //        ptr.ReadInt32(0x00),
        //        ptr.ReadInt32(0x04));

        //    int RoomFile = ptr.ReadInt32(0x10);
        //    VRom = RamDmadata.GetFileAddress(RoomFile);
        //}

        //public static RamRoom GetRoomInfo()
        //{
        //    Ptr ptr = SPtr.New(Room_Alloc_Table);
        //    return new RamRoom(ptr);
        //}

        public static List <SimpleFile> GetRoomInfo()
        {
            RoomCtx roomCtx  = new RoomCtx(SpectrumVariables.Room_Context);
            var     roomList = SpectrumVariables.Room_List_Ptr;

            List <SimpleFile> files = new List <SimpleFile>();

            foreach (var item in new RoomCtx.Room[] { roomCtx.CurRoom, roomCtx.PrevRoom })
            {
                if (item.Num == -1)
                {
                    continue;
                }

                if (roomList == 0)
                {
                    continue;
                }

                FileAddress vrom = RamDmadata.GetFileAddress(roomList.RelOff(item.Num * 8).ReadInt32(0));
                N64PtrRange ram  = new N64PtrRange(item.segment, item.segment + vrom.Size);

                SimpleFile file = new SimpleFile()
                {
                    VRom        = vrom,
                    Ram         = ram,
                    Description = $"ROOM {item.Num}: {vrom}"
                };
                files.Add(file);
            }
            return(files);
        }
Beispiel #6
0
 public MBlock(FileAddress addr)
 {
     Address  = addr;
     StartSet = true;
     EndSet   = true;
     Self     = new LinkedListNode <MBlock>(this);
 }
 private static void UpdateSceneTable(BinaryWriter bw, int scene, FileAddress addr)
 {
     //update the scene table
     bw.BaseStream.Position = SceneTable_Start + (scene * 5 * sizeof(int));
     bw.WriteBig(addr.Start);
     bw.WriteBig(addr.End);
 }
Beispiel #8
0
 private MBlock(object asset, FileAddress addr, bool startSet, bool endSet)
 {
     Asset    = asset;
     Address  = addr;
     StartSet = startSet;
     EndSet   = endSet;
 }
Beispiel #9
0
        public async Task <Guid> UploadAsync(User user, IFormFile file)
        {
            try
            {
                if (string.IsNullOrEmpty(file.FileName) || file.Length == 0)
                {
                    throw new ExperienceManagementGlobalException(UploadServiceErrors.UploadFileValidError);
                }
                var extension = file.FileName.Split('.')[file.FileName.Split('.').Length - 1];
                var fileName  = Guid.NewGuid().ToString() + "." + extension;
                var path      = Path.Combine(_siteSettings.Value.UserAttachedFile.PhysicalPath, fileName);

                using (var bits = new FileStream(path, FileMode.Create))
                {
                    await file.CopyToAsync(bits);
                }
                var uploadFile = new FileAddress()
                {
                    FilePath     = path,
                    FileType     = extension,
                    UserId       = user.Id,
                    FileSize     = file.Length,
                    CreationDate = DateTime.Now,
                };
                await _context.FileAddresses.AddAsync(uploadFile);

                await _context.SaveChangesAsync();

                return(uploadFile.FileId);
            }
            catch (Exception ex)
            {
                throw new ExperienceManagementGlobalException(UploadServiceErrors.UploadFileError, ex);
            }
        }
Beispiel #10
0
        public CodeFile()
        {
            var ramStart = SpectrumVariables.Code_Addr;

            VRom = RamDmadata.GetFileAddress(SpectrumVariables.Code_VRom);
            Ram  = new N64PtrRange(ramStart, ramStart + VRom.Size);
        }
Beispiel #11
0
        private void evalButton_Click(object sender, EventArgs e)
        {
            if (rom == null)
            {
                return;
            }
            Scene         scene = null;
            StringBuilder sb    = new StringBuilder();
            Room          room  = null;

            for (int sceneNumber = 0; sceneNumber < rom.Scenes; sceneNumber++)
            {
                scene = null;
                room  = null;

                var sceneFile = rom.Files.GetSceneFile(sceneNumber);
                if (sceneFile == null)
                {
                    sb.AppendLine($"Warning: Scene {sceneNumber} not found");
                    continue;
                }
                try
                {
                    scene = SceneRoomReader.InitializeScene(sceneFile, sceneNumber);
                }
                catch (Exception ex)
                {
                    var va = sceneFile.Record.VirtualAddress;
                    sb.AppendLine($"ParseError: Scene {sceneNumber} {va.Start:X8}-{va.End:X8}");
                    sb.AppendLine(ex.TargetSite.ToString());
                }

                var roomAddrs = scene.Header.GetRoomAddresses();
                for (int i = 0; i < roomAddrs.Count; i++)
                {
                    FileAddress addr     = roomAddrs[i];
                    RomFile     roomFile = null;

                    try
                    {
                        roomFile = rom.Files.GetFile(addr);
                        room     = SceneRoomReader.InitializeRoom(roomFile);
                    }
                    catch //(Exception ex)
                    {
                        if (roomFile == null)
                        {
                            sb.AppendLine($"Exception: Scene {sceneNumber}, room {addr.Start:X8}:{addr.End:X8} not found");
                        }
                        else
                        {
                            sb.AppendLine($"ParseError: Scene {sceneNumber}, room {addr.Start:X8}:{addr.End:X8}");
                            //sb.AppendLine(ex.StackTrace.ToString());
                        }
                    }
                }
            }
            sb.AppendLine("Evaluation Complete");
            outputRichTextBox.Text = sb.ToString();
        }
Beispiel #12
0
        protected FileAddress GetFileByTable(TableInfo.Table refTable, int index)
        {
            RomFileToken token = ORom.FileList.invalid;

            if (Version.Game == Game.OcarinaOfTime)
            {
                token = ORom.FileList.code;
            }
            if (Version.Game == Game.MajorasMask)
            {
                token = MRom.FileList.code;
            }

            int size = refTable.Length;
            int offset = refTable.StartOff;
            int recordAddr, startAddr, endAddr;

            recordAddr = Addresser.GetRom(token, Version, refTable.Id);
            startAddr  = recordAddr + (index * size) + offset;
            endAddr    = startAddr + 4;
            startAddr  = ReadInt32(startAddr);
            endAddr    = ReadInt32(endAddr);
            FileAddress result = new FileAddress();

            try
            {
                result = GetVRomAddress(startAddr);
            }
            catch
            {
                result = new FileAddress(startAddr, endAddr);
            }

            return(result);
        }
Beispiel #13
0
 public FileRecord(FileRecord fileRecord)
 {
     VirtualAddress  = fileRecord.VirtualAddress;
     PhysicalAddress = fileRecord.PhysicalAddress;
     DataAddress     = fileRecord.DataAddress;
     Index           = fileRecord.Index;
 }
Beispiel #14
0
        public ActionResult EditFileOnPost(PostAddress postAddress, FileAddress fileAddress, FileInput fileInput, string returnUri)
        {
            Post post = postService.GetPost(postAddress);

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

            post.EditFile(fileAddress, fileInput);
            postService.EditPost(post);

            if (!string.IsNullOrEmpty(returnUri))
            {
                return(new RedirectResult(returnUri));
            }

            File newFile = post.GetFile(new FileAddress(fileInput.Url));

            if (newFile != null)
            {
                return(PartialView("ManageFile", new OxiteModelItem <File> {
                    Item = newFile, Container = post
                }));
            }

            return(new JsonResult {
                Data = false
            });;
        }
Beispiel #15
0
        private void FileDownLoad_Load(object sender, EventArgs e)
        {
            int Index           = 0;
            var FileNameList    = FileName.Split('|');
            var FileAddressList = FileAddress.Split('|');

            for (int i = 0; i < FileAddressList.Length; i++)
            {
                string          FileName    = FileNameList[i];
                string          FileAddress = FileAddressList[i];
                DataGridViewRow dgr         = new DataGridViewRow();

                DataGridViewTextBoxCell C1 = new DataGridViewTextBoxCell();
                C1.Value = Index + 1;

                DataGridViewTextBoxCell C2 = new DataGridViewTextBoxCell();
                C2.Value = FileName;

                DataGridViewLinkCell C3 = new DataGridViewLinkCell();
                C3.Value = "下载";

                DataGridViewLinkCell C4 = new DataGridViewLinkCell();
                C4.Value = FileAddress;

                Index++;

                dgr.Cells.Add(C1);
                dgr.Cells.Add(C2);
                dgr.Cells.Add(C3);
                dgr.Cells.Add(C4);

                dgv_file_list.Rows.Add(dgr);
            }
        }
Beispiel #16
0
 private static void UpdateFileTable(BinaryWriter bw, FileAddress fileAddr)
 {
     bw.BaseStream.Position = FileTable_Off;
     bw.Write(Endian.ConvertInt32(fileAddr.Start));
     bw.Write(Endian.ConvertInt32(fileAddr.End));
     bw.Write(Endian.ConvertInt32(fileAddr.Start));
     FileTable_Off += 0x10;
 }
Beispiel #17
0
 private static void UpdateFileTable(BinaryWriter bw, FileAddress fileAddr)
 {
     bw.BaseStream.Position = FileTable_Off;
     bw.WriteBig(fileAddr.Start);
     bw.WriteBig(fileAddr.End);
     bw.WriteBig(fileAddr.Start);
     FileTable_Off += 0x10;
 }
Beispiel #18
0
        private void Initialize(BinaryReader br)
        {
            RamStart = br.ReadBigUInt32();
            VRom     = new FileAddress(br.ReadBigUInt32(), br.ReadBigUInt32());
            VRam     = new N64PtrRange(br.ReadBigUInt32(), br.ReadBigUInt32());

            DungeonMarkData = br.ReadBigInt32();
        }
 private void Initialize(int index, BinaryReader br)
 {
     Index        = index;
     RamStart     = br.ReadBigUInt32();
     VRam         = new N64PtrRange(br.ReadBigUInt32(), br.ReadBigUInt32());
     VRom         = new FileAddress(br.ReadBigUInt32(), br.ReadBigUInt32());
     unk          = br.ReadBigUInt32();
     AllocateSize = br.ReadBigInt32();
 }
Beispiel #20
0
        public RamDmadata()
        {
            Ptr ptr = SpectrumVariables.Dmadata_Addr;

            VRom = new FileAddress(ptr.ReadInt32(0x20), ptr.ReadInt32(0x24));
            Ram  = new N64PtrRange(ptr, ptr + VRom.Size);

            Data = this;
        }
Beispiel #21
0
 private List <V8File> ReadToC(V8Document tocDocument)
 {
     using (var reader = tocDocument.Open())
     {
         var files = FileAddress.ReadToC(reader)
                     .Select(addr => V8File.FromStream(this, addr));
         return(files.ToList());
     }
 }
Beispiel #22
0
 public JFileInfo(string file, RomVersion version, FileAddress rom, FileAddress ram, JSectionInfo section)
 {
     File    = file;
     Game    = version.Game.ToString();
     Version = version.ToString();
     Rom     = rom;
     Ram     = ram;
     Sections.Add(section);
 }
Beispiel #23
0
        public static void DmaMap(IExperimentFace face, List <string> filePath)
        {
            Rom sourceRom = new MRom(filePath[0], MRom.Build.J0);
            Rom targetRom = new MRom(filePath[1], MRom.Build.U0);

            VFileTable source;                                                             //rom containing the complete file list
            VFileTable target;                                                             //rom we're using to link to file names
            Dictionary <long, FileRecord> unmatched = new Dictionary <long, FileRecord>(); //address pool
            Dictionary <long, FOut>       fOut      = new Dictionary <long, FOut>();

            source = sourceRom.Files;
            target = targetRom.Files;

            //Load file table data
            foreach (FileRecord t in target)
            {
                if (t.VRom.End != 0)
                {
                    fOut.Add(t.VRom.Start, new FOut(t));
                }
            }
            foreach (FileRecord s in source)
            {
                if (s.VRom.End != 0)
                {
                    unmatched.Add(s.VRom.Start, s);
                }
            }

            //match scene files
            MatchGeneric(TableInfo.Type.Scenes, source, target, fOut, unmatched);

            //match room files
            MatchRooms(source, target, fOut, unmatched);

            MatchGeneric(TableInfo.Type.GameOvls, source, target, fOut, unmatched);
            MatchGeneric(TableInfo.Type.TitleCards, source, target, fOut, unmatched);
            MatchGeneric(TableInfo.Type.Actors, source, target, fOut, unmatched);
            MatchGeneric(TableInfo.Type.Objects, source, target, fOut, unmatched);
            MatchGeneric(TableInfo.Type.HyruleSkybox, source, target, fOut, unmatched);
            MatchGeneric(TableInfo.Type.Particles, source, target, fOut, unmatched);
            MatchGeneric(TableInfo.Type.Transitions, source, target, fOut, unmatched);


            StringBuilder sw = new StringBuilder();

            {
                foreach (FOut item in fOut.Values)
                {
                    FileAddress vS = item.Source;
                    FileAddress vT = item.Target;
                    sw.AppendLine($"{item.SourceIndex}\t{vS.Start}\t{vS.End}\t{item.TargetIndex}\t{vT.Start}\t{vT.End}");
                }
            }
            face.OutputText(sw.ToString());
        }
Beispiel #24
0
        /// <summary>
        /// Returns a stream pointed to the decompressed file at the given address
        /// </summary>
        /// <param name="vAddr"></param>
        /// <returns></returns>
        public RomFile GetFile(FileAddress vAddr)
        {
            if (dmadata.TryGetFileRecord(vAddr.Start, out FileRecord record) &&
                vAddr.Size == record.VirtualAddress.Size)
            {
                return(GetFile(record));
            }

            return(GetFile(new FileRecord(vAddr, new FileAddress(vAddr.Start, 0), -1)));
        }
        private void Initialize(int index, BinaryReader br)
        {
            Id   = index;
            VRom = new FileAddress(br.ReadBigUInt32(), br.ReadBigUInt32());
            VRam = new N64PtrRange(br.ReadBigUInt32(), br.ReadBigUInt32());

            RamStart   = br.ReadBigUInt32();
            UnknownPtr = br.ReadBigUInt32();
            Unknown1   = br.ReadBigUInt32();
        }
Beispiel #26
0
        public RamRoom(Ptr ptr)
        {
            Ram = new N64PtrRange(
                ptr.ReadInt32(0x00),
                ptr.ReadInt32(0x04));

            int RoomFile = ptr.ReadInt32(0x10);

            VRom = RamDmadata.GetFileAddress(RoomFile);
        }
Beispiel #27
0
        public RamObject(Ptr ptr)
        {
            Object   = ptr.ReadInt16(0);
            IsLoaded = Object >= 0;
            Object   = Math.Abs(Object);
            N64Ptr addr = ptr.ReadUInt32(4);

            VRom = (MemoryMapper.ObjectFiles.Length <= Object || Object < 0) ? new FileAddress(0, 0) : MemoryMapper.ObjectFiles[Object];
            Ram  = new N64PtrRange(addr, addr + VRom.Size);
        }
        public PlayPauseOverlayRecord(int index, BinaryReader br)
        {
            Item = index;

            RamStart = br.ReadBigUInt32();
            VRom     = new FileAddress(br.ReadBigUInt32(), br.ReadBigUInt32());
            VRam     = new N64PtrRange(br.ReadBigUInt32(), br.ReadBigUInt32());
            br.ReadBigUInt32();
            RamFileName = br.ReadBigUInt32();
        }
Beispiel #29
0
        private void Initialize(int index, BinaryReader br)
        {
            Item = index;

            RamStart    = br.ReadBigUInt32();
            VRom        = new FileAddress(br.ReadBigUInt32(), br.ReadBigUInt32());
            VRam        = new N64PtrRange(br.ReadBigUInt32(), br.ReadBigUInt32());
            Unk_0x14    = br.ReadBigInt32();
            RamFileName = br.ReadBigUInt32();
        }
Beispiel #30
0
        private void Initialize(Stream fs, int address)
        {
            FileRecord fileRecord;
            int        length;      //length of file table
            int        position;    //offset into rom of file table
            int        positionEnd; //end offset for the file table

            FileAddress fileVirtualAddress;
            FileAddress filePhysicalAddress;

            //initialize file table
            Table = new Dictionary <long, FileRecord>();


            BinaryReader br = new BinaryReader(fs);

            //set rom type dependent values
            position = address;

            //set stream position
            fs.Position = position;

            positionEnd = GetEndAddress(br);

            length = (positionEnd - position) / 0x10;

            for (int i = 0; i < length; i++)
            {
                fileVirtualAddress = new FileAddress(
                    br.ReadBigInt32(),
                    br.ReadBigInt32());
                filePhysicalAddress = new FileAddress(
                    br.ReadBigInt32(),
                    br.ReadBigInt32());

                if (fileVirtualAddress.Start == 0 &&
                    fileVirtualAddress.End == 0)
                {
                    continue;
                }

                fileRecord = new FileRecord(fileVirtualAddress, filePhysicalAddress, i);
                if (Table.ContainsKey(fileRecord.VirtualAddress.Start))
                {
                }
                else
                {
                    Table.Add(fileRecord.VirtualAddress.Start, fileRecord);
                }
            }
            FileRecord addr;

            Table.TryGetValue(address, out addr);
            Address = addr;
        }