Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // HSA 1.0 include by Hauke Marquardt alias |-|auke - 23.03.2012
- /*
- License:
- This code is free: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This code is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- You´re not allowed to copy any code from this, into your code without
- naming authors name in credits!
- */
- #if defined _hsa_included
- #endinput
- #endif
- #define _hsa_included
- #if !defined _hsa_cache_offset
- #define _hsa_cache_offset 0
- #endif
- #if !defined _hsa_line_cache_offset
- #define _hsa_line_cache_offset 0
- #endif
- #define _STRING_KEY 72635
- #define _STRING_KEY_OFFSET 28364
- #define _ENCRYPT 0
- #define _DECRYPT 1
- #define _MAX_FILE_CACHE 1048 + _hsa_cache_offset
- #define _MAX_LINE_CACHE 256 + _hsa_line_cache_offset
- #if !defined _h_library_norm_included
- #define PAWN_TYPE_INT 1
- #define PAWN_TYPE_FLOAT 2
- #define PAWN_TYPE_ARRAY 3
- #define _h_library_norm_included
- #endif
- #define getInt:%1(%2) _GetInt(%1,%2)
- #define getFloat:%1(%2) _GetFloat(%1,%2)
- #define getString:%1(%2) _GetArray(%1,%2)
- #define setInt:%1(%2,%3) _SetInt(%1,%2,%3)
- #define setFloat:%1(%2,%3) _SetFloat(%1,%2,%3)
- #define setString:%1(%2,%3) _SetArray(%1,%2,%3)
- stock _GetInt ( File[ ] , Key[ ] ) {
- new Result[ _MAX_LINE_CACHE ];
- _GetData ( File , Key , Result , PAWN_TYPE_INT );
- return strval ( Result );
- }
- stock Float:_GetFloat ( File[ ] , Key[ ] ) {
- new Result[ _MAX_LINE_CACHE ];
- _GetData ( File , Key , Result , PAWN_TYPE_FLOAT );
- return floatstr ( Result );
- }
- stock _GetArray ( File[ ] , Key[ ] ) {
- new Result[ _MAX_LINE_CACHE ];
- _GetData ( File , Key , Result , PAWN_TYPE_ARRAY );
- return Result;
- }
- stock _SetInt ( File[ ] , Key[ ] , Value ) {
- new uValue[ _MAX_LINE_CACHE ];
- format ( uValue , _MAX_LINE_CACHE , "%d" , Value );
- _SetData ( File , Key , uValue );
- }
- stock _SetFloat ( File[ ] , Key[ ] , Float:Value ) {
- new uValue[ _MAX_LINE_CACHE ];
- format ( uValue , _MAX_LINE_CACHE , "%f" , Value );
- _SetData ( File , Key , uValue );
- }
- stock _SetArray ( File[ ] , Key[ ] , Value[ _MAX_LINE_CACHE ] ) {
- _SetData ( File , Key , Value );
- }
- stock _GetData ( File[ ] , Key[ ] , Result[ _MAX_LINE_CACHE ] , Type ) {
- new FileName[ 32 ] , KeyName[ 32 ] , File:file , bool:FoundKey = false , Line[ _MAX_LINE_CACHE ];
- format ( FileName , 32 , "%s.hsa" , File );
- format ( KeyName , 32 , "%s=" , _StringModificator ( _ENCRYPT , Key ) );
- file = fopen ( FileName , io_readwrite );
- while ( fread ( file , Line ) )
- if ( strfind ( Line , KeyName , false ) != -1 ) {
- Line[ strlen ( Line ) -2 ] = '\0';
- strmid ( Result , Line , strlen ( KeyName ) , strlen ( Line ) , sizeof Result );
- format ( Result , sizeof Result , _StringModificator ( _DECRYPT , Result ) );
- FoundKey = true;
- }
- if ( !FoundKey ) {
- new TmpLine[ _MAX_LINE_CACHE ];
- switch ( Type ) {
- case PAWN_TYPE_INT:
- format ( TmpLine , _MAX_LINE_CACHE , "%s%s\r\n" , KeyName , _StringModificator ( _ENCRYPT , "0" ) );
- case PAWN_TYPE_FLOAT:
- format ( TmpLine , _MAX_LINE_CACHE , "%s%s\r\n" , KeyName , _StringModificator ( _ENCRYPT , "0.0" ) );
- case PAWN_TYPE_ARRAY:
- format ( TmpLine , _MAX_LINE_CACHE , "%s\r\n" , KeyName );
- }
- fwrite ( file , TmpLine );
- }
- fclose ( file );
- }
- stock _SetData ( File[ ] , Key[ ] , Value[ ] ) {
- new FileName[ 32 ] , KeyName[ 32 ] , File:file , FileCache[ _MAX_FILE_CACHE ] , Line[ _MAX_LINE_CACHE ] , bool:FoundKey = false;
- format ( FileName , 32 , "%s.hsa" , File );
- format ( KeyName , 32 , "%s=" , _StringModificator ( _ENCRYPT , Key ) );
- file = fopen ( FileName , io_readwrite );
- while ( fread ( file , Line ) ) {
- if ( strfind ( Line , KeyName , false ) != -1 ) {
- new uLine[ _MAX_LINE_CACHE ];
- format ( uLine , _MAX_LINE_CACHE , "%s%s\r\n" , KeyName , _StringModificator ( _ENCRYPT , Value ) );
- strcat ( FileCache , uLine );
- FoundKey = true;
- }
- else
- strcat ( FileCache , Line );
- }
- fclose ( file );
- if ( !FoundKey ) {
- new uLine[ _MAX_LINE_CACHE ];
- format ( uLine , _MAX_LINE_CACHE , "%s%s\r\n" , KeyName , _StringModificator ( _ENCRYPT , Value ) );
- strcat ( FileCache , uLine );
- }
- file = fopen ( FileName , io_write );
- fwrite ( file , FileCache );
- fclose ( file );
- }
- stock _StringModificator ( Method , String[ ] ) {
- new Converted[ _MAX_LINE_CACHE ];
- for ( new i = 0; i < strlen ( String ); i++ )
- Converted[ i ] = Method == _ENCRYPT ? ( String[ i ] - _STRING_KEY ) + _STRING_KEY_OFFSET : ( String[ i ] + _STRING_KEY ) - _STRING_KEY_OFFSET;
- return Converted;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement