summaryrefslogtreecommitdiff
path: root/gmod/console.hpp
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 /gmod/console.hpp
parent564d979b79e8a5aaa5014eba0ecd36c61575934f (diff)
first
Diffstat (limited to 'gmod/console.hpp')
-rw-r--r--gmod/console.hpp123
1 files changed, 123 insertions, 0 deletions
diff --git a/gmod/console.hpp b/gmod/console.hpp
new file mode 100644
index 0000000..cfeb255
--- /dev/null
+++ b/gmod/console.hpp
@@ -0,0 +1,123 @@
+#pragma once
+#include <memory>
+#include <Windows.h>
+#include <vector>
+#include <functional>
+
+#include "con_fn.hpp"
+#include "con_alias.hpp"
+#include "input_system.hpp"
+#include "math.hpp"
+
+#pragma warning(disable: 4996)
+
+class console {
+public:
+ console( ) {
+ m_input = std::make_shared< util::c_input_manager >( );
+ }
+
+ static constexpr size_t TOP_HEIGHT = 22;
+ static constexpr size_t WIDTH = 400;
+ static constexpr size_t HEIGHT = 450;
+
+ bool m_consuming_input{ };
+ bool m_active{ };
+ bool m_open{ };
+
+ struct con_log {
+ float m_time;
+ char m_msg[ 128 ];
+ };
+
+ void draw_text( int x, int y, bool greyed, const char* msg, ... );
+ void draw_text( int x, int y, const char* msg, ... );
+ void draw_rect( int x, int y, int w, int h, clr_t col );
+ void register_fn( con_fn_base* fn ) { m_functions.push_back( fn ); }
+
+ void input( );
+ void draw( );
+
+ auto& get_input( ) {
+ return m_input;
+ }
+
+ void log( const char* fmt, ... ) {
+ va_list args;
+ char buf[ 128 ];
+
+ __crt_va_start( args, fmt );
+ vsprintf_s< 128 >( buf, fmt, args );
+ __crt_va_end( args );
+
+ con_log log;
+ log.m_time = ( float )GetTickCount( ) * 0.001f;
+ memcpy( log.m_msg, buf, 128 );
+
+ print( "%s\n", buf );
+
+ m_logs.push_back( log );
+ }
+
+ void print( const char* fmt, ... ) {
+ va_list args;
+ va_start( args, fmt );
+ vprintf_s( fmt, args );
+ va_end( args );
+ }
+
+ void create( ) {
+ #ifdef _DEBUG
+ AllocConsole( );
+ freopen( xors( "CONOUT$" ), "w", stdout );
+ const char* hack_names[ ] = {
+ xors( "dunk hack" ),
+ xors( "dweeb dumpster" ),
+ xors( "nova killER" ),
+ xors( "moms credit card" ),
+ xors( "dad hook" ),
+ xors( "retard remover" ),
+ xors( "slam hook" ),
+ xors( "swoosh" ),
+ xors( "retard remover" ),
+ xors( "shotgun hack" ),
+ };
+
+ SetConsoleTitleA( hack_names[ math::random_number( 0, 9 ) ] );
+ #endif
+ game_console_print = reinterpret_cast< msg_t >( GetProcAddress( GetModuleHandleA( "tier0.dll" ), "Msg" ) );
+ }
+
+ void destroy( ) {
+ //FreeConsole( );
+ //fclose( stdout );
+ }
+
+ std::vector< con_log > m_logs;
+ std::vector< con_fn_base* > m_functions;
+ std::vector< std::shared_ptr< ISetting > > m_aliases;
+
+ void register_alias( std::shared_ptr< ISetting >& alias );
+
+ using msg_t = void( __cdecl* )( const char*, ... );
+ msg_t game_console_print;
+
+private:
+ ISetting* find_var( hash_t name );
+ ISetting* find_alias( hash_t name );
+
+ std::string impl_alias_str( std::string str );
+
+ con_fn_base* find_fn( hash_t name );
+ void capture_command( );
+ void execute_command( const char* cmd );
+
+ int m_x{ 100 }, m_y{ 100 };
+
+ char m_cur_cmd[ 200 ]{ };
+ uint8_t m_key_states[ 256 ]{ };
+ float m_last_key_input[ 256 ]{ };
+ std::shared_ptr< util::c_input_manager > m_input;
+};
+
+extern std::shared_ptr< console > g_con; \ No newline at end of file