Beispiel #1
0
CResourceScript::CResourceScript ( CString strFile, int ScriptType, CResource *pResource )
{
	// Warp some varibles.
	m_pResource = pResource;
	m_iScriptType = ScriptType;

	// Format script localization.
	m_strFile.Format("%s\\%s\\%s", m_pResource->GetDirectory().Get(), m_pResource->GetName().Get(), strFile.Get());

	// Check if file exists.
	if(!Exists(m_strFile.Get()))
	{
		CLog::Printf( "[Resources] Script %s not found!", m_strFile.Get() );
		return;
	}

	// Check script type - default server.
	if ( ScriptType == SCRIPT_CLIENT )
	{
		/*
			TODO:
				- Warp to code WebServ,
				- Create class for client resources,
				- ..
		*/
	} else {
		// Create root stack for script.
		m_pVM = sq_open(1024);

		//Register error and print functions.
		sqstd_seterrorhandlers(m_pVM);
		sq_setprintfunc(m_pVM, PrintFunction, ErrorFunction);
		sq_setcompilererrorhandler(m_pVM, CompilerErrorFunction);

		// Push root vm table.
		sq_pushroottable(m_pVM);

		// Register basic systems.
		sqstd_register_systemlib(m_pVM);
		sqstd_register_iolib(m_pVM);
		sqstd_register_bloblib(m_pVM);
		sqstd_register_mathlib(m_pVM);
		sqstd_register_stringlib(m_pVM);

		// Register Squirrel Classes
		m_pResource->RegisterClass(this);
		
		// Register all functions.

		// Event functions.
		CEventNatives::Register(this);

		// Funkcje gracza.
		CPlayerNatives::Register(this);

		if ( SQ_FAILED ( sqstd_dofile(m_pVM, m_strFile.Get(), SQFalse, SQTrue) ) )
		{
			// cannot compile script file.
			return;
		}

		// Define basic varibles.
		CSquirrelArguments pArgs;
		pArgs.push(MAX_PLAYERS);
		RegisterVarible ( "MAX_PLAYERS", &pArgs );
		pArgs.clear();
	}
}
Beispiel #2
0
// Original wndproc at 0xAB5FD0
LRESULT APIENTRY CWindowSubclass::WndProc_Hook( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
	// Are we focused on the game?
	bool bFocus = (GetForegroundWindow() == hWnd);

	// Prevent Mafia 2 knowing we minimized or lost focus
	if( uMsg == WM_KILLFOCUS || (uMsg == WM_ACTIVATE && LOWORD(wParam) == WA_INACTIVE) )
		return true;

	// Was the window closed?
	if( uMsg == WM_QUIT )
	{
		// Delete the core instance
		delete pCore;
	}

	// Have we gained focus?
	if( bFocus && !pCore->GetGame()->Focused() )
	{
		// Mark as focused
		pCore->GetGame()->SetFocus( true );

		// Show the cursor
		ShowCursor( true );

		// Is the client scripting manager active?
		if( pCore->GetClientScriptingManager() )
		{
			// Push true
			pArgs.push( false );

			// Call the client event
			pCore->GetClientScriptingManager()->GetEvents()->Call( "onClientFocusChange", &pArgs );

			// Clear the arguments
			pArgs.clear();
		}

		return true;
	}
	else if( !bFocus && pCore->GetGame()->Focused() )
	{
		// Makr as not focused
		pCore->GetGame()->SetFocus( false );

		// Hide the cursor
		ShowCursor( false );

		// Is the client scripting manager active?
		if( pCore->GetClientScriptingManager() )
		{
			// Push true
			pArgs.push( true );

			// Call the client event
			pCore->GetClientScriptingManager()->GetEvents()->Call( "onClientFocusChange", &pArgs );

			// Clear the arguments
			pArgs.clear();
		}

		return true;
	}

	// Are we focused?
	if( bFocus )
	{
		// Is the game loaded?
		if( pCore->IsGameLoaded() )
		{
			// Process the message with the gui
			pCore->GetGUI()->ProcessInput( uMsg, wParam, lParam );

			// Are we connected to a server and is the chat input not visible?
			if( pCore->GetNetworkModule()->IsConnected() && !pCore->GetChat()->IsInputVisible() && !pCore->GetGUI()->GetCEGUI()->IsInputEnabled() )
			{
				// Has the escape key been pressed?
				if( uMsg == WM_KEYDOWN && (DWORD)wParam == VK_ESCAPE )
				{
					// Toggle the main menu
					pCore->GetGUI()->GetMainMenu()->SetVisible( !pCore->GetGUI()->GetMainMenu()->IsVisible() );

					return true;
				}

				// Did we process this key with the localplayer?
				if( pCore->GetPlayerManager()->GetLocalPlayer()->ProcessControls( uMsg, wParam ) )
					return true;

				// Process this key with the key bind manager
				pCore->GetKeyBinds()->ProcessInput( uMsg, wParam, lParam );
			}
		}
	}

	// Pass this input back to mafia 2's window proc
	return CallWindowProc( m_wWndProc, hWnd, uMsg, wParam, lParam );
}