summaryrefslogtreecommitdiff
path: root/tf2/console_log.hpp
blob: 4659ea14266c09ee80e485eeb5401a229b6f71a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#pragma once

#include <memory>
#include <Windows.h>
#pragma warning(disable: 4996)

class console {
public:
	void create( ) {
		AllocConsole( );
		freopen( "CONOUT$", "w", stdout );
		SetConsoleTitleA( "tf2internal" );

		game_console_print = reinterpret_cast< decltype( game_console_print ) >( GetProcAddress( GetModuleHandleA( "tier0.dll" ), "Msg" ) );
	}

	void destroy( ) {
		FreeConsole( );
		fclose( stdout );
	}

	__forceinline void log_function( const char* msg ) {
		printf( "%s: %s", __FUNCTION__, msg );
	}

	using msg_t = void( __cdecl* )( const char*, ... );
	msg_t game_console_print;


	static console *con( ) {
		static console g_singleton_;
		return &g_singleton_;
	}
};