private static void WriteMapObjects(byte[] Map, int Addr, List <int> Objects) { for (int i = 0; i < Objects.Count; i++) { ReadWriteUtils.Arr_WriteU16(Map, Addr + (i * 2), (ushort)Objects[i]); } }
public static void WriteCutsceneExits(int sceneNumber, byte setupIndex, byte cutsceneIndex, ushort spawnId) { Scene scene = RomData.SceneList.Single(u => u.Number == sceneNumber); int f = scene.File; var setup = scene.Setups[setupIndex]; if (setup.CutsceneListAddress == null) { return; } ReadWriteUtils.Arr_WriteU16(RomData.MMFileList[f].Data, setup.CutsceneListAddress.Value + cutsceneIndex * 8 + 4, spawnId); }
private static void WriteMapActors(byte[] Map, int Addr, List <Actor> Actors) { for (int i = 0; i < Actors.Count; i++) { ReadWriteUtils.Arr_WriteU16(Map, Addr + (i * 16), (ushort)(Actors[i].m | Actors[i].n)); ReadWriteUtils.Arr_WriteU16(Map, Addr + (i * 16) + 2, (ushort)Actors[i].p.x); ReadWriteUtils.Arr_WriteU16(Map, Addr + (i * 16) + 4, (ushort)Actors[i].p.y); ReadWriteUtils.Arr_WriteU16(Map, Addr + (i * 16) + 6, (ushort)Actors[i].p.z); ReadWriteUtils.Arr_WriteU16(Map, Addr + (i * 16) + 8, (ushort)Actors[i].r.x); ReadWriteUtils.Arr_WriteU16(Map, Addr + (i * 16) + 10, (ushort)Actors[i].r.y); ReadWriteUtils.Arr_WriteU16(Map, Addr + (i * 16) + 12, (ushort)Actors[i].r.z); ReadWriteUtils.Arr_WriteU16(Map, Addr + (i * 16) + 14, (ushort)Actors[i].v); } }
public static void WriteSceneExits(int sceneNumber, byte exitIndex, ushort spawnId) { Scene scene = RomData.SceneList.Single(u => u.Number == sceneNumber); int f = scene.File; if (scene.Setups.Count > 1) { Debug.WriteLine(scene.Number); } foreach (var setup in scene.Setups) { if (setup.ExitListAddress == null) { continue; } ReadWriteUtils.Arr_WriteU16(RomData.MMFileList[f].Data, setup.ExitListAddress.Value + exitIndex * 2, spawnId); } }
public static void WriteNewItem(ItemObject itemObject, List <MessageEntry> newMessages, GameplaySettings settings, ChestTypeAttribute.ChestType?overrideChestType, MessageTable messageTable, ExtendedObjects extendedObjects) { var item = itemObject.Item; var location = itemObject.NewLocation.Value; System.Diagnostics.Debug.WriteLine($"Writing {item.Name()} --> {location.Location()}"); if (!itemObject.IsRandomized) { var indices = location.GetCollectableIndices(); if (indices.Any()) { foreach (var collectableIndex in location.GetCollectableIndices()) { ReadWriteUtils.Arr_WriteU16(RomData.MMFileList[COLLECTABLE_TABLE_FILE_INDEX].Data, collectableIndex * 2, 0); } return; } } int f = RomUtils.GetFileIndexForWriting(GET_ITEM_TABLE); int baseaddr = GET_ITEM_TABLE - RomData.MMFileList[f].Addr; var getItemIndex = location.GetItemIndex().Value; int offset = (getItemIndex - 1) * 8 + baseaddr; var fileData = RomData.MMFileList[f].Data; GetItemEntry newItem; if (!itemObject.IsRandomized && location.IsNullableItem()) { newItem = new GetItemEntry(); } else if (item.IsExclusiveItem()) { newItem = item.ExclusiveItemEntry(); } else { newItem = RomData.GetItemList[item.GetItemIndex().Value]; } // Attempt to resolve extended object Id, which should affect "Exclusive Items" as well. var graphics = extendedObjects.ResolveGraphics(newItem); if (graphics.HasValue) { newItem.Object = graphics.Value.objectId; newItem.Index = graphics.Value.graphicId; } var data = new byte[] { newItem.ItemGained, newItem.Flag, newItem.Index, newItem.Type, (byte)(newItem.Message >> 8), (byte)(newItem.Message & 0xFF), (byte)(newItem.Object >> 8), (byte)(newItem.Object & 0xFF), }; ReadWriteUtils.Arr_Insert(data, 0, data.Length, fileData, offset); int?refillGetItemIndex = item switch { Item.ItemBottleMadameAroma => 0x91, Item.ItemBottleAliens => 0x92, _ => null, }; if (refillGetItemIndex.HasValue) { var refillItem = RomData.GetItemList[refillGetItemIndex.Value]; var refillGraphics = extendedObjects.ResolveGraphics(refillItem); if (refillGraphics.HasValue) { refillItem.Object = refillGraphics.Value.objectId; refillItem.Index = refillGraphics.Value.graphicId; } var refillData = new byte[] { refillItem.ItemGained, refillItem.Flag, refillItem.Index, refillItem.Type, (byte)(refillItem.Message >> 8), (byte)(refillItem.Message & 0xFF), (byte)(refillItem.Object >> 8), (byte)(refillItem.Object & 0xFF), }; var refillOffset = (refillGetItemIndex.Value - 1) * 8 + baseaddr; ReadWriteUtils.Arr_Insert(refillData, 0, refillData.Length, fileData, refillOffset); } if (location.IsRupeeRepeatable()) { settings.AsmOptions.MMRConfig.RupeeRepeatableLocations.Add(getItemIndex); } var isRepeatable = item.IsRepeatable(settings) || (!settings.PreventDowngrades && item.IsDowngradable()); if (settings.ProgressiveUpgrades && item.HasAttribute <ProgressiveAttribute>()) { isRepeatable = false; } if (item.IsReturnable(settings)) { isRepeatable = false; settings.AsmOptions.MMRConfig.ItemsToReturnIds.Add(getItemIndex); } if (!isRepeatable) { SceneUtils.UpdateSceneFlagMask(getItemIndex); } if (settings.UpdateChests) { UpdateChest(location, item, overrideChestType); } if (settings.UpdateShopAppearance) { UpdateShop(itemObject, newMessages, messageTable); } if (itemObject.IsRandomized) { var hackContentAttributes = location.GetAttributes <HackContentAttribute>(); if (location == item) { hackContentAttributes = hackContentAttributes.Where(h => !h.ApplyOnlyIfItemIsDifferent); } foreach (var hackContent in hackContentAttributes.Select(h => h.HackContent)) { ResourceUtils.ApplyHack(hackContent); } } }
public static void UpdateKafeiTunic(ref byte[] objectData, Color targetColor) { int[] kafeiPaletteAddress = new int[] { 0xB538, 0xDF68, 0xDF68, 0xD1B0 }; int[] hairPaletteAvoid = new int[] { 0, 4, 5, 6, 7, 9, 0xB, 0x14, 0x17, 0x18, 0x22, 0x23, 0x31, 0x32, 0x3E, 0x6B, 0x71, 0x8E, 0x100 }; var averageColour = new Color(); for (int i = 0; i < 4; i++) { var colourMask = new bool[0x100]; var coloursFound = new Color[0x100]; var k = 0; for (int j = 0; j < 0x100; j++) { var thisColour = ColorUtils.FromRGBA5551(ReadWriteUtils.Arr_ReadU16(objectData, kafeiPaletteAddress[i] + (j << 1))); // separate palette colours used for hair/clothes or they won't adjust very well if (i == 1) { if (j == hairPaletteAvoid[k]) { colourMask[j] = true; coloursFound[k] = thisColour; k++; } ; } else if (i == 2) { if (j != hairPaletteAvoid[j - k]) { colourMask[j] = true; coloursFound[k] = thisColour; k++; } ; } else if ((thisColour.B != 0) && ((thisColour.G == 0) || ((i != 0) && (thisColour.B > thisColour.G) && (thisColour.B > thisColour.R) && (thisColour.B + thisColour.R > 2.2 * thisColour.G)))) { colourMask[j] = true; coloursFound[k] = thisColour; k++; } ; } ; if (i != 1) { averageColour = ColorUtils.GetAverageColour(coloursFound, k); } ; coloursFound = ShiftHue(coloursFound, targetColor, k, averageColour); k = 0; for (int j = 0; j < 0x100; j++) { if (colourMask[j]) { ReadWriteUtils.Arr_WriteU16(objectData, kafeiPaletteAddress[i] + (j << 1), ColorUtils.ToRGBA5551(coloursFound[k])); k++; } } } }