[ create a new paste ] login | about

Link: http://codepad.org/S0vHlhF7    [ raw code | fork ]

Raheem - C, pasted on Sep 12:
#include <amxmodx> 

public plugin_init() 
{
	register_plugin("Arabic Chat Fix", "1.0", "Raheem")
    register_message(get_user_msgid("SayText"), "msgSayText") 
} 

public msgSayText() 
{ 
    new said[192], said_to_utf16[192], said_to_utf8[576]
    get_msg_arg_string(4, said, 191);

	replace_all(said, 191, "ا", "ﺎ")
	replace_all(said, 191, "ب", "ﺑ")
	replace_all(said, 191, "ت", "ﺗ")
	replace_all(said, 191, "ث", "ﺛ")
	replace_all(said, 191, "ج", "ﺟ")
	replace_all(said, 191, "ح", "ﺣ")
	replace_all(said, 191, "خ", "ﺧ")
	replace_all(said, 191, "س", "ﺳ")
	replace_all(said, 191, "ش", "ﺷ")
	replace_all(said, 191, "ص", "ﺻ")
	replace_all(said, 191, "ﺽ‎", "ﺿ‎")
	replace_all(said, 191, "ع", "ﻋ")
	replace_all(said, 191, "غ", "ﻏ")
	replace_all(said, 191, "ف", "ﻓ")
	replace_all(said, 191, "ق", "ﻗ")
	replace_all(said, 191, "ك", "ﻛ")
	replace_all(said, 191, "م", "ﻣ")
	replace_all(said, 191, "ن", "ﻧ")
	replace_all(said, 191, "ي", "ﻳ")
	replace_all(said, 191, "ة", "ﺔ")
	replace_all(said, 191, "ى", "ﻰ")
	replace_all(said, 191, "ه", "ﻪ")
	replace_all(said, 191, "ل", "ﻟ")
	
	MultiByteToWideChar(said, said_to_utf16)
	
	if(isEnglish(said_to_utf16))
		return PLUGIN_CONTINUE;

    ReverseString(said_to_utf16)

	WideCharToMultiByte(said_to_utf16, said_to_utf8)

    set_msg_arg_string(4, said_to_utf8);
}

stock ReverseString(toggle[]) 
{ 
    for(new i = strlen(toggle) - 1, j = 0, temp ; i > j ; i--, j++) 
    { 
        temp = toggle[i]; 
        toggle[i] = toggle[j]; 
        toggle[j] = temp; 
    } 
}

stock MultiByteToWideChar(const mbszInput[], wcszOutput[])
{ 
    new nOutputChars = 0; 
    for (new n = 0; mbszInput[n] != EOS; n++) { 
        if (mbszInput[n] < 0x80) { // 0... 1-byte ASCII 
            wcszOutput[nOutputChars] = mbszInput[n]; 
        } else if ((mbszInput[n] & 0xE0) == 0xC0) { // 110... 2-byte UTF-8 
            wcszOutput[nOutputChars] = (mbszInput[n] & 0x1F) << 6; // Upper 5 bits 
             
            if ((mbszInput[n + 1] & 0xC0) == 0x80) { // Is 10... ? 
                wcszOutput[nOutputChars] |= mbszInput[++n] & 0x3F; // Lower 6 bits 
            } else { // Decode error 
                wcszOutput[nOutputChars] = '?'; 
            } 
        } else if ((mbszInput[n] & 0xF0) == 0xE0) { // 1110... 3-byte UTF-8 
            wcszOutput[nOutputChars] = (mbszInput[n] & 0xF) << 12; // Upper 4 bits 
             
            if ((mbszInput[n + 1] & 0xC0) == 0x80) { // Is 10... ? 
                wcszOutput[nOutputChars] |= (mbszInput[++n] & 0x3F) << 6; // Middle 6 bits 
                 
                if ((mbszInput[n + 1] & 0xC0) == 0x80) { // Is 10... ? 
                    wcszOutput[nOutputChars] |= mbszInput[++n] & 0x3F; // Lower 6 bits 
                } else { // Decode error 
                    wcszOutput[nOutputChars] = '?'; 
                } 
            } else { // Decode error 
                wcszOutput[nOutputChars] = '?'; 
            } 
        } else { // Decode error 
            wcszOutput[nOutputChars] = '?'; 
        } 
         
        nOutputChars++; 
    } 
    wcszOutput[nOutputChars] = EOS; 
}

stock WideCharToMultiByte(const wcszInput[], mbszOutput[])
{ 
    new nOutputChars = 0; 
    for (new n = 0; wcszInput[n] != EOS; n++) { 
        if (wcszInput[n] < 0x80) { 
            mbszOutput[nOutputChars++] = wcszInput[n]; 
        } else if (wcszInput[n] < 0x800) { 
            mbszOutput[nOutputChars++] = (wcszInput[n] >> 6) | 0xC0; 
            mbszOutput[nOutputChars++] = (wcszInput[n] & 0x3F) | 0x80; 
        } else { 
            mbszOutput[nOutputChars++] = (wcszInput[n] >> 12) | 0xE0; 
            mbszOutput[nOutputChars++] = ((wcszInput[n] >> 6) & 0x3F) | 0x80; 
            mbszOutput[nOutputChars++] = (wcszInput[n] & 0x3F) | 0x80; 
        } 
    } 
    mbszOutput[nOutputChars] = EOS; 
}

isEnglish(const szString[])
{
    new i = 0;
    new ch;
    while((ch = szString[i]) != EOS)
    {
        if(0x41 <= ch <= 0x7a)
            return true;
        
        i++;
    }
	
    return false;
}

//if(0x600 <= ch <= 0x6FF) Arabic UniCode Range


Create a new paste based on this one


Comments: