コード例 #1
0
        public static List <SegmentAddress> GetSegmentAddressMap(bool showAllSegments)
        {
            List <SegmentAddress> addrs = new List <SegmentAddress>();

            if (SegmentAddressTable == 0)
            {
                return(addrs);
            }

            Ptr ptr = SPtr.New(SegmentAddressTable);

            for (int i = 0; i < 0x10; i++)
            {
                addrs.Add(new SegmentAddress(i, new N64PtrRange(ptr.ReadInt32(i * 0x4), 0)));
            }

            if (showAllSegments)
            {
                return(addrs.Where(x => !x.Ram.Start.IsNull()).ToList());
            }
            else
            {
                return(addrs.Where(x => new int[] { 0x03 }.Contains(x.segment)).ToList());
            }
        }
コード例 #2
0
        static void BindSegment(RomVersion version, ORom.FileList fileO, MRom.FileList fileM, ref Ptr ram, ref Ptr rom)
        {
            RomFileToken token = RomFileToken.Select(version, fileO, fileM);

            if (Options.MapfileOptions.CanUseMap(version))
            {
                Segment seg = Options.MapfileOptions.SymbolMap.GetSegment(token.ToString());
                if (seg != null)
                {
                    ram = SPtr.New(seg.Address);
                    rom = SPtr.New(seg.LoadAddress);
                }
                else
                {
                    Console.WriteLine($"Segment {token} not found.");
                }
            }
            else
            {
                Addresser.TryGetRam(token, version, out var t1);
                ram = SPtr.New(t1);
                Addresser.TryGetRom(token, version, t1, out var t2);
                rom = SPtr.New(t2);
            }
        }
コード例 #3
0
        private static void TestBetaQuestShuffleData(Arguments args)
        {
            if (Options.Version != ORom.Build.N0)
            {
                return;
            }
            Ptr staticCtx    = SPtr.New(0x11BA00).Deref();
            Ptr shuffleTable = staticCtx.RelOff(BetaQuest.GetTBL_OFFSET());

            Dictionary <short, int> collisions = new Dictionary <short, int>();

            int shuffle = BetaQuest.GetSHUFFLE();

            for (int i = 0; i < shuffle; i++)
            {
                short index = shuffleTable.ReadInt16(i * 2);
                if (collisions.ContainsKey(index))
                {
                    collisions[index] += 1;
                }
                else
                {
                    collisions.Add(index, 1);
                }
            }
            Console.Clear();
            Console.WriteLine("Repeats: ");
            foreach (var item in collisions)
            {
                if (item.Value > 1)
                {
                    Console.WriteLine($"{item.Key:X4} - {item.Value}");
                }
            }
        }
コード例 #4
0
 private void Update()
 {
     byte[] data = SPtr.New(Options.StartPtr).ReadBytes(0, Align.To4(Options.Size));
     foreach (var item in Data)
     {
         item.prev = item.cur;
         item.cur  = Endian.ConvertInt32(data, item.off);
     }
 }
コード例 #5
0
        public BlockNode(N64Ptr addr)
        {
            Ptr ptr = SPtr.New(addr);

            IsFree = (ptr.ReadInt32(0) & 1) == 1;
            Size   = ptr.ReadUInt32(4);
            Next   = ptr.ReadInt32(8);
            Prev   = ptr.ReadInt32(0xC);
            Ram    = new N64PtrRange(addr, addr + LENGTH);
        }
コード例 #6
0
ファイル: ValueSearch.cs プロジェクト: laetemn/MasterOcarina
        private void Update()
        {
            Ptr ptr = SPtr.New(Options.StartPtr);

            foreach (var item in Data)
            {
                item.prev = item.cur;
                item.cur  = ptr.ReadInt32(item.off);
            }
        }
コード例 #7
0
ファイル: TorchLol.cs プロジェクト: notwa/MasterOcarina
        private static void callback(object state)
        {
            Test obj = (Test)state;


            if (obj.RandTick < 0)
            {
                obj.RandTick = Rand.Next(8, 26);
            }
            else if (obj.RandTick == 0)
            {
                List <ActorInstance> unlitTorches = new List <ActorInstance>();
                var map = ActorMemoryMapper.FetchFilesAndInstances();

                var allTorches = map.Instances
                                 .Where(x => x.Actor == 0x5E).ToList();


                foreach (var item in allTorches)
                {
                    Ptr localTorch = SPtr.New(item.Ram.Start);
                    var time       = localTorch.ReadInt16(TORCH_TIMER_OFFSET);
                    if (time <= 0)
                    {
                        unlitTorches.Add(item);
                    }
                }

                if (unlitTorches.Count > 0)
                {
                    var torchOvl = map.Files.Where(x => x.Actor == 0x5E).SingleOrDefault();
                    var select   = Rand.Next(0, unlitTorches.Count);

                    Ptr torch = SPtr.New(unlitTorches[select].Ram.Start);

                    torch.Write(TORCH_TIMER_OFFSET, TORCH_TIMER);

                    if (torchOvl != null)
                    {
                        Ptr ovl = SPtr.New(torchOvl.Ram.Start);
                        int lit = ovl.ReadInt32(TORCHES_LIT_OFFSET);
                        lit++;
                        ovl.Write(TORCHES_LIT_OFFSET, lit);
                    }
                    //Console.WriteLine(string.Format("Light! {0:X6}", (int)torch));
                }
            }
            obj.RandTick--;
        }
コード例 #8
0
ファイル: OvlPause.cs プロジェクト: shawlucas/MasterOcarina
        internal static List <OvlPause> GetActive()
        {
            List <OvlPause> ovlPause    = new List <OvlPause>();
            Ptr             ovlPausePtr = SPtr.New(TABLE_ADDRESS);

            for (int i = 0; i < COUNT; i++)
            {
                Ptr      ptr     = ovlPausePtr.RelOff(LENGTH * i);
                OvlPause working = new OvlPause(i, ptr);
                if (working.Ram.Start != 0)
                {
                    ovlPause.Add(working);
                }
            }
            return(ovlPause);
        }
コード例 #9
0
 public static void SetGfxContext(RomVersion version)
 {
     if (!Addresser.TryGetRam(AddressToken.GFX_START, version, out int temp))
     {
         if (GlobalContext != 0)
         {
             Gfx = GlobalContext.Deref();
         }
         else
         {
             Gfx = SPtr.New(0);
         }
     }
     else
     {
         Gfx = SPtr.New(temp);
     }
 }
コード例 #10
0
        public void Initialize()
        {
            Data = new List <Record>();
            byte[] data = SPtr.New(Options.StartPtr).ReadBytes(0, Align.To4(Options.Size));

            for (int i = 0; i < Options.Size; i += 4)
            {
                int v   = Endian.ConvertInt32(data, i);
                var rec = new Record()
                {
                    off     = i,
                    initial = v,
                    prev    = v,
                    cur     = v
                };
                Data.Add(rec);
            }
        }
コード例 #11
0
        public IEnumerable <(short, short)> YieldPolyChain(int[] colsec, int index)
        {
            N64Ptr colsecAddr = GetColSecDataPtr(colsec);
            Ptr    colsecPtr  = SPtr.New(colsecAddr);

            int   depthLimit = 800;
            short topLinkId  = colsecPtr.ReadInt16(index * 2);
            short linkId     = topLinkId;

            while (depthLimit > 0 && linkId != -1)
            {
                depthLimit--;

                //Get Next Link Record
                short polyId = Links.ReadInt16(linkId * 4);
                linkId = Links.ReadInt16(linkId * 4 + 2);
                yield return(polyId, linkId);
            }
        }
コード例 #12
0
ファイル: ValueSearch.cs プロジェクト: laetemn/MasterOcarina
        public void Initialize()
        {
            Data = new List <Record>();
            Ptr ptr = SPtr.New(Options.StartPtr);

            for (int i = 0; i < Options.Size; i += 4)
            {
                var addr = Options.StartPtr + i;
                int v    = ptr.ReadInt32(i);
                var rec  = new Record()
                {
                    off     = i,
                    initial = v,
                    prev    = v,
                    cur     = v
                };
                Data.Add(rec);
            }
        }
コード例 #13
0
        public ThreadStack(N64Ptr addr)
        {
            Ram = new N64PtrRange(addr, addr + 0x20);

            Ptr ptr = SPtr.New(addr);

            NextPtr = ptr.ReadInt32(0x00);
            PrevPtr = ptr.ReadInt32(0x04);
            N64Ptr StartPtr = ptr.ReadInt32(0x08);
            N64Ptr EndPtr   = ptr.ReadInt32(0x0C);

            Unknown = ptr.ReadInt32(0x14);
            //NamePtr = ptr.ReadInt32(0x18);
            Unknown2 = ptr.ReadInt32(0x1C);

            byte[] nameBuff = ptr.Deref(0x18).ReadBytes(0, 0x20);
            Name      = CStr.Get(nameBuff, Encoding.GetEncoding("EUC-JP"), 0x20);
            StackAddr = new NamedBuffer(new N64PtrRange(StartPtr, EndPtr), $"{Name,-13} STACK");
        }
コード例 #14
0
        public static FileAddress GetFileAddress(int addr)
        {
            if (Data.VRom.Size < 0 || Data.VRom.Size > 0x4_0000)
            {
                throw new InvalidOperationException("dmadata reference is not initialized correctly");
            }

            Ptr ptr = SPtr.New(Data.Ram.Start);

            for (int i = 0; i < Data.VRom.Size; i += 0x10)
            {
                int start = ptr.ReadInt32(i);
                if (addr == start)
                {
                    return(new FileAddress(start, ptr.ReadInt32(i + 0x04)));
                }
            }
            return(new FileAddress());
        }
コード例 #15
0
 static Ptr BindPtr(AddressToken token, RomVersion version, Func <int, Ptr> func)
 {
     if (Options.MapfileOptions.CanUseMap(version))
     {
         if (Addresser.TryGetSymbolRef(token, version, out MapBinding binding) && binding != null &&
             Options.MapfileOptions.SymbolMap.TryGetSymbolAddress(binding, out N64Ptr ptr))
         {
             return(func(ptr));
         }
         Console.WriteLine($"{token} symbol not found");
         return(SPtr.New(0));
     }
     else if (Addresser.TryGetRam(token, version, out int temp))
     {
         return(func(temp));
     }
     else
     {
         return(SPtr.New(0));
     }
 }
コード例 #16
0
        internal static void ChangeVersion(RomVersion v, bool g)
        {
            if (v.Game == Game.OcarinaOfTime)
            {
                OBJECT_FILE_COUNT = 0x192;
            }
            else if (v.Game == Game.MajorasMask)
            {
                OBJECT_FILE_COUNT = 0x283;
            }


            ObjectFiles = new FileAddress[OBJECT_FILE_COUNT];

            Ptr ptr = SPtr.New(OBJ_FILE_TABLE_ADDR);

            for (int i = 0; i < OBJECT_FILE_COUNT; i++)
            {
                int off = i * 8;
                ObjectFiles[i] = new FileAddress(ptr.ReadInt32(off), ptr.ReadInt32(off + 4));
            }
        }
コード例 #17
0
ファイル: ActorInstance.cs プロジェクト: notwa/MasterOcarina
        public ActorInstance(RomVersion version, N64Ptr address, ActorMemoryMapper map)
        {
            Ptr ptr = SPtr.New(address);


            ActorId = ptr.ReadUInt16(0);
            Type    = ptr.ReadByte(2);
            Room    = ptr.ReadByte(3);
            Address = address;

            Variable = ptr.ReadUInt16(0x1C);

            Position = new Vector3 <float>(
                ptr.ReadFloat(0x24),
                ptr.ReadFloat(0x28),
                ptr.ReadFloat(0x2C));


            int off = version.Game == Game.OcarinaOfTime ? 0 : 8;

            Rotation = new Vector3 <short>(
                ptr.ReadInt16(0xB4 + off),
                ptr.ReadInt16(0xB6 + off),
                ptr.ReadInt16(0xB8 + off));

            PrevActor       = ptr.ReadInt32(0x120 + off);
            NextActor       = ptr.ReadInt32(0x124 + off);
            Update          = ptr.ReadInt32(0x130 + off);
            ProcessInstance = ptr.ReadByte(0x115);


            map.GetActorIdAndSize(this, out ushort actorId, out uint instanceSize);
            ActorId = actorId;

            Ram = new N64PtrRange(Address, Address + instanceSize);
        }
コード例 #18
0
        private static void LocateBetaQuestEntrance(Arguments args)
        {
            if (Options.Version != ORom.Build.N0)
            {
                return;
            }
            Ptr staticCtx    = SPtr.New(0x11BA00).Deref();
            Ptr shuffleTable = staticCtx.RelOff(BetaQuest.GetTBL_OFFSET());

            short index = (short)args[0];

            short[] VAR_Entrances = BetaQuest.GetVAR_Entrances();

            for (int i = 0; i < 326; i++)
            {
                var read = shuffleTable.ReadInt16(i * 2);
                if (index == read)
                {
                    Console.WriteLine($"{VAR_Entrances[i]:X4}");
                    return;
                }
            }
            Console.WriteLine("NOT FOUND");
        }
コード例 #19
0
        internal static void ChangeVersion(RomVersion version, bool setGctx = true)
        {
            RomFileToken fileToken;

            //dma data
            fileToken = (version == Game.OcarinaOfTime) ?
                        (RomFileToken)ORom.FileList.dmadata : (RomFileToken)MRom.FileList.dmadata;
            Addresser.TryGetRam(fileToken, version, out int temp);
            Dmadata_Addr = SPtr.New(temp);

            //code
            fileToken = (version == Game.OcarinaOfTime) ?
                        (RomFileToken)ORom.FileList.code : (RomFileToken)MRom.FileList.code;
            Addresser.TryGetRam(fileToken, version, out Code_Addr);
            Addresser.TryGetRom(fileToken, version, (uint)Code_Addr, out Code_VRom);

            //Global Context
            if (setGctx)
            {
                Addresser.TryGetRam("RAM_GLOBAL_CONTEXT", version, out temp);
                if (version == ORom.Build.IQUEC || version == ORom.Build.IQUET)
                {
                    GlobalContext = SPtr.New(temp);
                }
                else
                {
                    GlobalContext = SPtr.New(temp).Deref();
                }
            }

            SetGfxContext(version);

            //Heap
            Addresser.TryGetRam("RAM_ARENA_MAIN", version, out temp);
            Main_Heap_Ptr = SPtr.New(temp).Deref();

            Addresser.TryGetRam("RAM_ARENA_SCENES", version, out temp);
            Scene_Heap_Ptr = SPtr.New(temp).Deref();

            Addresser.TryGetRam("RAM_ARENA_DEBUG", version, out temp);
            if (temp == 0)
            {
                Debug_Heap_Ptr = SPtr.New(0);
            }
            else
            {
                Debug_Heap_Ptr = SPtr.New(temp).Deref();
            }


            Addresser.TryGetOffset("ACTOR_CAT_LL_Start", version, out temp);
            Actor_Category_Table = GlobalContext.RelOff(temp);

            //Overlay Tables
            Addresser.TryGetRam("ActorTable_Start", ORom.FileList.code, version, out Actor_Ovl_Table);
            Addresser.TryGetRam("PlayerPauseOverlayTable_Start", ORom.FileList.code, version, out Player_Pause_Ovl_Table);
            Addresser.TryGetRam("ParticleTable_Start", ORom.FileList.code, version, out ParticleEffect_Ovl_Table);
            Addresser.TryGetRam("ObjectTable_Start", ORom.FileList.code, version, out Object_File_Table);


            Addresser.TryGetOffset("OBJ_ALLOC_TABLE", version, out temp);
            Object_Allocation_Table = GlobalContext.RelOff(temp);

            Addresser.TryGetOffset("ROOM_ALLOC_ADDR", version, out temp);
            Room_Allocation_Table = GlobalContext.RelOff(temp);


            Addresser.TryGetRam("SRAM_START", version, out temp);
            SaveContext = SPtr.New(temp);

            Addresser.TryGetRam("RAM_SEGMENT_TABLE", version, out temp);
            Segment_Table = temp;

            if (Addresser.TryGetRam("SceneTable_Start", version, out temp))
            {
                SceneTable = SPtr.New(temp);
            }
            else
            {
                SceneTable = null;
            }

            if (Addresser.TryGetRam("EntranceIndexTable_Start", version, out temp))
            {
                EntranceTable = SPtr.New(temp);
            }
            else
            {
                EntranceTable = null;
            }

            Addresser.TryGetRam("QUEUE_THREAD", version, out temp);
            Queue_Thread_Ptr = SPtr.New(temp);

            Addresser.TryGetRam("STACK_LIST", version, out temp);
            Stack_List_Ptr = SPtr.New(temp);
        }
コード例 #20
0
        public string GetPolyFormattedInfo(N64Ptr ptr)
        {
            CollisionPoly poly = new CollisionPoly(this, SPtr.New(ptr));

            return(poly.ToString());
        }
コード例 #21
0
ファイル: RamRoom.cs プロジェクト: laetemn/MasterOcarina
        public static RamRoom GetRoomInfo()
        {
            Ptr ptr = SPtr.New(Room_Alloc_Table);

            return(new RamRoom(ptr));
        }
コード例 #22
0
        public ActorInstance(RomVersion version, N64Ptr address)
        {
            int instanceSize;
            int off = 0;

            Ptr ptr = SPtr.New(address);


            ActorId = ptr.ReadUInt16(0);
            Type    = ptr.ReadByte(2);
            Room    = ptr.ReadByte(3);
            Address = address;

            try
            {
                if (version.Game == Game.OcarinaOfTime)
                {
                    if (ActorId == 0 && Type == 4)
                    {
                        ActorId       = 0x008F;
                        forcedActorId = true;
                    }
                }
                // & 0xFFF is hack to correct instances with no proper actor id
                instanceSize = OvlActor.GetInstanceSize(ActorId & 0xFFF);
            }
            catch
            {
                instanceSize = 0;
            }

            Ram = new N64PtrRange(Address, Address + instanceSize);


            Variable = ptr.ReadUInt16(0x1C);

            Position = new Vector3 <float>(
                ptr.ReadFloat(0x24),
                ptr.ReadFloat(0x28),
                ptr.ReadFloat(0x2C));


            if (version.Game == Game.OcarinaOfTime)
            {
                off = 0;
            }
            else
            {
                off = 8;
            }

            Rotation = new Vector3 <short>(
                ptr.ReadInt16(0xB4 + off),
                ptr.ReadInt16(0xB6 + off),
                ptr.ReadInt16(0xB8 + off));


            PrevActor = ptr.ReadInt32(0x120 + off);
            NextActor = ptr.ReadInt32(0x124 + off);

            ProcessInstance = ptr.ReadByte(0x115);
        }
コード例 #23
0
        internal static void ChangeVersion(RomVersion version, bool setGctx = true)
        {
            RomFileToken fileToken;

            //dma data
            fileToken = RomFileToken.Select(version, ORom.FileList.dmadata, MRom.FileList.dmadata);
            Addresser.TryGetRam(fileToken, version, out N64Ptr dmadataStart);
            Dmadata_Addr = SPtr.New(dmadataStart);

            //code
            fileToken = RomFileToken.Select(version, ORom.FileList.code, MRom.FileList.code);
            Addresser.TryGetRam(fileToken, version, out Code_Addr);
            Addresser.TryGetRom(fileToken, version, Code_Addr.Offset, out Code_VRom);


            int temp;

            //Global Context
            if (setGctx)
            {
                Addresser.TryGetRam(AddressToken.RAM_GLOBAL_CONTEXT, version, out temp);
                if (version == ORom.Build.IQUEC || version == ORom.Build.IQUET)
                {
                    GlobalContext = SPtr.New(temp);
                }
                else
                {
                    GlobalContext = SPtr.New(temp).Deref();
                }
            }

            SetGfxContext(version);

            //Heap
            Addresser.TryGetRam(AddressToken.RAM_ARENA_MAIN, version, out temp);
            Main_Heap_Ptr = SPtr.New(temp).Deref();

            Addresser.TryGetRam(AddressToken.RAM_ARENA_SCENES, version, out temp);
            Scene_Heap_Ptr = SPtr.New(temp).Deref();

            Addresser.TryGetRam(AddressToken.RAM_ARENA_DEBUG, version, out temp);
            if (temp == 0)
            {
                Debug_Heap_Ptr = SPtr.New(0);
            }
            else
            {
                Debug_Heap_Ptr = SPtr.New(temp).Deref();
            }


            Addresser.TryGetOffset(AddressToken.ACTOR_CAT_LL_Start, version, out temp);
            Actor_Category_Table = GlobalContext.RelOff(temp);

            //Overlay Tables
            Addresser.TryGetRam(AddressToken.ActorTable_Start, ORom.FileList.code, version, out Actor_Ovl_Table);
            Addresser.TryGetRam(AddressToken.PlayerPauseOverlayTable_Start, ORom.FileList.code, version, out Player_Pause_Ovl_Table);
            Addresser.TryGetRam(AddressToken.ParticleTable_Start, ORom.FileList.code, version, out ParticleEffect_Ovl_Table);
            Addresser.TryGetRam(AddressToken.ObjectTable_Start, ORom.FileList.code, version, out Object_File_Table);


            Addresser.TryGetOffset(AddressToken.OBJ_ALLOC_TABLE, version, out temp);
            Object_Allocation_Table = GlobalContext.RelOff(temp);

            Addresser.TryGetOffset(AddressToken.ROOM_ALLOC_ADDR, version, out temp);
            Room_Allocation_Table = GlobalContext.RelOff(temp);


            Addresser.TryGetRam(AddressToken.SRAM_START, version, out temp);
            SaveContext = SPtr.New(temp);

            Addresser.TryGetRam(AddressToken.RAM_SEGMENT_TABLE, version, out temp);
            Segment_Table = temp;

            if (Addresser.TryGetRam(AddressToken.SceneTable_Start, version, out temp))
            {
                SceneTable = SPtr.New(temp);
            }
            else
            {
                SceneTable = null;
            }

            if (Addresser.TryGetRam(AddressToken.EntranceIndexTable_Start, version, out temp))
            {
                EntranceTable = SPtr.New(temp);
            }
            else
            {
                EntranceTable = null;
            }

            Addresser.TryGetRam(AddressToken.QUEUE_THREAD, version, out temp);
            Queue_Thread_Ptr = SPtr.New(temp);

            Addresser.TryGetRam(AddressToken.STACK_LIST, version, out temp);
            Stack_List_Ptr = SPtr.New(temp);
        }
コード例 #24
0
 static SpectrumVariables()
 {
     GlobalContext = SPtr.New(0);
     SaveContext   = SPtr.New(0);
 }
コード例 #25
0
 public static void SetGfxContext(int addr)
 {
     Gfx = SPtr.New(addr);
 }