2024-12-11 22:36:38 +00:00
# include <fstream>
# include <iostream>
template < typename typ1 >
typ1 readFromStream ( std : : ifstream & stream , char * dest ) {
if ( stream . is_open ( ) ) {
stream . read ( dest , sizeof ( char [ 1024 ] ) ) ;
typ1 * ptr = reinterpret_cast < typ1 * > ( dest ) ;
return std : : move ( * ptr ) ;
}
else {
std : : runtime_error ( " Could not read from File! " ) ;
}
}
void Aufg9Main ( ) {
char * dest = new char [ 1024 ] ;
try {
std : : string fileName = " ../Aufg9/IO-Files/charakter.d2s " ;
std : : ifstream stream ( fileName ) ;
auto header = readFromStream < long > ( stream , dest ) ;
printf ( " I read something! \n %X \n " , header ) ;
2024-12-11 22:45:28 +00:00
for ( int i = 0 ; i < 1024 ; i + + ) {
2024-12-11 22:36:38 +00:00
std : : cout < < dest [ i ] < < std : : endl ;
}
long * test = reinterpret_cast < long * > ( dest ) ;
2024-12-11 22:45:28 +00:00
printf ( " Verification Code: %X \n " , * test ) ;
char * fuckery = ( char * ) test ;
printf ( " Fuckery: %X \n " , fuckery ) ;
2024-12-11 23:01:55 +00:00
// Name
char * byte20 = & dest [ 20 ] ;
std : : cout < < " Name: " ;
2024-12-11 22:45:28 +00:00
for ( int i = 0 ; i < 16 ; i + + ) {
2024-12-11 23:01:55 +00:00
std : : cout < < byte20 [ i ] ;
2024-12-11 22:45:28 +00:00
}
2024-12-11 23:01:55 +00:00
std : : cout < < std : : endl ;
2024-12-11 23:07:26 +00:00
// Status
2024-12-11 23:01:55 +00:00
char * byte36 = & dest [ 36 ] ;
2024-12-11 23:07:26 +00:00
std : : cout < < " Status: " < < ( ( ( int ) ( * byte36 ) ) % 8 ) / 4 < < std : : endl ; // geh zu Byte 36, lies genau 1 byte, interpretiere es als int, berechne mod 8 -> wegwerfen der linken Bits, /4 -> wegwerfen der rechten beiden Bits -> Tada, nur das 3. Bit von Rechts bleibt übrig
// 0 -> Not HardCore?
2024-12-11 23:01:55 +00:00
// Klasse
bool * byte40 = ( bool * ) & dest [ 40 ] ;
std : : cout < < " Klasse: " < < byte40 [ 0 ] < < std : : endl ;
// 2 -> Necromancer
2024-12-11 22:45:28 +00:00
2024-12-11 23:07:26 +00:00
// Level
bool * byte43 = ( bool * ) & dest [ 43 ] ;
std : : cout < < " Level: " < < byte43 [ 0 ] < < std : : endl ;
2024-12-11 22:36:38 +00:00
} catch ( const std : : exception & e ) {
std : : cout < < e . what ( ) < < std : : endl ;
}
}