Beispiel #1
0
SpewRetval_t NewSpew(SpewType_t Type, const char *What) {
	if (Removed || (!What || !ml_Lua)) {
		return SPEW_CONTINUE;
	}
	
	Color tempColor = GetSpewOutputColor();
	tempColor.GetColor(Red,Green,Blue,Alpha);
	
	ILuaObject* hook = ml_Lua->GetGlobal("hook");
		ILuaObject* hookCall = hook->GetMember("Call");
			ml_Lua->Push(hookCall);
			ml_Lua->Push("SimpleSpew");
			ml_Lua->PushNil();
			ml_Lua->PushLong(Type);
			ml_Lua->Push(What);
			ml_Lua->Push( GetSpewOutputGroup() );
			ml_Lua->PushLong( GetSpewOutputLevel() );
			ml_Lua->PushLong(Red);
			ml_Lua->PushLong(Green);
			ml_Lua->PushLong(Blue);
			ml_Lua->PushLong(Alpha);
			ml_Lua->Call(10,0);
		hookCall->UnReference();
	hook->UnReference();
	
	
	if (OldSpew) {
		return OldSpew(Type, What);
	} else {
		return (SpewRetval_t)0;
	}
}
Beispiel #2
0
int Init(lua_State* L)
{
	gLua = Lua();

	CreateInterfaceFn engineFactory	= Sys_GetFactory("engine.dll");

	engine = (IVEngineServer*)engineFactory(INTERFACEVERSION_VENGINESERVER, NULL);

	if(!engine)
	{
		gLua->Error("gmsv_teleport: Failed to load IVEngineServer\n");
	}

	Msg("gmsv_teleport: Loaded\n");

	ILuaObject *oEntity = gLua->GetGlobal("Entity");
	oEntity->Push();
	refEntity = gLua->GetReference(-1, true);
	oEntity->UnReference();

	ILuaObject *ohook = gLua->GetGlobal("hook");
		ILuaObject *oCall = ohook->GetMember("Call");
		oCall->Push();
		refHookCall = gLua->GetReference(-1, true);
		oCall->UnReference();
	ohook->UnReference();

	ILuaObject *oEntityMeta = gLua->GetMetaTable("Entity", GLua::TYPE_ENTITY);
		ILuaObject *oEntIndex = oEntityMeta->GetMember("EntIndex");
		oEntIndex->Push();
		refEntIndex = gLua->GetReference(-1, true);
		oEntIndex->UnReference();
	oEntityMeta->UnReference();

	ILuaObject *entityMeta = gLua->GetMetaTable("Entity", GLua::TYPE_ENTITY);
	if(entityMeta)
	{
		entityMeta->SetMember("SetupTeleportHook", SetupTeleportHook);
	}
    entityMeta->UnReference();

	return 0;
}
Beispiel #3
0
void AddRemoveHook(const char* What) {
	ILuaObject* hook = ml_Lua->GetGlobal("hook");
		ILuaObject* hookAdd = hook->GetMember("Add");
			ml_Lua->Push(hookAdd);
			ml_Lua->Push(What);
			ml_Lua->Push("SimpleSpew");
			ml_Lua->Push(RemoveSpew);
			ml_Lua->Call(3,0);
		hookAdd->UnReference();
	hook->UnReference();
}
Beispiel #4
0
int Init(lua_State* L)
{
	ILuaObject *navMeta = Lua()->GetMetaTable(NAV_NAME, NAV_TYPE);
	ILuaObject *indexTable = navMeta->GetMember("__index");
	indexTable->SetMember("FloodTerritory", Nav_Flood);
	indexTable->SetMember("GetTerritory", Nav_GetTerritory);
	indexTable->UnReference();
	navMeta->UnReference();

	Msg("gmsv_sassilization: Loaded\n");

	return 0;
}
inline ILuaObject *PushVector( ILuaInterface *gLua, const Vector& vec )
{
	ILuaObject* G = gLua->Global();
	ILuaObject* NVec = G->GetMember("Vector");

	gLua->Push( NVec );
	gLua->Push( vec.x );
	gLua->Push( vec.y );
	gLua->Push( vec.z );
	gLua->Call( 3, 1 );

	ILuaObject* returno = gLua->GetReturn( 0 );

	NVec->UnReference();

	return returno;
}
void CLuaInterface_Hooks::ErrorFromLua_H( const char *err, ... )
{
	ILuaInterface *luaInterface = (ILuaInterface *)this;

	// Construct error string
	char szBuf[512];
	va_list arg_ptr;
	va_start( arg_ptr, err );
	_vsntprintf( szBuf, sizeof(szBuf)-1, (char *)err, arg_ptr );
	va_end( arg_ptr );

	// Only call hook if the state has the module loaded
	if ( g_LuaInterfaces.Find( luaInterface ) == -1 )
	{
		(this->*ErrorFromLua_T)( szBuf );

		return;
	}

	// Call LuaError hook

	ILuaObject *hookTable = luaInterface->GetGlobal( "hook" );
	ILuaObject *hookCallFunction = hookTable->GetMember( "Call" );
	hookCallFunction->Push();

	luaInterface->Push( "LuaError" );
	luaInterface->PushNil();
	luaInterface->Push( szBuf );
	luaInterface->Call( 3, 1 );

	hookTable->UnReference();
	hookCallFunction->UnReference();

	// Check return value

	ILuaObject *returnValue = luaInterface->GetReturn( 0 );

	// Call original if nothing is returned
	if ( returnValue->isNil() )
		(this->*ErrorFromLua_T)( szBuf );

	returnValue->UnReference();
}
Beispiel #7
0
int Init(lua_State* L)
{
	CreateInterfaceFn interfaceFactory = Sys_GetFactory("engine.dll");

	engine = (IVEngineServer*)interfaceFactory(INTERFACEVERSION_VENGINESERVER, NULL);

	if(!engine)
	{
		Lua()->Error("gm_navigation: Missing IVEngineServer interface.\n");
	}

#ifdef LUA_SERVER
	enginetrace = (IEngineTrace*)interfaceFactory(INTERFACEVERSION_ENGINETRACE_SERVER, NULL);
#else
	enginetrace = (IEngineTrace*)interfaceFactory(INTERFACEVERSION_ENGINETRACE_CLIENT, NULL);
#endif
	
	if(!enginetrace)
	{
		Lua()->Error("gm_navigation: Missing IEngineTrace interface.\n");
	}

#ifndef USE_BOOST_THREADS
	threadPool = CreateThreadPool();

	ThreadPoolStartParams_t params;
	params.nThreads = 2;

	if(!threadPool->Start(params))
	{
		SafeRelease(threadPool);
		Lua()->Error("gm_navigation: Thread pool is null\n");
	}
#endif

	ILuaObject* navTable = Lua()->GetNewTable();
		navTable->SetMember("Create", nav_Create);
		navTable->SetMember("Poll", nav_Poll);

		navTable->SetMember("NORTH", (float)NORTH);
		navTable->SetMember("SOUTH", (float)SOUTH);
		navTable->SetMember("EAST", (float)EAST);
		navTable->SetMember("WEST", (float)WEST);

		navTable->SetMember("NORTHEAST", (float)NORTHEAST);
		navTable->SetMember("NORTHWEST", (float)NORTHWEST);
		navTable->SetMember("SOUTHEAST", (float)SOUTHEAST);
		navTable->SetMember("SOUTHWEST", (float)SOUTHWEST);

		navTable->SetMember("UP", (float)UP);
		navTable->SetMember("DOWN", (float)DOWN);
		navTable->SetMember("LEFT", (float)LEFT);
		navTable->SetMember("RIGHT", (float)RIGHT);
		navTable->SetMember("FORWARD", (float)FORWARD);
		navTable->SetMember("BACKWARD", (float)BACKWARD);

		navTable->SetMember("NUM_DIRECTIONS", (float)NUM_DIRECTIONS);
		navTable->SetMember("NUM_DIRECTIONS_DIAGONAL", (float)NUM_DIRECTIONS_DIAGONAL);
		navTable->SetMember("NUM_DIRECTIONS_MAX", (float)NUM_DIRECTIONS_MAX);

		navTable->SetMember("HEURISTIC_MANHATTAN", (float)Nav::HEURISTIC_MANHATTAN);
		navTable->SetMember("HEURISTIC_EUCLIDEAN", (float)Nav::HEURISTIC_EUCLIDEAN);
		navTable->SetMember("HEURISTIC_CUSTOM", (float)Nav::HEURISTIC_CUSTOM);

	Lua()->SetGlobal("nav", navTable);
	navTable->UnReference();

	ILuaObject *MetaNav = Lua()->GetMetaTable(NAV_NAME, NAV_TYPE);
		ILuaObject *NavIndex = Lua()->GetNewTable();
			NavIndex->SetMember("GetNodeByID", Nav_GetNodeByID);
			NavIndex->SetMember("GetNodes", Nav_GetNodes);
			NavIndex->SetMember("GetNearestNodes", Nav_GetNearestNodes);

			NavIndex->SetMember("GetNodeTotal", Nav_GetNodeTotal);

			NavIndex->SetMember("AddWalkableSeed", Nav_AddGroundSeed); // TODO: Remove
			NavIndex->SetMember("AddGroundSeed", Nav_AddGroundSeed);
			NavIndex->SetMember("AddAirSeed", Nav_AddAirSeed);

			NavIndex->SetMember("ClearWalkableSeeds", Nav_ClearGroundSeeds); // TODO: Remove
			NavIndex->SetMember("ClearGroundSeeds", Nav_ClearGroundSeeds);
			NavIndex->SetMember("ClearAirSeeds", Nav_ClearAirSeeds);

			NavIndex->SetMember("SetupMaxDistance", Nav_SetupMaxDistance);
			NavIndex->SetMember("Generate", Nav_Generate);
			NavIndex->SetMember("FullGeneration", Nav_FullGeneration);
			NavIndex->SetMember("IsGenerated", Nav_IsGenerated);
			NavIndex->SetMember("FindPath", Nav_FindPath);
			NavIndex->SetMember("FindPathImmediate", Nav_FindPathImmediate);
			NavIndex->SetMember("FindPathHull", Nav_FindPathHull);
			NavIndex->SetMember("GetHeuristic", Nav_GetHeuristic);
			NavIndex->SetMember("GetStart", Nav_GetStart);
			NavIndex->SetMember("GetEnd", Nav_GetEnd);
			NavIndex->SetMember("SetHeuristic", Nav_SetHeuristic);
			NavIndex->SetMember("SetStart", Nav_SetStart);
			NavIndex->SetMember("SetEnd", Nav_SetEnd);
			NavIndex->SetMember("GetNode", Nav_GetNode);
			NavIndex->SetMember("GetClosestNode", Nav_GetClosestNode);
			NavIndex->SetMember("GetNearestNodes", Nav_GetNearestNodes);
			NavIndex->SetMember("GetNodesInSphere", Nav_GetNearestNodes);
			NavIndex->SetMember("Save", Nav_Save);
			NavIndex->SetMember("Load", Nav_Load);
			NavIndex->SetMember("GetDiagonal", Nav_GetDiagonal);
			NavIndex->SetMember("SetDiagonal", Nav_SetDiagonal);
			NavIndex->SetMember("GetGridSize", Nav_GetGridSize);
			NavIndex->SetMember("SetGridSize", Nav_SetGridSize);
			NavIndex->SetMember("GetMask", Nav_GetMask);
			NavIndex->SetMember("SetMask", Nav_SetMask);
			NavIndex->SetMember("CreateNode", Nav_CreateNode);
			NavIndex->SetMember("RemoveNode", Nav_RemoveNode);
		MetaNav->SetMember("__index", NavIndex);
		NavIndex->UnReference();
	MetaNav->UnReference();

	ILuaObject *MetaNode = Lua()->GetMetaTable(NODE_NAME, NODE_TYPE);
		ILuaObject *NodeIndex = Lua()->GetNewTable();
			NodeIndex->SetMember("GetID", Node_GetID);
			NodeIndex->SetMember("GetPosition", Node_GetPosition);
			NodeIndex->SetMember("GetPos", Node_GetPosition);
			NodeIndex->SetMember("GetNormal", Node_GetNormal);
			NodeIndex->SetMember("GetConnections", Node_GetConnections);
			NodeIndex->SetMember("GetConnectedNode", Node_GetConnectedNode);
			NodeIndex->SetMember("GetScoreF", Node_GetScoreF);
			NodeIndex->SetMember("GetScoreG", Node_GetScoreG);
			NodeIndex->SetMember("IsConnected", Node_IsConnected);
			NodeIndex->SetMember("IsDisabled", Node_IsDisabled);
			NodeIndex->SetMember("SetDisabled", Node_SetDisabled);
			NodeIndex->SetMember("SetNormal", Node_SetNormal);
			NodeIndex->SetMember("SetPosition", Node_SetPosition);
			NodeIndex->SetMember("ConnectTo", Node_ConnectTo);
			NodeIndex->SetMember("RemoveConnection", Node_RemoveConnection);
		MetaNode->SetMember("__index", NodeIndex);
		MetaNode->SetMember("__eq", Node__eq);
		NodeIndex->UnReference();
	MetaNode->UnReference();

	// Based on azuisleet's method.
	// hook.Add("Think", "NavPoll", nav.Poll)
	ILuaObject *hook = Lua()->GetGlobal("hook");
	ILuaObject *add = hook->GetMember("Add");
	add->Push();
		Lua()->Push("Think");
		Lua()->Push("NavPoll");
		Lua()->Push(nav_Poll);
	Lua()->Call(3);
	hook->UnReference();
	add->UnReference();

#ifdef LUA_SERVER
	Msg("gmsv_navigation_win32: Loaded\n");
#else
	Msg("gmcl_navigation_win32: Loaded\n");
#endif

#ifdef FILEBUG
	pDebugFile = fopen("garrysmod/filebug.txt", "a+");
	FILEBUG_WRITE("Opened Module\n");
#endif

	return 0;
}