Redundant Classes and junk files removed.

This commit is contained in:
HikikoMarmy
2025-04-14 19:51:17 +01:00
parent cb5d839770
commit 3c9db7c9eb
11 changed files with 0 additions and 1311 deletions

View File

@@ -1,167 +0,0 @@
#include <ctime>
#include <array>
#include "../misc/math.h"
#include "../Crypto/NorrathCrypt.h"
#include "RealmCrypt.h"
bool RealmCrypt::ms_initialized = false;
RealmCrypt::RealmCrypt()
{
if( !ms_initialized )
{
ms_initialized = true;
std::srand( static_cast< unsigned >( std::time( nullptr ) ) );
RealmCrypt::test();
}
}
std::vector< uint8_t > RealmCrypt::generateSymmetricKey( void )
{
constexpr size_t KEY_LENGTH = 32;
std::vector< uint8_t > keyData( KEY_LENGTH, 0 );
// Generate 32 random bytes
for( size_t i = 0; i < KEY_LENGTH; ++i )
{
keyData[ i ] = static_cast< uint8_t >( rand() % 255 );
}
return keyData;
}
std::vector<uint8_t> RealmCrypt::getSymmetricKey( void )
{
return default_sym_key;
}
std::string RealmCrypt::encryptString( std::string &input )
{
if( input.size() % 16 != 0 )
{
input.append( 16 - ( input.size() % 16 ), '\0' );
}
rijndael aes( KeyLength::_256 );
auto result = aes.EncryptECB( reinterpret_cast< const uint8_t * >( input.c_str() ), input.size(), default_sym_key.data() );
return std::string( reinterpret_cast< const char * >( result ), input.size() );
}
std::string RealmCrypt::decryptString( std::string &input )
{
if( input.size() % 16 != 0 )
{
input.append( 16 - ( input.size() % 16 ), '\0' );
}
rijndael aes( KeyLength::_256 );
auto result = aes.DecryptECB( reinterpret_cast< const uint8_t * >( input.c_str() ), input.size(), default_sym_key.data() );
return std::string( reinterpret_cast< const char * >( result ), input.size() );
}
std::wstring RealmCrypt::encryptString( std::wstring &input )
{
if( input.size() % 16 != 0 )
{
input.append( 16 - ( input.size() % 16 ), L'\0' );
}
rijndael aes( KeyLength::_256 );
auto result = aes.EncryptECB( reinterpret_cast< const uint8_t * >( input.c_str() ), input.size(), default_sym_key.data() );
return std::wstring( reinterpret_cast< const wchar_t * >( result ), input.size() );
}
std::wstring RealmCrypt::decryptString( std::wstring &input )
{
if( input.size() % 16 != 0 )
{
input.append( 16 - ( input.size() % 16 ), L'\0' );
}
rijndael aes( KeyLength::_256 );
auto result = aes.DecryptECB( reinterpret_cast< const uint8_t * >( input.c_str() ), input.size(), default_sym_key.data() );
return std::wstring( reinterpret_cast< const wchar_t * >( result ), input.size() );
}
std::vector< uint8_t > RealmCrypt::encryptSymmetric( std::vector< const uint8_t > &input )
{
return std::vector< uint8_t >();
}
std::vector< uint8_t > RealmCrypt::decryptSymmetric( std::vector< const uint8_t > &input )
{
return std::vector< uint8_t >();
}
std::vector< uint8_t > RealmCrypt::encryptSymmetric( std::span< const uint8_t > input )
{
if( input.size() % 16 != 0 )
{
std::vector< uint8_t > paddedInput( input.begin(), input.end() );
paddedInput.resize( ( ( input.size() / 16 ) + 1 ) * 16, 0 );
input = paddedInput;
}
rijndael aes( KeyLength::_256 );
auto result = aes.EncryptECB( reinterpret_cast< const uint8_t * >( input.data() ), input.size(), default_sym_key.data() );
return std::vector< uint8_t >( result, result + input.size() );
}
std::vector< uint8_t > RealmCrypt::decryptSymmetric( std::span< const uint8_t > input )
{
if( input.size() % 16 != 0 )
{
std::vector< uint8_t > paddedInput( input.begin(), input.end() );
paddedInput.resize( ( ( input.size() / 16 ) + 1 ) * 16, 0 );
input = paddedInput;
}
rijndael aes( KeyLength::_256 );
auto result = aes.DecryptECB( reinterpret_cast< const uint8_t * >( input.data() ), input.size(), default_sym_key.data() );
return std::vector< uint8_t >( result, result + input.size() );
}
void RealmCrypt::test()
{
std::string inputStr = "HelloWorldThisIsATest"; // Input string to encrypt and decrypt
// Generate symmetric key
auto symmetricKey = generateSymmetricKey();
// Encrypt the input string using the symmetric key
auto intermediateEncryptedStr = encryptString( inputStr );
// Log intermediate encryption result
std::cout << "Encrypted string: " << intermediateEncryptedStr << std::endl;
// Decrypt the encrypted string using the symmetric key
auto intermediateDecryptedStr = decryptString( intermediateEncryptedStr );
// Log final decryption result
std::cout << "Decrypted string: " << intermediateDecryptedStr << std::endl;
// Check if decryption matches the original input
if( inputStr == intermediateDecryptedStr )
{
std::cout << "Test passed: Decryption matches original input." << std::endl;
}
else
{
std::cout << "Test failed: Decryption does not match original input." << std::endl;
}
}

View File

@@ -1,49 +0,0 @@
#pragma once
#include <string>
#include <vector>
#include <span>
// This class is based on the games Encryptor class,
// and is a wrapper around the rijndael ECB implementation.
//
// Normally CoN would generate a random symmetric key for each user,
// but for the sake of simplicity we will just use the games default key,
// since we have nothing to hide.
class RealmCrypt {
private:
// Byte array of dlfk qs';r+t iqe4t9ueerjKDJ wdaj
const static inline std::vector< uint8_t > default_sym_key =
{
0x64, 0x6c, 0x66, 0x6b, 0x20, 0x71, 0x73, 0x27,
0x3b, 0x72, 0x2b, 0x74, 0x20, 0x69, 0x71, 0x65,
0x34, 0x74, 0x39, 0x75, 0x65, 0x65, 0x72, 0x6a,
0x4b, 0x44, 0x4a, 0x20, 0x77, 0x64, 0x61, 0x6a
};
public:
RealmCrypt();
// Generate a new symmetric key for the user.
static std::vector< uint8_t > generateSymmetricKey( void );
static std::vector< uint8_t > getSymmetricKey( void );
// Encrypt and decrypt strings.
static std::string encryptString( std::string &input );
static std::string decryptString( std::string &input );
static std::wstring encryptString( std::wstring &input );
static std::wstring decryptString( std::wstring &input );
// Encrypt and decrypt byte arrays.
static std::vector< uint8_t > encryptSymmetric( std::vector< const uint8_t > &input );
static std::vector< uint8_t > decryptSymmetric( std::vector< const uint8_t > &input );
static std::vector< uint8_t > encryptSymmetric( std::span< const uint8_t > input );
static std::vector< uint8_t > decryptSymmetric( std::span< const uint8_t > input );
// Test to make sure the encryption and decryption works.
void test();
// Initializer state for srand.
static bool ms_initialized;
};

View File

@@ -1,210 +0,0 @@
#include "Timer.h"
CTimer::CTimer()
{
m_stopped = true;
m_inited = false;
m_usingQPF = false;
m_lastElapsedTime = 0.0;
m_baseTime = 0.0;
m_stopTime = 0.0;
m_currSysTime = 0.0;
m_currElapsedTime = 0.0;
m_baseMilliTime = 0.0;
m_currSysMilliTime = 0.0;
m_currElapsedMilliTime = 0.0;
m_QPFTicksPerSec = 0;
m_QPFStopTime = 0;
m_QPFLastElapsedTime = 0;
m_QPFBaseTime = 0;
}
CTimer::~CTimer()
{
}
void CTimer::Start()
{
if( !m_inited )
{
LARGE_INTEGER qwTicksPerSec;
m_usingQPF = QueryPerformanceFrequency( &qwTicksPerSec );
if( m_usingQPF )
m_QPFTicksPerSec = qwTicksPerSec.QuadPart;
if( m_usingQPF )
{
QueryPerformanceCounter( &m_QPFTime );
m_QPFBaseTime = m_QPFTime.QuadPart;
m_currSysTime = m_QPFBaseTime / ( double )m_QPFTicksPerSec;
m_baseTime = m_currSysTime;
m_currSysMilliTime = m_currSysTime * 1000.0;
m_baseMilliTime = m_baseTime * 1000.0;
}
else
{
m_currSysTime = GetTickCount() * 0.001;
m_baseTime = m_currSysTime;
m_currSysMilliTime = m_currSysTime * 1000.0;
m_baseMilliTime = m_baseTime * 1000.0;
}
m_inited = true;
}
if( m_usingQPF )
{
QueryPerformanceCounter( &m_QPFTime );
m_currSysTime = m_QPFTime.QuadPart / ( double )m_QPFTicksPerSec;
m_currSysMilliTime = m_currSysTime * 1000.0;
m_QPFStopTime = 0;
m_QPFLastElapsedTime = m_QPFTime.QuadPart;
}
else
{
m_currSysTime = GetTickCount() * 0.001;
m_currSysMilliTime = m_currSysTime * 1000.0;
m_stopTime = 0.0f;
m_lastElapsedTime = m_currSysTime;
}
m_stopped = false;
}
void CTimer::Stop()
{
if( m_stopped ) return;
if( m_usingQPF )
{
QueryPerformanceCounter( &m_QPFTime );
m_currSysTime = m_QPFTime.QuadPart / ( double )m_QPFTicksPerSec;
m_currSysMilliTime = m_currSysTime * 1000.0;
m_QPFStopTime = m_QPFTime.QuadPart;
m_QPFLastElapsedTime = m_QPFTime.QuadPart;
}
else
{
m_currSysTime = GetTickCount() * 0.001;
m_currSysMilliTime = m_currSysTime * 1000.0;
m_stopTime = m_currSysTime;
m_lastElapsedTime = m_currSysTime;
}
m_stopped = true;
}
void CTimer::Advance()
{
if( m_usingQPF )
m_QPFStopTime += m_QPFTicksPerSec / 10;
else
m_stopTime += 0.1f;
}
void CTimer::Reset()
{
if( m_usingQPF )
{
QueryPerformanceCounter( &m_QPFTime );
m_currSysTime = m_QPFTime.QuadPart / ( double )m_QPFTicksPerSec;
m_currSysMilliTime = m_currSysTime * 1000.0;
m_QPFBaseTime = m_QPFTime.QuadPart;
m_QPFLastElapsedTime = m_QPFTime.QuadPart;
m_QPFStopTime = 0;
m_baseTime = m_QPFBaseTime / ( double )m_QPFTicksPerSec;
}
else
{
m_currSysTime = GetTickCount() * 0.001;
m_currSysMilliTime = m_currSysTime * 1000.0;
m_baseTime = m_currSysTime;
m_lastElapsedTime = m_currSysTime;
m_stopTime = 0.0;
}
m_stopped = false;
}
double CTimer::Tick()
{
if( m_stopped )
{
if( m_usingQPF )
{
m_currSysTime = m_QPFStopTime / ( double )m_QPFTicksPerSec;
m_currSysMilliTime = m_currSysTime * 1000.0;
}
else
{
m_currSysTime = m_stopTime;
m_currSysMilliTime = m_currSysTime * 1000.0;
}
}
else
{
if( m_usingQPF )
{
QueryPerformanceCounter( &m_QPFTime );
m_currSysTime = m_QPFTime.QuadPart / ( double )m_QPFTicksPerSec;
m_currSysMilliTime = m_currSysTime * 1000.0;
m_currElapsedTime = ( double )( m_QPFTime.QuadPart - m_QPFLastElapsedTime ) / ( double )m_QPFTicksPerSec;
m_QPFLastElapsedTime = m_QPFTime.QuadPart;
m_currElapsedMilliTime = m_currElapsedTime * 1000.0;
}
else
{
m_currSysTime = GetTickCount() * 0.001;
m_currSysMilliTime = m_currSysTime * 1000.0;
m_currElapsedTime = ( double )( m_currSysTime - m_lastElapsedTime );
m_lastElapsedTime = m_currSysTime;
m_currElapsedMilliTime = m_currElapsedTime * 1000.0;
}
}
return ( float )m_currElapsedTime;
}
double CTimer::GetAbsoluteTime()
{
if( m_stopped )
{
if( m_usingQPF )
{
return ( m_QPFStopTime / ( double )m_QPFTicksPerSec );
}
else
{
return ( m_stopTime );
}
}
else
{
if( m_usingQPF )
{
QueryPerformanceCounter( &m_QPFTime );
return ( m_QPFTime.QuadPart / ( double )m_QPFTicksPerSec );
}
else
{
return ( GetTickCount() * 0.001 );
}
}
}

View File

@@ -1,59 +0,0 @@
#pragma once
#include <chrono>
class Timer {
private:
std::chrono::high_resolution_clock::time_point m_startTime;
std::chrono::high_resolution_clock::time_point m_stopTime;
bool m_running;
public:
Timer() : m_running(false) {}
void Start() {
if (!m_running) {
m_startTime = std::chrono::high_resolution_clock::now();
m_running = true;
}
}
void Stop() {
if (m_running) {
m_stopTime = std::chrono::high_resolution_clock::now();
m_running = false;
}
}
void Reset() {
m_startTime = std::chrono::high_resolution_clock::now();
m_stopTime = m_startTime;
m_running = false;
}
double GetElapsedTime() const
{
if (m_running) {
auto currentTime = std::chrono::high_resolution_clock::now();
return std::chrono::duration<double>(currentTime - m_startTime).count();
}
else {
return std::chrono::duration<double>(m_stopTime - m_startTime).count();
}
}
long long GetElapsedTimeMilliseconds() const
{
if( m_running )
{
auto currentTime = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast< std::chrono::milliseconds >( currentTime - m_startTime );
return duration.count();
}
else
{
auto duration = std::chrono::duration_cast< std::chrono::milliseconds >( m_stopTime - m_startTime );
return duration.count();
}
}
};

View File

@@ -1,44 +0,0 @@
#include "..\global_define.h"
int32_t Math::round_up( int32_t numToRound, int32_t multiple )
{
if( multiple == 0 )
return numToRound;
int32_t remainder = abs( numToRound ) % multiple;
if( remainder == 0 )
return numToRound;
if( numToRound < 0 )
return -( abs( numToRound ) - remainder );
else
return numToRound + multiple - remainder;
}
int32_t Math::round_down( int32_t numToRound, int32_t multiple )
{
if( multiple == 0 )
return numToRound;
int32_t remainder = abs( numToRound ) % multiple;
if( remainder == 0 )
return numToRound;
if( numToRound < 0 )
return -( abs( numToRound ) + remainder );
else
return numToRound - remainder;
}
uint16_t Math::swap_endian( uint16_t val )
{
return ( val << 8 ) | ( val >> 8 );
}
uint32_t Math::swap_endian( uint32_t val )
{
return ( ( val << 24 ) & 0xFF000000 ) |
( ( val << 8 ) & 0x00FF0000 ) |
( ( val >> 8 ) & 0x0000FF00 ) |
( ( val >> 24 ) & 0x000000FF );
}

View File

@@ -1,10 +0,0 @@
#pragma once
namespace Math
{
int32_t round_up( int32_t numToRound, int32_t multiple );
int32_t round_down( int32_t numToRound, int32_t multiple );
uint16_t swap_endian( uint16_t val );
uint32_t swap_endian( uint32_t val );
}

View File

@@ -1,87 +0,0 @@
#pragma once
#include <list>
#include <mutex>
template< typename T >
class threadsafe_queue
{
public:
using value_type = T;
threadsafe_queue() : mutex_(), list_()
{
}
~threadsafe_queue()
{
}
size_t size()
{
return list_.size();
}
bool empty()
{
return list_.empty();
}
void push( T t )
{
mutex_.lock();
list_.push_back( t );
mutex_.unlock();
}
void pop()
{
mutex_.lock();
if( !list_.empty() )
{
list_.pop_front();
}
mutex_.unlock();
}
bool front( T& result )
{
bool ret = false;
mutex_.lock();
if( !list_.empty() )
{
result = list_.front();
ret = true;
}
mutex_.unlock();
return ret;
}
// Saves time by poping in the same lock that we get front. Only one lock.
bool front_and_pop( T& result )
{
bool ret = false;
mutex_.lock();
if( !list_.empty() )
{
result = list_.front();
list_.pop_front();
ret = true;
}
mutex_.unlock();
return ret;
}
void clear()
{
mutex_.lock();
list_.clear();
mutex_.unlock();
}
private:
std::mutex mutex_;
std::list< T > list_;
};