Esempio n. 1
0
        private void entityType_LostFocus(object sender, EventArgs e)
        {
            if (!entityType.IsHandleCreated)
            {
                return;
            }

            var chest = chestDataList[chestIndex];

            try
            {
                var type = Convert.ToByte(entityType.Text, 16);

                if (type == chest.type)
                {
                    return;
                }

                Project.Instance.AddPendingChange(new ChestDataChange(MainWindow.currentArea, MainWindow.currentRoom.Index));

                chest.type = type;
            }
            catch
            {
                entityType.Text = StringUtil.AsStringHex2(chest.type);
            }

            chestDataList[chestIndex] = chest;
        }
Esempio n. 2
0
        private void entityId_LostFocus(object sender, EventArgs e)
        {
            if (!entityId.IsHandleCreated)
            {
                return;
            }

            var chest = chestDataList[chestIndex];

            try
            {
                var chestId = Convert.ToByte(entityId.Text, 16);

                if (chestId == chest.chestId)
                {
                    return;
                }

                MainWindow.AddPendingChange(new ChestDataChange(MainWindow.currentArea, MainWindow.currentRoom.Index));

                chest.chestId = chestId;
            }
            catch
            {
                entityId.Text = StringUtil.AsStringHex2(chest.chestId);
            }
            chestDataList[chestIndex] = chest;
        }
Esempio n. 3
0
        private void RemoveButton_Click(object sender, EventArgs e)
        {
            if (chestDataList == null || chestDataList.Count <= 0)
            {
                return;
            }

            MainWindow.AddPendingChange(new ChestDataChange(MainWindow.currentArea, MainWindow.currentRoom.Index));
            MainWindow.currentRoom.RemoveChestData(chestDataList[chestIndex]);

            if (chestDataList.Count <= 0)
            {
                chestIndex           = -1;
                entityType.Enabled   = false;
                entityId.Enabled     = false;
                itemName.Enabled     = false;
                kinstoneType.Enabled = false;
                itemAmount.Enabled   = false;
                xPosition.Enabled    = false;
                yPosition.Enabled    = false;
                nextButton.Enabled   = false;
                prevButton.Enabled   = false;
                newButton.Visible    = true;
            }

            if (chestIndex >= chestDataList.Count)
            {
                chestIndex = chestDataList.Count - 1;
            }

            if (chestIndex < chestDataList.Count - 1)
            {
                nextButton.Enabled = true;
            }
            else
            {
                nextButton.Enabled = false;
            }

            if (chestIndex > 0)
            {
                prevButton.Enabled = true;
            }
            else
            {
                prevButton.Enabled = false;
            }

            if (chestIndex >= 0)
            {
                indexLabel.Text = StringUtil.AsStringHex2(chestIndex);
                LoadChestData(chestIndex);
            }
            else
            {
                indexLabel.Text = "";
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Uniformly fills items in locations, checking to make sure the items are logically available.
        /// </summary>
        /// <param name="items">The items to fill with</param>
        /// <param name="locations">The locations to be filled</param>
        /// <param name="assumedItems">The items that are available by default</param>
        /// <returns>A list of the locations that were filled</returns>
        private List <Location> FillLocations(List <Item> items, List <Location> locations, List <Item> assumedItems = null)
        {
            List <Location> filledLocations = new List <Location>();

            assumedItems = assumedItems ?? new List <Item>();

            for (int i = items.Count - 1; i >= 0; i--)
            {
                // Get a random item from the list and save its index
                int  itemIndex = RNG.Next(items.Count);
                Item item      = items[itemIndex];

                // Write placing information to spoiler log
                Console.WriteLine($"Placing: {item.Type.ToString()}");
                if (item.Type == ItemType.KinstoneX)
                {
                    Console.WriteLine($"Type: {item.Kinstone.ToString()}");
                }

                if (item.Dungeon != "")
                {
                    Console.WriteLine($"Dungeon: {item.Dungeon}");
                }

                // Take item out of pool
                items.RemoveAt(itemIndex);

                List <Item> availableItems = GetAvailableItems(items.Concat(assumedItems).ToList());

                // Find locations that are available for placing the item
                List <Location> availableLocations = locations.Where(location => location.CanPlace(item, availableItems, Locations)).ToList();

                if (availableLocations.Count <= 0)
                {
                    // The filler broke, show all available items and get out
                    availableItems.ForEach(itm => Console.WriteLine($"{itm.Type} sub {itm.SubValue}"));
                    throw new ShuffleException($"Could not place {item.Type}!");
                }

                int locationIndex = RNG.Next(availableLocations.Count);

                availableLocations[locationIndex].Fill(item);
                Console.WriteLine($"Placed {item.Type.ToString()} subtype {StringUtil.AsStringHex2(item.SubValue)} at {availableLocations[locationIndex].Name} with {items.Count} items remaining\n");

                locations.Remove(availableLocations[locationIndex]);

                filledLocations.Add(availableLocations[locationIndex]);

                // Location caches are no longer valid because available items have changed
                Locations.ForEach(location => location.InvalidateCache());
            }

            return(filledLocations);
        }
Esempio n. 5
0
        public void SetData(List <ChestData> data)
        {
            this.chestDataList = data;

            prevButton.Enabled = false;
            nextButton.Enabled = false;
            newButton.Enabled  = true;

            if (data.Count == 0)
            {
                chestIndex           = -1;
                entityType.Enabled   = false;
                entityId.Enabled     = false;
                itemName.Enabled     = false;
                kinstoneType.Enabled = false;
                itemAmount.Enabled   = false;
                xPosition.Enabled    = false;
                yPosition.Enabled    = false;
                nextButton.Enabled   = false;
                removeButton.Enabled = false;
            }
            else
            {
                entityType.Enabled   = true;
                entityId.Enabled     = true;
                itemName.Enabled     = true;
                kinstoneType.Enabled = true;
                itemAmount.Enabled   = true;
                xPosition.Enabled    = true;
                yPosition.Enabled    = true;
                removeButton.Enabled = true;
                chestIndex           = 0;

                LoadChestData(0);

                if (data.Count > 1)
                {
                    nextButton.Enabled = true;
                }
            }

            if (chestIndex >= 0)
            {
                indexLabel.Text = StringUtil.AsStringHex2(chestIndex);
            }
            else
            {
                indexLabel.Text = "";
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Write the define and item value to the event file
        /// </summary>
        /// <param name="w">A writer to the event stream</param>
        /// <param name="item">The item to write to the define</param>
        public void WriteDefine(StringBuilder stringBuilder, Item item)
        {
            if ((Type & AddressType.FirstByte) == AddressType.FirstByte)
            {
                // Write the hex representation of the item ID to the define
                Define.WriteDefineString(stringBuilder, "0x" + StringUtil.AsStringHex2((byte)item.Type));
            }

            if ((Type & AddressType.SecondByte) == AddressType.SecondByte)
            {
                // Write the hex representation of the subvalue
                // Probably a very bad thing if the first was also written, might kill EA
                Define.WriteDefineString(stringBuilder, "0x" + StringUtil.AsStringHex2(item.SubValue));
            }
        }
Esempio n. 7
0
        private void LoadChestData(int chest)
        {
            ChestData chestData = chestDataList[chest];

            entityType.Text = StringUtil.AsStringHex2(chestData.type);

            if ((TileEntityType)chestData.type == TileEntityType.Chest || (TileEntityType)chestData.type == TileEntityType.BigChest)
            {
                entityId.Text             = StringUtil.AsStringHex2(chestData.chestId);
                itemName.SelectedItem     = (ItemType)chestData.itemId;
                kinstoneType.SelectedItem = (KinstoneType)chestData.itemSubNumber;
                itemAmount.Text           = chestData.itemSubNumber.ToString();

                ushort chestPos = chestData.chestLocation;
                int    yPos     = chestPos >> 6;
                int    xPos     = chestPos - (yPos << 6);
                xPosition.Text = xPos.Hex();
                yPosition.Text = yPos.Hex();
                ((MainWindow)Application.OpenForms[0]).HighlightChest(xPos, yPos);
                itemName.Enabled     = true;
                kinstoneType.Enabled = true;
                itemAmount.Enabled   = true;
                xPosition.Enabled    = true;
                yPosition.Enabled    = true;
                entityId.Enabled     = true;
                unknown.Text         = chestData.unknown.Hex();
            }
            else
            {
                entityId.Text             = "00";
                itemName.SelectedItem     = ItemType.Untyped;
                kinstoneType.SelectedItem = KinstoneType.UnTyped;
                itemAmount.Text           = "0";
                xPosition.Text            = "0";
                yPosition.Text            = "0";
                ((MainWindow)Application.OpenForms[0]).HighlightChest(-1, -1);
                itemName.Enabled     = false;
                kinstoneType.Enabled = false;
                itemAmount.Enabled   = false;
                xPosition.Enabled    = false;
                yPosition.Enabled    = false;
                entityId.Enabled     = false;
            }
        }
Esempio n. 8
0
        private void prevButton_Click(object sender, EventArgs e)
        {
            chestIndex--;
            nextButton.Enabled = true;
            if (chestIndex == 0)
            {
                prevButton.Enabled = false;
            }

            if (chestIndex >= 0)
            {
                indexLabel.Text = StringUtil.AsStringHex2(chestIndex);
            }
            else
            {
                indexLabel.Text = "";
            }

            LoadChestData(chestIndex);
        }
Esempio n. 9
0
        private void LoadMaps()
        {
            mapManager_ = new MapManager();

            roomTreeView.Nodes.Clear();
            // Set up room list
            roomTreeView.BeginUpdate();
            int subsection = 0;

            foreach (MapManager.Area area in mapManager_.MapAreas)
            {
                var areaName = "Area " + StringUtil.AsStringHex2(area.Index);
                var areaKey  = new Tuple <int, int>(area.Index, -1);

                if (Project.Instance.roomNames.ContainsKey(areaKey))
                {
                    areaName = Project.Instance.roomNames[areaKey];
                }

                var areaNode = roomTreeView.Nodes.Add(areaName);
                areaNode.Name = StringUtil.AsStringHex(area.Index, 1);

                foreach (Room room in area.Rooms)
                {
                    var roomName = "Room " + StringUtil.AsStringHex2(room.Index);
                    var roomKey  = new Tuple <int, int>(area.Index, room.Index);

                    if (Project.Instance.roomNames.ContainsKey(roomKey))
                    {
                        roomName = Project.Instance.roomNames[roomKey];
                    }

                    var roomNode = areaNode.Nodes.Add(roomName);
                    roomNode.Name = StringUtil.AsStringHex(room.Index, 1);
                }

                subsection++;
            }

            roomTreeView.EndUpdate();
        }
Esempio n. 10
0
        private void newButton_Click(object sender, EventArgs e)
        {
            if (chestDataList == null)
            {
                return;
            }

            chestIndex = chestDataList.Count;

            indexLabel.Text = StringUtil.AsStringHex2(chestIndex);

            MainWindow.AddPendingChange(new ChestDataChange(MainWindow.currentArea, MainWindow.currentRoom.Index));
            MainWindow.currentRoom.AddChestData(new ChestData(0x02, 0, 0, 0, 0, 0));
            LoadChestData(chestIndex);

            // Don't enable the previous button if there weren't previously any chests
            if (chestDataList.Count > 1)
            {
                prevButton.Enabled = true;
            }

            nextButton.Enabled = false;
        }
Esempio n. 11
0
        private void LoadMaps()
        {
            mapManager_ = new MapManager();

            roomTreeView.Nodes.Clear();
            // Set up room list
            roomTreeView.BeginUpdate();
            int subsection = 0;

            foreach (MapManager.Area area in mapManager_.MapAreas)
            {
                roomTreeView.Nodes.Add("Area " + StringUtil.AsStringHex2(area.Index));

                foreach (Room room in area.Rooms)
                {
                    roomTreeView.Nodes[subsection].Nodes.Add("Room " + StringUtil.AsStringHex2(room.Index));
                }

                subsection++;
            }

            roomTreeView.EndUpdate();
        }
Esempio n. 12
0
 public override string GetFolderLocation()
 {
     return("/Area " + StringUtil.AsStringHex2(areaId) + "/Room " + StringUtil.AsStringHex2(roomId));
 }
Esempio n. 13
0
        private void LoadMetaData(int areaIndex, int roomIndex)
        {
            areaPath = Project.Instance.projectPath + "/Areas/Area " + StringUtil.AsStringHex2(areaIndex);
            roomPath = areaPath + "/Room " + StringUtil.AsStringHex2(roomIndex);

            var r      = ROM.Instance.reader;
            var header = ROM.Instance.headers;

            int areaRMDTableLoc      = r.ReadAddr(header.MapHeaderBase + (areaIndex << 2));
            int roomMetaDataTableLoc = areaRMDTableLoc + (roomIndex * 0x0A);

            this.mapPosX = r.ReadUInt16(roomMetaDataTableLoc) >> 4;
            this.mapPosY = r.ReadUInt16() >> 4;
            this.width   = r.ReadUInt16() >> 4;           //bytes 5+6 pixels/16 = tiles
            this.height  = r.ReadUInt16() >> 4;           //bytes 7+8 pixels/16 = tiles

            //get addr of TPA data
            int tileSetOffset = r.ReadUInt16() << 2;                                //bytes 9+10

            int areaTileSetTableLoc = r.ReadAddr(header.globalTileSetTableLoc + (areaIndex << 2));
            int roomTileSetLoc      = r.ReadAddr(areaTileSetTableLoc + tileSetOffset);

            r.SetPosition(roomTileSetLoc);

            ParseData(r, Set1);

            //metatiles
            int metaTileSetsLoc = r.ReadAddr(header.globalMetaTileSetTableLoc + (areaIndex << 2));

            r.SetPosition(metaTileSetsLoc);

            ParseData(r, Set2);

            //get addr of room data
            int areaTileDataTableLoc = r.ReadAddr(header.globalTileDataTableLoc + (areaIndex << 2));
            int tileDataLoc          = r.ReadAddr(areaTileDataTableLoc + (roomIndex << 2));

            r.SetPosition(tileDataLoc);

            ParseData(r, Set3);

            //attempt at obtaining chest data (+various)
            int areaEntityTableAddrLoc = header.AreaMetadataBase + (areaIndex << 2);
            int areaEntityTableAddr    = r.ReadAddr(areaEntityTableAddrLoc);

            int roomEntityTableAddrLoc = areaEntityTableAddr + (roomIndex << 2);
            int roomEntityTableAddr    = r.ReadAddr(roomEntityTableAddrLoc);

            //4 byte chunks, 1-3 are unknown use, 4th seems to be chests
            string chestDataPath = roomPath + "/" + DataType.chestData + "Dat.bin";

            if (File.Exists(chestDataPath))
            {
                byte[] data  = File.ReadAllBytes(chestDataPath);
                int    index = 0;
                while (index < data.Length && (TileEntityType)data[index] != TileEntityType.None)
                {
                    var    type   = data[index];
                    var    id     = data[index + 1];
                    var    item   = data[index + 2];
                    var    subNum = data[index + 3];
                    ushort loc    = (ushort)(data[index + 4] | (data[index + 5] << 8));
                    ushort other  = (ushort)(data[index + 6] | (data[index + 7] << 8));
                    chestInformation.Add(new ChestData(type, id, item, subNum, loc, other));
                    index += 8;
                }
            }
            else
            {
                int chestTableAddr = r.ReadAddr(roomEntityTableAddr + 12);

                var data = r.ReadBytes(8, chestTableAddr);

                while ((TileEntityType)data[0] != TileEntityType.None) //ends on type 0
                {
                    var    type   = data[0];
                    var    id     = data[1];
                    var    item   = data[2];
                    var    subNum = data[3];
                    ushort loc    = (ushort)(data[4] | (data[5] << 8));
                    ushort other  = (ushort)(data[6] | (data[7] << 8));
                    chestInformation.Add(new ChestData(type, id, item, subNum, loc, other));
                    data = r.ReadBytes(8);
                }
            }
        }
Esempio n. 14
0
        public void LoadArea(int areaId)
        {
            loading        = true;
            areaLabel.Text = "Area: " + areaId.Hex();
            mapX.Text      = "FFF";
            mapY.Text      = "FFF";
            roomLabel.Text = "Selected Room: -";
            mapX.Enabled   = false;
            mapY.Enabled   = false;

            canFlute.Enabled   = true;
            dungeonMap.Enabled = true;
            moleCave.Enabled   = true;
            redName.Enabled    = true;
            keysShown.Enabled  = true;

            areaSongId.Enabled = true;

            roomRects.Clear();

            currentArea = areaId;
            var maps = MapManager.Instance.MapAreas;

            MapManager.Area area = maps.Single(a => a.Index == currentArea);
            var             spot = maps.IndexOf(area);

            var data = new byte[4];

            var    areaPath     = Project.Instance.projectPath + "/Areas/Area " + StringUtil.AsStringHex2(areaId);
            string areaInfoPath = areaPath + "/" + DataType.areaInfo + "Dat.bin";

            if (!area.areaInfo.SequenceEqual(new byte[] { 0, 0, 0, 0 }))//already a value loaded in
            {
                data = area.areaInfo;
            }
            if (File.Exists(areaInfoPath))
            {
                data          = File.ReadAllBytes(areaInfoPath);
                area.areaInfo = data;
                maps[spot]    = area;
            }
            else
            {
                var reader  = ROM.Instance.reader;
                var dataloc = ROM.Instance.headers.areaInformationTableLoc + areaId * 4;
                reader.SetPosition(dataloc);
                data = reader.ReadBytes(4);

                area.areaInfo = data;
                maps[spot]    = area;

                //Console.WriteLine(dataloc.Hex());
                //Console.WriteLine(data[0]);
            }

            canFlute.Checked = (data[0] % 2 == 1);//bit 1

            data[0]           = (byte)(data[0] >> 1);
            keysShown.Checked = (data[0] % 2 == 1);//bit 2

            data[0]         = (byte)(data[0] >> 1);
            redName.Checked = (data[0] % 2 == 1);//bit 4

            data[0]            = (byte)(data[0] >> 1);
            dungeonMap.Checked = (data[0] % 2 == 1);//bit 8

            data[0]  = (byte)(data[0] >> 1);
            unknown1 = (byte)(data[0] % 2);//bit 10 //currently unknown use

            data[0]          = (byte)(data[0] >> 1);
            moleCave.Checked = (data[0] % 2 == 1);//bit 20

            data[0]  = (byte)(data[0] >> 1);
            unknown2 = (byte)(data[0] % 2);//bit 40 //unknown

            data[0]          = (byte)(data[0] >> 1);
            canFlute.Checked = (data[0] % 2 == 1 || canFlute.Checked);//bit 80 //unused in eur, seems to be same as bit 1?

            areaNameId.Text = data[1].Hex();

            flagOffset = data[2];

            areaSongId.Text = data[3].Hex();

            biggestX = 0;
            biggestY = 0;

            foreach (var room in area.Rooms)
            {
                var rect = room.GetMapRect(areaId);
                roomRects.Add(room.Index, rect);

                if (rect.Bottom > biggestY)
                {
                    biggestY = rect.Bottom;
                }

                if (rect.Right > biggestX)
                {
                    biggestX = rect.Right;
                }
            }
            DrawRects();
            //modify text

            loading = false;
        }
Esempio n. 15
0
        private void LoadMetaData(int areaIndex, int roomIndex)
        {
            areaPath = Project.Instance.projectPath + "/Areas/Area " + StringUtil.AsStringHex2(areaIndex);
            roomPath = areaPath + "/Room " + StringUtil.AsStringHex2(roomIndex);

            var r      = ROM.Instance.reader;
            var header = ROM.Instance.headers;

            int areaRMDTableLoc      = r.ReadAddr(header.MapHeaderBase + (areaIndex << 2));
            int roomMetaDataTableLoc = areaRMDTableLoc + (roomIndex * 0x0A);

            if (File.Exists(roomPath + "/" + DataType.roomMetaData + "Dat.bin"))
            {
                var data = File.ReadAllBytes(roomPath + "/" + DataType.roomMetaData + "Dat.bin");
                this.mapPosX = (data[0] + (data[1] << 8)) >> 4;
                this.mapPosY = (data[2] + (data[3] << 8)) >> 4;

                if (data.Length == 4) //backwards compatibility because WHY DIDNT I SAVE IT ALL AT FIRST
                {
                    this.width    = r.ReadUInt16();
                    this.height   = r.ReadUInt16();
                    tileSetOffset = r.ReadUInt16();
                }
                else
                {
                    this.width    = (data[4] + (data[5] << 8));
                    this.height   = (data[6] + (data[7] << 8));
                    tileSetOffset = (data[8] + (data[9] << 8));
                }
                r.SetPosition(roomMetaDataTableLoc + 8);
            }
            else
            {
                this.mapPosX  = r.ReadUInt16(roomMetaDataTableLoc) >> 4;
                this.mapPosY  = r.ReadUInt16() >> 4;
                this.width    = r.ReadUInt16();
                this.height   = r.ReadUInt16();
                tileSetOffset = r.ReadUInt16();
            }

            //get addr of TPA data

            int areaTileSetTableLoc = r.ReadAddr(header.globalTileSetTableLoc + (areaIndex << 2));
            int roomTileSetLoc      = r.ReadAddr(areaTileSetTableLoc + (tileSetOffset << 2));

            r.SetPosition(roomTileSetLoc);

            ParseData(r, Set1);

            //metatiles
            int metaTileSetsLoc = r.ReadAddr(header.globalMetaTileSetTableLoc + (areaIndex << 2));

            r.SetPosition(metaTileSetsLoc);

            ParseData(r, Set2);

            //get addr of room data
            int areaTileDataTableLoc = r.ReadAddr(header.globalTileDataTableLoc + (areaIndex << 2));
            int tileDataLoc          = r.ReadAddr(areaTileDataTableLoc + (roomIndex << 2));

            r.SetPosition(tileDataLoc);

            ParseData(r, Set3);

            //attempt at obtaining chest data (+various)
            int areaEntityTableAddrLoc = header.AreaMetadataBase + (areaIndex << 2);
            int areaEntityTableAddr    = r.ReadAddr(areaEntityTableAddrLoc);

            int roomEntityTableAddrLoc = areaEntityTableAddr + (roomIndex << 2);
            int roomEntityTableAddr    = r.ReadAddr(roomEntityTableAddrLoc);

            int areaWarpTableAddrLoc = header.warpInformationTableLoc + (areaIndex << 2);
            int areaWarpTableAddr    = r.ReadAddr(areaWarpTableAddrLoc);

            int roomWarpTableAddrLoc = areaWarpTableAddr + (roomIndex << 2);

            LoadGroup(r, roomEntityTableAddr, 0xFF, DataType.list1Data, 0x10, List1Binding);
            LoadGroup(r, roomEntityTableAddr + 4, 0xFF, DataType.list2Data, 0x10, List2Binding);
            LoadGroup(r, roomEntityTableAddr + 8, 0xFF, DataType.list3Data, 0x10, List3Binding);

            LoadGroup(r, roomEntityTableAddr + 12, 0x0, DataType.chestData, 0x08, ChestBinding);
            //technically not a group but should work with the function
            LoadGroup(r, roomWarpTableAddrLoc, 0xFF, DataType.warpData, 20, WarpBinding);
        }