private static void WriteColours(int fileNumber, int addressInFile, int count, Color[] colorArray) { for (int i = 0; i < count; i++) { int colorAddress = addressInFile + (i * 2); ushort rgba = ColorUtils.ToRGBA5551(colorArray[i]); var data = new byte[] { (byte)(rgba >> 8), (byte)(rgba & 0xFF), }; ReadWriteUtils.Arr_Insert(data, 0, data.Length, RomData.MMFileList[fileNumber].Data, colorAddress); } }
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++; } } } }