Skip to content

Commit

Permalink
Предположительно поправил вылет при запуске на steam-версии (надо зап…
Browse files Browse the repository at this point in the history
…ускать движок с ключём "-steam")

closed #49
  • Loading branch information
xrSimpodin committed Aug 2, 2018
1 parent cb5e884 commit 64670e1
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 158 deletions.
224 changes: 72 additions & 152 deletions ogsr_engine/xr_3da/trivial_encryptor.h
Original file line number Diff line number Diff line change
@@ -1,160 +1,80 @@
#ifndef TRIVIAL_ENCRYPTOR_H
#define TRIVIAL_ENCRYPTOR_H

// before including this file
// you should define at least one of the following macro:
// #define TRIVIAL_ENCRYPTOR_ENCODER
// #define TRIVIAL_ENCRYPTOR_DECODER

#pragma warning(push)
#pragma warning(disable:4995)
#include <malloc.h>
#pragma warning(pop)

//#define trivial_encryptor temp_stuff

/**/
#define RUSSIAN_BUILD
/**/
#pragma once

class trivial_encryptor {
private:
typedef u8 type;
typedef void* pvoid;
typedef const void* pcvoid;

private:
enum {alphabet_size = u32(1 << (8*sizeof(type)))};

private:
class random32 {
private:
u32 m_seed;
protected:
typedef u8 type;
typedef void* pvoid;
typedef const void* pcvoid;

public:
IC void seed (const u32 &seed)
{
m_seed = seed;
}
static constexpr u32 alphabet_size = u32( 1 << ( 8 * sizeof( type ) ) );

IC u32 random (const u32 &range)
{
m_seed = 0x08088405*m_seed + 1;
return (u32(u64(m_seed)*u64(range) >> 32));
}
};
class random32 {
protected:
u32 m_seed;

public:
static u32 m_table_iterations;
static u32 m_table_seed;
static u32 m_encrypt_seed;

#ifdef TRIVIAL_ENCRYPTOR_ENCODER
# ifdef TRIVIAL_ENCRYPTOR_DECODER
private: static bool m_initialized;
# endif // TRIVIAL_ENCRYPTOR_DECODER
#endif // TRIVIAL_ENCRYPTOR_ENCODER

#ifdef TRIVIAL_ENCRYPTOR_ENCODER
private: static type m_alphabet[alphabet_size];
#endif // TRIVIAL_ENCRYPTOR_ENCODER

#ifdef TRIVIAL_ENCRYPTOR_DECODER
private: static type m_alphabet_back[alphabet_size];
#endif // TRIVIAL_ENCRYPTOR_DECODER

private:
IC static void initialize ()
{
#ifndef TRIVIAL_ENCRYPTOR_ENCODER
type *m_alphabet = (type*)_alloca(sizeof(type)*alphabet_size);
#endif // TRIVIAL_ENCRYPTOR_ENCODER

for (u32 i=0; i<alphabet_size; ++i)
m_alphabet[i] = (type)i;

random32 temp;
temp.seed (m_table_seed);
for (u32 i=0; i<m_table_iterations; ++i) {
u32 j = temp.random(alphabet_size);
u32 k = temp.random(alphabet_size);
while (j == k)
k = temp.random(alphabet_size);

std::swap (m_alphabet[j],m_alphabet[k]);
}

#ifdef TRIVIAL_ENCRYPTOR_DECODER
for (u32 i=0; i<alphabet_size; ++i)
m_alphabet_back[m_alphabet[i]] = (type)i;
#endif // TRIVIAL_ENCRYPTOR_DECODER
}

#ifdef TRIVIAL_ENCRYPTOR_ENCODER
public: IC static void encode (pcvoid source, const u32 &source_size, pvoid destination)
{
# ifndef TRIVIAL_ENCRYPTOR_DECODER
static bool m_initialized = false;
# endif // TRIVIAL_ENCRYPTOR_DECODER
if (!m_initialized) {
initialize ();
m_initialized = true;
}

random32 temp;
temp.seed (m_encrypt_seed);
const u8 *I = (const u8*)source;
const u8 *E = (const u8*)source + source_size;
u8 *J = (u8*)destination;
for ( ; I != E; ++I, ++J)
*J = m_alphabet[*I] ^ type(temp.random(256) & 0xff);
}
#endif // TRIVIAL_ENCRYPTOR_ENCODER

#ifdef TRIVIAL_ENCRYPTOR_DECODER
public: IC static void decode (pcvoid source, const u32 &source_size, pvoid destination)
{
# ifndef TRIVIAL_ENCRYPTOR_ENCODER
static bool m_initialized = false;
# endif // TRIVIAL_ENCRYPTOR_ENCODER
if (!m_initialized) {
initialize ();
m_initialized = true;
}

random32 temp;
temp.seed (m_encrypt_seed);
const u8 *I = (const u8*)source;
const u8 *E = (const u8*)source + source_size;
u8 *J = (u8*)destination;
for ( ; I != E; ++I, ++J)
*J = m_alphabet_back[(*I) ^ type(temp.random(256) & 0xff)];
}
#endif // TRIVIAL_ENCRYPTOR_DECODER
IC void seed( const u32& seed ) {
m_seed = seed;
}

IC u32 random( const u32& range ) {
m_seed = 0x08088405 * m_seed + 1;
return ( u32( u64( m_seed ) * u64( range ) >> 32 ) );
}
};

protected:
static u32 m_table_iterations, m_table_seed, m_encrypt_seed;
static type m_alphabet_back[ alphabet_size ];

static IC void initialize() {
if ( !strstr( GetCommandLine(), "-steam" ) ) {
m_table_iterations = 2048;
m_table_seed = 20091958;
m_encrypt_seed = 20031955;
} else {
m_table_iterations = 1024;
m_table_seed = 6011979;
m_encrypt_seed = 24031979;
}

auto m_alphabet = ( type* )_alloca( sizeof( type ) * alphabet_size );

for ( u32 i = 0; i < alphabet_size; ++i )
m_alphabet[ i ] = ( type )i;

random32 temp;
temp.seed( m_table_seed );
for ( u32 i = 0; i < m_table_iterations; ++i ) {
u32 j = temp.random( alphabet_size );
u32 k = temp.random( alphabet_size );
while ( j == k )
k = temp.random( alphabet_size );

std::swap( m_alphabet[ j ], m_alphabet[ k ] );
}

for ( u32 i = 0; i < alphabet_size; ++i )
m_alphabet_back[ m_alphabet[ i ] ] = ( type )i;
}

public:
static IC void decode( pcvoid source, const u32& source_size, pvoid destination ) {
static bool m_initialized = false;
if ( !m_initialized ) {
initialize();
m_initialized = true;
}

random32 temp;
temp.seed( m_encrypt_seed );
const u8* I = ( const u8* )source;
const u8* E = ( const u8* )source + source_size;
u8* J = ( u8* )destination;
for ( ; I != E; ++I, ++J )
*J = m_alphabet_back[ ( *I ) ^ type( temp.random( 256 ) & 0xff ) ];
}
};

#ifdef TRIVIAL_ENCRYPTOR_ENCODER
# ifdef TRIVIAL_ENCRYPTOR_DECODER
bool trivial_encryptor::m_initialized = false;
# endif // TRIVIAL_ENCRYPTOR_DECODER
#endif // TRIVIAL_ENCRYPTOR_ENCODER

#ifdef RUSSIAN_BUILD
u32 trivial_encryptor::m_table_iterations = 2048;
u32 trivial_encryptor::m_table_seed = 20091958;
u32 trivial_encryptor::m_encrypt_seed = 20031955;
#else // RUSSIAN_BUILD
u32 trivial_encryptor::m_table_iterations = 1024;
u32 trivial_encryptor::m_table_seed = 6011979;
u32 trivial_encryptor::m_encrypt_seed = 24031979;
#endif // RUSSIAN_BUILD

#ifdef TRIVIAL_ENCRYPTOR_ENCODER
trivial_encryptor::type trivial_encryptor::m_alphabet[trivial_encryptor::alphabet_size];
#endif // TRIVIAL_ENCRYPTOR_ENCODER

#ifdef TRIVIAL_ENCRYPTOR_DECODER
trivial_encryptor::type trivial_encryptor::m_alphabet_back[trivial_encryptor::alphabet_size];
#endif // TRIVIAL_ENCRYPTOR_DECODER

#endif // TRIVIAL_ENCRYPTOR_H
u32 trivial_encryptor::m_table_iterations, trivial_encryptor::m_table_seed, trivial_encryptor::m_encrypt_seed;
trivial_encryptor::type trivial_encryptor::m_alphabet_back[ trivial_encryptor::alphabet_size ];
8 changes: 2 additions & 6 deletions ogsr_engine/xr_3da/x_ray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,10 @@ struct damn_keys_filter {

#include "xr_ioc_cmd.h"

typedef void DUMMY_STUFF (const void*,const u32&,void*);
XRCORE_API DUMMY_STUFF *g_temporary_stuff;

#define TRIVIAL_ENCRYPTOR_DECODER
typedef void DUMMY_STUFF( const void*, const u32&, void* );
XRCORE_API DUMMY_STUFF* g_temporary_stuff;
#include "trivial_encryptor.h"

//#define RUSSIAN_BUILD

ENGINE_API bool g_dedicated_server = false;

int APIENTRY WinMain_impl(HINSTANCE hInstance,
Expand Down

0 comments on commit 64670e1

Please sign in to comment.