Advertisement
Hauke

HSA 1.0

Mar 23rd, 2012
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.15 KB | None | 0 0
  1. // HSA 1.0 include by Hauke Marquardt alias |-|auke - 23.03.2012
  2. /*
  3. License:
  4.     This code is free: you can redistribute it and/or modify
  5.     it under the terms of the GNU General Public License as published by
  6.     the Free Software Foundation, either version 3 of the License, or
  7.     (at your option) any later version.
  8.  
  9.     This code is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.     GNU General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU General Public License
  15.     along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16.     You´re not allowed to copy any code from this, into your code without
  17.     naming authors name in credits!
  18. */
  19.  
  20. #if defined _hsa_included
  21.     #endinput
  22. #endif
  23.  
  24. #define _hsa_included
  25.  
  26. #if !defined _hsa_cache_offset
  27.     #define _hsa_cache_offset   0
  28. #endif
  29.  
  30. #if !defined _hsa_line_cache_offset
  31.     #define _hsa_line_cache_offset      0
  32. #endif
  33.  
  34. #define _STRING_KEY                     72635
  35. #define _STRING_KEY_OFFSET              28364
  36. #define _ENCRYPT                        0
  37. #define _DECRYPT                        1
  38. #define _MAX_FILE_CACHE                 1048 + _hsa_cache_offset
  39. #define _MAX_LINE_CACHE                 256 + _hsa_line_cache_offset
  40.  
  41. #if !defined _h_library_norm_included
  42.     #define PAWN_TYPE_INT               1
  43.     #define PAWN_TYPE_FLOAT             2
  44.     #define PAWN_TYPE_ARRAY             3
  45.     #define _h_library_norm_included
  46. #endif
  47.  
  48. #define getInt:%1(%2)           _GetInt(%1,%2)
  49. #define getFloat:%1(%2)         _GetFloat(%1,%2)
  50. #define getString:%1(%2)        _GetArray(%1,%2)
  51. #define setInt:%1(%2,%3)        _SetInt(%1,%2,%3)
  52. #define setFloat:%1(%2,%3)      _SetFloat(%1,%2,%3)
  53. #define setString:%1(%2,%3)     _SetArray(%1,%2,%3)
  54.  
  55. stock _GetInt ( File[ ] , Key[ ] ) {
  56.     new Result[ _MAX_LINE_CACHE ];
  57.     _GetData ( File , Key , Result , PAWN_TYPE_INT );
  58.     return strval ( Result );
  59. }
  60.  
  61. stock Float:_GetFloat ( File[ ] , Key[ ] ) {
  62.     new Result[ _MAX_LINE_CACHE ];
  63.     _GetData ( File , Key , Result , PAWN_TYPE_FLOAT );
  64.     return floatstr ( Result );
  65. }
  66.  
  67. stock _GetArray ( File[ ] , Key[ ] ) {
  68.     new Result[ _MAX_LINE_CACHE ];
  69.     _GetData ( File , Key , Result , PAWN_TYPE_ARRAY );
  70.     return Result;
  71. }
  72.  
  73.  
  74. stock _SetInt ( File[ ] , Key[ ] , Value ) {
  75.     new uValue[ _MAX_LINE_CACHE ];
  76.     format ( uValue , _MAX_LINE_CACHE , "%d" , Value );
  77.     _SetData ( File , Key , uValue );
  78. }
  79.  
  80. stock _SetFloat ( File[ ] , Key[ ] , Float:Value ) {
  81.     new uValue[ _MAX_LINE_CACHE ];
  82.     format ( uValue , _MAX_LINE_CACHE , "%f" , Value );
  83.     _SetData ( File , Key , uValue );
  84. }
  85.  
  86.  
  87. stock _SetArray ( File[ ] , Key[ ] , Value[ _MAX_LINE_CACHE ] ) {
  88.     _SetData ( File , Key , Value );
  89. }
  90.  
  91. stock _GetData ( File[ ] , Key[ ] , Result[ _MAX_LINE_CACHE ] , Type ) {
  92.     new FileName[ 32 ] , KeyName[ 32 ] , File:file , bool:FoundKey = false , Line[ _MAX_LINE_CACHE ];
  93.     format ( FileName , 32 , "%s.hsa" , File );
  94.     format ( KeyName , 32 , "%s=" , _StringModificator ( _ENCRYPT , Key ) );
  95.     file = fopen ( FileName , io_readwrite );
  96.     while ( fread ( file , Line ) )
  97.         if ( strfind ( Line , KeyName , false ) != -1 ) {
  98.             Line[ strlen ( Line ) -2 ] = '\0';
  99.             strmid ( Result , Line , strlen ( KeyName ) , strlen ( Line ) , sizeof Result );
  100.             format ( Result , sizeof Result , _StringModificator ( _DECRYPT , Result ) );
  101.             FoundKey = true;
  102.         }
  103.     if ( !FoundKey ) {
  104.         new TmpLine[ _MAX_LINE_CACHE ];
  105.         switch ( Type ) {
  106.             case PAWN_TYPE_INT:
  107.                 format ( TmpLine , _MAX_LINE_CACHE , "%s%s\r\n" , KeyName , _StringModificator ( _ENCRYPT , "0" ) );
  108.             case PAWN_TYPE_FLOAT:
  109.                 format ( TmpLine , _MAX_LINE_CACHE , "%s%s\r\n" , KeyName , _StringModificator ( _ENCRYPT , "0.0" ) );
  110.             case PAWN_TYPE_ARRAY:
  111.                 format ( TmpLine , _MAX_LINE_CACHE , "%s\r\n" , KeyName );
  112.         }
  113.         fwrite ( file , TmpLine );
  114.     }
  115.     fclose ( file );
  116. }
  117.  
  118. stock _SetData ( File[ ] , Key[ ] , Value[ ] ) {
  119.     new FileName[ 32 ] , KeyName[ 32 ] , File:file , FileCache[ _MAX_FILE_CACHE ] , Line[ _MAX_LINE_CACHE ] , bool:FoundKey = false;
  120.     format ( FileName , 32 , "%s.hsa" , File );
  121.     format ( KeyName , 32 , "%s=" , _StringModificator ( _ENCRYPT , Key ) );
  122.     file = fopen ( FileName , io_readwrite );
  123.     while ( fread ( file , Line ) ) {
  124.         if ( strfind ( Line , KeyName , false ) != -1 ) {
  125.             new uLine[ _MAX_LINE_CACHE ];
  126.             format ( uLine , _MAX_LINE_CACHE , "%s%s\r\n" , KeyName , _StringModificator ( _ENCRYPT , Value ) );
  127.             strcat ( FileCache , uLine );
  128.             FoundKey = true;
  129.         }
  130.         else
  131.             strcat ( FileCache , Line );
  132.     }
  133.     fclose ( file );
  134.     if ( !FoundKey ) {
  135.         new uLine[ _MAX_LINE_CACHE ];
  136.         format ( uLine , _MAX_LINE_CACHE , "%s%s\r\n" , KeyName , _StringModificator ( _ENCRYPT , Value ) );
  137.         strcat ( FileCache , uLine );
  138.     }
  139.     file = fopen ( FileName , io_write );
  140.     fwrite ( file , FileCache );
  141.     fclose ( file );
  142. }
  143.  
  144. stock _StringModificator ( Method , String[ ] ) {
  145.     new Converted[ _MAX_LINE_CACHE ];
  146.     for ( new i = 0; i < strlen ( String ); i++ )
  147.         Converted[ i ] = Method == _ENCRYPT ? ( String[ i ] - _STRING_KEY ) + _STRING_KEY_OFFSET : ( String[ i ] + _STRING_KEY ) - _STRING_KEY_OFFSET;
  148.     return Converted;
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement