# HG changeset patch # User Grumpy7 # Date 1393089918 -3600 # Node ID 10c909eb6766df8ac1f1736a2cc5d5c97d0ed552 # Parent 080fd5a5433d6b5fc380a3fe560c4d87342bd2ce dword_AE336C to NPCStats::dword_AE336C_LastMispronouncedNameFirstLetter, dword_AE3370 to NPCStats::dword_AE3370_LastMispronouncedNameResult sub_495366 to NPCStats::sub_495366_MispronounceName + cleanup diff -r 080fd5a5433d -r 10c909eb6766 NPC.cpp --- a/NPC.cpp Wed Feb 19 22:30:39 2014 +0100 +++ b/NPC.cpp Sat Feb 22 18:25:18 2014 +0100 @@ -19,6 +19,9 @@ int uNumDialogueNPCPortraits; // weak struct NPCStats *pNPCStats = nullptr; +int NPCStats::dword_AE336C_LastMispronouncedNameFirstLetter = -1; +int NPCStats::dword_AE3370_LastMispronouncedNameResult = -1; + void InitializeAwards(); void InitializeScrolls(); void InitializeMerchants(); @@ -891,6 +894,43 @@ pNPCDataBuff->evt_F = 0; } + +//----- (00495366) -------------------------------------------------------- +char *NPCStats::sub_495366_MispronounceName(unsigned __int8 firstLetter, unsigned __int8 genderId) +{ + int pickedName; // edx@2 + + if ( firstLetter == dword_AE336C_LastMispronouncedNameFirstLetter) + pickedName = dword_AE3370_LastMispronouncedNameResult; + else + { + dword_AE336C_LastMispronouncedNameFirstLetter = firstLetter; + if ( this->uNumNPCNames[genderId] == 0 ) + pickedName = rand() % this->uNumNPCNames[(genderId + 1) % 2]; //originally without " + 1) % 2", but that would yield a div by zero + else + { + int rangeBottom = 0; + int rangeTop = 0; + for ( int i = 0; i < this->uNumNPCNames[genderId]; ++i ) + { + if (tolower(this->pNPCNames[i][genderId][0])) + { + if ( rangeBottom ) + rangeTop = i; + else + rangeBottom = i; + } + } + if ( rangeTop != 0 ) + pickedName = rangeBottom + rand() % (rangeTop - rangeBottom); + else + pickedName = rand() % this->uNumNPCNames[genderId]; + } + } + dword_AE3370_LastMispronouncedNameResult = pickedName; + return this->pNPCNames[pickedName][genderId]; +} + //----- (00476387) -------------------------------------------------------- bool PartyHasDragon() { diff -r 080fd5a5433d -r 10c909eb6766 NPC.h --- a/NPC.h Wed Feb 19 22:30:39 2014 +0100 +++ b/NPC.h Sat Feb 22 18:25:18 2014 +0100 @@ -161,6 +161,7 @@ void Release(); void InitializeAdditionalNPCs(NPCData *pNPCDataBuff, int npc_uid, int uLocation2D, int uMapId); void _476C60(); + char * sub_495366_MispronounceName(unsigned __int8 firstLetter, unsigned __int8 genderId); NPCData pNPCData[501]; //0 - 94BCh count from 1 @@ -190,6 +191,9 @@ char *pNPCDistTXT_Raw; char *pNPCGreetTXT_Raw; char *pNCPGroupTXT_Raw; + + static int dword_AE336C_LastMispronouncedNameFirstLetter; + static int dword_AE3370_LastMispronouncedNameResult; }; #pragma pack(pop) diff -r 080fd5a5433d -r 10c909eb6766 UI/UiGame.cpp --- a/UI/UiGame.cpp Wed Feb 19 22:30:39 2014 +0100 +++ b/UI/UiGame.cpp Sat Feb 22 18:25:18 2014 +0100 @@ -246,7 +246,7 @@ char pContainer[32]; // [sp+14h] [bp-28h]@3 dword_A74CDC = -1; - dword_AE336C = -1; + pNPCStats->dword_AE336C_LastMispronouncedNameFirstLetter = -1; pEventTimer->Pause(); pMiscTimer->Pause(); pAudioPlayer->StopChannels(-1, -1); diff -r 080fd5a5433d -r 10c909eb6766 mm7_4.cpp --- a/mm7_4.cpp Wed Feb 19 22:30:39 2014 +0100 +++ b/mm7_4.cpp Sat Feb 22 18:25:18 2014 +0100 @@ -1160,55 +1160,6 @@ return 1; } -//----- (00495366) -------------------------------------------------------- -char *__fastcall sub_495366(unsigned __int8 a1, unsigned __int8 a2) -{ - int v2; // edi@1 - int v3; // edx@2 - //int v4; // esi@3 - int v5; // ebx@5 - signed int v7; // [sp+Ch] [bp-14h]@1 - signed int v8; // [sp+10h] [bp-10h]@1 - int **v9; // [sp+14h] [bp-Ch]@4 - signed int v10; // [sp+18h] [bp-8h]@3 - unsigned __int8 v11; // [sp+1Ch] [bp-4h]@1 - - v2 = a1; - v11 = a2; - v8 = 0; - v7 = 0; - if ( dword_AE336C == a1 ) - v3 = dword_AE3370; - else - { - //v4 = a2; - dword_AE336C = a1; - if ( (signed int)pNPCStats->uNumNPCNames[a2] <= 0 ) - v3 = rand() % (signed int)pNPCStats->uNumNPCNames[a2]; - else - { - v9 = (int **)((char *)pNPCStats->pNPCNames + a2 * 4); - for ( v10 = 0; v10 < (signed int)pNPCStats->uNumNPCNames[a2]; ++v10 ) - { - v5 = tolower(*(char *)*v9); - if ( v5 == tolower(v2) ) - { - if ( v8 ) - v7 = v10; - else - v8 = v10; - } - v9 += 2; - } - if ( v8 && v8 != v7 ) - v3 = v8 + rand() % (v7 - v8); - else - v3 = rand() % (signed int)pNPCStats->uNumNPCNames[a2]; - } - } - dword_AE3370 = v3; - return pNPCStats->pNPCNames[0][v11 + 2 * v3]; -} //----- (00495430) -------------------------------------------------------- @@ -1414,7 +1365,7 @@ i += 2; break; case 13: - strcat(pTmpBuf2.data(), sub_495366(pPlayer->pName[0], pPlayer->uSex)); + strcat(pTmpBuf2.data(), pNPCStats->sub_495366_MispronounceName(pPlayer->pName[0], pPlayer->uSex)); dst = strlen(pTmpBuf2.data()); i += 2; break; diff -r 080fd5a5433d -r 10c909eb6766 mm7_data.cpp --- a/mm7_data.cpp Wed Feb 19 22:30:39 2014 +0100 +++ b/mm7_data.cpp Sat Feb 22 18:25:18 2014 +0100 @@ -1103,8 +1103,6 @@ std::array pClassNames; std::array aCharacterConditionNames; std::array pSkillNames; -int dword_AE336C; // weak -int dword_AE3370; // weak char byte_AE5B91; // weak std::array dword_F1B430; // weak //int dword_F8B144; // nexindex [-1] to the following diff -r 080fd5a5433d -r 10c909eb6766 mm7_data.h --- a/mm7_data.h Wed Feb 19 22:30:39 2014 +0100 +++ b/mm7_data.h Sat Feb 22 18:25:18 2014 +0100 @@ -754,8 +754,6 @@ extern std::array pClassNames; extern std::array aCharacterConditionNames; extern std::array pSkillNames; -extern int dword_AE336C; // weak -extern int dword_AE3370; // weak extern char byte_AE5B91; // weak extern std::array dword_F1B430; // weak extern std::array player_levels; diff -r 080fd5a5433d -r 10c909eb6766 mm7_unsorted_subs.h --- a/mm7_unsorted_subs.h Wed Feb 19 22:30:39 2014 +0100 +++ b/mm7_unsorted_subs.h Sat Feb 22 18:25:18 2014 +0100 @@ -205,7 +205,6 @@ void init_summoned_item(struct stru351_summoned_item *_this, __int64 duration); void _494035_timed_effects__water_walking_damage__etc(); unsigned int __fastcall _494820_training_time(unsigned int a1); -char *__fastcall sub_495366(unsigned __int8 a1, unsigned __int8 a2); const char *GetReputationString(signed int a1); char *BuildDialogueString(const char *lpsz, unsigned __int8 uPlayerID, struct ItemGen *a3, char *a4, int a5, __int64 *a6); void PlayerCreationUI_Draw();