summaryrefslogtreecommitdiff
path: root/loader/Source.cpp
diff options
context:
space:
mode:
authorJustSomePwner <crotchyalt@gmail.com>2018-08-30 14:01:54 +0200
committerJustSomePwner <crotchyalt@gmail.com>2018-08-30 14:01:54 +0200
commit7ccb819f867493f8ec202ea3b39c94c198c64584 (patch)
tree94622e61af0ff359e3d6689cf274d74f60b2492a /loader/Source.cpp
parent564d979b79e8a5aaa5014eba0ecd36c61575934f (diff)
first
Diffstat (limited to 'loader/Source.cpp')
-rw-r--r--loader/Source.cpp190
1 files changed, 190 insertions, 0 deletions
diff --git a/loader/Source.cpp b/loader/Source.cpp
new file mode 100644
index 0000000..8d72c2b
--- /dev/null
+++ b/loader/Source.cpp
@@ -0,0 +1,190 @@
+#include <thread>
+#include <fstream>
+#include "d3d_sprite.hpp"
+#include "window.hpp"
+#include "ui.h"
+
+#include "http.h"
+
+#include "manualmap.hpp"
+#include "iface.hpp"
+
+bool g_in_inject = false;
+
+void on_frame( ) {
+ if( g_d3d.run_frame( g_window.m_d3d_device ) ) {
+ g_d3d.begin( );
+ for( auto& it : d3d::sprites ) {
+ it->begin( g_window.m_d3d_device );
+ }
+
+ static auto last_time = GetTickCount( ) * 0.001f;
+ auto cur_time = GetTickCount( ) * 0.001f;
+
+ auto deltatime = cur_time - last_time;
+
+ last_time = cur_time;
+
+ constexpr float anim_step = 1.0f / 15.f;
+ static float anim_time = 0.f;
+ static bool flip = false;
+ if( anim_time == 1.0f ) {
+ flip = true;
+ }
+ if( anim_time == 0.f ) {
+ flip = false;
+ }
+
+ if( flip ) anim_time = std::clamp( anim_time - anim_step * deltatime, 0.f, 1.0f );
+ else anim_time = std::clamp( anim_time + anim_step * deltatime, 0.f, 1.0f );
+
+ ui::set_animtime( anim_time );
+ ui::render( );
+
+ RECT cur_rect{ };
+ GetWindowRect( g_window.get_hwnd( ), &cur_rect );
+
+ g_d3d.end( );
+ for( auto& it : d3d::sprites ) {
+ it->end( );
+ }
+ }
+}
+
+void decrypt_file( std::vector< uint8_t >& file, uint8_t key ) {
+ for( size_t i{ }; i < file.size( ); ++i ) {
+ file.data( )[ i ] ^= key;
+ }
+}
+
+int find_process( std::string name ) {
+ auto window = FindWindowA( 0, name.c_str( ) );
+ if( !window ) return -1;
+
+ ulong_t pid{ };
+ GetWindowThreadProcessId( window, &pid );
+
+ return pid;
+}
+
+void thread_fn( ) {
+ if( g_in_inject ) return;
+
+ g_in_inject = true;
+ ulong_t hwid{ };
+ GetVolumeInformationA( xors( "C:\\" ), 0, 0, &hwid, 0, 0, 0, 0 );
+
+ g_progress = 0.1f;
+
+ std::string game{ };
+ switch( g_game ) {
+ case 1:
+ game = xors( "Counter-Strike: Global Offensive" );
+ break;
+ case 2:
+ game = xors( "Team Fortress 2" );
+ break;
+ case 3:
+ game = xors( "Counter-Strike: Global Offensive" );
+ break;
+ case 4:
+ game = xors( "Garry's Mod" );
+ break;
+ default:
+ MessageBoxA( 0, xors( "unknown error" ), xors( "error" ), MB_OK );
+ exit( 0 );
+ break;
+ }
+
+ auto pid = find_process( game );
+ if( pid == -1 ) {
+ MessageBoxA( 0, xors( "game must be running" ), xors( "error" ), MB_OK );
+ g_progress = 0.f;
+ g_in_inject = false;
+ return;
+ }
+
+ auto h = OpenProcess( PROCESS_ALL_ACCESS, 0, pid );
+ iface::manager mgr( h );
+
+ mgr.dump_all_modules( pid );
+ if( !mgr.count( ) ) {
+ MessageBoxA( 0, xors( "unknown error" ), xors( "error" ), MB_OK );
+ exit( 0 );
+ }
+
+ g_progress = 0.3f;
+
+ //enter a new scope to run cleanup after we're done, epic life hack
+ {
+ auto result = http::send_request( g_login, hwid, g_game );
+
+ if( result.empty( ) ) {
+ MessageBoxA( 0, xors( "unknown error" ), xors( "error" ), MB_OK );
+ exit( 0 );
+ return;
+ }
+
+ if( result[ 0 ] == '1' ) {
+ char str[ 256 ];
+ strenc::w_sprintf_s( str, 256, xors( "hwid mismatch, request change: %08x" ), hwid );
+ MessageBoxA( 0, str, xors( "error" ), MB_OK );
+ exit( 0 );
+ }
+ if( result[ 0 ] == '2' ) {
+ MessageBoxA( 0, xors( "user unknown" ), xors( "error" ), MB_OK );
+ exit( 0 );
+ }
+ if( result[ 0 ] == '3' ) {
+ MessageBoxA( 0, xors( "coming soon" ), xors( "error" ), MB_OK );
+ g_progress = 0.f;
+ g_in_inject = false;
+ return;
+ }
+
+ g_progress = 0.5f;
+
+ //to meme whoever decides to reverse this
+ decrypt_file( result, [ ]( ) {
+ constexpr auto key_sqr = 49 * 49;
+ return 49;
+ }( ) );
+
+ inject::c_map map( result );
+ g_progress = 0.7f;
+
+ map.initialize( pid );
+ std::this_thread::sleep_for( std::chrono::milliseconds( 300 ) );
+ g_progress = 0.8f;
+ map.inject( mgr.write_to_process( ) );
+ g_progress = 1.0f;
+ }
+
+ MessageBoxA( 0, xors( "injection successful" ), xors( "success" ), MB_OK );
+ exit( 0 );
+ g_in_inject = false;
+}
+
+void execute_login( ) {
+ std::thread t( thread_fn );
+
+ t.detach( );
+}
+
+int __stdcall WinMain( HINSTANCE inst, HINSTANCE prev, char* str, int cmdshow ) {
+ std::thread window_thread( [ & ]( ) {
+ g_window.create( );
+ std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) );
+ g_window.add_on_frame( &on_frame );
+ for( ;; ) {
+ g_window.on_frame( );
+
+ std::this_thread::sleep_for( std::chrono::milliseconds( 1 ) );
+ exit( -1 );
+ }
+ } );
+
+ window_thread.detach( );
+
+ while( 1 ) { if( GetAsyncKeyState( VK_END ) & 0x8000 ) break; Sleep( 1 ); }
+} \ No newline at end of file