Ejemplo n.º 1
0
bool InitSteam()
{
	CreateInterfaceFn fnApiInterface = g_SteamAPILoader.Load();


	if (!fnApiInterface)
		return false;

	if (!(steamclient = (ISteamClient017 *)fnApiInterface(STEAMCLIENT_INTERFACE_VERSION_017, NULL)))
		return false;

	if (!(clientengine = (IClientEngine *)fnApiInterface(CLIENTENGINE_INTERFACE_VERSION, NULL)))
		return false;

	if (!(g_hSteamPipe = steamclient->CreateSteamPipe()))
		return false;

	if (!(g_hSteamUser = steamclient->ConnectToGlobalUser(g_hSteamPipe)))
		return false;

	if (!(steamuser = (ISteamUser017 *)steamclient->GetISteamUser(g_hSteamUser, g_hSteamPipe, STEAMUSER_INTERFACE_VERSION_017)))
		return false;

	if (!(clientaudio = (IClientAudio *)clientengine->GetIClientAudio(g_hSteamUser, g_hSteamPipe, CLIENTAUDIO_INTERFACE_VERSION)))
		return false;

	return true;
}
void SteamProxy_LoadGameOverlayRenderer()
{
	if (GetModuleHandle("gameoverlayrenderer.dll") != NULL)
	{
		return;
	}

	std::string gameOverlayRendererPath = loader.GetSteamDir() + "\\gameoverlayrenderer.dll";
	LoadLibrary(gameOverlayRendererPath.c_str());
}
bool SteamProxy_InitInternal()
{
	g_steamProxy.clientFactory = loader.Load();

	if (g_steamProxy.clientFactory == NULL)
	{
		return false;
	}

	g_steamProxy.steamClient = (ISteamClient008*)g_steamProxy.clientFactory(STEAMCLIENT_INTERFACE_VERSION_008, NULL);

	if (g_steamProxy.steamClient == NULL)
	{
		return false;
	}

	g_steamProxy.pipe = g_steamProxy.steamClient->CreateSteamPipe();

	if (g_steamProxy.pipe == NULL)
	{
		return false;
	}

	g_steamProxy.user = g_steamProxy.steamClient->ConnectToGlobalUser(g_steamProxy.pipe);

	if (g_steamProxy.user == NULL)
	{
		return false;
	}

	ISteamUtils005* steamUtils = (ISteamUtils005*)g_steamProxy.steamClient->GetISteamUtils(g_steamProxy.pipe, STEAMUTILS_INTERFACE_VERSION_005);
	int appID = steamUtils->GetAppID();

	if (appID == 0)
	{
		return false;
	}

	ISteamUser012* steamUser = (ISteamUser012*)g_steamProxy.steamClient->GetISteamUser(g_steamProxy.user, g_steamProxy.pipe, STEAMUSER_INTERFACE_VERSION_012);
	CSteamID steamID = steamUser->GetSteamID();

	NP_SetExternalSteamID(steamID.ConvertToUint64());

	return true;
}
Ejemplo n.º 4
0
int main(int argc, char** argv)
{
	if (argc > 1)
	{
		ipAndSuch = argv[1];

		if (argc > 2)
		{
			port = atoi(argv[2]);
		}
	}

	CSteamAPILoader* loader   = new CSteamAPILoader();
	CreateInterfaceFn factory = loader->Load();

	BGetCallback          = static_cast<Steam_BGetCallbackFn>    (loader->GetSteamClientModule()->GetSymbol("Steam_BGetCallback"));
	FreeLastCallback      = static_cast<Steam_FreeLastCallbackFn>(loader->GetSteamClientModule()->GetSymbol("Steam_FreeLastCallback"));
	IClientEngine *client = static_cast<IClientEngine *>         (factory(CLIENTENGINE_INTERFACE_VERSION, NULL));

	HSteamPipe pipe = client->CreateSteamPipe();
	HSteamUser user = client->ConnectToGlobalUser(pipe);

	IClientFriends *clientfriends = static_cast<IClientFriends*>(client->GetIClientFriends(user, pipe, CLIENTFRIENDS_INTERFACE_VERSION));
	IClientUser *clientuser       = static_cast<IClientUser*>   (client->GetIClientUser(user, pipe, CLIENTUSER_INTERFACE_VERSION));

	cout << "Now connected to steam and awaiting callbacks!" << endl;

	while(true)
	{
		CallbackMsg_t callBack;
		if (BGetCallback( pipe, &callBack ) )
		{
			switch (callBack.m_iCallback)
			{
			case ChatRoomMsg_t::k_iCallback:
			case 810: // Chat room callback
                {
				    ChatRoomMsg_t Info = *(ChatRoomMsg_t *)callBack.m_pubParam;

				    if (Info.m_ulSteamIDUser == clientuser->GetSteamID())
					    break;
				
				    CSteamID userID;
				    string userName = clientfriends->GetFriendPersonaName(Info.m_ulSteamIDUser);
				    EChatEntryType entry = k_EChatEntryTypeInvalid;

                    char* temp = new char[4096];
				    clientfriends->GetChatRoomEntry(Info.m_ulSteamIDChat, Info.m_iChatID, &userID, temp, 4096, &entry);
                    std::string message = temp;
                    delete[] temp;

				    if (entry != k_EChatEntryTypeChatMsg && entry != k_EChatEntryTypeEmote)
						    break;

				    cout << "[Group] " << userName << " said something!" << endl;
				
                    bool foundOny = (ci_find_substr<string>(message, "ony") != -1);

					if (!foundOny && entry == k_EChatEntryTypeChatMsg)
					{
						RunBotCommand(Info.m_ulSteamIDUser, Message_Tell, message, userName, Chat_Group);
					}
                    
                    if (!foundOny)
                        break;
				
				    string response = RunBotCommand(Info.m_ulSteamIDUser, Message_Interact, message, userName, Chat_Group);

				    if(response.length() == 0)
                    {
                        cout << " !!Bot didn't respond!!" << endl;
					    break;
                    }
                    else if (response.front() == '!')
                    {
                        cout << " !" << response << "!" << endl;
                        break;
                    }
                    
				    EChatEntryType toSend = k_EChatEntryTypeChatMsg;
				    if (response.front() == '*' && response.back() == '*')
				    {
					    toSend = k_EChatEntryTypeEmote;
					    response.erase(response.begin());
					    response.erase(response.end()-1);
				    }

				    clientfriends->SendChatMsg(Info.m_ulSteamIDChat, toSend, response.c_str(), response.length()+1);

				    break;
                }

		    case 805:
			case FriendChatMsg_t::k_iCallback:
                {
				    FriendChatMsg_t Info = *(FriendChatMsg_t *)callBack.m_pubParam;

				    if (Info.m_ulSender == clientuser->GetSteamID())
					    break;

				    EChatEntryType entry = k_EChatEntryTypeInvalid;

                    char* temp = new char[4096];
				    clientfriends->GetFriendMessage(Info.m_ulReceiver, Info.m_iChatID, temp, 4096, &entry);
                    std::string message = temp;
                    delete[] temp;

				    if (entry != k_EChatEntryTypeChatMsg)
					    break;

                    string userName = clientfriends->GetFriendPersonaName(Info.m_ulSender);

				    cout << "[Friend] " << userName << " said something!" << endl;

				    string response = RunBotCommand(Info.m_ulSender, Message_Interact, message, userName, Chat_Private);

                    if(response.length() == 0)
                    {
                        cout << " !!Bot didn't respond!!" << endl;
					    break;
                    }
                    else if (response.front() == '!')
                    {
                        cout << " !" << response << "!" << endl;
                        break;
                    }

				    clientfriends->SendMsgToFriend(Info.m_ulSender, k_EChatEntryTypeChatMsg, response.c_str(), response.length()+1);
				    break;
                }

			default:
                {
#ifdef _DEBUG
                    cout << "Uncaught callback " << callBack.m_iCallback << " (" << GetCallbackType(callBack.m_iCallback) << ")" << endl;
#endif
				    break;
                }
			}

			FreeLastCallback(pipe);
		}

		sf::Sleep(10);
	}

	return 0;
}