Advertisement
RanAway

[ Pawn - advanced plugins ] Reversed hebrew (not finished)

Sep 8th, 2024 (edited)
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 10.84 KB | Source Code | 0 0
  1. //---------------------------------------------- Thanks ------------------------------------------------//
  2. //                                      Rahim for the byte system                                       //
  3. //                          chatgpt for understanding the stupied system of cs 1.6                      //
  4.  
  5. //-------------------------- known bugs ( until i find a way to fix them ) -----------------------------//
  6. //          1. if 1 hebrew word contain more then 16 letters it will bugged.                            //
  7. //          2. the order of the words not perfect. the order is changing for each lang                  //
  8. //          example: hebrew english hebrew english will be exacly this order. the idea is to            //
  9. //          make it work depend on the start lang which mean if it start with hebrew so the hebrew      //
  10. //          will be the last and after the english first sentense and then hebrew sentense              //
  11.  
  12. //-------------------- Includes --------------------//
  13. #include < amxmodx >
  14.  
  15. new sentblock
  16.  
  17. //-------------------- Plugin init --------------------//
  18. public plugin_init()
  19. {
  20.     register_plugin( "Reversed Hebrew", "v1.0", "RanAway`" )
  21.  
  22.     register_clcmd( "say", "ReverseMessage", false )
  23.     register_clcmd( "say_team", "ReverseMessage", true )
  24. }
  25.  
  26. //-------------------- ReverseMessage --------------------//
  27. public ReverseMessage( id, bool:Tsay )
  28. {
  29.     //-------------------- Prevent spam --------------------//
  30.     if( id == sentblock ) return sentblock = 0
  31.  
  32.     //-------------------- Message functions --------------------//
  33.     new message[ 192 ], tempWord[ 32 ], reversedMessage[ 192 ] = "", UTF[ 32 ], Character = 0, wordCount = 0
  34.     read_args( message, charsmax( message ) )
  35.     remove_quotes( message )
  36.  
  37.     //-------------------- Process Each Character --------------------//
  38.     while( Character < strlen( message ) )
  39.     {
  40.         new wordStart = Character
  41.  
  42.         //-------------------- Find the next space, special character, or English letter --------------------//
  43.         while( Character < strlen( message ) && !isspace( message[ Character ] ) && !IsSpecialCharacter( message[ Character ] ) && !isalpha( message[ Character ] ) ) Character++
  44.  
  45.         //-------------------- Calculate word length --------------------//
  46.         new wordLength = Character - wordStart
  47.         if( wordLength >= sizeof( tempWord ) ) wordLength = sizeof( tempWord )
  48.  
  49.         //-------------------- Copy the word to tempWord --------------------//
  50.         for( new j = 0; j < wordLength; j++ ) tempWord[ j ] = message[ wordStart + j ]
  51.         tempWord[ wordLength ] = EOS
  52.  
  53.         //-------------------- Convert and reverse Hebrew word if applicable --------------------//
  54.         MultiByteToWideChar( tempWord, UTF )
  55.         if( IsHebrew( UTF ) )
  56.         {
  57.             new reverseWord[ 32 ]
  58.             ReverseString( UTF, reverseWord )
  59.             WideCharToMultiByte( reverseWord, tempWord )
  60.             wordCount++
  61.         }
  62.  
  63.         //-------------------- Append the reversed word to the final message --------------------//
  64.         strcat( reversedMessage, tempWord, charsmax( reversedMessage ) )
  65.  
  66.         //-------------------- Handle special characters or English letters without flipping them --------------------//
  67.         while( Character < strlen( message ) && ( IsSpecialCharacter( message[ Character ] ) || isalpha( message[ Character ] ) ) )
  68.         {
  69.             new specialChar[ 2 ]
  70.             specialChar[ 0 ] = message[ Character ]
  71.             specialChar[ 1 ] = EOS
  72.             strcat( reversedMessage, specialChar, charsmax( reversedMessage ) )
  73.             Character++
  74.         }
  75.  
  76.         //-------------------- Append space --------------------//
  77.         if( Character < strlen( message ) && isspace( message[ Character ] ) )
  78.         {
  79.             strcat( reversedMessage, " ", charsmax( reversedMessage ) )
  80.             Character++
  81.         }
  82.     }
  83.  
  84.     //-------------------- Reverse order of Hebrew words if necessary --------------------//
  85.     if( wordCount > 1 ) ReverseWordsOrder( reversedMessage )
  86.  
  87.     sentblock = id
  88.     //-------------------- Send Message to Team or General Chat --------------------//
  89.     amxclient_cmd( id, Tsay ? "say_team" : "say", reversedMessage )
  90.     return 1
  91. }
  92.  
  93. //-------------------- Check if Character is a special character --------------------//
  94. stock IsSpecialCharacter( symbol )
  95. {
  96.     return  ( symbol >= 0x0021 && symbol <= 0x002F ) || // ! " # $ % & ' ( ) * + , - . /
  97.             ( symbol >= 0x003A && symbol <= 0x0040 ) || // : ; < = > ? @
  98.             ( symbol >= 0x005B && symbol <= 0x0060 ) || // [ \ ] ^ _ `
  99.             ( symbol >= 0x007B && symbol <= 0x007E )    // { | } ~
  100. }
  101.  
  102. //-------------------- Check if String Contains Hebrew Characters --------------------//
  103. stock IsHebrew( input[] )
  104. {
  105.     for( new i = 0; input[ i ] != EOS; i++ ) if( input[ i ] >= 0x0590 && input[ i ] <= 0x05FF ) return true
  106.     return false
  107. }
  108.  
  109. //-------------------- Reverse String in Buffer --------------------
  110. stock ReverseString( input[], output[] )
  111. {
  112.     new len = strlen( input )
  113.     for( new i = 0; i < len; i++ ) output[ i ] = input[ len - i - 1 ]
  114.     output[ len ] = EOS
  115. }
  116.  
  117. //-------------------- Reverse Words Order in Message --------------------//
  118. stock ReverseWordsOrder( reversedMessage[] )
  119. {
  120.     //-------------------- Message functions --------------------//
  121.     new words[ 32 ][ 32 ], hebrewWords[ 32 ][ 32 ], output[ 192 ] = ""
  122.     new Character = 0, wordStart = 0, wordCount = 0, hebrewWordCount = 0, hebrewGroupStart = -1
  123.  
  124.     //-------------------- Iterate Through Characters to Extract Words --------------------//
  125.     while( Character < strlen( reversedMessage ) )
  126.     {
  127.         //-------------------- Identify Start of New Word --------------------//
  128.         if( !isspace( reversedMessage[ Character ] ) )
  129.         {
  130.             wordStart = Character
  131.  
  132.             //-------------------- Find End of Current Word --------------------//
  133.             while( Character < strlen( reversedMessage ) && !isspace( reversedMessage[ Character ] ) ) Character++
  134.  
  135.             //-------------------- Calculate Word Length and Validate --------------------//
  136.             new wordLength = Character - wordStart
  137.             if( wordLength > 0 && wordLength < 32 )
  138.             {
  139.                 //-------------------- Copy Current Word to Array --------------------//
  140.                 copy( words[ wordCount ], sizeof( words ), reversedMessage[ wordStart ] )
  141.                 words[ wordCount ][ wordLength ] = EOS
  142.  
  143.                 //-------------------- Convert Multi-Byte - 8 - to Wide-Character - 16 - --------------------//
  144.                 new UTF16[ 32 ]
  145.                 MultiByteToWideChar( words[ wordCount ], UTF16 )
  146.  
  147.                 //-------------------- Handle Hebrew Words --------------------//
  148.                 if( IsHebrew( UTF16 ) )
  149.                 {
  150.                     //-------------------- Define Start of Hebrew Word Group --------------------//
  151.                     if( hebrewGroupStart == -1 ) hebrewGroupStart = wordCount
  152.  
  153.                     //-------------------- Add Hebrew Word to List --------------------//
  154.                     copy( hebrewWords[ hebrewWordCount ], sizeof( hebrewWords ), words[ wordCount ] )
  155.                     hebrewWords[ hebrewWordCount ][ wordLength ] = EOS
  156.                     hebrewWordCount++
  157.                 }
  158.                 //-------------------- Handle Non-Hebrew Words --------------------//
  159.                 else
  160.                 {
  161.                     //-------------------- Check and Reverse Hebrew Words Group --------------------//
  162.                     if( hebrewGroupStart != -1 )
  163.                     {
  164.                         //-------------------- Reverse Order of Hebrew Words in Group --------------------//
  165.                         new reversedHebrewWords[ 32 ][ 32 ]
  166.                         for( new j = 0; j < hebrewWordCount; j++ ) copy( reversedHebrewWords[ hebrewWordCount - j - 1 ], sizeof( reversedHebrewWords ), hebrewWords[ j ] )
  167.                         //-------------------- Add Reversed Hebrew Words to Output --------------------//
  168.                         for( new j = 0; j < hebrewWordCount; j++ )
  169.                         {
  170.                             strcat( output, reversedHebrewWords[ j ], sizeof( output ) )
  171.                             strcat( output, " ", sizeof( output ) )
  172.                         }
  173.                         //-------------------- Reset Hebrew Group Tracking --------------------//
  174.                         hebrewGroupStart = -1
  175.                         hebrewWordCount = 0
  176.                     }
  177.                     //-------------------- Append Non-Hebrew Word to Output --------------------//
  178.                     strcat( output, words[ wordCount ], sizeof( output ) )
  179.                     strcat( output, " ", sizeof( output ) )
  180.                 }
  181.                 wordCount++
  182.             }
  183.         }
  184.  
  185.         //-------------------- Procced to the next character --------------------//
  186.         if( Character < strlen( reversedMessage ) ) Character++
  187.     }
  188.  
  189.     //-------------------- Handle Remaining Hebrew Words at End --------------------//
  190.     if( hebrewGroupStart != -1 )
  191.     {
  192.         //-------------------- Handle Remaining Hebrew Words at End --------------------//
  193.         new reversedHebrewWords[ 32 ][ 32 ]
  194.         for( new j = 0; j < hebrewWordCount; j++ ) copy( reversedHebrewWords[ hebrewWordCount - j - 1 ], sizeof( reversedHebrewWords ), hebrewWords[ j ] )
  195.         //-------------------- Add Reversed Hebrew Words to Output --------------------//
  196.         for( new j = 0; j < hebrewWordCount; j++ )
  197.         {
  198.             strcat( output, reversedHebrewWords[ j ], sizeof( output ) )
  199.             strcat( output, " ", sizeof( output ) )
  200.         }
  201.     }
  202.  
  203.     //-------------------- Remove Trailing Space from Output String --------------------//
  204.     if( strlen( output ) > 0 ) output[ strlen( output ) - 1 ] = EOS
  205.  
  206.     //-------------------- Copy Final Output to ReversedMessage --------------------//
  207.     copy( reversedMessage, 192, output )
  208. }
  209.  
  210. //-------------------- Convert Multi-Byte - 8 - to Wide-Character - 16 - --------------------//
  211. stock MultiByteToWideChar( input[], output[] )
  212. {
  213.     new OutputChars = 0
  214.     //-------------------- Loop through input characters --------------------//
  215.     for( new InputChars = 0; input[ InputChars ] != EOS; InputChars++ )
  216.     {
  217.         //-------------------- Convert single-byte UTF-8 character --------------------//
  218.         if( input[ InputChars ] < 0x80 ) output[ OutputChars++ ] = input[ InputChars ]
  219.         //-------------------- Convert two-byte UTF-8 character --------------------//
  220.         else if( ( input[ InputChars ] & 0xE0 ) == 0xC0 ) output[ OutputChars++ ] = ( input[ InputChars ] & 0x1F ) << 6 | ( input[ ++InputChars ] & 0x3F )
  221.         //-------------------- Convert three-byte UTF-8 character --------------------//
  222.         else if( ( input[ InputChars ] & 0xF0 ) == 0xE0 ) output[ OutputChars++ ] = ( input[ InputChars ] & 0xF ) << 12 | ( ( input[ ++InputChars ] & 0x3F ) << 6 ) | ( input[ ++InputChars ] & 0x3F )
  223.     }
  224.     output[ OutputChars ] = EOS
  225. }
  226.  
  227. //-------------------- Convert Wide-Character - 16 - to Multi-Byte - 8 - --------------------//
  228. stock WideCharToMultiByte( input[], output[] )
  229. {
  230.     new OutputChars = 0
  231.     //-------------------- Loop through input characters --------------------//
  232.     for( new InputChars = 0; input[ InputChars ] != EOS; InputChars++ )
  233.     {
  234.         //-------------------- Convert single-byte UTF-16 to 8 characters --------------------//
  235.         if( input[ InputChars ] < 0x80 ) output[ OutputChars++ ] = input[ InputChars ]
  236.         //-------------------- Convert two-byte UTF-16 to 8 characters --------------------//
  237.         else if( input[ InputChars ] < 0x800 )
  238.         {
  239.             output[ OutputChars++ ] = ( input[ InputChars ] >> 6 ) | 0xC0
  240.             output[ OutputChars++ ] = ( input[ InputChars ] & 0x3F ) | 0x80
  241.         }
  242.         //-------------------- Convert three-byte UTF-16 to 8 characters --------------------//
  243.         else
  244.         {
  245.             output[ OutputChars++ ] = ( input[ InputChars ] >> 12 ) | 0xE0
  246.             output[ OutputChars++ ] = ( ( input[ InputChars ] >> 6 ) & 0x3F ) | 0x80
  247.             output[ OutputChars++ ] = ( input[ InputChars ] & 0x3F ) | 0x80
  248.         }
  249.     }
  250.     output[ OutputChars ] = EOS
  251. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement