forked from Panguins/OneTap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.cpp
37 lines (28 loc) · 944 Bytes
/
settings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "settings.h"
#include <windows.h>
void simple_save( const char* path, const char* name, const void* src, size_t size, const char* filename )
{
auto buffer = reinterpret_cast<char*>( alloca( size * 2 + 1 ) );
auto data = reinterpret_cast<const uint8_t*>( src );
for ( size_t i = 0; i < size; i++ )
sprintf( &buffer[2 * i], "%02X", data[i] );
WritePrivateProfileStringA( path, name, buffer, filename );
}
void simple_load( const char* path, const char* name, void* dest, size_t size, const char* filename )
{
auto buffer = reinterpret_cast<char*>( alloca( size * 2 + 1 ) );
auto data = reinterpret_cast<uint8_t*>( dest );
GetPrivateProfileStringA( path, name, "", buffer, size * 2 + 1, filename );
if ( *buffer == 0 )
{
for ( size_t i = 0; i < size; i++ )
data[i] = 0;
return;
}
for ( size_t i = 0; i < size; i++ )
{
unsigned temp;
sscanf( &buffer[2 * i], xors( "%02X" ), &temp );
data[i] = temp;
}
}