/********************************************************************************************************************** CConvertibleEnum::Register_Entry -- registers a string and integer value pair as convertible entry_name -- corresponding string value value -- integer to convert to/from **********************************************************************************************************************/ void CConvertibleEnum::Register_Entry( const std::string &entry_name, uint64 value ) { std::string upper_entry_name; NStringUtils::To_Upper_Case( entry_name, upper_entry_name ); auto name_iter = NameToValueTable.find( upper_entry_name ); FATAL_ASSERT( name_iter == NameToValueTable.end() ); auto value_iter = ValueToNameTable.find( value ); FATAL_ASSERT( value_iter == ValueToNameTable.end() ); NameToValueTable[ upper_entry_name ] = value; ValueToNameTable[ value ] = upper_entry_name; }
virtual void ProcessingMaterial(GLMmodel* model, KScene& scene, const stdext::hash_map<UINT32, UINT32>& nodeToMtl) { // Create material KMaterialLibrary* pML = KMaterialLibrary::GetInstance(); for (UINT32 mi = 0; mi < model->nummaterials; ++mi) { ISurfaceShader* pSurfShader = pML->CreateMaterial("simple_phong_default.template", model->materials[mi].name); pSurfShader->SetParam("diffuse_color", model->materials[mi].diffuse, sizeof(float)*3); if (model->materials[mi].shininess > 3.0f) { pSurfShader->SetParam("specular_color", model->materials[mi].specular, sizeof(float)*3); pSurfShader->SetParam("power", &model->materials[mi].shininess, sizeof(float)); } else { float specular[3] = {0,0,0}; float pow = 0; pSurfShader->SetParam("specular_color", specular, sizeof(float)*3); pSurfShader->SetParam("power", &pow, sizeof(float)); } pSurfShader->SetParam("opacity", model->materials[mi].transparency, sizeof(float)*3); if (mUseTexMap && model->materials[mi].diffuse_map) { pSurfShader->SetParam("diffuse_map", model->materials[mi].diffuse_map, 0); } } for (UINT32 i = 0; i < scene.GetNodeCnt(); ++i) { KNode* pNode = scene.GetNode(i); stdext::hash_map<UINT32, UINT32>::const_iterator it = nodeToMtl.find(i); assert(it != nodeToMtl.end()); pNode->mpSurfShader = pML->OpenMaterial(model->materials[it->second].name); } }
/********************************************************************************************************************** CConvertibleEnum::Convert_Internal -- internal function to convert from an integer value to a string value -- integer to convert from entry_name -- output parameter for the string value Returns: success/failure **********************************************************************************************************************/ bool CConvertibleEnum::Convert_Internal( uint64 value, std::string &entry_name ) const { auto iter = ValueToNameTable.find( value ); if ( iter == ValueToNameTable.end() ) { return false; } entry_name = iter->second; return true; }
/********************************************************************************************************************** CConvertibleEnum::Convert_Internal -- internal function to convert from a string to an integer value entry_name -- string value to convert from output_value -- output parameter for the integer to convert to Returns: success/failure **********************************************************************************************************************/ bool CConvertibleEnum::Convert_Internal( const std::string &entry_name, uint64 &output_value ) const { std::string upper_entry_name; NStringUtils::To_Upper_Case( entry_name, upper_entry_name ); auto iter = NameToValueTable.find( upper_entry_name ); if ( iter == NameToValueTable.end() ) { return false; } output_value = iter->second; return true; }
HRESULT __wrapper_FilterGetMessage( HANDLE hPort, PFILTER_MESSAGE_HEADER lpMessageBuffer, DWORD dwMessageBufferSize, LPOVERLAPPED lpOverlapped ) { Chess::SyncVarAccess(GetWin32SyncManager()->GetSyncVarFromHandle(hPorte), SVOP::FLT_RW); if(qsize.find(hPorte) == qsize.end()) qsize[hPorte] = 0; if(lpOverlapped != NULL){ HRESULT ret = Real_FilterGetMessage(hPort, lpMessageBuffer, dwMessageBufferSize, lpOverlapped); if(ret == ERROR_IO_PENDING) qsize[hPorte]++; return ret; } LPOVERLAPPED myOverlapped; OVERLAPPED tempOverlapped; memset(&tempOverlapped, 0, sizeof(OVERLAPPED)); myOverlapped = &tempOverlapped; myOverlapped->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); HRESULT ret = Real_FilterGetMessage(hPort, lpMessageBuffer, dwMessageBufferSize, myOverlapped); //if(ret != S_OK || ret != ERROR_IO_PENDING) // return ret; assert(ret != S_OK); qsize[hPorte]++; Chess::SyncVarAccess(GetWin32SyncManager()->GetSyncVarFromHandle(hPorte), SVOP::FLT_RW); while(true){ HRESULT retVal = WaitForSingleObject(myOverlapped->hEvent, 0); switch(retVal){ case WAIT_OBJECT_0 : CloseHandle(myOverlapped->hEvent); return S_OK; case WAIT_TIMEOUT : Chess::LocalBacktrack(); break; default: fprintf(stderr, "Waiting for event failed in Wrapper FilterGetMessage"); return retVal; } } assert(false); return S_OK; }
HRESULT __wrapper_FilterSendMessage( HANDLE hPort, LPVOID lpInBuffer, DWORD dwInBufferSize, LPVOID lpOutBuffer, DWORD dwOutBufferSize, LPDWORD lpBytesReturned ) { Chess::SyncVarAccess(GetWin32SyncManager()->GetSyncVarFromHandle(hPorte), SVOP::FLT_RW); if(qsize.find(hPorte) == qsize.end()) qsize[hPorte] = 0; while(qsize[hPorte] == 0){ Chess::LocalBacktrack(); } qsize[hPorte]--; return Real_FilterSendMessage(hPort, lpInBuffer, dwInBufferSize, lpOutBuffer, dwOutBufferSize, lpBytesReturned); }
static void push( lua_State* lua_state, const stdext::hash_map<Key, Data, Traits, Allocator>& value ) { lua_push( lua_state, value.begin(), value.end() ); }
DWORD _stdcall AIGetLastTarget(DWORD source) { iter itr=targets.find(source); if(itr==targets.end()) return 0; else return itr->second; }
DWORD _stdcall AIGetLastAttacker(DWORD target) { iter itr=sources.find(target); if(itr==sources.end()) return 0; else return itr->second; }
bool LoadDIASymbols(const wxString &strPDBFile, wxInt32 modulenum, std::list<CFunctionDescription> & llFuncs, stdext::hash_map<BasedAddress,int> & addressmap ) { // Create DIA80 Data Source Object IDiaDataSource *pDataSource; HRESULT hr = NoRegCoCreate( L"msdia80.dll", _uuidof( DiaSource ), _uuidof( IDiaDataSource ), (void **) &(pDataSource)); if(!SUCCEEDED(hr)) { return false; } /* HMODULE mod=LoadLibrary(L"msdia80.dll"); if(!mod) { return false; } TYPEOF_DllGetClassObject *pGetClassObject=(TYPEOF_DllGetClassObject *)GetProcAddress(mod,"DllGetClassObject"); if(!pGetClassObject) { FreeLibrary(mod); return false; } IClassFactory *pcf; HRESULT hr=(*pGetClassObject)(CLSID_DiaSource,IID_IClassFactory,(void **)&pcf); if(!SUCCEEDED(hr)) { FreeLibrary(mod); return false; } IDiaDataSource *pDataSource; hr=pcf->CreateInstance(NULL,_uuidof(IDiaDataSource),(void **)&pDataSource); if(!SUCCEEDED(hr)) { pcf->Release(); FreeLibrary(mod); return false; } pcf->Release(); */ // Load the executable's debug symbols hr=pDataSource->loadDataFromPdb(strPDBFile); if(!SUCCEEDED(hr)) { pDataSource->Release(); return false; } // Open a symbol session IDiaSession *pDIASession; hr=pDataSource->openSession(&pDIASession); if(!SUCCEEDED(hr)) { pDataSource->Release(); return false; } // Set the UNBASED address on the session, for resolving BasedAddress addrs hr=pDIASession->put_loadAddress(0); if(!SUCCEEDED(hr)) { pDIASession->Release(); pDataSource->Release(); return false; } // Get addresses for this module std::list<BasedAddress> addresses; for(stdext::hash_map<BasedAddress,int>::iterator iter=addressmap.begin();iter!=addressmap.end();iter++) { if(iter->first.nModule==modulenum) { addresses.push_back(iter->first); } } stdext::hash_map<DWORD,wxInt32> functions; int curidx=(int)llFuncs.size(); for(std::list<BasedAddress>::iterator itera=addresses.begin();itera!=addresses.end();itera++) { // Get the symbol for this thing IDiaSymbol* pFunc; if(FAILED(pDIASession->findSymbolByVA(itera->nAddr, SymTagFunction, &pFunc)) || pFunc==NULL) { continue; } // Get the unique symbol index id DWORD indexId; if(FAILED(pFunc->get_symIndexId(&indexId))) { pFunc->Release(); continue; } // See if we have this function already stdext::hash_map<DWORD,int>::iterator iterf=functions.find(indexId); if(iterf!=functions.end()) { addressmap[*itera]=iterf->second; } else { CFunctionDescription func; ////// ULONGLONG addr; if(FAILED(pFunc->get_virtualAddress(&addr))) { pFunc->Release(); continue; } ////// ULONGLONG length; if(FAILED(pFunc->get_length(&length))) { pFunc->Release(); continue; } ///////// BSTR pName; if(FAILED(pFunc->get_name(&pName))) { pFunc->Release(); continue; } func.strMangledName=(const LPWSTR)pName; LocalFree(pName); char mangled[512]; WideCharToMultiByte(CP_UTF8,0,func.strMangledName,-1,mangled,512,NULL,NULL); ///////// char outbase[512]; __unDName(outbase,mangled,512,&malloc,&free,0x1000); wchar_t outbasew[512]; MultiByteToWideChar(CP_UTF8,0,outbase,-1,outbasew,512); func.strBaseName=(const wchar_t *)(outbasew); ///////// char outfull[512]; __unDName(outfull,mangled,512,&malloc,&free,0); wchar_t outfullw[512]; MultiByteToWideChar(CP_UTF8,0,outfull,-1,outfullw,512); func.strFullName=(const wchar_t *)(outfullw); ////////// func.nAddress=BasedAddress(addr,modulenum); func.nByteLength=length; ///////// IDiaEnumLineNumbers *pdeln; func.strSourceFile=wxT("<unknown>"); func.nFirstSourceLine=0; func.nLastSourceLine=0; bool bGotFile=false; if(SUCCEEDED(pDIASession->findLinesByVA(addr,length,&pdeln))) { IDiaLineNumber *pdln; int nLineItem=0; while(SUCCEEDED(pdeln->Item(nLineItem,&pdln))) { DWORD dwLineNumber; IDiaSourceFile *pdsf; if(SUCCEEDED(pdln->get_lineNumber(&dwLineNumber)) && SUCCEEDED(pdln->get_sourceFile(&pdsf))) { BSTR filename; if(SUCCEEDED(pdsf->get_fileName(&filename))) { if(bGotFile) { if(filename==func.strSourceFile) { if(dwLineNumber<func.nFirstSourceLine) { func.nFirstSourceLine=dwLineNumber; } if(dwLineNumber>func.nLastSourceLine) { func.nLastSourceLine=dwLineNumber; } } } else { bGotFile=true; func.strSourceFile=filename; func.nFirstSourceLine=dwLineNumber; func.nLastSourceLine=dwLineNumber; } LocalFree(filename); } pdsf->Release(); } pdln->Release(); nLineItem++; } pdeln->Release(); } llFuncs.push_back(func); functions[indexId]=curidx; addressmap[*itera]=curidx; curidx++; } } pDIASession->Release(); pDataSource->Release(); // FreeLibrary(mod); return true; }