diff mm7_3.cpp @ 167:90521fb9766c

NPCDialogue fix
author Ritor1
date Thu, 14 Feb 2013 16:17:23 +0600
parents 71b13d70f5a6
children d1dde383af89 e6db0995ac4b
line wrap: on
line diff
--- a/mm7_3.cpp	Thu Feb 14 14:48:54 2013 +0600
+++ b/mm7_3.cpp	Thu Feb 14 16:17:23 2013 +0600
@@ -15920,10 +15920,10 @@
 //----- (00445350) --------------------------------------------------------
 void __cdecl DrawDialogueUI()
 {
-  NPCData *v0; // ebx@2
+  NPCData *pNPC; // ebx@2
   int v1; // eax@2
   unsigned __int16 v2; // di@2
-  unsigned int v3; // eax@2
+  //unsigned int v3; // eax@2
   char *v4; // esi@3
   int v5; // eax@11
   char *v6; // ecx@13
@@ -15968,7 +15968,7 @@
   unsigned int v45; // ecx@104
   unsigned __int16 *v46; // edx@104
   unsigned __int16 v47; // ax@104
-  char pFont; // [sp+4h] [bp-110h]@39
+  GUIWindow pWindow; // [sp+4h] [bp-110h]@39
   int v49; // [sp+Ch] [bp-108h]@39
   int v50; // [sp+14h] [bp-100h]@39
   GUIWindow v51; // [sp+58h] [bp-BCh]@2
@@ -15982,7 +15982,7 @@
   if ( !pDialogueWindow )
     return;
   memcpy(&v51, pDialogueWindow, sizeof(v51));
-  v0 = GetNPCData(uDialogue_SpeakingActorNPC_ID);
+  pNPC = GetNPCData(uDialogue_SpeakingActorNPC_ID);
   v1 = sub_445C8B(uDialogue_SpeakingActorNPC_ID);
   v51.uFrameWidth -= 10;
   v51.uFrameZ -= 10;
@@ -15990,41 +15990,81 @@
   GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0xFFu);
   GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xE1u, 0xCDu, 0x23u);
   v2 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0x15u, 0x99u, 0xE9u);
-  pRenderer->DrawTextureIndexed(0x1DDu, 0, pTexture_Dialogue_Background);
-  pRenderer->DrawTextureTransparent(0x1D4u, 0, (Texture *)(uTextureID_507B04 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_507B04] : 0));
+  pRenderer->DrawTextureIndexed(477, 0, pTexture_Dialogue_Background);
+  pRenderer->DrawTextureTransparent(468, 0, (Texture *)(uTextureID_507B04 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_507B04] : 0));
   pRenderer->DrawTextureIndexed(pNPCPortraits_x - 4, pNPCPortraits_y - 4, (Texture *)(uTextureID_50795C != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_50795C] : 0));
   pRenderer->DrawTextureIndexed(pNPCPortraits_x, pNPCPortraits_y, pDialogueNPCPortraits[0]);
-  v3 = v0->uProfession;
-  if ( v3 )
-  {
-    v4 = pTmpBuf;
-    sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[429], v0->pName, aNPCProfessionNames[v3]);
-  }
-  else
-  {
-    strcpy(pTmpBuf, v0->pName);
-    v4 = pTmpBuf;
-  }
-  v51.DrawTitleText(pFontArrus, 0x1E3u, 0x70u, v2, v4, 3u);
+  if ( pNPC->uProfession )
+  {
+    sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[429], pNPC->pName, aNPCProfessionNames[pNPC->uProfession]);//^Pi[%s] %s
+  }
+  else
+  {
+    strcpy(pTmpBuf, pNPC->pName);
+  }
+  v51.DrawTitleText(pFontArrus, 483, 112, v2, pTmpBuf, 3);
   pParty->GetPartyFame();
   if ( (signed int)uDialogueType > 89 )
   {
     if ( uDialogueType == 90 )
     {
-      v7 = pGlobalTXT_LocalizationStrings[577]; // "Get back in there you wimps:"
-      goto LABEL_37;
+      pWindow.uFrameWidth = 460;
+      pWindow.uFrameZ = 452;
+      pOutString = pFontArrus;
+      v12 = pFontArrus->CalcTextHeight(pGlobalTXT_LocalizationStrings[577], &pWindow, 13, 0) + 7;//"Get back in there you wimps:"
+      if ( 352 - v12 < 8 )
+      {
+        pOutString = pFontCreate;
+        v12 = pFontCreate->CalcTextHeight(pGlobalTXT_LocalizationStrings[577], &pWindow, 13, 0) + 7;
+      }
+      pRenderer->_4A6A68(8, 352 - v12, (Texture *)(uTextureID_Leather != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_Leather] : 0),
+        (uTextureID_Leather != -1 ? pIcons_LOD->pTextures[uTextureID_Leather].uTextureHeight : 26) - v12);
+      pRenderer->DrawTextureIndexed(8, 347 - v12, pTexture_591428);
+      v13 = FitTextInAWindow(pGlobalTXT_LocalizationStrings[577], pFontArrus, &pWindow, 0xDu, 0);
+      pDialogueWindow->DrawText(pFontArrus, 13, 354 - v12, 0, v13, 0, 0, 0);
+      goto LABEL_42;
     }
     if ( uDialogueType == 91 )
     {
       sprintf(v4, pGlobalTXT_LocalizationStrings[576], dword_F8B1B4);// "Congratulations on your win: here's your stuff: %u gold."
       pInString = v4;
       v8 = 0;
-      goto LABEL_39;
+      pWindow.uFrameWidth = 460;
+      pWindow.uFrameZ = 452;
+      pOutString = pFontArrus;
+      v12 = pFontArrus->CalcTextHeight(pInString, &pWindow, 13, v8) + 7;
+      if ( 352 - v12 < 8 )
+      {
+        pOutString = pFontCreate;
+        v12 = pFontCreate->CalcTextHeight(pInString, &pWindow, 13, v8) + 7;
+      }
+      pRenderer->_4A6A68(8, 352 - v12, (Texture *)(uTextureID_Leather != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_Leather] : 0),
+        (uTextureID_Leather != -1 ? pIcons_LOD->pTextures[uTextureID_Leather].uTextureHeight : 26) - v12);
+      pRenderer->DrawTextureIndexed(8u, 347 - v12, pTexture_591428);
+      v13 = FitTextInAWindow(pInString, pOutString, &pWindow, 0xDu, v8);
+      pDialogueWindow->DrawText(pOutString, 13, 354 - v12, v8, v13, v8, v8, v8);
+      goto LABEL_42;
     }
     if ( uDialogueType == 92 )
     {
       v7 = pGlobalTXT_LocalizationStrings[582]; // "You already won this trip to the Arena:"
-      goto LABEL_37;
+      v8 = 0;
+      pInString = v7;
+      pWindow.uFrameWidth = 460;
+      pWindow.uFrameZ = 452;
+      pOutString = pFontArrus;
+      v12 = pFontArrus->CalcTextHeight(pInString, &pWindow, 13, v8) + 7;
+      if ( 352 - v12 < 8 )
+      {
+        pOutString = pFontCreate;
+        v12 = pFontCreate->CalcTextHeight(pInString, &pWindow, 13, v8) + 7;
+      }
+      pRenderer->_4A6A68(8, 352 - v12, (Texture *)(uTextureID_Leather != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_Leather] : 0),
+        (uTextureID_Leather != -1 ? pIcons_LOD->pTextures[uTextureID_Leather].uTextureHeight : 26) - v12);
+      pRenderer->DrawTextureIndexed(8u, 347 - v12, pTexture_591428);
+      v13 = FitTextInAWindow(pInString, pOutString, &pWindow, 0xDu, v8);
+      pDialogueWindow->DrawText(pOutString, 13, 354 - v12, v8, v13, v8, v8, v8);
+      goto LABEL_42;
     }
   }
   else
@@ -16032,12 +16072,46 @@
     if ( uDialogueType == 89 )
     {
       v7 = pGlobalTXT_LocalizationStrings[574]; // "Welcome to the Arena of Life and Death.  Remember, you are only allowed one arena combat per visit.  To fight an arena battle, select the option that best describes your abilities and return to me- if you survive:"
-      goto LABEL_37;
+      v8 = 0;
+      pInString = v7;
+      pWindow.uFrameWidth = 460;
+      pWindow.uFrameZ = 452;
+      pOutString = pFontArrus;
+      v12 = pFontArrus->CalcTextHeight(pInString, &pWindow, 13, v8) + 7;
+      if ( 352 - v12 < 8 )
+      {
+        pOutString = pFontCreate;
+        v12 = pFontCreate->CalcTextHeight(pInString, &pWindow, 13, v8) + 7;
+      }
+      pRenderer->_4A6A68(8, 352 - v12, (Texture *)(uTextureID_Leather != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_Leather] : 0),
+        (uTextureID_Leather != -1 ? pIcons_LOD->pTextures[uTextureID_Leather].uTextureHeight : 26) - v12);
+      pRenderer->DrawTextureIndexed(8u, 347 - v12, pTexture_591428);
+      v13 = FitTextInAWindow(pInString, pOutString, &pWindow, 0xDu, v8);
+      pDialogueWindow->DrawText(pOutString, 13, 354 - v12, v8, v13, v8, v8, v8);
+      goto LABEL_42;
     }
     if ( uDialogueType == 13 )
     {
-      v5 = 5 * v0->uProfession;
-      goto LABEL_18;
+      v5 = 5 * pNPC->uProfession;
+      v6 = (char *)*(&pNPCStats->field_13A64 + v5);
+      v8 = 0;
+      v7 = sub_495461(v6, uActiveCharacter - 1, 0, 0, 0, 0);
+      pInString = v7;
+      pWindow.uFrameWidth = 460;
+      pWindow.uFrameZ = 452;
+      pOutString = pFontArrus;
+      v12 = pFontArrus->CalcTextHeight(pInString, &pWindow, 13, v8) + 7;
+      if ( 352 - v12 < 8 )
+      {
+        pOutString = pFontCreate;
+        v12 = pFontCreate->CalcTextHeight(pInString, &pWindow, 13, v8) + 7;
+      }
+      pRenderer->_4A6A68(8, 352 - v12, (Texture *)(uTextureID_Leather != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_Leather] : 0),
+        (uTextureID_Leather != -1 ? pIcons_LOD->pTextures[uTextureID_Leather].uTextureHeight : 26) - v12);
+      pRenderer->DrawTextureIndexed(8u, 347 - v12, pTexture_591428);
+      v13 = FitTextInAWindow(pInString, pOutString, &pWindow, 0xDu, v8);
+      pDialogueWindow->DrawText(pOutString, 13, 354 - v12, v8, v13, v8, v8, v8);
+      goto LABEL_42;
     }
     if ( (signed int)uDialogueType > 18 )
     {
@@ -16045,44 +16119,103 @@
       {
         if ( uDialogueType == 77 )
         {
-          v5 = 5 * v0->uProfession;
+          v5 = 5 * pNPC->uProfession;
           if ( byte_F8B1EC )
           {
-            v6 = (char *)*(&pNPCStats->field_13A5C + 5 * v0->uProfession);
-            goto LABEL_19;
-          }
-          if ( v0->uFlags & 0x80 )
-          {
-            v6 = (char *)*(&pNPCStats->field_13A68 + 5 * v0->uProfession);
-LABEL_19:
+            v6 = (char *)*(&pNPCStats->field_13A5C + 5 * pNPC->uProfession);
+            v8 = 0;
+            v7 = sub_495461(v6, uActiveCharacter - 1, 0, 0, 0, 0);
+            pInString = v7;
+            pWindow.uFrameWidth = 460;
+            pWindow.uFrameZ = 452;
+            pOutString = pFontArrus;
+            v12 = pFontArrus->CalcTextHeight(pInString, &pWindow, 13, v8) + 7;
+            if ( 352 - v12 < 8 )
+            {
+              pOutString = pFontCreate;
+              v12 = pFontCreate->CalcTextHeight(pInString, &pWindow, 13, v8) + 7;
+            }
+            pRenderer->_4A6A68(8, 352 - v12, (Texture *)(uTextureID_Leather != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_Leather] : 0),
+                              (uTextureID_Leather != -1 ? pIcons_LOD->pTextures[uTextureID_Leather].uTextureHeight : 26) - v12);
+            pRenderer->DrawTextureIndexed(8u, 347 - v12, pTexture_591428);
+            v13 = FitTextInAWindow(pInString, pOutString, &pWindow, 0xDu, v8);
+            pDialogueWindow->DrawText(pOutString, 13, 354 - v12, v8, v13, v8, v8, v8);
+            goto LABEL_42;
+          }
+          if ( pNPC->uFlags & 0x80 )
+          {
+            v6 = (char *)*(&pNPCStats->field_13A68 + 5 * pNPC->uProfession);
             v8 = 0;
             v7 = sub_495461(v6, uActiveCharacter - 1, 0, 0, 0, 0);
-LABEL_38:
             pInString = v7;
-            goto LABEL_39;
-          }
-LABEL_18:
+            pWindow.uFrameWidth = 460;
+            pWindow.uFrameZ = 452;
+            pOutString = pFontArrus;
+            v12 = pFontArrus->CalcTextHeight(pInString, &pWindow, 13, v8) + 7;
+            if ( 352 - v12 < 8 )
+            {
+              pOutString = pFontCreate;
+              v12 = pFontCreate->CalcTextHeight(pInString, &pWindow, 13, v8) + 7;
+            }
+            pRenderer->_4A6A68(8, 352 - v12, (Texture *)(uTextureID_Leather != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_Leather] : 0),
+                               (uTextureID_Leather != -1 ? pIcons_LOD->pTextures[uTextureID_Leather].uTextureHeight : 26) - v12);
+            pRenderer->DrawTextureIndexed(8u, 347 - v12, pTexture_591428);
+            v13 = FitTextInAWindow(pInString, pOutString, &pWindow, 0xDu, v8);
+            pDialogueWindow->DrawText(pOutString, 13, 354 - v12, v8, v13, v8, v8, v8);
+            goto LABEL_42;
+          }
           v6 = (char *)*(&pNPCStats->field_13A64 + v5);
-          goto LABEL_19;
+          v8 = 0;
+          v7 = sub_495461(v6, uActiveCharacter - 1, 0, 0, 0, 0);
+          pInString = v7;
+          pWindow.uFrameWidth = 460;
+          pWindow.uFrameZ = 452;
+          pOutString = pFontArrus;
+          v12 = pFontArrus->CalcTextHeight(pInString, &pWindow, 13, v8) + 7;
+          if ( 352 - v12 < 8 )
+          {
+            pOutString = pFontCreate;
+            v12 = pFontCreate->CalcTextHeight(pInString, &pWindow, 13, v8) + 7;
+          }
+          pRenderer->_4A6A68(8, 352 - v12, (Texture *)(uTextureID_Leather != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_Leather] : 0),
+                                     (uTextureID_Leather != -1 ? pIcons_LOD->pTextures[uTextureID_Leather].uTextureHeight : 26) - v12);
+          pRenderer->DrawTextureIndexed(8u, 347 - v12, pTexture_591428);
+          v13 = FitTextInAWindow(pInString, pOutString,  &pWindow, 0xDu, v8);
+          pDialogueWindow->DrawText(pOutString, 13, 354 - v12, v8, v13, v8, v8, v8);
+          goto LABEL_42;
         }
         goto LABEL_24;
       }
       if ( byte_5B0938[0] )
         goto LABEL_24;
       v7 = (char *)ptr_F8B1E8;
-LABEL_37:
       v8 = 0;
-      goto LABEL_38;
+      pInString = v7;
+      pWindow.uFrameWidth = 460;
+      pWindow.uFrameZ = 452;
+      pOutString = pFontArrus;
+      v12 = pFontArrus->CalcTextHeight(pInString, &pWindow, 13, v8) + 7;
+      if ( 352 - v12 < 8 )
+      {
+        pOutString = pFontCreate;
+        v12 = pFontCreate->CalcTextHeight(pInString, &pWindow, 13, v8) + 7;
+      }
+      pRenderer->_4A6A68(8, 352 - v12, (Texture *)(uTextureID_Leather != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_Leather] : 0),
+        (uTextureID_Leather != -1 ? pIcons_LOD->pTextures[uTextureID_Leather].uTextureHeight : 26) - v12);
+      pRenderer->DrawTextureIndexed(8u, 347 - v12, pTexture_591428);
+      v13 = FitTextInAWindow(pInString, pOutString, &pWindow, 0xDu, v8);
+      pDialogueWindow->DrawText(pOutString, 13, 354 - v12, v8, v13, v8, v8, v8);
+      goto LABEL_42;
     }
   }
 LABEL_24:
   if ( *(int *)v54 == 1 )
   {
-    v11 = v0->greet;
+    v11 = pNPC->greet;
     v8 = 0;
     if ( v11 )
     {
-      v10 = (char *)*(&pNPCStats->field_17884 + ((v0->uFlags & 3) == 2) + 2 * v11);
+      v10 = (char *)*(&pNPCStats->field_17884 + ((pNPC->uFlags & 3) == 2) + 2 * v11);
       goto LABEL_32;
     }
   }
@@ -16091,32 +16224,28 @@
     if ( *(int *)v54 == 2 )
     {
       v8 = 0;
-      if ( v0->uFlags & 0x80 )
-        v9 = (char *)*(&pNPCStats->field_13A68 + 5 * v0->uProfession);
-      else
-        v9 = (char *)*(&pNPCStats->field_13A64 + 5 * v0->uProfession);
+      if ( pNPC->uFlags & 0x80 )
+        v9 = (char *)*(&pNPCStats->field_13A68 + 5 * pNPC->uProfession);
+      else
+        v9 = (char *)*(&pNPCStats->field_13A64 + 5 * pNPC->uProfession); //"Invalid String Passed"
       v10 = sub_495461(v9, uActiveCharacter - 1, 0, 0, 0, 0);
 LABEL_32:
       pInString = v10;
       if ( v10 == (char *)v8 )
         goto LABEL_42;
-LABEL_39:
-      v49 = 460;
-      v50 = 452;
+      pWindow.uFrameWidth = 460;
+      pWindow.uFrameZ = 452;
       pOutString = pFontArrus;
-      v12 = pFontArrus->CalcTextHeight(pInString, (GUIWindow *)&pFont, 13, v8) + 7;
+      v12 = pFontArrus->CalcTextHeight(pInString, &pWindow, 13, v8) + 7;
       if ( 352 - v12 < 8 )
       {
         pOutString = pFontCreate;
-        v12 = pFontCreate->CalcTextHeight(pInString, (GUIWindow *)&pFont, 13, v8) + 7;
-      }
-      pRenderer->_4A6A68(
-        8u,
-        352 - v12,
-        (Texture *)(uTextureID_Leather != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_Leather] : 0),
+        v12 = pFontCreate->CalcTextHeight(pInString, &pWindow, 13, v8) + 7;
+      }
+      pRenderer->_4A6A68(8, 352 - v12, (Texture *)(uTextureID_Leather != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_Leather] : 0),
         (uTextureID_Leather != -1 ? pIcons_LOD->pTextures[uTextureID_Leather].uTextureHeight : 26) - v12);
       pRenderer->DrawTextureIndexed(8u, 347 - v12, pTexture_591428);
-      v13 = FitTextInAWindow(pInString, pOutString, (GUIWindow *)&pFont, 0xDu, v8);
+      v13 = FitTextInAWindow(pInString, pOutString, &pWindow, 0xDu, v8);
       pDialogueWindow->DrawText(pOutString, 13, 354 - v12, v8, v13, v8, v8, v8);
       goto LABEL_42;
     }
@@ -16153,7 +16282,10 @@
               if ( v29 )
               {
                 if ( v29 != 1 )
-                  goto LABEL_71;
+                {
+                  v24 = "";
+                  goto LABEL_79;
+                }
                 v24 = pGlobalTXT_LocalizationStrings[581];
               }
               else
@@ -16178,10 +16310,9 @@
       }
       else
       {
-        if ( v0->uFlags & 0x80 )
-        {
-LABEL_59:
-          sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[408], v0->pName);
+        if ( pNPC->uFlags & 0x80 )
+        {
+          sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[408], pNPC->pName);
           v24 = pTmpBuf;
           goto LABEL_79;
         }
@@ -16192,9 +16323,9 @@
     {
       if ( v16 == 24 )
       {
-        v23 = v0->evtf;
+        v23 = pNPC->evtf;
 LABEL_63:
-		v24 = pNPCTopics[v23-1].pTopic;//(&dword_721660)[8 * v23];
+        v24 = pNPCTopics[v23-1].pTopic;//(&dword_721660)[8 * v23];
         if ( !v24 )
         {
           v24 = "";
@@ -16205,7 +16336,7 @@
       v17 = v16 - 9;
       if ( !v17 )
       {
-        v24 = (const char *)sub_445308(v0->uProfession);
+        v24 = (const char *)sub_445308(pNPC->uProfession);
         goto LABEL_79;
       }
       v18 = v17 - 4;
@@ -16214,38 +16345,41 @@
         v19 = v18 - 6;
         if ( !v19 )
         {
-          v23 = v0->bDrawSomeAnim;
+          v23 = pNPC->bDrawSomeAnim;
           goto LABEL_63;
         }
         v20 = v19 - 1;
         if ( !v20 )
         {
-          v23 = v0->_anim_current_time;
+          v23 = pNPC->_anim_current_time;
           goto LABEL_63;
         }
         v21 = v20 - 1;
         if ( !v21 )
         {
-          v23 = v0->_anim_end_time;
+          v23 = pNPC->_anim_end_time;
           goto LABEL_63;
         }
         v22 = v21 - 1;
         if ( !v22 )
         {
-          v23 = v0->evtd;
+          v23 = pNPC->evtd;
           goto LABEL_63;
         }
         if ( v22 == 1 )
         {
-          v23 = v0->evte;
+          v23 = pNPC->evte;
           goto LABEL_63;
         }
-LABEL_71:
         v24 = "";
         goto LABEL_79;
       }
-      if ( v0->uFlags & 0x80 )
-        goto LABEL_59;
+      if ( pNPC->uFlags & 0x80 )
+      {
+        sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[408], pNPC->pName);
+        v24 = pTmpBuf;
+        goto LABEL_79;
+      }
       v24 = pGlobalTXT_LocalizationStrings[122];
     }
 LABEL_79:
@@ -16326,10 +16460,7 @@
       while ( (signed int)v41 < pDialogueWindow->pNumPresenceButton + pDialogueWindow->pStartingPosActiveItem );
     }
   }
-  pRenderer->DrawTextureIndexed(
-    0x1D7u,
-    0x1BDu,
-    (Texture *)(uTextureID_506438 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_506438] : 0));
+  pRenderer->DrawTextureIndexed(471, 445, (Texture *)(uTextureID_506438 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_506438] : 0));
 }
 
 //----- (004459F9) --------------------------------------------------------
@@ -19826,95 +19957,147 @@
 //----- (0044C768) --------------------------------------------------------
 char *__fastcall FitTextInAWindow(const char *pInString, GUIFont *pFont, GUIWindow *pWindow, unsigned int uX, int a5)
 {
+  const char *v5; // edi@1
+  GUIFont *v6; // esi@1
   unsigned int v8; // eax@3
+  int v9; // edi@3
   unsigned __int8 v10; // cl@4
+  int v11; // edx@10
   GUICharMetric *v12; // ecx@10
+  int v13; // edx@11
+  int v14; // edx@12
+  int v15; // edx@13
   unsigned int v16; // esi@15
   unsigned int v17; // edx@15
   unsigned int v18; // ecx@15
+  int v19; // ebx@16
+  unsigned __int8 v20; // zf@16
+  char v21; // sf@16
+  unsigned __int8 v22; // of@16
+  int v23; // edi@16
   unsigned __int8 v24; // dl@17
   int v25; // edi@39
   int v26; // eax@42
   std::string v27; // [sp-18h] [bp-40h]@2
   const char *v28; // [sp-8h] [bp-30h]@2
   int v29; // [sp-4h] [bp-2Ch]@2
+  const char *v30; // [sp+Ch] [bp-1Ch]@1
   char Str[3]; // [sp+10h] [bp-18h]@42
   char v32; // [sp+13h] [bp-15h]@42
-  int v33; // [sp+14h] [bp-14h]@3
+  size_t v33; // [sp+14h] [bp-14h]@3
+  unsigned int v34; // [sp+18h] [bp-10h]@3
+  GUIFont *v35; // [sp+1Ch] [bp-Ch]@1
   int v36; // [sp+20h] [bp-8h]@3
-
+  int v37; // [sp+24h] [bp-4h]@3
+
+  v5 = pInString;
+  v6 = pFont;
+  v30 = pInString;
+  v35 = pFont;
   if ( !pInString )
   {
     MessageBoxW(nullptr, L"Invalid string passed !", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Font.cpp:445", 0);
     return 0;
   }
   v33 = strlen(pInString);
-  strcpy(pTmpBuf3, pInString);
+  strcpy(pTmpBuf3, v5);
   v8 = uX;
+  v9 = 0;
   v36 = 0;
-  for(int i=0;i<v33;i++)
-  {
-    v10 = pTmpBuf3[i];
-    if(!(v10 < pFont->cFirstChar || v10 > pFont->cLastChar) || v10 == '\f' || v10 == '\r' || v10 == '\t' || v10 == '\n' )
-	{
-		v12 = &pFont->pMetrics[v10];
-		if ( v10 == '\t' )
-		{
-			strncpy(Str, &pTmpBuf3[i + 1], 3u);
-			v32 = 0;
-			v26 = atoi(Str);
-			v8 = uX + v26;
-			i+=3;
-		}
-		else if ( v10 == '\n' )
-		{
-			v36 = i;
-		}
-		else if ( v10 == '\f' )
-		{
-			i+=5;
-		}
-		else if ( v10 == '\r' && !a5)
-			return (char *)pInString;
-		else if ( v10 == ' ' )
-		{
-			v8 += v12->uWidth;
-			v36 = i;
-		}
-		else
-		{
-			v16 = v12->uRightSpacing;
-			v17 = v12->uWidth;
-			v18 = v12->uLeftSpacing;
-			if ( v8 + v16 + v18 + v17 < pWindow->uFrameWidth )
-			{
-				if ( i > v36 )
-					v8 += v18;
-				v8 += v17;
-				if ( i < v33 )
-					v8 += v16;
-			}
-			else
-			{
-				pTmpBuf3[v36] = 10;
-				if ( v36 == i )//(unsigned __int8)(v21 ^ v22) | v20 )
-				{
-					for(int j=v36;j<=i;j++)
-					{
-						v24 = pTmpBuf3[j];
-						if ( v24 >= pFont->cFirstChar && v24 <= pFont->cLastChar || v24 == '\f' || v24 == '\r' || v24 == '\t' || v24 == '\n' )
-						{
-							if ( j > v36 )
-								v8 += pFont->pMetrics[v24].uLeftSpacing;
-							v8 += pFont->pMetrics[v24].uWidth;//*((int *)&pFont->cFirstChar + 3 * v24 + 9);
-							if ( j < i )
-								v8 += pFont->pMetrics[v24].uRightSpacing;
-						}
-					}
-				}
-			}
-		}
-	}							
+  v34 = uX;
+  v37 = 0;
+  if ( (signed int)v33 > 0 )
+  {
+    while ( 1 )
+    {
+      v10 = pTmpBuf3[v9];
+      if ((v10 < v6->cFirstChar || v10 > v6->cLastChar)
+          && v10 != '\f' && v10 != '\r' && v10 != '\t' && v10 != '\n' )
+        goto LABEL_34;
+      v11 = v10 - 9;
+      v12 = &v6->pMetrics[v10];
+      if ( !v11 )
+      {
+        strncpy(Str, &pTmpBuf3[v9 + 1], 3u);
+        v32 = 0;
+        v26 = atoi(Str);
+        v8 = uX + v26;
+        v25 = v9 + 3;
+        v34 = v8;
+        goto LABEL_43;
+      }
+      v13 = v11 - 1;
+      if ( !v13 )
+        break;
+      v14 = v13 - 2;
+      if ( !v14 )
+      {
+        v25 = v9 + 5;
+LABEL_43:
+        v37 = v25;
+        goto LABEL_34;
+      }
+      v15 = v14 - 1;
+      if ( v15 )
+      {
+        if ( v15 != 19 )
+        {
+          v16 = v12->uRightSpacing;
+          v17 = v12->uWidth;
+          v18 = v12->uLeftSpacing;
+          if ( v8 + v16 + v18 + v17 < pWindow->uFrameWidth )
+          {
+            if ( v37 > v36 )
+              v8 += v18;
+            v8 += v17;
+            if ( v37 < (signed int)v33 )
+              v8 += v16;
+            v6 = v35;
+          }
+          else
+          {
+            v19 = v36;
+            v8 = v34;
+            v22 = v36 > v37;
+            v20 = v36 == v37;
+            v21 = v36 - v37 < 0;
+            v6 = v35;
+            pTmpBuf3[v36] = 10;
+            v23 = v19;
+            if ( (unsigned __int8)(v21 ^ v22) | v20 )
+            {
+              do
+              {
+                v24 = pTmpBuf3[v23];
+                if ( v24 >= v6->cFirstChar && v24 <= v6->cLastChar || v24 == 12 || v24 == 13 || v24 == 9 || v24 == 10 )
+                {
+                  if ( v23 > v19 )
+                    v8 += v6->pMetrics[v24].uLeftSpacing;
+                  v8 += *((int *)&v6->cFirstChar + 3 * v24 + 9);
+                  if ( v23 < v37 )
+                    v8 += v6->pMetrics[v24].uRightSpacing;
+                }
+                ++v23;
+              }
+              while ( v23 <= v37 );
+            }
+          }
+          goto LABEL_34;
+        }
+        v8 += v12->uWidth;
+        goto LABEL_41;
+      }
+      if ( !a5 )
+        return (char *)v30;
+LABEL_34:
+      v9 = v37++ + 1;
+      if ( v37 >= (signed int)v33 )
+        return pTmpBuf3;
+    }
+    v8 = v34;
+LABEL_41:
+    v36 = v9;
+    goto LABEL_34;
   }
   return pTmpBuf3;
 }