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 Open(lua_State *L) {
	ml_Lua = Lua();
	
	
	CreateInterfaceFn g_pEngineFactory = Sys_GetFactory("engine.dll"); //Engine
	g_pEngine = (IVEngineClient*)g_pEngineFactory(VENGINE_CLIENT_INTERFACE_VERSION, NULL);
	if (!g_pEngine) {
		ml_Lua->Msg("[gmcl_replicator] Can't get IVEngineClient interface " VENGINE_CLIENT_INTERFACE_VERSION " :(\n");
		return 0;
	}
	
	CreateInterfaceFn VSTDLibFactory = Sys_GetFactory("vstdlib.dll");
	if (!VSTDLibFactory) {
		ml_Lua->Msg("[gmcl_replicator] Error getting vstdlib.dll factory.\n");
		return 0;
	}
	g_ICvar = (ICvar*)VSTDLibFactory(CVAR_INTERFACE_VERSION, NULL);
	if (!g_ICvar) {
		ml_Lua->Msg("[gmcl_replicator] Error getting ICvar " CVAR_INTERFACE_VERSION " interface.\n");
		return 0;
	}
	
	ml_Lua->NewGlobalTable("replicator");
	ILuaObject* replicator = ml_Lua->GetGlobal("replicator");
		replicator->SetMember("ConCommand",			DoClientCommand);
		replicator->SetMember("GetAllConVars",		GetAllCvars);
		replicator->SetMember("GetAllConCommands",	GetAllCmds);
		replicator->SetMember("GetConCommand", 		GetCommand);
	replicator->UnReference();
	
	ml_Lua->SetGlobal("FCVAR_DEVELOPMENTONLY", (float) FCVAR_DEVELOPMENTONLY);
	ml_Lua->SetGlobal("FCVAR_HIDDEN", (float) FCVAR_HIDDEN);
	
	ILuaObject* conVarMeta = ml_Lua->GetMetaTable("ConVar", GLua::TYPE_CONVAR);
	if (conVarMeta) {
		conVarMeta->SetMember("SetValue",		SetConVarValue);
		//conVarMeta->SetMember("GetBool",		GetConVarBool);
		conVarMeta->SetMember("GetDefault",		GetConVarDefault);
		conVarMeta->SetMember("GetFloat",		GetConVarFloat);
		//conVarMeta->SetMember("GetInt",		GetConVarInt);
		conVarMeta->SetMember("GetName",		GetConVarName);
		conVarMeta->SetMember("SetName",		SetConVarName);
		//conVarMeta->SetMember("GetString",	GetConVarString);
		conVarMeta->SetMember("SetFlags",		SetConVarFlags);
		conVarMeta->SetMember("GetFlags",		GetConVarFlags);
		conVarMeta->SetMember("HasFlag",		ConVarHasFlag);
		conVarMeta->SetMember("SetHelpText",	SetConVarHelpText);
		//conVarMeta->SetMember("GetHelpText",	GetConVarHelpText);
		conVarMeta->SetMember("Reset",			ResetConVarValue);
		conVarMeta->SetMember("Remove",			RemoveConVar);
		conVarMeta->SetMember("__tostring",		__tostring);
		conVarMeta->SetMember("__eq",			__eq);
		conVarMeta->SetMember("__index",		conVarMeta);
	}
	conVarMeta->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;
}
Beispiel #5
0
int Open(lua_State *L) {
	ml_Lua = Lua();
	
	OldSpew = GetSpewOutputFunc();
	SpewOutputFunc(NewSpew);
	
	ml_Lua->SetGlobal("SPEW_MESSAGE", 		(float)SPEW_MESSAGE);
	ml_Lua->SetGlobal("SPEW_WARNING",		(float)SPEW_WARNING);
	ml_Lua->SetGlobal("SPEW_ASSERT", 		(float)SPEW_ASSERT);
	ml_Lua->SetGlobal("SPEW_ERROR", 		(float)SPEW_ERROR);
	ml_Lua->SetGlobal("SPEW_LOG", 			(float)SPEW_LOG);
	ml_Lua->SetGlobal("SPEW_TYPE_COUNT", 	(float)SPEW_TYPE_COUNT);
	ml_Lua->SetGlobal("SPEW_DEBUGGER", 		(float)SPEW_DEBUGGER);
	ml_Lua->SetGlobal("SPEW_CONTINUE", 		(float)SPEW_CONTINUE);
	ml_Lua->SetGlobal("SPEW_TYPE_COUNT", 	(float)SPEW_TYPE_COUNT);
	ml_Lua->SetGlobal("SPEW_ABORT", 		(float)SPEW_ABORT);
	
	ml_Lua->NewGlobalTable("simplespew");
	ILuaObject* simplespew = ml_Lua->GetGlobal("simplespew");
		simplespew->SetMember("Remove", RemoveSpew);
	simplespew->UnReference();
	
	AddRemoveHook("ShutDown");
	AddRemoveHook("OnConfirmQuit"); //Extras
	
	return 0;
}
Beispiel #6
0
int Init( lua_State *L )
{
	if (FAILED(::CoInitialize(NULL)))
        return 1;

	HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&Voice);
    if( !SUCCEEDED( hr ) )
        return 1;

	Voice->GetVolume(&DefaultVolume);
	Voice->GetRate(&DefaultRate);
	Voice->GetVoice(&DefaultVoice);

	ILuaInterface* gLua = Lua();

	ILuaObject* tts = gLua->GetNewTable();
		tts->SetMember( "Say", Say );
		tts->SetMember( "IsSpeaking", IsSpeaking );
		tts->SetMember( "QueueSize", QueueSize );
		tts->SetMember( "Pause", Pause );
		tts->SetMember( "Resume", Resume );
		gLua->SetGlobal( "tts", tts );
	tts->UnReference();
	return 0;
}
bool LuaObjectBase::checkValidity(lua_State* state, int position, bool error)
{
#ifdef FULL_USER_DATA
// Make sure it's some user data!
	int type = LUA->GetType(position);
	if(type != GarrysMod::Lua::Type::USERDATA && type <= GarrysMod::Lua::Type::COUNT)
	{
		if (error)
		{
			LUA->ThrowError( "Invalid object! (not userdata)\n" );
		}
		return 0;
	}

// Acually do the check
	GarrysMod::Lua::UserData*  obj = (GarrysMod::Lua::UserData*)LUA->GetUserdata(position);
	LuaObjectBase* object = (LuaObjectBase*)(obj->data);
#else
	ILuaObject* table = luaInterface->GetObject(position);
	if (!table)
		return 0;

	LuaObjectBase* object = reinterpret_cast<LuaObjectBase*>( table->GetMemberUserDataLite("_this") );
	int type = 0;

	table->UnReference();
#endif

	return checkValidity(state, type, object, error);
}
int Start(lua_State *L)
{
	CreateInterfaceFn interfaceFactory = Sys_GetFactory( ENGINE_LIB );
	CreateInterfaceFn gameServerFactory = Sys_GetFactory( SERVER_LIB );
	CreateInterfaceFn physicsFactory = Sys_GetFactory( VPHYSICS_LIB );

	surfaceprop = (IPhysicsSurfaceProps*)physicsFactory(VPHYSICS_SURFACEPROPS_INTERFACE_VERSION, NULL);

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

	ILuaInterface *gLua = Lua();

	ILuaObject *vmeta = gLua->GetMetaTable("Vehicle", GLua::TYPE_ENTITY);

		vmeta->SetMember("GetOperatingParams", getoperatingparams);
		vmeta->SetMember("GetVehicleParams", getvehicleparams);
		vmeta->SetMember("SetVehicleParams", setvehicleparams);
		vmeta->SetMember("SetWheelMaterial", SetWheelMaterial);
		vmeta->SetMember("GetWheelMaterial", GetWheelMaterial);

	vmeta->UnReference();

	gLua->SetGlobal("GetUcmdButtons", GetUcmdButtons);
	gLua->SetGlobal("SetUcmdButtons", SetUcmdButtons);

	return 0;
}
Beispiel #9
0
int Open(lua_State *L) {
	sv_Lua = Lua();
	
	
	InpOut32 = LoadLibrary("garrysmod/lua/includes/modules/InpOut32.dll");
	if (!InpOut32) {
		sv_Lua->Error("[gm_para]: No InpOut32.dll in modules folder!\n");
	}
	
	Inp32 = (lpInp32)GetProcAddress(InpOut32, "Inp32");
	Out32 = (lpOut32)GetProcAddress(InpOut32, "Out32");
	
	if (!Inp32 || !Out32) {
		sv_Lua->Error("[gm_para]: Can't get Inp32/Out32 from InpOut32.dll!\n");
	}
	
	
	sv_Lua->NewGlobalTable("para");
	ILuaObject* para = sv_Lua->GetGlobal("para");
		para->SetMember("Read",		ReadByte);
		para->SetMember("Write",	WriteByte);
		para->SetMember("Beep",		DoBeep);
	para->UnReference();
	
	
	/*
		Data Register
		Bit     D0  D1  D2  D3  D4  D5  D6  D7
		Value   1   2   4   8   16  32  64  128
	*/
	sv_Lua->SetGlobal("DP_NONE", (float)0 );
	sv_Lua->SetGlobal("DP_ALL", (float)255 );
	
	sv_Lua->SetGlobal("DP0", (float)1 );
	sv_Lua->SetGlobal("DP1", (float)2 );
	sv_Lua->SetGlobal("DP2", (float)4 );
	sv_Lua->SetGlobal("DP3", (float)8 );
	sv_Lua->SetGlobal("DP4", (float)16 );
	sv_Lua->SetGlobal("DP5", (float)32 );
	sv_Lua->SetGlobal("DP6", (float)64 );
	sv_Lua->SetGlobal("DP7", (float)128 );
	
	
	/*
		Status Register
		Bit     SP3  SP4  SP5  SP6  SP7
		Value   8    16   32   64   128
	*/
	sv_Lua->SetGlobal("SP_NONE", (float)0 );
	sv_Lua->SetGlobal("SP_ALL", (float)248 );
	
	sv_Lua->SetGlobal("SP3", (float)8 );
	sv_Lua->SetGlobal("SP4", (float)16 );
	sv_Lua->SetGlobal("SP5", (float)32 );
	sv_Lua->SetGlobal("SP6", (float)64 );
	sv_Lua->SetGlobal("SP7", (float)128 );
	
	return 0;
}
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 #11
0
int Open(lua_State* L)
{
	ILuaInterface *gLua = Lua();
	ILuaObject* gntp = gLua->GetNewTable();
	gntp->SetMember("Notify", growl_notify);
	gLua->SetGlobal("gntp", gntp);
	gntp->UnReference();

	return 0;
}
Beispiel #12
0
int Open( lua_State *L )
{
	ILuaInterface* gLua = Lua();

	gLua->NewGlobalTable( "cmd" );

	ILuaObject *cmdTable = gLua->GetGlobal( "cmd" );
		cmdTable->SetMember( "exec", cmd_exec );
	cmdTable->UnReference();
	return 0;
}
Beispiel #13
0
void LuaObjectBase::pushObject()
{
	if (!m_luaState)
		return;

#ifdef FULL_USER_DATA
	m_gcRefCount++;
	GarrysMod::Lua::UserData* ud = (GarrysMod::Lua::UserData*)MLUA->NewUserdata(sizeof(GarrysMod::Lua::UserData));
	ud->data = this;
	ud->type = m_classInfo.typeId();
	MLUA->ReferencePush( m_classInfo.m_metatable );
	MLUA->SetMetaTable(-2);
#else
	if (latestRef())
	{
		latestRef()->Push();
	}
	else
	{
		ILuaObject* metaTable = m_luaInterface->GetNewTable();
		metaTable->SetMember("__gc", LuaObjectBase::gcDeleteWrapper );
		metaTable->SetMember("__tostring", LuaObjectBase::toStringWrapper);

		ILuaObject* object = m_luaInterface->GetNewTable();
		object->SetMemberUserDataLite("_this", this);
		const std::vector<LuaBoundFunction*>& list = m_classInfo.functionList();
		for (std::vector<LuaBoundFunction*>::const_iterator it = list.begin(); 
				it != list.end(); 
				++it)
		{
			object->SetMember( (*it)->functionName(), (*it)->function() );
		}
		object->SetMetaTable(metaTable);

		object->Push();
    
		metaTable->UnReference();
		object->UnReference();
	}
#endif
}
Beispiel #14
0
int Open(lua_State *L) {
	gm_Lua = Lua();
	
	gm_Lua->NewGlobalTable("rereq");
	ILuaObject* rereq = gm_Lua->GetGlobal("rereq");
		rereq->SetMember("require", 	ReReq);
		rereq->SetMember("unrequire", 	UnReq);
	rereq->UnReference();
	
	gm_Lua->Msg("! loaded\n");
    return 0;
}
Beispiel #15
0
bool ShouldTeleport(int playerIndex)
{
	gLua->PushReference(refEntity);
		gLua->Push((float)playerIndex);
	gLua->Call(1, 1);
	ILuaObject *pPlayer = gLua->GetReturn(0);

	gLua->PushReference(refHookCall);
		gLua->Push("ShouldTeleport");
		gLua->PushNil();
		gLua->Push(pPlayer);
	gLua->Call(3, 1);
	ILuaObject *ret = gLua->GetReturn(0);

	pPlayer->UnReference();

	bool result = ret->GetBool();
	
	ret->UnReference();

	return result;
}
Beispiel #16
0
void PushAStarNode(AStarNode *node)
{
	if(node)
	{
		ILuaObject* meta = gLua->GetMetaTable(ASTAR_NODE_NAME, ASTAR_NODE_TYPE);
			gLua->PushUserData(meta, node);
		meta->UnReference();
	}
	else
	{
		gLua->Push(false);
	}
}
Beispiel #17
0
void PushAStar(AStar *astar)
{
	if(astar)
	{
		ILuaObject* meta = gLua->GetMetaTable(ASTAR_NAME, ASTAR_TYPE);
			gLua->PushUserData(meta, astar);
		meta->UnReference();
	}
	else
	{
		gLua->Push(false);
	}
}
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;
}
Beispiel #19
0
void VFUNC newDispatchUserMessage( IBaseClientDLL *baseCLDLL, int peebis, int msg_type, bf_read &msg_data ) {

	for ( int i=0; i <= 1; i++) {
		ILuaInterface* gLua = CStateManager::GetByIndex( i );
		if ( gLua == NULL ){ continue; }

		gLua->Push( gLua->GetGlobal("hook")->GetMember("Call") );
			gLua->Push("DispatchUserMessage");
			gLua->PushNil();

			gLua->Push( (float) peebis );
			gLua->Push( (float) msg_type );

			ILuaObject *metaT = gLua->GetMetaTable( CBITREAD_NAME, CBITREAD_ID ); //Push our custom stringtable object
				gLua->PushUserData( metaT, &msg_data );
			metaT->UnReference();

		gLua->Call(4, 0);
	}

	return origDispatchUserMessage( baseCLDLL, peebis, msg_type, msg_data );
}
Beispiel #20
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 #21
0
int Init(lua_State *L) {

	if ( !Lua()->IsClient() )
		Lua()->Error( "gmcl_usermessages can only be loaded on the client!" );

	CreateInterfaceFn ClientFactory = Sys_GetFactory( CLIENT_LIB );
	if ( !ClientFactory )
		Lua()->Error( "gmcl_usermessages: Error getting " CLIENT_LIB " factory." );

	g_BaseClientDLL = ( IBaseClientDLL* )ClientFactory( CLIENT_DLL_INTERFACE_VERSION, NULL );
	if ( !g_BaseClientDLL )
		Lua()->Error( "gmcl_usermessages: Error getting IBaseClientDLL interface.\n" );
	
	HOOKVFUNC( g_BaseClientDLL, 36, origDispatchUserMessage, newDispatchUserMessage );
	
	Color Blue( 0, 162, 232, 255 );
	Color White( 255, 255, 255, 255 );

	ConColorMsg( Blue, "gmcl_usermessages" );
	ConColorMsg( White, ": Loaded!\n" );

	/*
	Lua()->NewGlobalTable("usermessages");
		ILuaObject *usermessages = Lua()->GetGlobal("usermessages");
		usermessages->SetMember( "Lookup", LookupUserMessage );
		usermessages->SetMember( "GetSize", GetUserMessageSize );
		usermessages->SetMember( "GetName", GetUserMessageName );
		usermessages->SetMember( "IsValidIndex", IsValidIndex );
	usermessages->UnReference();
	*/

	ILuaObject *metaT = Lua()->GetMetaTable( CBITREAD_NAME, CBITREAD_ID );
		metaT->SetMember( "GetSize", GetSize );
		metaT->SetMember( "GetDebugName", GetDebugName );
		metaT->SetMember( "GetNumBitsLeft", GetNumBitsLeft );
		metaT->SetMember( "GetNumBitsRead", GetNumBitsRead );
		metaT->SetMember( "GetNumBytesLeft", GetNumBytesLeft );
		metaT->SetMember( "IsOverflowed", IsOverflowed );
		metaT->SetMember( "PeekUBitLong", PeekUBitLong );
		metaT->SetMember( "ReadAndAllocateString", ReadAndAllocateString );
		metaT->SetMember( "ReadBitAngle", ReadBitAngle );
		metaT->SetMember( "ReadBitAngles", ReadBitAngles );
		metaT->SetMember( "ReadBitCoord", ReadBitCoord );
		metaT->SetMember( "ReadBitCoordMP", ReadBitCoordMP );
		metaT->SetMember( "ReadBitFloat", ReadBitFloat );
		metaT->SetMember( "ReadBitNormal", ReadBitNormal );
		metaT->SetMember( "ReadBitVec3Coord", ReadBitVec3Coord );
		metaT->SetMember( "ReadBitVec3Normal", ReadBitVec3Normal );
		metaT->SetMember( "ReadByte", ReadByte );
		metaT->SetMember( "ReadChar", ReadChar );
		metaT->SetMember( "ReadFloat", ReadFloat );
		metaT->SetMember( "ReadLong", ReadLong );
		metaT->SetMember( "ReadOneBit", ReadOneBit );
		metaT->SetMember( "ReadSBitLong", ReadSBitLong );
		metaT->SetMember( "ReadShort", ReadShort );
		metaT->SetMember( "ReadString", ReadString );
		metaT->SetMember( "ReadUBitLong", ReadUBitLong );
		metaT->SetMember( "ReadUBitVar", ReadUBitVar );
		metaT->SetMember( "ReadWord", ReadWord );
		metaT->SetMember( "Seek", Seek );
		metaT->SetMember( "SeekRelative", SeekRelative );
		metaT->SetMember( "SetDebugName", SetDebugName );
		metaT->SetMember( "SetOverflowFlag", SetOverflowFlag );
		metaT->SetMember( "Tell", Tell );
		metaT->SetMember( "TotalBytesAvailable", TotalBytesAvailable );

		metaT->SetMember( "__tostring", __tostring );
		metaT->SetMember( "__eq", __eq );
		metaT->SetMember( "__index", metaT );
	metaT->UnReference();

	return 0;
}
Beispiel #22
0
void LUA_PushVector(lua_State* L, Vector& vec)
{
	ILuaObject* obj = NewVectorObject(L, vec);
		Lua()->Push(obj);
	obj->UnReference();
}
Beispiel #23
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;
}
Beispiel #24
0
void GMOD_PushVector(Vector& vec)
{
	ILuaObject* obj = NewVectorObject(vec);
		gLua->Push(obj);
	obj->UnReference();
}
Beispiel #25
0
int Init(lua_State* L)
{
	gLua = Lua();

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

	engine = (IVEngineServer*)interfaceFactory(INTERFACEVERSION_VENGINESERVER, NULL);
	if(!engine)
	{
		gLua->Error("gm_astar: Missing IVEngineServer interface.\n");
	}
	
	CreateInterfaceFn fsFactory;

	if(gLua->IsDedicatedServer())
	{
		fsFactory = GetFactories().fileSystemFactory;
	}
	else
	{
		fsFactory = Sys_GetFactory("filesystem_steam.dll");
	}

	if(!fsFactory)
	{
		gLua->Error("gm_astar: Missing fsFactory\n");
	}

	filesystem = (IFileSystem*)fsFactory(FILESYSTEM_INTERFACE_VERSION, NULL);
	if(!filesystem)
	{
		gLua->Error("gm_astar: Missing IFileSystem interface.\n");
	}

	// Get a reference to the function to survive past 510 calls!
	ILuaObject *VectorMeta = gLua->GetGlobal("Vector");
		VectorMeta->Push();
		VectorMetaRef = gLua->GetReference(-1, true);
	VectorMeta->UnReference();

	gLua->SetGlobal("HEURISTIC_MANHATTAN", (float)AStar::HEURISTIC_MANHATTAN);
	gLua->SetGlobal("HEURISTIC_EUCLIDEAN", (float)AStar::HEURISTIC_EUCLIDEAN);
	gLua->SetGlobal("HEURISTIC_DISTANCE", (float)AStar::HEURISTIC_DISTANCE);
	gLua->SetGlobal("HEURISTIC_CUSTOM", (float)AStar::HEURISTIC_CUSTOM);

	gLua->SetGlobal("CreateAStar", CreateAStar);

	ILuaObject *MetaAStar = gLua->GetMetaTable(ASTAR_NAME, ASTAR_TYPE);
		ILuaObject *AStarIndex = gLua->GetNewTable();
			AStarIndex->SetMember("GetNode", AStar_GetNode);
			AStarIndex->SetMember("GetNodeTotal", AStar_GetNodeTotal);
			AStarIndex->SetMember("GetNodes", AStar_GetNodes);
			AStarIndex->SetMember("FindPath", AStar_FindPath);
			AStarIndex->SetMember("AddNode", AStar_AddNode);
			AStarIndex->SetMember("GetHeuristic", AStar_GetHeuristic);
			AStarIndex->SetMember("GetStart", AStar_GetStart);
			AStarIndex->SetMember("GetEnd", AStar_GetEnd);
			AStarIndex->SetMember("SetHeuristic", AStar_SetHeuristic);
			AStarIndex->SetMember("SetStart", AStar_SetStart);
			AStarIndex->SetMember("SetEnd", AStar_SetEnd);
			AStarIndex->SetMember("Save", AStar_Save);
			AStarIndex->SetMember("Load", AStar_Load);
			AStarIndex->SetMember("NearestNode", AStar_NearestNode);
			AStarIndex->SetMember("LinkNodes", AStar_LinkNodes);
			AStarIndex->SetMember("AutoLinkNodes", AStar_AutoLinkNodes);
		MetaAStar->SetMember("__index", AStarIndex);
		AStarIndex->UnReference();
	MetaAStar->UnReference();

	ILuaObject *MetaAStarNode = gLua->GetMetaTable(ASTAR_NODE_NAME, ASTAR_NODE_TYPE);
		ILuaObject *AStarNodeIndex = gLua->GetNewTable();
			AStarNodeIndex->SetMember("Link", AStarNode_Link);
			AStarNodeIndex->SetMember("IsLink", AStarNode_IsLink);
			AStarNodeIndex->SetMember("GetPos", AStarNode_GetPos);
			AStarNodeIndex->SetMember("GetLinks", AStarNode_GetLinks);
		MetaAStarNode->SetMember("__index", AStarNodeIndex);
		AStarNodeIndex->UnReference();
	MetaAStarNode->UnReference();

	Msg("gm_astar: Programmed by Spacetech; Not for Troin's eyes!\n");

	return 0;
}