Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef unsigned char u8;
- typedef unsigned short u16;
- typedef unsigned int u32;
- enum class DesignType : u8 {
- DressLongSleeve = 0,
- DressShortSleeve = 1,
- DressSleeveless = 2,
- ShirtLongSleeve = 3,
- ShirtShortSleeve = 4,
- ShirtSleeveless = 5,
- HornedHat = 6,
- KnitHat = 7,
- PhotoBoard = 8,
- Pattern = 9
- };
- static const u16 word_88EA5C[12] = {0x1000, 0xE00, 0xC00, 0xC00, 0xA00, 0x800, 0x400, 0x400, 0xB81, 0x400, 0x400, 0x400};
- static const u8 byte_88E754[8] = {0, 0, 0, 0x20, 0x20, 0, 0x20, 0x20};
- static const u32 dword_88E85C[128] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x3FC00000, 0xFFF80000, 0xFFFE0000, 0xFFFF0000, 0xFFFF8000, 0xFFFFC000,
- 0xFFFFC000, 0xFFFFE000, 0xFFFFE000, 0xFFFFE000, 0xFFFFE000, 0xFFFFE000, 0xFFFFC000, 0xFFFFC000, 0xFFFF8000,
- 0xFFFF0000, 0xFFFC0000, 0xFFF00000, 0x1F800000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 0xF, 0x1F, 0x3F, 0x3F, 0x7F, 0x7F, 0x7F,
- 0x7F, 0x7F, 0x3F, 0x1F, 0x1F, 0xF, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0
- };
- static const u8 byte_88E75C[256] = {
- 0x0A, 0x0A, 0x0A, 0x0A, 0x02, 0x08, 0x08, 0x02, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0A, 0x0A, 0x02, 0x02,
- 0x02, 0x09, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0B, 0x01, 0x03, 0x03, 0x03, 0x09, 0x03, 0x09,
- 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x09, 0x09, 0x09, 0x09, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x0B, 0x0A, 0x08, 0x08, 0x08, 0x08, 0x0B, 0x08, 0x08, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B,
- 0x0A, 0x0A, 0x08, 0x0A, 0x0A, 0x0B, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B, 0x0E, 0x09, 0x09, 0x09,
- 0x09, 0x09, 0x09, 0x07, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x09, 0x09,
- 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x07, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x0B, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B,
- 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B, 0x04, 0x04, 0x04, 0x04,
- 0x04, 0x0B, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B, 0x0D, 0x0D, 0x05, 0x0D, 0x05, 0x05, 0x05, 0x05,
- 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x05, 0x05, 0x07, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x07, 0x04, 0x04, 0x04, 0x04, 0x0D, 0x0B, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07,
- 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
- };
- u8 PatternUnknownSetter(Pattern* pattern) {
- u8 result = 0;
- u8 oldChecksum = 0;
- u16 patternTypeModifierValue = word_88EA5C[pattern->Type];
- u16 tempBuffer[16]; // Each palette index (0 - 0xFF) has an entry in @byte_88E75C. This tempBuffer increments one of its values based on the palette index's offset value in that byte array.
- if (pattern->Type == DesignType::PhotoBoard) {
- for (u32 patternEntry = 0; patternEntry < 4; patternEntry++) {
- for (u32 y = 0; y < 32; y++) {
- for (u32 x = 0; x < 32; x++) {
- if (byte_88E754[2 * patternEntry] + x < 0x34 && !(dword_88E85C[y + 32 * patternEntry] & (1 << x))) {
- u32 patternPixelPaletteIndex = (*(u32*) pattern->PatternData[4 * (((patternEntry * 0x80) & 0x1FF) + 4 * ((y & 0x1F) / 8))] >> (4 * x & 0x1F);
- if (patternPixelPaletteIndex == 0xF) {
- patternPixelPaletteIndex = 0;
- }
- tempBuffer[byte_88E75C[pattern->Palette[patternPixelPaletteIndex]]]++;
- }
- }
- }
- }
- }
- // TODO: Other Pattern types
- // Process the temp buffer.
- // Grab the index with the highest occurrance.
- u32 mostOccurredIdx = 0;
- for (u32 i = 0; i < 15; i++) {
- if (tempBuffer[i] > tempBuffer[mostOccurredIdx]) {
- mostOccurredIdx = i;
- }
- }
- // Grab the second most occurring index.
- u32 secondMostOccurredIndex = 0;
- for (u32 i = 0; i < 15; i++) {
- if (i != mostOccurredIdx && tempBuffer[i] > tempBuffer[secondMostOccurredIndex]) {
- secondMostOccurredIndex = i;
- }
- }
- u16* mostOccurredPtr = &tempBuffer[mostOccurredIdx];
- u16 mostOccurredValue = tempBuffer[mostOccurredIdx];
- float patternTypeThreshold = (float) patternTypeModifierValue * 0.9f;
- // Clamp pattern type modifier value to minimum. That's what the COERCE_SIGNED_INT is doing. It's some way to check the precision of the floating point value.
- if (patternTypeThreshold <= 0.0002) {
- patternTypeThreshold = 0.0002;
- }
- float patternTypeThreshold2 = (float) patternTypeModifierValue * 0.35f;
- if (patternTypeThreshold2 < 0.0002) {
- patternTypeThreshold2 = 0.0002;
- }
- if ((float) mostOccurredValue < patternTypeThreshold) {
- if ((float) mostOccurredValue < patternTypeThreshold2) {
- oldChecksum = pattern->Checksum;
- result = 0xCC; // Default checksum?
- }
- else {
- pattern->Checksum = pattern->Checksum & 0xF0 | mostOccurredIdx & 0x0F;
- u8 lowerChecksumNibble = pattern->Checksum & 0x0F;
- float secondMostOccurranceThreshold = (float) (patternTypeModifierValue - mostOccurredValue) * 0.6f;
- if (secondMostOccurranceThreshold < 0.0002) {
- secondMostOccurranceThreshold = 0.0002;
- }
- if ((float) tempBuffer[secondMostOccurredIndex] < secondMostOccurranceThreshold) {
- result = 0xC0 | lowerChecksumNibble; // could be simplified to result = 0xC0 | (mostOccurredIdx & 0xF);
- }
- else {
- result = ((secondMostOccurredIndex & 0x0F) << 4) | lowerChecksumNibble; // Again could be simplified to: ((secondMostOccurredIndex & 0x0F) << 4) | (mostOccurredIdx & 0xF);
- }
- }
- }
- else {
- result = (pattern->Checksum & 0xF0 | mostOccurredValue) & 0xF | ((mostOccurredValue & 0xF) << 4);
- }
- Pattern->Checksum = result;
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement