/* * * * * * * * * * * * * * * * 
 * 	 ______     __  __     ______     __  __     ______     ______     __  __    
 *	/\  __ \   /\ \/\ \   /\  == \   /\ \_\ \   /\  __ \   /\  ___\   /\ \/ /    
 *	\ \ \/\ \  \ \ \_\ \  \ \  __<   \ \  __ \  \ \  __ \  \ \ \____  \ \  _"-.  
 *	 \ \_____\  \ \_____\  \ \_____\  \ \_\ \_\  \ \_\ \_\  \ \_____\  \ \_\ \_\ 
 *	  \/_____/   \/_____/   \/_____/   \/_/\/_/   \/_/\/_/   \/_____/   \/_/\/_/ 
 *
 *  - Version : 3L
 *  - By Oubliette
 * * * * * * * * * * * * * * * */

#ifndef _OUBHACK

#define _OUBHACK

// Paths
#define LUA_BASEFOLDER	"bin/lua/"
#define LUA_CLIENTLOAD	"bin/lua/client_load.lua"
#define LUA_MENULOAD	"bin/lua/menu_load.lua"
#define LUA_MENU		"bin/lua/menu/oubhack_v3l.lua"
#define LUA_CLIENT		"bin/lua/client/oubhack_v3l.lua"

// Lua states
#define LUA_STATE_CLIENT	0
#define LUA_STATE_MENU		2

// Headers
#include "oubhack_iluainterface.h"
#include "oubhack_interfaces.h"
#include "oubhack_iluashared.h"
#include "oubhack_lua_l.h"
#include "oubhack_fileio.h"
#include "oubhack_client_hook.h"
#include "oubhack_menu_hook.h"
#include "oubhack_engineclient.h"
#include "oubhack_concoms.h"
#include "oubhack_cvar.h"
#include "oubhack_mrender.h"
#include "oubhack_exports.h"
#include "main.h"

#include <stdint.h>
#include <map>

// To do with nospread random calculations
class IUniformRandomStream;
extern IUniformRandomStream *random;

// OubHack class
class OubHack {

private:

	ILuaInterface* m_pClientLua;
	ILuaInterface* m_pMenuLua;

public:
	
	OubHack( );
	~OubHack( );

	void Init( );

	// Events

	void LoadLuaWrappers(); // Called when it's safe to load lua class wrappers
	void LoadWrappers();	// Called when it's safe to load C++ class wrappers
	void LoadAuthListener(); // Called when the DLL's injected, listens in it's own thread for auth details

	void OnStateCreated( PDWORD_PTR* );
	void OnStateDestroyed();

	void OnAuthed();

	// Class libraries
	IFileIO*			m_pFileIO;				// File operations library
	IConsoleCommands*	m_pConsoleCommands;		// Console commands library, state friendly
	ICvarInterface*		m_pCvarInterface;		// CVar library
	ILuaLibrary*		m_pLuaLibrary;			// Lua library, functions used in C++ => Lua bindings
	ICHook*				m_pCHooks;				// Client Hook library, used to call lua hooks when C++ events occur
	IMHook*				m_pMHooks;				// Menu Hook library, used to call lua hooks when C++ events occur
	CMenuRender*		m_pMenuRender;			// Rendering library, used to write stuff to screen
	CLuaExports*		m_pLuaExports;			// Lua exports library, a collection of lua functions exported in lua_shared.dll

	// Threads
	HANDLE m_RenderThread;
	HANDLE m_AuthThread;

	// Files
	std::map<std::string, std::string> mapDataCache;
	std::map<std::string, int64_t> mapSizeCache;

	// Network
	const char* m_ccIP;
	int64_t m_l64SessionID;

	// AES
	byte m_bDecKey[ 16 ];
	byte m_bDecIV[ 16 ];

	// Login
	std::string m_sUsername;
	int64_t m_llSteamID64;

	// Logging
	bool m_bDebug;

	// Version
	int m_iVersion;

	// Structures
	Interface Interfaces; // Source engine interface stucture

	// Wrappers
	IEngineClient*	m_pClient;
	
	// Initialization functions
	void InitLuaLibraries();
	void InitClientBindings();
	void InitMenuBindings();

	bool InitInterfaces();	// Can fail
	void InitLibraries();

	// Logging

	void Log( const char *, ... );

	void Log( Color, const char *, ... );

	void LogNoEnd( const char *, ... );

	void LogNoEnd( Color, const char *, ... );

	void Error( const char *, ... );

	void Warning( const char *, ... );

	void SevereError( const char *, ... );

	void Debug( const char *, ... );

	void LogToFile( const char *, bool, ... );

	// Get
	ILuaInterface*	GetLuaInterface( int );
	PDWORD_PTR*		RawGetLuaInterface( int );

};

extern OubHack* oubhack;

#endif