Mercurial > mm7
diff mm7_2.cpp @ 237:2799737f8a74
more text parsers refactor
author | Gloval |
---|---|
date | Mon, 18 Feb 2013 00:47:36 +0400 |
parents | 47e06334c564 |
children | fb8a876f41e1 |
line wrap: on
line diff
--- a/mm7_2.cpp Sun Feb 17 18:50:35 2013 +0400 +++ b/mm7_2.cpp Mon Feb 18 00:47:36 2013 +0400 @@ -7565,7 +7565,7 @@ v11 = pMapInfo->uEncounterMonster1AtMost; pTexture = pMapInfo->pEncounterMonster1Texture; v12 = v10 % (v11 - v9 + 1); - v13 = pMapInfo->field_34; + v13 = pMapInfo->Dif_M1; goto LABEL_20; case 3u: pTexture = pMapInfo->pEncounterMonster1Texture; @@ -7585,7 +7585,7 @@ v15 = pMapInfo->uEncounterMonster2AtMost; pTexture = pMapInfo->pEncounterMonster2Texture; v12 = v14 % (v15 - v9 + 1); - v13 = pMapInfo->field_37; + v13 = pMapInfo->Dif_M2; goto LABEL_20; case 6u: pTexture = pMapInfo->pEncounterMonster1Texture; @@ -7605,7 +7605,7 @@ v17 = pMapInfo->uEncounterMonster3AtMost; pTexture = pMapInfo->pEncounterMonster3Texture; v12 = v16 % (v17 - v9 + 1); - v13 = pMapInfo->field_3A; + v13 = pMapInfo->Dif_M3; LABEL_20: v57 = v13; v56 = v9 + v12; @@ -7936,7 +7936,7 @@ v4 = rand(); v34 = 0; v5 = v4 % 100; - v6 = 2 * (v2->field_2F + 7 * v3->uIndex) - 14; + v6 = 2 * (v2->Treasure_prob + 7 * v3->uIndex) - 14; v7 = (unsigned __int8)byte_4E8168[v6 + 16]; v8 = (unsigned __int8)byte_4E8168[v6 + 17]; v32 = v5; @@ -8114,8 +8114,8 @@ if ( (v3->uItemID & 0x80000000u) == 0 ) goto LABEL_56; v4 = rand() % 5 + 1; - v5 = (unsigned __int8)byte_4E8168[2 * (v2->field_2F + 7 * abs((int)v3->uItemID)) + 2]; - v6 = (unsigned __int8)byte_4E8168[2 * (v2->field_2F + 7 * abs((int)v3->uItemID)) + 3]; + v5 = (unsigned __int8)byte_4E8168[2 * (v2->Treasure_prob + 7 * abs((int)v3->uItemID)) + 2]; + v6 = (unsigned __int8)byte_4E8168[2 * (v2->Treasure_prob + 7 * abs((int)v3->uItemID)) + 3]; v7 = rand(); v8 = v6 - v5 + 1; v9 = v5 + v7 % v8; @@ -9245,393 +9245,328 @@ //----- (00453F62) -------------------------------------------------------- void MapStats::Initialize() { - MapStats *v1; // esi@1 - unsigned int v2; // ebx@3 - char *v3; // eax@4 - char *v4; // edi@4 - char v5; // cl@5 - int v6; // eax@5 - size_t v7; // eax@32 - size_t v8; // eax@35 - size_t v9; // eax@42 - size_t v10; // eax@45 - size_t v11; // eax@52 - size_t v12; // eax@55 - char Str[32]; // [sp+Ch] [bp-34h]@30 - char *v14; // [sp+2Ch] [bp-14h]@9 - int v15; // [sp+30h] [bp-10h]@4 - int v16; // [sp+34h] [bp-Ch]@4 - unsigned int v17; // [sp+38h] [bp-8h]@30 - MapStats *v18; // [sp+3Ch] [bp-4h]@30 - - v1 = this; + char work_str[32]; // [sp+Ch] [bp-34h]@3 + int work_str_pos; + int work_str_len; + int i; + char* test_string; + unsigned char c; + bool break_loop; + unsigned int temp_str_len; + char* tmp_pos; + int decode_step; + int item_counter; + if ( pMapStatsTXT_Raw ) pAllocator->FreeChunk(pMapStatsTXT_Raw); - pMapStatsTXT_Raw = 0; + pMapStatsTXT_Raw = NULL; pMapStatsTXT_Raw = (char *)pEvents_LOD->LoadRaw("MapStats.txt", 0); strtok(pMapStatsTXT_Raw, "\r"); - strtok(0, "\r"); - strtok(0, "\r"); - v2 = 1; - v1->uNumMaps = 77; - do - { - v3 = strtok(0, "\r"); - v16 = 0; - v15 = 0; - v4 = v3; - do - { - v5 = *v4; - v6 = 0; - while ( v5 != 9 && v5 ) - { - ++v6; - v5 = v4[v6]; - } - v14 = &v4[v6]; - if ( !v4[v6] ) - v15 = 1; - v4[v6] = 0; - if ( v6 ) - { - switch ( v16 ) - { - case 1: - v1->pInfos[v2].pName = (char *)RemoveQuotes(v4); - break; - case 2: - v1->pInfos[v2].pFilename = (char *)RemoveQuotes(v4); - break; - case 3: - v1->pInfos[v2].uNumResets = atoi(v4); - break; - case 4: - v1->pInfos[v2].uFirstVisitedAt = atoi(v4); - break; - case 5: - v1->pInfos[v2]._per = atoi(v4); - break; - case 6: - v1->pInfos[v2].uRespawnIntervalDays = atoi(v4); - break; - case 7: - v1->pInfos[v2]._alert_days = atoi(v4); - break; - case 8: - v1->pInfos[v2]._steal_perm = atoi(v4); - break; - case 9: - v1->pInfos[v2].field_2D = atoi(v4); - break; - case 10: - v1->pInfos[v2].field_2E = atoi(v4); - break; - case 11: - v1->pInfos[v2].field_2F = atoi(v4); - break; - case 12: - v1->pInfos[v2].field_30 = atoi(v4); - break; - case 13: - v1->pInfos[v2].field_31 = atoi(v4); - break; - case 14: - v1->pInfos[v2].field_32 = atoi(v4); - break; - case 15: - v1->pInfos[v2].field_33 = atoi(v4); - break; - case 16: - v1->pInfos[v2].pEncounterMonster1Texture = (char *)RemoveQuotes(v4); - break; - case 18: - v1->pInfos[v2].field_34 = atoi(v4); - break; - case 19: - v18 = (MapStats *)((char *)v1 + 68 * v2); - v18->pInfos[0].uEncounterMonster1AtLeast = 1; - strcpy(Str, v4); - v17 = 0; - if ( strlen(Str) ) - { - while ( Str[v17] != 45 ) - { - ++v17; - v7 = strlen(Str); - if ( v17 >= v7 ) - goto LABEL_35; - } - Str[v17] = 0; - v18->pInfos[0].uEncounterMonster1AtLeast = atoi(Str); - } -LABEL_35: - v8 = strlen(Str); - if ( v17 == v8 ) - v18->pInfos[0].uEncounterMonster1AtMost = atoi(&v4[v17 + 1]); - else - v18->pInfos[0].uEncounterMonster1AtMost = v18->pInfos[0].uEncounterMonster1AtLeast; - break; - case 20: - v1->pInfos[v2].pEncounterMonster2Texture = (char *)RemoveQuotes(v4); - break; - case 22: - v1->pInfos[v2].field_37 = atoi(v4); - break; - case 23: - v18 = (MapStats *)((char *)v1 + 68 * v2); - v18->pInfos[0].uEncounterMonster2AtLeast = 1; - strcpy(Str, v4); - v17 = 0; - if ( strlen(Str) ) - { - while ( Str[v17] != 45 ) - { - ++v17; - v9 = strlen(Str); - if ( v17 >= v9 ) - goto LABEL_45; - } - Str[v17] = 0; - v18->pInfos[0].uEncounterMonster2AtLeast = atoi(Str); - } -LABEL_45: - v10 = strlen(Str); - if ( v17 == v10 ) - v18->pInfos[0].uEncounterMonster2AtMost = atoi(&v4[v17 + 1]); - else - v18->pInfos[0].uEncounterMonster2AtMost = v18->pInfos[0].uEncounterMonster2AtLeast; - break; - case 24: - v1->pInfos[v2].pEncounterMonster3Texture = (char *)RemoveQuotes(v4); - break; - case 26: - v1->pInfos[v2].field_3A = atoi(v4); - break; - case 27: - v18 = (MapStats *)((char *)v1 + 68 * v2); - v18->pInfos[0].uEncounterMonster3AtLeast = 1; - strcpy(Str, v4); - v17 = 0; - if ( strlen(Str) ) - { - while ( Str[v17] != 45 ) - { - ++v17; - v11 = strlen(Str); - if ( v17 >= v11 ) - goto LABEL_55; - } - Str[v17] = 0; - v18->pInfos[0].uEncounterMonster3AtLeast = atoi(Str); - } -LABEL_55: - v12 = strlen(Str); - if ( v17 == v12 ) - v18->pInfos[0].uEncounterMonster3AtMost = atoi(&v4[v17 + 1]); - else - v18->pInfos[0].uEncounterMonster3AtMost = v18->pInfos[0].uEncounterMonster3AtLeast; - break; - case 28: - v1->pInfos[v2].uRedbookTrackID = atoi(v4); - break; - case 29: - if ( strcmp(v4, "GENERIC") ) - { - if ( strcmp(v4, "PADDEDCELL") ) - { - if ( strcmp(v4, "ROOM") ) - { - if ( strcmp(v4, "BATHROOM") ) - { - if ( strcmp(v4, "LIVINGROOM") ) - { - if ( strcmp(v4, "STONEROOM") ) - { - if ( strcmp(v4, "AUDITORIUM") ) - { - if ( strcmp(v4, "CONCERTHALL") ) - { - if ( strcmp(v4, "CAVE") ) - { - if ( strcmp(v4, "ARENA") ) - { - if ( strcmp(v4, "HANGAR") ) - { - if ( strcmp(v4, "CARPETEDHALLWAY") ) - { - if ( strcmp(v4, "HALLWAY") ) - { - if ( strcmp(v4, "STONECORRIDOR") ) - { - if ( strcmp(v4, "ALLEY") ) - { - if ( strcmp(v4, "FOREST") ) - { - if ( strcmp(v4, "CITY") ) - { - if ( strcmp(v4, "MOUNTAINS") ) - { - if ( strcmp(v4, "QUARRY") ) - { - if ( strcmp(v4, "PLAIN") ) - { - if ( strcmp(v4, "PARKINGLOT") ) - { - if ( strcmp(v4, "SEWERPIPE") ) - { - if ( strcmp(v4, "UNDERWATER") ) - { - if ( strcmp(v4, "DRUGGED") ) - { - if ( strcmp(v4, "DIZZY") ) - { - if ( strcmp(v4, "PSYCHOTIC") ) - v1->pInfos[v2].uEAXEnv = 26; - else - v1->pInfos[v2].uEAXEnv = 25; - } - else - { - v1->pInfos[v2].uEAXEnv = 24; - } - } - else - { - v1->pInfos[v2].uEAXEnv = 23; - } - } - else - { - v1->pInfos[v2].uEAXEnv = 22; - } - } - else - { - v1->pInfos[v2].uEAXEnv = 21; - } - } - else - { - v1->pInfos[v2].uEAXEnv = 20; - } - } - else - { - v1->pInfos[v2].uEAXEnv = 19; - } - } - else - { - v1->pInfos[v2].uEAXEnv = 18; - } - } - else - { - v1->pInfos[v2].uEAXEnv = 17; - } - } - else - { - v1->pInfos[v2].uEAXEnv = 16; - } - } - else - { - v1->pInfos[v2].uEAXEnv = 15; - } - } - else - { - v1->pInfos[v2].uEAXEnv = 14; - } - } - else - { - v1->pInfos[v2].uEAXEnv = 13; - } - } - else - { - v1->pInfos[v2].uEAXEnv = 12; - } - } - else - { - v1->pInfos[v2].uEAXEnv = 11; - } - } - else - { - v1->pInfos[v2].uEAXEnv = 10; - } - } - else - { - v1->pInfos[v2].uEAXEnv = 9; - } - } - else - { - v1->pInfos[v2].uEAXEnv = 8; - } - } - else - { - v1->pInfos[v2].uEAXEnv = 7; - } - } - else - { - v1->pInfos[v2].uEAXEnv = 6; - } - } - else - { - v1->pInfos[v2].uEAXEnv = 5; - } - } - else - { - v1->pInfos[v2].uEAXEnv = 4; - } - } - else - { - v1->pInfos[v2].uEAXEnv = 3; - } - } - else - { - v1->pInfos[v2].uEAXEnv = 2; - } - } - else - { - v1->pInfos[v2].uEAXEnv = 1; - } - } - else - { - v1->pInfos[v2].uEAXEnv = 0; - } - break; - default: - break; - } - } - else - { - v15 = 1; - } - ++v16; - v4 = v14 + 1; - } - while ( v16 - 1 <= 29 && !v15 ); - ++v2; - } - while ( (signed int)v2 < 77 ); - v1->uNumMaps = v2; + strtok(NULL, "\r"); + strtok(NULL, "\r"); + + for (i=1; i<77; ++i) + { + test_string = strtok(NULL, "\r") + 1; + break_loop = false; + decode_step=0; + do + { + c = *(unsigned char*)test_string; + temp_str_len = 0; + while((c!='\t')&&(c>0)) + { + ++temp_str_len; + c=test_string[temp_str_len]; + } + tmp_pos=test_string+temp_str_len; + if (*tmp_pos == 0) + break_loop = true; + *tmp_pos = 0; + if (temp_str_len) + { + switch (decode_step) + { + case 1: + pInfos[i].pName = RemoveQuotes(test_string); + break; + case 2: + pInfos[i].pFilename = RemoveQuotes(test_string); + break; + case 3: + pInfos[i].uNumResets = atoi(test_string); + break; + case 4: + pInfos[i].uFirstVisitedAt = atoi(test_string); + break; + case 5: + pInfos[i]._per = atoi(test_string); + break; + case 6: + pInfos[i].uRespawnIntervalDays = atoi(test_string); + break; + case 7: + pInfos[i]._alert_days = atoi(test_string); + break; + case 8: + pInfos[i]._steal_perm = atoi(test_string); + break; + case 9: + pInfos[i].LockX5 = atoi(test_string); + break; + case 10: + pInfos[i].Trap_D20 = atoi(test_string); + break; + case 11: + pInfos[i].Treasure_prob = atoi(test_string); + break; + case 12: + pInfos[i].Encounter_percent = atoi(test_string); + break; + case 13: + pInfos[i].EncM1percent = atoi(test_string); + break; + case 14: + pInfos[i].EncM2percent = atoi(test_string); + break; + case 15: + pInfos[i].EncM3percent = atoi(test_string); + break; + case 16: + pInfos[i].pEncounterMonster1Texture = RemoveQuotes(test_string); + break; + case 18: + pInfos[i].Dif_M1 = atoi(test_string); + break; + case 19: + pInfos[i].uEncounterMonster1AtLeast = 1; + pInfos[i].uEncounterMonster1AtMost = 1; + strcpy(work_str, test_string); + work_str_pos = 0; + work_str_len=strlen(work_str); + if (work_str_len ) + { + while (work_str[work_str_pos] != '-' ) + { + ++work_str_pos; + if (work_str_pos >= work_str_len ) + break; + } + work_str[work_str_pos] = 0; + pInfos[i].uEncounterMonster1AtLeast = atoi(work_str); + if ( work_str_pos < work_str_len ) + pInfos[i].uEncounterMonster1AtMost = atoi(&work_str[work_str_pos + 1]); + else + pInfos[i].uEncounterMonster1AtMost = pInfos[i].uEncounterMonster1AtLeast; + } + break; + case 20: + pInfos[i].pEncounterMonster2Texture = RemoveQuotes(test_string); + break; + case 22: + pInfos[i].Dif_M2 = atoi(test_string); + break; + case 23: + pInfos[i].uEncounterMonster2AtLeast = 1; + pInfos[i].uEncounterMonster2AtMost = 1; + strcpy(work_str, test_string); + work_str_pos = 0; + work_str_len=strlen(work_str); + if (work_str_len ) + { + while (work_str[work_str_pos] != '-' ) + { + ++work_str_pos; + if (work_str_pos >= work_str_len ) + break; + } + work_str[work_str_pos] = 0; + pInfos[i].uEncounterMonster2AtLeast = atoi(work_str); + if ( work_str_pos < work_str_len ) + pInfos[i].uEncounterMonster2AtMost = atoi(&work_str[work_str_pos + 1]); + else + pInfos[i].uEncounterMonster2AtMost = pInfos[i].uEncounterMonster2AtLeast; + } + break; + case 24: + pInfos[i].pEncounterMonster3Texture = RemoveQuotes(test_string); + break; + case 26: + pInfos[i].Dif_M3 = atoi(test_string); + break; + case 27: + pInfos[i].uEncounterMonster3AtLeast = 1; + pInfos[i].uEncounterMonster3AtMost = 1; + strcpy(work_str, test_string); + work_str_pos = 0; + work_str_len=strlen(work_str); + if (work_str_len ) + { + while (work_str[work_str_pos] != '-' ) + { + ++work_str_pos; + if (work_str_pos >= work_str_len ) + break; + } + work_str[work_str_pos] = 0; + pInfos[i].uEncounterMonster3AtLeast = atoi(work_str); + if ( work_str_pos < work_str_len ) + pInfos[i].uEncounterMonster3AtMost = atoi(&work_str[work_str_pos + 1]); + else + pInfos[i].uEncounterMonster3AtMost = pInfos[i].uEncounterMonster3AtLeast; + } + break; + case 28: + pInfos[i].uRedbookTrackID = atoi(test_string); + break; + case 29: + { + if ( !strcmp(test_string, "CAVE") ) + { + pInfos[i].uEAXEnv = 8; + break; + } + if ( !strcmp(test_string, "STONEROOM") ) + { + pInfos[i].uEAXEnv = 5; + break; + } + if ( !strcmp(test_string, "MOUNTAINS") ) + { + pInfos[i].uEAXEnv = 17; + break; + } + if ( !strcmp(test_string, "PLAIN") ) + { + pInfos[i].uEAXEnv = 19; + break; + } + if ( !strcmp(test_string, "FOREST") ) + { + pInfos[i].uEAXEnv = 15; + break; + } + if ( !strcmp(test_string, "CITY") ) + { + pInfos[i].uEAXEnv = 16; + break; + } + if ( !strcmp(test_string, "UNDERWATER") ) + { + pInfos[i].uEAXEnv = 22; + break; + } + if ( !strcmp(test_string, "ARENA") ) + { + pInfos[i].uEAXEnv = 9; + break; + } + if ( !strcmp(test_string, "GENERIC") ) + { + pInfos[i].uEAXEnv = 0; + break; + } + if ( !strcmp(test_string, "PADDEDCELL") ) + { + pInfos[i].uEAXEnv = 1; + break; + } + if ( !strcmp(test_string, "ROOM") ) + { + pInfos[i].uEAXEnv = 2; + break; + } + if ( !strcmp(test_string, "BATHROOM") ) + { + pInfos[i].uEAXEnv = 3; + break; + } + if ( !strcmp(test_string, "LIVINGROOM") ) + { + pInfos[i].uEAXEnv = 4; + break; + } + if ( !strcmp(test_string, "AUDITORIUM") ) + { + pInfos[i].uEAXEnv = 6; + break; + } + if ( !strcmp(test_string, "CONCERTHALL") ) + { + pInfos[i].uEAXEnv = 7; + break; + } + if ( !strcmp(test_string, "HANGAR") ) + { + pInfos[i].uEAXEnv = 10; + break; + } + if ( !strcmp(test_string, "CARPETEDHALLWAY") ) + { + pInfos[i].uEAXEnv = 11; + break; + } + if ( !strcmp(test_string, "HALLWAY") ) + { + pInfos[i].uEAXEnv = 12; + break; + } + if ( !strcmp(test_string, "STONECORRIDOR") ) + { + pInfos[i].uEAXEnv = 13; + break; + } + if ( !strcmp(test_string, "ALLEY") ) + { + pInfos[i].uEAXEnv = 14; + break; + } + if ( !strcmp(test_string, "QUARRY") ) + { + pInfos[i].uEAXEnv = 18; + break; + } + if ( !strcmp(test_string, "PARKINGLOT") ) + { + pInfos[i].uEAXEnv = 20; + break; + } + if ( !strcmp(test_string, "SEWERPIPE") ) + { + pInfos[i].uEAXEnv = 21; + break; + } + if ( !strcmp(test_string, "DRUGGED") ) + { + pInfos[i].uEAXEnv = 23; + break; + } + if ( !strcmp(test_string, "DIZZY") ) + { + pInfos[i].uEAXEnv = 24; + break; + } + if ( !strcmp(test_string, "PSYCHOTIC") ) + { + pInfos[i].uEAXEnv = 25; + break; + } + pInfos[i].uEAXEnv = 26; + + } + break; + } + } + else + { + break_loop = true; + } + ++decode_step; + test_string=tmp_pos+1; + } while ((decode_step<31)&&!break_loop); + } + + uNumMaps = 77; } // 453F62: using guessed type char Str[32]; @@ -9673,73 +9608,55 @@ //----- (004547E4) -------------------------------------------------------- void FactionTable::Initialize() { - char *v1; // ebx@1 - char *v2; // eax@4 - signed int v3; // edi@4 - int v4; // ebp@4 - char v5; // dl@5 - char *v6; // ecx@5 - int v7; // esi@9 - signed int v8; // [sp+4h] [bp-Ch]@3 - signed int v9; // [sp+8h] [bp-8h]@4 - char *v10; // [sp+Ch] [bp-4h]@1 - - v1 = 0; - v10 = (char *)relations; + int i; + char* test_string; + unsigned char c; + bool break_loop; + unsigned int temp_str_len; + char* tmp_pos; + int decode_step; + int item_counter; + if ( pHostileTXT_Raw ) pAllocator->FreeChunk(pHostileTXT_Raw); - pHostileTXT_Raw = 0; + pHostileTXT_Raw = NULL; pHostileTXT_Raw = (char *)pEvents_LOD->LoadRaw("hostile.txt", 0); strtok(pHostileTXT_Raw, "\r"); - v8 = 0; - do - { - v2 = strtok(v1, "\r") + 1; - v3 = 0; - v9 = (signed int)v1; - v4 = (int)&v10[v8-89]; - do - { - v5 = *v2; - v6 = 0; - if ( *v2 != 9 ) - { - v1 = 0; - do - { - if ( !v5 ) - break; - ++v6; - v5 = v2[(int)v6]; - } - while ( v5 != 9 ); - } - v7 = (int)&v2[(int)v6]; - if ( v2[(int)v6] == (char)v1 ) - v9 = 1; - *(char *)v7 = (char)v1; - if ( v6 == v1 ) - { - v9 = 1; - } - else - { - if ( v3 >= 1 && v3 <= 90 ) - *(char *)v4 = atoi(v2); - } - ++v3; - v4 += 89; - v2 = (char *)(v7 + 1); - } - while ( v3 - 1 <= 90 && (char *)v9 == v1 ); - ++v8; - } - while ( v8 < 89 ); - - if ( pHostileTXT_Raw != v1 ) + for (i=0; i<89; ++i) + { + test_string = strtok(NULL, "\r") + 1; + break_loop = false; + decode_step=0; + do + { + c = *(unsigned char*)test_string; + temp_str_len = 0; + while((c!='\t')&&(c>0)) + { + ++temp_str_len; + c=test_string[temp_str_len]; + } + tmp_pos=test_string+temp_str_len; + if (*tmp_pos == 0) + break_loop = true; + *tmp_pos = 0; + if (temp_str_len) + { + if ( decode_step >= 1 && decode_step < 90 ) + relations[decode_step-1][i] = atoi(test_string); + } + else + { + break_loop = true; + } + ++decode_step; + test_string=tmp_pos+1; + } while ((decode_step<92)&&!break_loop); + } + if ( pHostileTXT_Raw) { pAllocator->FreeChunk(pHostileTXT_Raw); - pHostileTXT_Raw = v1; + pHostileTXT_Raw = NULL; } }