Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //---------------------------------------------- Thanks ------------------------------------------------//
- // Rahim for the byte system //
- // chatgpt for understanding the stupied system of cs 1.6 //
- //-------------------------- known bugs ( until i find a way to fix them ) -----------------------------//
- // 1. if 1 hebrew word contain more then 16 letters it will bugged. //
- // 2. the order of the words not perfect. the order is changing for each lang //
- // example: hebrew english hebrew english will be exacly this order. the idea is to //
- // make it work depend on the start lang which mean if it start with hebrew so the hebrew //
- // will be the last and after the english first sentense and then hebrew sentense //
- //-------------------- Includes --------------------//
- #include < amxmodx >
- new sentblock
- //-------------------- Plugin init --------------------//
- public plugin_init()
- {
- register_plugin( "Reversed Hebrew", "v1.0", "RanAway`" )
- register_clcmd( "say", "ReverseMessage", false )
- register_clcmd( "say_team", "ReverseMessage", true )
- }
- //-------------------- ReverseMessage --------------------//
- public ReverseMessage( id, bool:Tsay )
- {
- //-------------------- Prevent spam --------------------//
- if( id == sentblock ) return sentblock = 0
- //-------------------- Message functions --------------------//
- new message[ 192 ], tempWord[ 32 ], reversedMessage[ 192 ] = "", UTF[ 32 ], Character = 0, wordCount = 0
- read_args( message, charsmax( message ) )
- remove_quotes( message )
- //-------------------- Process Each Character --------------------//
- while( Character < strlen( message ) )
- {
- new wordStart = Character
- //-------------------- Find the next space, special character, or English letter --------------------//
- while( Character < strlen( message ) && !isspace( message[ Character ] ) && !IsSpecialCharacter( message[ Character ] ) && !isalpha( message[ Character ] ) ) Character++
- //-------------------- Calculate word length --------------------//
- new wordLength = Character - wordStart
- if( wordLength >= sizeof( tempWord ) ) wordLength = sizeof( tempWord )
- //-------------------- Copy the word to tempWord --------------------//
- for( new j = 0; j < wordLength; j++ ) tempWord[ j ] = message[ wordStart + j ]
- tempWord[ wordLength ] = EOS
- //-------------------- Convert and reverse Hebrew word if applicable --------------------//
- MultiByteToWideChar( tempWord, UTF )
- if( IsHebrew( UTF ) )
- {
- new reverseWord[ 32 ]
- ReverseString( UTF, reverseWord )
- WideCharToMultiByte( reverseWord, tempWord )
- wordCount++
- }
- //-------------------- Append the reversed word to the final message --------------------//
- strcat( reversedMessage, tempWord, charsmax( reversedMessage ) )
- //-------------------- Handle special characters or English letters without flipping them --------------------//
- while( Character < strlen( message ) && ( IsSpecialCharacter( message[ Character ] ) || isalpha( message[ Character ] ) ) )
- {
- new specialChar[ 2 ]
- specialChar[ 0 ] = message[ Character ]
- specialChar[ 1 ] = EOS
- strcat( reversedMessage, specialChar, charsmax( reversedMessage ) )
- Character++
- }
- //-------------------- Append space --------------------//
- if( Character < strlen( message ) && isspace( message[ Character ] ) )
- {
- strcat( reversedMessage, " ", charsmax( reversedMessage ) )
- Character++
- }
- }
- //-------------------- Reverse order of Hebrew words if necessary --------------------//
- if( wordCount > 1 ) ReverseWordsOrder( reversedMessage )
- sentblock = id
- //-------------------- Send Message to Team or General Chat --------------------//
- amxclient_cmd( id, Tsay ? "say_team" : "say", reversedMessage )
- return 1
- }
- //-------------------- Check if Character is a special character --------------------//
- stock IsSpecialCharacter( symbol )
- {
- return ( symbol >= 0x0021 && symbol <= 0x002F ) || // ! " # $ % & ' ( ) * + , - . /
- ( symbol >= 0x003A && symbol <= 0x0040 ) || // : ; < = > ? @
- ( symbol >= 0x005B && symbol <= 0x0060 ) || // [ \ ] ^ _ `
- ( symbol >= 0x007B && symbol <= 0x007E ) // { | } ~
- }
- //-------------------- Check if String Contains Hebrew Characters --------------------//
- stock IsHebrew( input[] )
- {
- for( new i = 0; input[ i ] != EOS; i++ ) if( input[ i ] >= 0x0590 && input[ i ] <= 0x05FF ) return true
- return false
- }
- //-------------------- Reverse String in Buffer --------------------
- stock ReverseString( input[], output[] )
- {
- new len = strlen( input )
- for( new i = 0; i < len; i++ ) output[ i ] = input[ len - i - 1 ]
- output[ len ] = EOS
- }
- //-------------------- Reverse Words Order in Message --------------------//
- stock ReverseWordsOrder( reversedMessage[] )
- {
- //-------------------- Message functions --------------------//
- new words[ 32 ][ 32 ], hebrewWords[ 32 ][ 32 ], output[ 192 ] = ""
- new Character = 0, wordStart = 0, wordCount = 0, hebrewWordCount = 0, hebrewGroupStart = -1
- //-------------------- Iterate Through Characters to Extract Words --------------------//
- while( Character < strlen( reversedMessage ) )
- {
- //-------------------- Identify Start of New Word --------------------//
- if( !isspace( reversedMessage[ Character ] ) )
- {
- wordStart = Character
- //-------------------- Find End of Current Word --------------------//
- while( Character < strlen( reversedMessage ) && !isspace( reversedMessage[ Character ] ) ) Character++
- //-------------------- Calculate Word Length and Validate --------------------//
- new wordLength = Character - wordStart
- if( wordLength > 0 && wordLength < 32 )
- {
- //-------------------- Copy Current Word to Array --------------------//
- copy( words[ wordCount ], sizeof( words ), reversedMessage[ wordStart ] )
- words[ wordCount ][ wordLength ] = EOS
- //-------------------- Convert Multi-Byte - 8 - to Wide-Character - 16 - --------------------//
- new UTF16[ 32 ]
- MultiByteToWideChar( words[ wordCount ], UTF16 )
- //-------------------- Handle Hebrew Words --------------------//
- if( IsHebrew( UTF16 ) )
- {
- //-------------------- Define Start of Hebrew Word Group --------------------//
- if( hebrewGroupStart == -1 ) hebrewGroupStart = wordCount
- //-------------------- Add Hebrew Word to List --------------------//
- copy( hebrewWords[ hebrewWordCount ], sizeof( hebrewWords ), words[ wordCount ] )
- hebrewWords[ hebrewWordCount ][ wordLength ] = EOS
- hebrewWordCount++
- }
- //-------------------- Handle Non-Hebrew Words --------------------//
- else
- {
- //-------------------- Check and Reverse Hebrew Words Group --------------------//
- if( hebrewGroupStart != -1 )
- {
- //-------------------- Reverse Order of Hebrew Words in Group --------------------//
- new reversedHebrewWords[ 32 ][ 32 ]
- for( new j = 0; j < hebrewWordCount; j++ ) copy( reversedHebrewWords[ hebrewWordCount - j - 1 ], sizeof( reversedHebrewWords ), hebrewWords[ j ] )
- //-------------------- Add Reversed Hebrew Words to Output --------------------//
- for( new j = 0; j < hebrewWordCount; j++ )
- {
- strcat( output, reversedHebrewWords[ j ], sizeof( output ) )
- strcat( output, " ", sizeof( output ) )
- }
- //-------------------- Reset Hebrew Group Tracking --------------------//
- hebrewGroupStart = -1
- hebrewWordCount = 0
- }
- //-------------------- Append Non-Hebrew Word to Output --------------------//
- strcat( output, words[ wordCount ], sizeof( output ) )
- strcat( output, " ", sizeof( output ) )
- }
- wordCount++
- }
- }
- //-------------------- Procced to the next character --------------------//
- if( Character < strlen( reversedMessage ) ) Character++
- }
- //-------------------- Handle Remaining Hebrew Words at End --------------------//
- if( hebrewGroupStart != -1 )
- {
- //-------------------- Handle Remaining Hebrew Words at End --------------------//
- new reversedHebrewWords[ 32 ][ 32 ]
- for( new j = 0; j < hebrewWordCount; j++ ) copy( reversedHebrewWords[ hebrewWordCount - j - 1 ], sizeof( reversedHebrewWords ), hebrewWords[ j ] )
- //-------------------- Add Reversed Hebrew Words to Output --------------------//
- for( new j = 0; j < hebrewWordCount; j++ )
- {
- strcat( output, reversedHebrewWords[ j ], sizeof( output ) )
- strcat( output, " ", sizeof( output ) )
- }
- }
- //-------------------- Remove Trailing Space from Output String --------------------//
- if( strlen( output ) > 0 ) output[ strlen( output ) - 1 ] = EOS
- //-------------------- Copy Final Output to ReversedMessage --------------------//
- copy( reversedMessage, 192, output )
- }
- //-------------------- Convert Multi-Byte - 8 - to Wide-Character - 16 - --------------------//
- stock MultiByteToWideChar( input[], output[] )
- {
- new OutputChars = 0
- //-------------------- Loop through input characters --------------------//
- for( new InputChars = 0; input[ InputChars ] != EOS; InputChars++ )
- {
- //-------------------- Convert single-byte UTF-8 character --------------------//
- if( input[ InputChars ] < 0x80 ) output[ OutputChars++ ] = input[ InputChars ]
- //-------------------- Convert two-byte UTF-8 character --------------------//
- else if( ( input[ InputChars ] & 0xE0 ) == 0xC0 ) output[ OutputChars++ ] = ( input[ InputChars ] & 0x1F ) << 6 | ( input[ ++InputChars ] & 0x3F )
- //-------------------- Convert three-byte UTF-8 character --------------------//
- else if( ( input[ InputChars ] & 0xF0 ) == 0xE0 ) output[ OutputChars++ ] = ( input[ InputChars ] & 0xF ) << 12 | ( ( input[ ++InputChars ] & 0x3F ) << 6 ) | ( input[ ++InputChars ] & 0x3F )
- }
- output[ OutputChars ] = EOS
- }
- //-------------------- Convert Wide-Character - 16 - to Multi-Byte - 8 - --------------------//
- stock WideCharToMultiByte( input[], output[] )
- {
- new OutputChars = 0
- //-------------------- Loop through input characters --------------------//
- for( new InputChars = 0; input[ InputChars ] != EOS; InputChars++ )
- {
- //-------------------- Convert single-byte UTF-16 to 8 characters --------------------//
- if( input[ InputChars ] < 0x80 ) output[ OutputChars++ ] = input[ InputChars ]
- //-------------------- Convert two-byte UTF-16 to 8 characters --------------------//
- else if( input[ InputChars ] < 0x800 )
- {
- output[ OutputChars++ ] = ( input[ InputChars ] >> 6 ) | 0xC0
- output[ OutputChars++ ] = ( input[ InputChars ] & 0x3F ) | 0x80
- }
- //-------------------- Convert three-byte UTF-16 to 8 characters --------------------//
- else
- {
- output[ OutputChars++ ] = ( input[ InputChars ] >> 12 ) | 0xE0
- output[ OutputChars++ ] = ( ( input[ InputChars ] >> 6 ) & 0x3F ) | 0x80
- output[ OutputChars++ ] = ( input[ InputChars ] & 0x3F ) | 0x80
- }
- }
- output[ OutputChars ] = EOS
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement