SHARE
TWEET

Untitled

a guest Oct 14th, 2018 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "SDK\amx\amx.h"
  2. #include "SDK\plugincommon.h"
  3. #include <string>
  4.  
  5. typedef void(*logprintf_t)(char* format, ...);
  6.  
  7. logprintf_t logprintf;
  8. extern void *pAMXFunctions;
  9.  
  10. PLUGIN_EXPORT bool PLUGIN_CALL Load(void **ppData)
  11. {
  12.     pAMXFunctions = ppData[PLUGIN_DATA_AMX_EXPORTS];
  13.     logprintf = (logprintf_t)ppData[PLUGIN_DATA_LOGPRINTF];
  14.  
  15.     logprintf(" =======================================");
  16.     logprintf("  ** Color Embed by Aktah loaded");
  17.     logprintf(" =======================================");
  18.     return 1;
  19. }
  20.  
  21. PLUGIN_EXPORT void PLUGIN_CALL Unload()
  22. {
  23.     logprintf(" =======================================");
  24.     logprintf("  ** Color Embed by Aktah unloaded");
  25.     logprintf(" =======================================");
  26. }
  27.  
  28. char* subc(const char* input, int offset, int len, char* dest)
  29. {
  30.     int input_len = strlen(input);
  31.  
  32.     if (offset + len > input_len)
  33.     {
  34.         return NULL;
  35.     }
  36.  
  37.     strncpy(dest, input + offset, len);
  38.     return dest;
  39. }
  40.  
  41. int shiftLeft(char text[], char color[], int Pos, int shiftBy)
  42. {
  43.     int count = 0;
  44.     char igor_spaces[] = { ' ', '\n', '\t' };
  45.  
  46.     while (shiftBy > 0) {
  47.  
  48.         text[Pos + 7 - count] = text[Pos - 1 - count];
  49.  
  50.         if (!memchr(igor_spaces, text[Pos - 1 - count], sizeof(igor_spaces)))
  51.         {
  52.             shiftBy--;
  53.         }
  54.         count++;
  55.  
  56.     }
  57.  
  58.     text[Pos - count] = color[0];
  59.     text[Pos - count + 1] = color[1];
  60.     text[Pos - count + 2] = color[2];
  61.     text[Pos - count + 3] = color[3];
  62.     text[Pos - count + 4] = color[4];
  63.     text[Pos - count + 5] = color[5];
  64.     text[Pos - count + 6] = color[6];
  65.     text[Pos - count + 7] = color[7];
  66.     return Pos - count + 7;
  67. }
  68.  
  69. cell AMX_NATIVE_CALL CE_Convert(AMX *amx, cell *params)
  70. {
  71.     int
  72.         len = NULL,
  73.         ret = NULL;
  74.  
  75.     cell *addr = NULL;
  76.  
  77.     amx_GetAddr(amx, params[1], &addr);
  78.     amx_StrLen(addr, &len);
  79.  
  80.     if (len)
  81.     {
  82.         len++; // for \0
  83.         char* text = new char[len];
  84.         amx_GetString(text, addr, 0, len);
  85.  
  86.         int next_space = -1;
  87.         int last_check = 0;
  88.         int vowel_count = 0;
  89.         char vowel[] = { 'ั', 'ิ', 'ี', 'ึ', 'ื', 'ุ', 'ู', '็', '่', '้', '๊', '๋', '์', 'ํ', 'ำ' };
  90.         char double_vowel[] = { 'ั', 'ิ', 'ี', 'ึ', 'ื', '่', '้', '๊', '๋', 'ํ', 'ำ' };
  91.  
  92.         for (int i = 0, j = len; i < j; ++i) {
  93.  
  94.             next_space = i + 7;
  95.             if (text[i] == '{' && next_space < j && text[next_space] == '}') {
  96.  
  97.                 char EmbledColor[8];
  98.                 subc(text, i, 8, EmbledColor);
  99.  
  100.                 for (int x = last_check + 1; x < i; x++) {
  101.                     if (memchr(vowel, text[x], sizeof(vowel)))
  102.                     {
  103.                         vowel_count++;
  104.                     }
  105.  
  106.                     // DOUBLE VOWEL WITH SPACES like นั้น_ or นี้_ << underscore are blank space or newline
  107.                     if (memchr(double_vowel, text[x], sizeof(double_vowel)) && memchr(double_vowel, text[x + 1], sizeof(double_vowel))
  108.                         && (text[x + 2] == ' ' || text[next_space + 1] == ' ' || text[x + 3] == '\n'))
  109.                     {
  110.                         vowel_count--;
  111.                     }
  112.                 }
  113.  
  114.                 if (vowel_count > 0) {
  115.                     shiftLeft(text, EmbledColor, i, vowel_count);
  116.                 }
  117.  
  118.                 last_check = next_space;
  119.  
  120.             }
  121.  
  122.         }
  123.  
  124.         amx_SetString(addr, text, 0, 0, len);
  125.         delete[] text;
  126.     }
  127.     return 1;
  128. }
  129.  
  130. AMX_NATIVE_INFO projectNatives[] =
  131. {
  132.     { "CE_Convert", CE_Convert }
  133. };
  134.  
  135.  
  136. PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports()
  137. {
  138.     return SUPPORTS_VERSION | SUPPORTS_AMX_NATIVES;
  139. }
  140.  
  141. PLUGIN_EXPORT int PLUGIN_CALL AmxLoad(AMX *amx)
  142. {
  143.     return amx_Register(amx, projectNatives, -1);
  144. }
  145.  
  146. PLUGIN_EXPORT int PLUGIN_CALL AmxUnload(AMX *amx)
  147. {
  148.     return AMX_ERR_NONE;
  149. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top