Guest User

Untitled

a guest
Jun 15th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "empire_text_convert.h"
  3.  
  4. namespace
  5. {
  6. struct STextConvertTable
  7. {
  8. char acUpper[26];
  9. char acLower[26];
  10. BYTE aacHan[5000][2];
  11. BYTE aacJaum[50][2];
  12. BYTE aacMoum[50][2];
  13. } g_aTextConvTable[3];
  14. }
  15.  
  16. bool LoadEmpireTextConvertTable(DWORD dwEmpireID, const char* c_szFileName)
  17. {
  18. if (dwEmpireID < 1 || dwEmpireID > 3)
  19. return false;
  20.  
  21. FILE * fp = fopen(c_szFileName, "rb");
  22.  
  23. if (!fp)
  24. return false;
  25.  
  26. DWORD dwEngCount = 26;
  27. DWORD dwHanCount = (0xC8 - 0xB0+1) * (0xFE - 0xA1+1);
  28. DWORD dwHanSize = dwHanCount * 2;
  29.  
  30. STextConvertTable& rkTextConvTable=g_aTextConvTable[dwEmpireID-1];
  31.  
  32. fread(rkTextConvTable.acUpper, 1, dwEngCount, fp);
  33. fread(rkTextConvTable.acLower, 1, dwEngCount, fp);
  34. fread(rkTextConvTable.aacHan, 1, dwHanSize, fp);
  35.  
  36. fread(rkTextConvTable.aacJaum, 1, 60, fp);
  37. fread(rkTextConvTable.aacMoum, 1, 42, fp);
  38.  
  39. fclose(fp);
  40.  
  41. return true;
  42. }
  43.  
  44. void ConvertEmpireText(DWORD dwEmpireID, char* szText, size_t len, int iPct)
  45. {
  46. if (dwEmpireID < 1 || dwEmpireID > 3 || len == 0)
  47. return;
  48.  
  49. const STextConvertTable& rkTextConvTable = g_aTextConvTable[dwEmpireID - 1];
  50.  
  51. for (BYTE* pbText = reinterpret_cast<BYTE*>(szText) ; len > 0 && *pbText != '\0' ; --len, ++pbText)
  52. {
  53. if (number(1,100) > iPct)
  54. {
  55. if (*pbText & 0x80)
  56. {
  57. if (g_iUseLocale)
  58. {
  59. static char s_cChinaTable[][3] = {"ˇň","ŁŁ","٤","ˇů","ˇđ" };
  60. int n = number(0, 4);
  61. pbText[0] = s_cChinaTable[n][0];
  62. pbText[1] = s_cChinaTable[n][1];
  63. }
  64. else
  65. {
  66. if (pbText[0] >= 0xB0 && pbText[0] <= 0xC8 && pbText[1] >= 0xA1 && pbText[1] <= 0xFE)
  67. {
  68. UINT uHanPos = (pbText[0] - 0xB0) * (0xFE - 0xA1 + 1) + (pbText[1] - 0xA1);
  69. pbText[0] = rkTextConvTable.aacHan[uHanPos][0];
  70. pbText[1] = rkTextConvTable.aacHan[uHanPos][1];
  71. }
  72. else if ( pbText[0] == 0xA4 )
  73. {
  74. if ( pbText[1] >=0xA1 && pbText[1] <= 0xBE )
  75. {
  76. pbText[0] = rkTextConvTable.aacJaum[pbText[1]-0xA1][0];
  77. pbText[1] = rkTextConvTable.aacJaum[pbText[1]-0xA1][1];
  78. }
  79. else if ( pbText[1] >= 0xBF && pbText[1] <= 0xD3 )
  80. {
  81. pbText[0] = rkTextConvTable.aacMoum[pbText[1]-0xBF][0];
  82. pbText[1] = rkTextConvTable.aacMoum[pbText[1]-0xBF][1];
  83. }
  84. }
  85. }
  86.  
  87. ++pbText;
  88. --len;
  89. }
  90. else
  91. {
  92. if (*pbText >= 'a' && *pbText <= 'z')
  93. {
  94. *pbText = rkTextConvTable.acLower[*pbText - 'a'];
  95. }
  96. else if (*pbText >= 'A' && *pbText <= 'Z')
  97. {
  98. *pbText = rkTextConvTable.acUpper[*pbText - 'A'];
  99. }
  100. }
  101. }
  102. else
  103. {
  104. if (*pbText & 0x80)
  105. {
  106. ++pbText;
  107. --len;
  108. }
  109. }
  110. }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment