Mercurial > mm7
changeset 700:1d05543f522d
Some occasional crashes in PaletteManager and sprite loading fixed.
author | Nomad |
---|---|
date | Sun, 17 Mar 2013 22:46:18 +0200 |
parents | 0c6510a626e2 |
children | d5b16a44d9b3 a5ee769b02c6 |
files | LOD.cpp PaletteManager.cpp PaletteManager.h Sprites.cpp mm7_2.cpp |
diffstat | 5 files changed, 268 insertions(+), 209 deletions(-) [+] |
line wrap: on
line diff
--- a/LOD.cpp Sun Mar 17 18:32:09 2013 +0400 +++ b/LOD.cpp Sun Mar 17 22:46:18 2013 +0200 @@ -251,7 +251,7 @@ } } - if (uNumLoadedSprites == 1500 ) + if (uNumLoadedSprites >= 1500 ) return -1; //if not loaded - load from file @@ -275,7 +275,8 @@ sprite_file = FindContainer(pContainerName, 0); if ( !sprite_file ) return -1; - fread(&temp_sprite_hdr, 1, sizeof(LODSprite), sprite_file); + //fread(&temp_sprite_hdr, 1, sizeof(LODSprite), sprite_file); + fread(&temp_sprite_hdr, 1, 0x20, sprite_file); pHardwareSprites[uNumLoadedSprites].uBufferWidth = temp_sprite_hdr.uWidth; pHardwareSprites[uNumLoadedSprites].uBufferHeight = temp_sprite_hdr.uHeight; pSpriteHeaders[uNumLoadedSprites].uWidth = temp_sprite_hdr.uWidth;
--- a/PaletteManager.cpp Sun Mar 17 18:32:09 2013 +0400 +++ b/PaletteManager.cpp Sun Mar 17 22:46:18 2013 +0200 @@ -1,7 +1,10 @@ +#include <assert.h> + #include "PaletteManager.h" #include "Texture.h" #include "Game.h" #include "LOD.h" +#include "Log.h" #include "mm7_data.h" @@ -244,41 +247,41 @@ //----- (00489BE0) -------------------------------------------------------- -int PaletteManager::CalcPalettes_LUT(int a2) +void PaletteManager::CalcPalettes_LUT(int a2) { PaletteManager *v2; // esi@1 - char *v3; // edi@1 - signed int v4; // ebx@4 - float v5; // ST08_4@5 - float v6; // ST04_4@5 - float v7; // ST00_4@5 - int v8; // eax@7 - float *v9; // edx@8 - float *v10; // ST0C_4@8 - float *v11; // ecx@8 - int v12; // ebx@8 - int v13; // eax@8 - float v14; // ebx@8 + //char *v3; // edi@1 + //signed int v4; // ebx@4 + //float v5; // ST08_4@5 + //float v6; // ST04_4@5 + //float v7; // ST00_4@5 + //int v8; // eax@7 + //float *v9; // edx@8 + //float *v10; // ST0C_4@8 + //float *v11; // ecx@8 + //int v12; // ebx@8 + //int v13; // eax@8 + //float v14; // ebx@8 float v15; // ST08_4@8 float v16; // ST04_4@8 float v17; // ST00_4@8 - unsigned __int8 v18; // sf@8 - unsigned __int8 v19; // of@8 - int v20; // eax@10 + //unsigned __int8 v18; // sf@8 + //unsigned __int8 v19; // of@8 + //int v20; // eax@10 double v21; // st5@11 - float v22; // ST0C_4@13 + //float v22; // ST0C_4@13 unsigned int v23; // eax@13 - __int16 v24; // bx@16 - int v25; // eax@16 + //__int16 v24; // bx@16 + //int v25; // eax@16 double v26; // st7@20 - float v27; // ST0C_4@22 + //float v27; // ST0C_4@22 unsigned int v28; // eax@22 - __int16 v29; // bx@25 - __int16 *v30; // eax@25 - int v31; // eax@27 + //__int16 v29; // bx@25 + //__int16 *v30; // eax@25 + //int v31; // eax@27 double v32; // st5@28 - float v33; // ST0C_4@30 - float v34; // ST08_4@30 + //float v33; // ST0C_4@30 + //float v34; // ST08_4@30 unsigned int v35; // ebx@30 signed __int64 v36; // qax@33 signed int v37; // edx@33 @@ -287,15 +290,15 @@ signed int v40; // edi@33 unsigned int v41; // ecx@33 unsigned int v42; // ecx@35 - int v43; // eax@39 + //int v43; // eax@39 signed int v44; // edx@39 - unsigned __int8 v45; // al@40 - double v46; // st6@43 - signed int v47; // eax@43 - int v48; // eax@45 + //unsigned __int8 v45; // al@40 + //double v46; // st6@43 + //signed int v47; // eax@43 + //int v48; // eax@45 double v49; // st6@47 - float v50; // ST08_4@49 - unsigned int v51; // ebx@49 + //float v50; // ST08_4@49 + //unsigned int v51; // ebx@49 int v52; // edi@55 int v53; // ebx@55 signed __int64 v54; // qax@55 @@ -306,59 +309,68 @@ unsigned int v59; // ecx@61 unsigned int v60; // eax@63 char v61; // cl@63 - int result; // eax@63 + //int result; // eax@63 float v63[256]; // [sp+1Ch] [bp-C38h]@5 float v64[256]; // [sp+41Ch] [bp-838h]@5 - int a6[256]; // [sp+81Ch] [bp-438h]@5 + float a6[256]; // [sp+81Ch] [bp-438h]@5 int v66; // [sp+C1Ch] [bp-38h]@43 float v67; // [sp+C20h] [bp-34h]@43 float v68; // [sp+C24h] [bp-30h]@43 - PaletteManager *v69; // [sp+C28h] [bp-2Ch]@9 - float v70; // [sp+C2Ch] [bp-28h]@43 - double v71; // [sp+C30h] [bp-24h]@10 - int v72; // [sp+C38h] [bp-1Ch]@9 - int v73; // [sp+C3Ch] [bp-18h]@9 - int i; // [sp+C40h] [bp-14h]@7 - float v75; // [sp+C44h] [bp-10h]@5 + //PaletteManager *v69; // [sp+C28h] [bp-2Ch]@9 + //float v70; // [sp+C2Ch] [bp-28h]@43 + //double v71; // [sp+C30h] [bp-24h]@10 + //int v72; // [sp+C38h] [bp-1Ch]@9 + //int v73; // [sp+C3Ch] [bp-18h]@9 + //int i; // [sp+C40h] [bp-14h]@7 + //float v75; // [sp+C44h] [bp-10h]@5 float a2a; // [sp+C48h] [bp-Ch]@13 float a1; // [sp+C4Ch] [bp-8h]@13 float a3; // [sp+C50h] [bp-4h]@13 signed int v79; // [sp+C5Ch] [bp+8h]@33 - signed int v80; // [sp+C5Ch] [bp+8h]@43 + //signed int v80; // [sp+C5Ch] [bp+8h]@43 int v81; // [sp+C5Ch] [bp+8h]@57 v2 = this; - v3 = (char *)this + 768 * a2; + //v3 = (char *)pBaseColors[a2]; if (pPalette_tintColor[0] || pPalette_tintColor[1] || pPalette_tintColor[2]) { - v8 = 0; - i = 0; - do - { - v9 = (float *)((char *)v63 + v8); - v10 = (float *)((char *)a6 + v8); - v11 = (float *)((char *)v64 + v8); - v12 = pPalette_tintColor[1]; - LODWORD(v75) = pPalette_tintColor[2] + (unsigned __int8)v3[2]; - v13 = v12 + (unsigned __int8)v3[1]; - LODWORD(v14) = (unsigned __int8)*v3; - v15 = (double)SLODWORD(v75) * 0.00196078431372549; - LODWORD(v75) = v13; - LODWORD(v75) = LODWORD(v14) + pPalette_tintColor[0]; - v16 = (double)v13 * 0.00196078431372549; - v17 = (double)SLODWORD(v75) * 0.00196078431372549; - RGB2HSV(v11, v9, v17, v16, v15, v10); - v3 += 3; - v8 = i + 4; - v19 = __OFSUB__(i + 4, 1024); - v18 = i - 1020 < 0; - i += 4; - } - while ( v18 ^ v19 ); + //v8 = 0; + //i = 0; + + for (uint i = 0; i < 256; ++i) + RGB2HSV(&v64[i], &v63[i], (pBaseColors[a2][i][0] + pPalette_tintColor[0]) / (255.0f + 255.0f), + (pBaseColors[a2][i][1] + pPalette_tintColor[1]) / (255.0f + 255.0f), + (pBaseColors[a2][i][2] + pPalette_tintColor[2]) / (255.0f + 255.0f), &a6[i]); + //do + //{ + //v9 = (float *)((char *)v63 + v8); + //v10 = (float *)((char *)a6 + v8); + //v11 = (float *)((char *)v64 + v8); + //v12 = pPalette_tintColor[1]; + //LODWORD(v75) = pPalette_tintColor[2] + (unsigned __int8)v3[2]; + //v13 = pPalette_tintColor[1] + (unsigned __int8)v3[1]; + //LODWORD(v14) = (unsigned __int8)*v3; + //v15 = (double)((unsigned __int8)v3[2] + pPalette_tintColor[2]) / (2.0f * 255.0f); + //LODWORD(v75) = v13; + //LODWORD(v75) = (unsigned __int8)*v3 + pPalette_tintColor[0]; + //v16 = (double)((unsigned __int8)v3[1] + pPalette_tintColor[1]) / 510.0f; + //v17 = (double)((unsigned __int8)*v3 + pPalette_tintColor[0]) / 510.0f; + //RGB2HSV(&v64[i], &v63[i], v17, v16, v15, &a6[i]); + //v3 += 3; + //v8 = i + 4; + //v19 = __OFSUB__(i + 4, 1024); + //v18 = i - 1020 < 0; + //i += 4; + //} + //while ( i < ); } else { - v4 = 0; + for (uint i = 0; i < 256; ++i) + RGB2HSV(&v64[i], &v63[i], pBaseColors[a2][i][0] / 255.0f, + pBaseColors[a2][i][1] / 255.0f, + pBaseColors[a2][i][2] / 255.0f, &a6[i]); + /*v4 = 0; do { LODWORD(v75) = (unsigned __int8)v3[2]; @@ -367,66 +379,80 @@ v6 = (double)SLODWORD(v75) * 0.00392156862745098; LODWORD(v75) = (unsigned __int8)*v3; v7 = (double)SLODWORD(v75) * 0.00392156862745098; - RGB2HSV(&v64[v4], &v63[v4], v7, v6, v5, (float *)&a6[v4]); + RGB2HSV(&v64[v4], &v63[v4], v7, v6, v5, &a6[v4]); ++v4; v3 += 3; } - while ( v4 < 256 ); + while ( v4 < 256 );*/ } - v69 = (PaletteManager *)((char *)v2 + 16384 * a2); - v72 = 0; - v73 = (int)v69->pPalette1; - do + + //v69 = (PaletteManager *)((char *)v2 + 16384 * a2); + //v72 = 0; + //v73 = (int)pPalette1[a2]; + for (uint i = 0; i < 32; ++i) + //do { - v20 = 0; - i = 0; - v71 = 1.0 - (double)v72 * 0.03225806451612903; - do + //v20 = 0; + //i = 0; + //v71 = 1.0 - (double)v72 / 31.0f; + //do + for (uint j = 0; j < 256; ++j) { - v21 = *(float *)((char *)a6 + v20) * v71; + v21 = a6[j] * (1.0f - i / 32.0f); if ( v21 < 0.0 ) v21 = 0.0; - v22 = v21; - HSV2RGB(&a1, &a2a, &a3, *(float *)((char *)v64 + v20), *(float *)((char *)v63 + v20), v22); + + //v22 = v21; + HSV2RGB(&a1, &a2a, &a3, v64[j], v63[j], v21); v23 = v2->uNumTargetGBits; - if ( v23 == 6 ) + if ( v23 == 6 ) // r5g6b5 { a1 = a1 * 31.0; a2a = a2a * 62.0; a3 = a3 * 31.0; } - else + else if (v23 == 5) // r5g5b5 { a1 = a1 * 31.0; a2a = a2a * 31.0; a3 = a3 * 31.0; } - v24 = (unsigned __int64)(signed __int64)a3 | ((unsigned __int16)(signed __int64)a2a << v2->uNumTargetBBits) | (unsigned __int16)((unsigned __int16)(signed __int64)a1 << (v2->uNumTargetBBits + v23)); - v25 = v73; - v73 += 2; - *(short *)v25 = v24; - v20 = i + 4; - v19 = __OFSUB__(i + 4, 1024); - v18 = i - 1020 < 0; - i += 4; + else if (v23 == 0) + Log::Warning(L"Calling palette manager with num_target_bits == 0"); + else assert(false); + //v24 = (unsigned __int32)a3 | ((unsigned __int32)a2a << v2->uNumTargetBBits) | ((unsigned __int32)a1 << (v2->uNumTargetBBits + v2->uNumTargetGBits)); + //v25 = v73; + //v73 += 2; + //*(short *)v25 = v24; + pPalette1[a2][i][j] = (unsigned __int32)a3 | + ((unsigned __int32)a2a << v2->uNumTargetBBits) | + ((unsigned __int32)a1 << (v2->uNumTargetBBits + v2->uNumTargetGBits)); + //v20 = i + 4; + //v19 = __OFSUB__(i + 4, 1024); + //v18 = i - 1020 < 0; + //i += 4; } - while ( v18 ^ v19 ); - ++v72; + //while ( v18 ^ v19 ); + //++v72; } - while ( v72 < 32 ); - v72 = 0; - v73 = (int)v69->field_199600_palettes; - do + //while ( v72 < 32 ); + + //v72 = 0; + //v73 = (int)v69->field_199600_palettes; + //do + for (uint i = 0; i < 32; ++i) { - i = 0; - v71 = 1.0 - (double)v72 * 0.03225806451612903; - do + //i = 0; + //v71 = 1.0 - (double)v72 / 31.0f; + //do + for (uint j = 0; j < 256; ++j) { - v26 = *(float *)&a6[i] * v71; + v26 = a6[j] * (1.0 - i / 31.0f); if ( v26 < 0.0 ) v26 = 0.0; - v27 = v26; - HSV2RGB(&a1, &a2a, &a3, 1.0, 1.0, v27); + + //v27 = v26; + HSV2RGB(&a1, &a2a, &a3, 1.0, 1.0, v26); v28 = v2->uNumTargetGBits; if ( v28 == 6 ) { @@ -434,35 +460,44 @@ a2a = a2a * 62.0; a3 = a3 * 31.0; } - else + else if (v28 == 5) { a1 = a1 * 31.0; a2a = a2a * 31.0; a3 = a3 * 31.0; } - v29 = (unsigned __int64)(signed __int64)a3 | ((unsigned __int16)(signed __int64)a2a << v2->uNumTargetBBits) | (unsigned __int16)((unsigned __int16)(signed __int64)a1 << (v2->uNumTargetBBits + v28)); - v30 = (__int16 *)v73; - ++i; - v73 += 2; - v19 = __OFSUB__(i, 256); - v18 = i - 256 < 0; - *v30 = v29; + else if (v23 == 0) + Log::Warning(L"Calling palette manager with num_target_bits == 0"); + else assert(false); + + //v29 = (unsigned __int64)(signed __int64)a3 | ((unsigned __int16)(signed __int64)a2a << v2->uNumTargetBBits) | (unsigned __int16)((unsigned __int16)(signed __int64)a1 << (v2->uNumTargetBBits + v28)); + //v30 = (__int16 *)v73; + //++i; + //v73 += 2; + //v19 = __OFSUB__(i, 256); + //v18 = i - 256 < 0; + //*v30 = v29; + field_199600_palettes[a2][i][j] = (unsigned __int64)(signed __int64)a3 | ((unsigned __int16)(signed __int64)a2a << v2->uNumTargetBBits) | (unsigned __int16)((unsigned __int16)(signed __int64)a1 << (v2->uNumTargetBBits + v28)); } - while ( v18 ^ v19 ); - ++v72; + //while ( v18 ^ v19 ); + //++v72; } - while ( v72 < 32 ); - v73 = (int)((char *)v2 + 512 * (a2 + 4875)); - v31 = 0; - i = 0; - do + //while ( v72 < 32 ); + + //v73 = (int)((char *)v2 + 512 * (a2 + 4875)); // field_261600[a2] + //v31 = 0; + //i = 0; + for (uint i = 0; i < 256; ++i) + //do { - v32 = (*(float *)((char *)a6 + v31) - 0.8) * 0.8387096774193549 + 0.8; + //v32 = (*(float *)((char *)a6 + v31) - 0.8) * 0.8387096774193549 + 0.8; + v32 = (a6[i] - 0.8f) * 0.8387096774193549 + 0.8; if ( v32 < 0.0 ) v32 = 0.0; - v33 = v32; - v34 = *(float *)((char *)v63 + v31) * 0.7034339229968783; - HSV2RGB(&a1, &a2a, &a3, *(float *)((char *)v64 + v31), v34, v33); + + //v33 = v32; + //v34 = v63[i] * 0.7034339229968783; + HSV2RGB(&a1, &a2a, &a3, v64[i], v63[i] * 0.7034339229968783, v32); v35 = v2->uNumTargetGBits; if ( v35 == 6 ) { @@ -470,12 +505,16 @@ a2a = a2a * 62.0; a3 = a3 * 31.0; } - else + else if (v35 == 5) { a1 = a1 * 31.0; a2a = a2a * 31.0; a3 = a3 * 31.0; } + else if (v23 == 0) + Log::Warning(L"Calling palette manager with num_target_bits == 0"); + else assert(false); + v36 = (signed __int64)((a1 + a2a + a3) * 0.3333333333333333 * 8.0); v37 = (signed int)v36 >> (8 - v2->uNumTargetRBits); v38 = 8 - v35; @@ -490,60 +529,74 @@ v40 = (1 << v42) - 1; if ( v79 > (1 << v39) - 1 ) v79 = (1 << v39) - 1; - v43 = v73; + //v43 = v73; v44 = v37 << (v39 + v2->uNumTargetGBits); - v73 += 2; - *(short *)v43 = v79 | ((short)v40 << v39) | (unsigned __int16)v44; - v31 = i + 4; - v19 = __OFSUB__(i + 4, 1024); - v18 = i - 1020 < 0; - i += 4; + //v73 += 2; + //*(short *)v43 = v79 | ((short)v40 << v39) | (unsigned __int16)v44; + field_261600[a2][i] = v79 | ((unsigned short)v40 << v39) | (unsigned __int16)v44; + //v31 = i + 4; + //v19 = __OFSUB__(i + 4, 1024); + //v18 = i - 1020 < 0; + //i += 4; } - while ( v18 ^ v19 ); - v45 = pPalette_mistColor[0]; - if (v45 || pPalette_mistColor[1] || pPalette_mistColor[2]) + //while ( v18 ^ v19 ); + + //v45 = pPalette_mistColor[0]; + float mist_a, mist_b, mist_c; + if (pPalette_mistColor[0] || pPalette_mistColor[1] || pPalette_mistColor[2]) { - v46 = (double)v45; - v80 = pPalette_mistColor[1]; - v47 = pPalette_mistColor[2]; - v70 = v46 * 0.00392156862745098; - *((float *)&v71 + 1) = (double)v80 * 0.00392156862745098; - v75 = (double)v47 * 0.00392156862745098; - RGB2HSV(&v68, &v67, v70, *((float *)&v71 + 1), v75, (float *)&v66); + //v46 = (double)v45; + //v80 = pPalette_mistColor[1]; + //v47 = pPalette_mistColor[2]; + //v70 = v46 * 0.00392156862745098; + //*((float *)&v71 + 1) = (double)v80 * 0.00392156862745098; + //v75 = (double)v47 * 0.00392156862745098; + mist_a = pPalette_mistColor[0] / 255.0f; + mist_b = pPalette_mistColor[1] / 255.0f; + mist_c = pPalette_mistColor[2] / 255.0f; + + float unused; + RGB2HSV(&v68, &v67, mist_a, mist_b, mist_c, &unused); } - v72 = 0; - v73 = (int)v69->field_D1600; - - do + //v72 = 0; + //v73 = (int)v69->field_D1600; + //do + for (uint i = 0; i < 32; ++i) { - v48 = 0; - for ( i = 0; ; v48 = i ) + //v48 = 0; + //for ( i = 0; ; v48 = i ) + for (uint j = 0; j < 256; ++j) { - v49 = *(float *)((char *)v63 + v48); + v49 = v63[j]; if ( v49 < 0.0 ) v49 = 0.0; - v50 = v49; - HSV2RGB(&a1, &a2a, &a3, *(float *)((char *)v64 + v48), v50, *(float *)((char *)a6 + v48)); - v51 = v2->uNumTargetGBits; - if ( v51 == 6 ) + + //v50 = v49; + HSV2RGB(&a1, &a2a, &a3, v64[j], v49, a6[j]); + //v51 = v2->uNumTargetGBits; + if ( v2->uNumTargetGBits == 6 ) { a1 = a1 * 31.0; a2a = a2a * 62.0; a3 = a3 * 31.0; } - else + else if (v2->uNumTargetGBits == 5) { a1 = a1 * 31.0; a2a = a2a * 31.0; a3 = a3 * 31.0; } + else if (v23 == 0) + Log::Warning(L"Calling palette manager with num_target_bits == 0"); + else assert(false); + if (pPalette_mistColor[0] || pPalette_mistColor[1] || pPalette_mistColor[2]) { - v55 = (double)v72 * 0.03225806451612903; - v52 = (signed __int64)((double)(1 << v2->uNumTargetRBits) * v70 * v55 + a1 * (1.0 - v55)); - v53 = (signed __int64)((double)(1 << v51) * *((float *)&v71 + 1) * v55 + a2a * (1.0 - v55)); - v54 = (signed __int64)((double)(1 << v2->uNumTargetBBits) * v75 * v55 + a3 * (1.0 - v55)); + v55 = (double)i / 31.0f; + v52 = (signed __int64)((double)(1 << v2->uNumTargetRBits) * mist_a * v55 + a1 * (1.0 - v55)); + v53 = (signed __int64)((double)(1 << v2->uNumTargetGBits) * mist_b * v55 + a2a * (1.0 - v55)); + v54 = (signed __int64)((double)(1 << v2->uNumTargetBBits) * mist_c * v55 + a3 * (1.0 - v55)); } else { @@ -551,6 +604,7 @@ v53 = (signed __int64)a2a; v54 = (signed __int64)a3; } + v56 = v2->uNumTargetRBits; v81 = v54; if ( v52 > (1 << v56) - 1 ) @@ -563,20 +617,20 @@ if ( (signed int)v54 > (1 << v59) - 1 ) v81 = (1 << v59) - 1; v60 = v2->uNumTargetGBits; - i += 4; + //i += 4; v61 = uNumTargetBBits + v60; - result = v73; - v73 += 2; - v19 = __OFSUB__(i, 1024); - v18 = i - 1024 < 0; - *(short *)result = v81 | ((short)v53 << uNumTargetBBits) | (v52 << v61); - if ( !(v18 ^ v19) ) - break; + //result = v73; + //v73 += 2; + //v19 = __OFSUB__(i, 1024); + //v18 = i - 1024 < 0; + //*(short *)result = v81 | ((short)v53 << uNumTargetBBits) | (v52 << v61); + field_D1600[a2][i][j] = v81 | ((short)v53 << uNumTargetBBits) | (v52 << v61); + //if ( !(v18 ^ v19) ) + // break; } - ++v72; + //++v72; } - while ( v72 < 32 ); - return result; + //while ( v72 < 32 ); } @@ -684,8 +738,8 @@ float v18; // [sp+38Ch] [bp-14h]@7 float a2a; // [sp+390h] [bp-10h]@7 float a1; // [sp+394h] [bp-Ch]@7 - int a6; // [sp+398h] [bp-8h]@7 - int a3; // [sp+39Ch] [bp-4h]@7 + float a6; // [sp+398h] [bp-8h]@7 + float a3; // [sp+39Ch] [bp-4h]@7 v15 = this; v2 = (unsigned int *)&this->pPaletteIDs[1]; @@ -707,14 +761,14 @@ v17 = 1 - (int)&v10; do { - LODWORD(a1) = tex.pPalette24[v4]; - a1 = (double)SLODWORD(a1) * 0.0039215689; + //LODWORD(a1) = tex.pPalette24[v4]; + a1 = (double)tex.pPalette24[v4] / 255.0f; LODWORD(a2a) = (unsigned __int8)*(&v10 + v4 + v17 + (unsigned int)tex.pPalette24); - a2a = (double)SLODWORD(a2a) * 0.0039215689; - a3 = tex.pPalette24[v4 + 2]; - *(float *)&a3 = (double)a3 * 0.0039215689; - RGB2HSV(&v16, &v18, a1, a2a, *(float *)&a3, (float *)&a6); - v5 = *(float *)&a6 * 1.1; + a2a = (double)tex.pPalette24[v4 + 1] / 255.0f; + //a3 = tex.pPalette24[v4 + 2]; + a3 = (double)tex.pPalette24[v4 + 2] / 255.0f; + RGB2HSV(&v16, &v18, a1, a2a, a3, &a6); + v5 = a6 * 1.1; if ( v5 >= 0.0 && v5 >= 1.0 ) { v5 = 1.0; @@ -724,7 +778,7 @@ if ( v5 < 0.0 ) v5 = 0.0; } - *(float *)&a6 = v5; + a6 = v5; v6 = v18 * 0.64999998; if ( v6 >= 0.0 && v6 >= 1.0 ) { @@ -736,18 +790,18 @@ v6 = 0.0; } v18 = v6; - HSV2RGB(&a1, &a2a, (float *)&a3, v16, v18, *(float *)&a6); + HSV2RGB(&a1, &a2a, &a3, v16, v18, a6); v7 = a2a * 255.0; v10[v4] = (signed __int64)(a1 * 255.0); v8 = (signed __int64)v7; - v9 = *(float *)&a3 * 255.0; + v9 = a3 * 255.0; v10[v4 + 1] = v8; v10[v4 + 2] = (signed __int64)v9; v4 += 3; } while ( v4 < 768 ); tex.Release(); - result = v15->MakePaletteLUT(uPaletteID, v10); + result = v15->MakeBasePaletteLut(uPaletteID, v10); } else { @@ -761,27 +815,28 @@ // 48A3BC: using guessed type char var_386[766]; //----- (0048A5A4) -------------------------------------------------------- -int PaletteManager::MakePaletteLUT(int a2, char *entries) +int PaletteManager::MakeBasePaletteLut(int idx, char *entries) { - PaletteManager *v3; // edi@1 - signed int result; // eax@1 - int *v5; // ecx@1 + //PaletteManager *v3; // edi@1 + //signed int result; // eax@1 + //int *v5; // ecx@1 int v6; // eax@4 int v7; // esi@4 - int v8; // eax@9 - signed int v9; // ecx@9 - int v10; // edx@9 + //int v8; // eax@9 + //signed int v9; // ecx@9 + //int v10; // edx@9 + + //v3 = this; + //result = 0; + //v5 = this->pPaletteIDs; - v3 = this; - result = 0; - v5 = this->pPaletteIDs; - while ( *v5 != a2 ) - { - ++result; - ++v5; - if ( result >= 50 ) - { - v6 = (int)&v3->pPaletteIDs[1]; + for (uint i = 0; i < 50; ++i) + if (pPaletteIDs[i] == idx) + return i; + + + + v6 = (int)&pPaletteIDs[1]; v7 = 1; while ( *(int *)v6 ) { @@ -790,7 +845,7 @@ if ( v7 >= 50 ) return 0; } - v8 = (int)((char *)v3 + 768 * v7); + /*v8 = (int)pBaseColors[v7];//(int)((char *)v3 + 768 * v7); v9 = 768; v10 = (int)(entries - v8); do @@ -799,13 +854,15 @@ ++v8; --v9; } - while ( v9 ); - v3->pPaletteIDs[v7] = a2; + while ( v9 );*/ + unsigned __int8 *dst = (unsigned __int8 *)pBaseColors[v7]; + for (uint i = 0; i < 768; ++i) + dst[i] = entries[i]; + + pPaletteIDs[v7] = idx; CalcPalettes_LUT(v7); return v7; - } - } - return result; + } //----- (0048A614) --------------------------------------------------------
--- a/PaletteManager.h Sun Mar 17 18:32:09 2013 +0400 +++ b/PaletteManager.h Sun Mar 17 22:46:18 2013 +0200 @@ -8,10 +8,10 @@ PaletteManager(); int ResetNonTestLocked(); - int CalcPalettes_LUT(int a2); + void CalcPalettes_LUT(int a2); int ResetNonLocked(); int LoadPalette(unsigned int uPaletteID); - int MakePaletteLUT(int a2, char *entries); + int MakeBasePaletteLut(int a2, char *entries); void RecalculateAll(); int LockAll(); int LockTestAll(); @@ -23,7 +23,7 @@ static unsigned __int16 *_47C30E_get_palette(int a1, char a2); static unsigned __int16 *_47C33F_get_palette(int a1, char a2); - char pBaseColors[50][256][3]; + unsigned __int8 pBaseColors[50][256][3]; unsigned __int16 pPalette1[50][32][256]; unsigned __int16 field_D1600[50][32][256]; unsigned __int16 field_199600_palettes[50][32][256];
--- a/Sprites.cpp Sun Mar 17 18:32:09 2013 +0400 +++ b/Sprites.cpp Sun Mar 17 22:46:18 2013 +0200 @@ -48,7 +48,7 @@ //----- (0044D513) -------------------------------------------------------- void SpriteFrameTable::InitializeSprite( signed int uSpriteID ) - { +{ //SpriteFrameTable *v2; // esi@1 unsigned int v3; // ebx@3 //char *v4; // edx@3