string_view path::__parent_path() const { if (empty() || pbegin(*this) == --pend(*this)) { return {}; } auto end_it = --(--pend(*this)); auto end_i = parser::end_of(__pn_, end_it.__pos_); return string_view(__pn_).substr(0, end_i+1); }
void draw_frame(void) { // obtain the lock so no other thread can interrupt us pend(draw_lock); clear_screen(); goto_line(0,0); set_color_bold(FG_BLACK); set_color_bold(BG_WHITE); int x, y; for (y = 0; y < FRAME_HEIGHT; y++) { for (x = 0; x < FRAME_WIDTH; x++) { switch (frame[y][x]) { case '-': printf("\u2500"); break; case '|': printf("\u2502"); break; case ' ': printf(" "); break; default: printf("%s", pipes[frame[y][x]-'0']); } } printf("\n"); } reset_color(); hide_cursor(); // we're done, release the lock post(draw_lock); }
void draw_keymap(void) { // obtain the lock so no other thread can interrupt us pend(draw_lock); // figure out which x y to draw it at int x = keymap_loc[1]; int y = keymap_loc[0]; // draw the keymapping set_color(FG_BLACK); set_color_bold(BG_WHITE); goto_line(x, y+0); printf("[c] - Car in turn lane"); goto_line(x, y+1); printf("[w] - Press walk button"); goto_line(x, y+2); printf("[b] - Toggle broken"); goto_line(x, y+3); printf("[e] - Emergency for %d seconds", emergency_duration); goto_line(x, y+4); printf(" [-/+] - Inc/Dec"); goto_line(x, y+5); printf("[m] - Toggle manual"); goto_line(x, y+6); printf(" [j/k] - Next/Prev light"); goto_line(x, y+7); printf(" [1/2/3] - Red/Yellow/Green"); goto_line(x, y+8); printf("[r] - Redraw"); reset_color(); hide_cursor(); // we're done, release the lock post(draw_lock); }
void draw_car(char yes) { // obtain the lock so no other thread can interrupt us pend(draw_lock); // reset the colors reset_color(); // if we are drawing a car make it cyan if (yes) set_color_bold(BG_CYAN); // draw car 0 goto_line(street_loc[1]+car_loc[0][1]-1, street_loc[1]+car_loc[0][0]-1); printf(" "); // draw car 1 goto_line(street_loc[1]+car_loc[1][1]-1, street_loc[1]+car_loc[1][0]-1); printf(" "); reset_color(); hide_cursor(); // we're done, release the lock post(draw_lock); }
void DNASequence::NotifyAfter(SequencePosIterator begin, SequencePosIterator end, NotifyFunction after) { if(after) { SequencePosIterator nowBegin = begin; while(nowBegin != end) { SequencePosIterator nowEnd = nowBegin; for(; nowEnd != end && nowEnd->actual != SEPARATION_CHAR; ++nowEnd); StrandIterator pbegin(nowBegin, positive); StrandIterator pend(nowEnd, positive); after(pbegin, pend); after(pend.Invert(), pbegin.Invert()); nowBegin = nowEnd != end ? ++nowEnd : nowEnd; } } size_t pos = 0; std::vector<boost::reference_wrapper<SequencePosIterator> > resubscribe; for(; begin != end; ++begin, ++pos) { if(toReplace_[pos] != iteratorStore_.end()) { IteratorPlace it = toReplace_[pos]; **it = begin; resubscribe.push_back(boost::ref(**it)); it = iteratorStore_.erase(it); } } toReplace_.clear(); assert(posEnd_.back() == --sequence_.end()); std::for_each(resubscribe.begin(), resubscribe.end(), boost::bind(&DNASequence::SubscribeIterator, boost::ref(*this), _1)); }
void test_matches(const std::string& proto_key, const LLSD& possibles, const char** begin, const char** end) { std::set<std::string> succeed(begin, end); LLSD prototype(possibles[proto_key]); for (LLSD::map_const_iterator pi(possibles.beginMap()), pend(possibles.endMap()); pi != pend; ++pi) { std::string match(llsd_matches(prototype, pi->second)); std::set<std::string>::const_iterator found = succeed.find(pi->first); if (found != succeed.end()) { // This test is supposed to succeed. Comparing to the // empty string ensures that if the test fails, it will // display the string received so we can tell what failed. ensure_equals("match", match, ""); } else { // This test is supposed to fail. If we get a false match, // the string 'match' will be empty, which doesn't tell us // much about which case went awry. So construct a more // detailed description string. ensure(proto_key + " shouldn't match " + pi->first, ! match.empty()); } } }
int main() { std::ifstream ifs("../data/book.txt"); StrBlob blob; for (std::string str; std::getline(ifs, str); ) blob.push_back(str); for (StrBlobPtr pbeg(blob.begin()), pend(blob.end()); pbeg != pend; pbeg.incr()) std::cout << pbeg.deref() << std::endl; }
void BaskerMatrix<Int,Entry,Exe_Space>::clear_pend() { if(ncol > 0) { for(Int i = 0 ; i < ncol+1; ++i) { pend(i) = BASKER_MAX_IDX; } } }// end clear_pend()
void BaskerMatrix<Int,Entry,Exe_Space>::init_pend() { if(ncol > 0) { BASKER_ASSERT((ncol+1)>0, "matrix init_pend") MALLOC_INT_1DARRAY(pend,ncol+1); for(Int i =0; i < ncol+1; ++i) { pend(i) = BASKER_MAX_IDX; } } }//end init_pend()
void SdlGuiGraphics::drawLine(int32_t x1, int32_t y1, int32_t x2, int32_t y2) { const fcn::ClipRectangle& top = mClipStack.top(); x1 += top.xOffset; x2 += top.xOffset; y1 += top.yOffset; y2 += top.yOffset; Point pbegin(x1, y1); Point pend(x2, y2); m_renderbackend->drawLine(pbegin, pend, mColor.r, mColor.g, mColor.b, mColor.a); m_renderbackend->putPixel(pbegin.x, pbegin.y, mColor.r, mColor.g, mColor.b, mColor.a); m_renderbackend->putPixel(pend.x, pend.y, mColor.r, mColor.g, mColor.b, mColor.a); }
void OpenGLGuiGraphics::drawLine(int32_t x1, int32_t y1, int32_t x2, int32_t y2) { const fcn::ClipRectangle& top = mClipStack.top(); x1 += top.xOffset; x2 += top.xOffset; y1 += top.yOffset; y2 += top.yOffset; Point pbegin(static_cast<int32_t>(ceil(x1 + 0.375f)), static_cast<int32_t>(ceil(y1 + 0.375f))); Point pend(static_cast<int32_t>(ceil(x2 + 0.625f)), static_cast<int32_t>(ceil(y2 + 0.625f))); m_renderbackend->drawLine(pbegin, pend, mColor.r, mColor.g, mColor.b, mColor.a); m_renderbackend->putPixel(pbegin.x, pbegin.y, mColor.r, mColor.g, mColor.b, mColor.a); m_renderbackend->putPixel(pend.x, pend.y, mColor.r, mColor.g, mColor.b, mColor.a); }
void draw_street(void) { // obtain the lock so no other thread can interrupt us pend(draw_lock); set_color_bold(FG_WHITE); int x, y; for (y = 0; y < HEIGHT; y++) { goto_line(street_loc[1], street_loc[0]+y); for (x = 0; x < WIDTH; x++) { switch (diagram[y][x]) { // http://www.utf8-chartable.de/unicode-utf8-table.pl // lane markers case '=': set_color_dim(FG_YELLOW); printf("\u2550"); break; case ',': set_color_dim(FG_YELLOW); printf("\u2551"); break; case '-': set_color_bold(FG_WHITE); printf("\u2500"); break; case '|': set_color_bold(FG_WHITE); printf("\u2502"); break; case 'v': set_color_bold(FG_WHITE); printf("\u2518"); break; case 'r': set_color_bold(FG_WHITE); printf("\u250C"); break; case 'n': set_color_bold(FG_WHITE); printf("\u2510"); break; case 'l': set_color_bold(FG_WHITE); printf("\u2514"); break; // cross walks case 'h': printf(" "); break; case 'c': printf("C"); break; default: printf("%c", diagram[y][x]); } } } reset_color(); hide_cursor(); // we're done, release the lock post(draw_lock); }
void draw_status(int y, const char *msg) { // obtain the lock so no other thread can interrupt us pend(draw_lock); set_color(FG_BLACK); set_color_bold(BG_WHITE); goto_line(status_loc[1], status_loc[0]+y); printf(" "); goto_line(status_loc[1], status_loc[0]+y); printf(msg); reset_color(); hide_cursor(); // we're done, release the lock post(draw_lock); }
void draw_walk(int state) { // obtain the lock so no other thread can interrupt us pend(draw_lock); int i; for (i = 0; i < 4; i++) { goto_line(street_loc[1] + walk_loc[i][1] - 1, street_loc[0] + walk_loc[i][0] - 1); set_light_color(state); printf("C"); } reset_color(); hide_cursor(); // we're done, release the lock post(draw_lock); }
void DNASequence::NotifyBefore(SequencePosIterator begin, SequencePosIterator end, NotifyFunction before) { if(before) { SequencePosIterator nowBegin = begin; while(nowBegin != end) { SequencePosIterator nowEnd = nowBegin; for(; nowEnd != end && nowEnd->actual != SEPARATION_CHAR; ++nowEnd); StrandIterator pbegin(nowBegin, positive); StrandIterator pend(nowEnd, positive); before(pbegin, pend); before(pend.Invert(), pbegin.Invert()); nowBegin = nowEnd != end ? ++nowEnd : nowEnd; } } for(; begin != end; ++begin) { toReplace_.push_back(iteratorStore_.find(&begin)); } }
void draw_lights(void) { // obtain the lock so no other thread can interrupt us pend(draw_lock); char light_arrows[6][6] = { "\u2193", // down "\u2191", // up "\u2192", // right "\u2191", // up "\u2193", // down "\u2190" // left }; int i = 0; for (i = 0; i < 6; i++) { // goto light x,y goto_line(street_loc[1]+light_loc[i][1]-1, street_loc[0]+light_loc[i][0]-1); if (manual_mode && i == selected_light) set_color_bold(BG_BLUE); // set it to proper color set_light_color(lights[i]); // draw the arrow for this light printf(light_arrows[i]); reset_color(); } reset_color(); hide_cursor(); // we're done, release the lock post(draw_lock); }
void FFTPlot::refreshPixmap() { pixmap = QPixmap(size()); pixmap.fill(); qDebug() << "refresh"; int borderx = 40, bordery = 20, padding = 10, ticksize = 5; QPainter painter(&pixmap); QPen penWave, penGrid, penBorder; // painter.setRenderHint(QPainter::Antialiasing, true); penGrid.setStyle(Qt::DashLine); penGrid.setWidth(1); penGrid.setColor(QColor(150, 150, 150)); penBorder.setStyle(Qt::SolidLine); penBorder.setWidth(1); penBorder.setColor(QColor(150, 150, 150)); int ww = width(), wh = height(); qreal minfl = (qreal) log10((double) minfreq), maxfl = (qreal) log10((double) maxfreq); qreal minampll = (qreal) log10((double)minampl), maxampll = (qreal) log10((double)maxampl); qreal minampldB = minampll * 20, maxampldB = maxampll * 20; qreal sx = (qreal)(ww - borderx - 2*padding) / (maxfl - minfl), sy = (qreal)(wh - bordery - 2*padding) / (maxampldB - minampldB); for (int fl = qFloor(minfl); fl < qCeil(maxfl); fl++) { qreal x = padding + borderx + sx*(qreal)(log10((double)qPow(10, fl)) - minfl); QString str = QString("%1 Hz").arg(qPow(10, fl)); painter.drawText((int)x, wh-padding, str); } for (int al = qFloor(minampll); al < qCeil(maxampll); al++) { qreal y = wh - padding - bordery - (sy*20*(qreal)(log10(qPow(10, al)) - minampll)); QString str = QString("%1 dB").arg(-20-20*al); painter.drawText((int)padding, y+10, str); } painter.setPen(penBorder); painter.drawLine(borderx+padding, padding, ww-padding, padding); painter.drawLine(ww-padding, padding, ww-padding, wh-bordery-padding); painter.drawLine(borderx+padding, wh-bordery-padding, ww-padding, wh-bordery-padding); for (int fl = qFloor(minfl); fl < qCeil(maxfl); fl++) { qreal x = padding+borderx+sx*(qreal)(log10((double)qPow(10, fl)) - minfl); painter.drawLine((int)x, padding, (int)x, wh-bordery-padding+ticksize); } for (int al = qFloor(minampll); al < qCeil(maxampll); al++) { qreal y = wh-padding-bordery-(sy*20*(qreal)(log10(qPow(10, al)) - minampll)); painter.drawLine((int)borderx+padding-ticksize, y, (int)ww-padding, y); } painter.setClipRect(borderx+padding, padding, ww-borderx-padding*2, wh-bordery-padding*2); painter.setClipping(true); painter.setPen(penGrid); for (int fl = qFloor(minfl); fl < qCeil(maxfl); fl++) { for (int df = 1; df < 10; df++) { qreal x = borderx + padding + sx*(qreal)(log10((double)qPow(10, fl)*df) - minfl); painter.drawLine((int)x, padding, (int)x, wh-bordery-padding); } } for (int al = qFloor(minampll); al < qCeil(maxampll); al++) { for (int da = 1; da < 10; da++) { qreal y = wh - bordery - padding - (sy*20*(qreal)(log10(qPow(10, al)*da) - minampll)); painter.drawLine(borderx+padding, y, ww-padding, y); } } for (unsigned int ind_plot = 0; ind_plot < numPlots; ind_plot++) { qreal * fftampl = fftAmpls[ind_plot]; painter.setPen(fftPens[ind_plot]); if (fftSizes[ind_plot] != 0 && fftampl != 0) { for (unsigned int ind = 1; ind < fftSizes[ind_plot]/2; ind++) { qreal prevampl, ampl; prevampl = wh-padding-bordery - (sy*20*(qreal)(log10((double)fftampl[ind-1]) - minampll)); ampl = wh-padding-bordery - (sy*20*(qreal)(log10((double)fftampl[ind] ) - minampll)); qreal x = padding+borderx+(sx)*(qreal)(log10( ((double)ind)/periodLength) - minfl), prevx = padding+borderx+(sx)*(qreal)(log10( ((double)(ind-1))/periodLength) - minfl); QPointF pstart(prevx, prevampl), pend(x, ampl); // Prevent infinitely long line to -infinity if (ind == 1) { prevx = padding+borderx; } if (x > padding && prevx > padding) painter.drawLine(pstart, pend); // else { // qDebug() << ind_plot << ind << prevx << prevampl << x << ampl // << fftampl[ind - 1] << fftampl[ind]; // } // if (ind_plot == 2 && ind == 1) { // pstart.setX(pstart.x() - padding); // pend.setX(pend.x() - padding); // painter.drawLine(pstart, pend); // } } } } update(); }
/****************************************************************************** * Get triangles for rendering *****************************************************************************/ void ParticleTracer::getTriangles(double time, vector<ntlTriangle> *triangles, vector<ntlVec3Gfx> *vertices, vector<ntlVec3Gfx> *normals, int objectId ) { #ifdef ELBEEM_PLUGIN // suppress warnings... vertices = NULL; triangles = NULL; normals = NULL; objectId = 0; time = 0.; #else // ELBEEM_PLUGIN int pcnt = 0; // currently not used in blender objectId = 0; // remove, deprecated if(mDumpParts>1) { return; // only dump, no tri-gen } const bool debugParts = false; int tris = 0; int segments = mPartSegments; ntlVec3Gfx scale = ntlVec3Gfx( (mEnd[0]-mStart[0])/(mSimEnd[0]-mSimStart[0]), (mEnd[1]-mStart[1])/(mSimEnd[1]-mSimStart[1]), (mEnd[2]-mStart[2])/(mSimEnd[2]-mSimStart[2])); ntlVec3Gfx trans = mStart; time = 0.; // doesnt matter for(size_t t=0; t<mPrevs.size()+1; t++) { vector<ParticleObject> *dparts; if(t==0) { dparts = &mParts; } else { dparts = &mPrevs[t-1]; } //errMsg("TRAILT","prevs"<<t<<"/"<<mPrevs.size()<<" parts:"<<dparts->size() ); gfxReal partscale = mPartScale; if(t>1) { partscale *= (gfxReal)(mPrevs.size()+1-t) / (gfxReal)(mPrevs.size()+1); } gfxReal partNormSize = 0.01 * partscale; //for(size_t i=0; i<mParts.size(); i++) { for(size_t i=0; i<dparts->size(); i++) { ParticleObject *p = &( (*dparts)[i] ); // mParts[i]; if(mShowOnly!=10) { // 10=show only deleted if( p->getActive()==false ) continue; } else { if( p->getActive()==true ) continue; } int type = p->getType(); if(mShowOnly>0) { switch(mShowOnly) { case 1: if(!(type&PART_BUBBLE)) continue; break; case 2: if(!(type&PART_DROP)) continue; break; case 3: if(!(type&PART_INTER)) continue; break; case 4: if(!(type&PART_FLOAT)) continue; break; case 5: if(!(type&PART_TRACER)) continue; break; } } else { // by default dont display inter if(type&PART_INTER) continue; } pcnt++; ntlVec3Gfx pnew = p->getPos(); if(type&PART_FLOAT) { // WARNING same handling for dump! if(p->getStatus()&PART_IN) { pnew[2] += 0.8; } // offset for display // add one gridcell offset //pnew[2] += 1.0; } #if LBMDIM==2 pnew[2] += 0.001; // DEBUG pnew[2] += 0.009; // DEBUG #endif ntlVec3Gfx pdir = p->getVel(); gfxReal plen = normalize( pdir ); if( plen < 1e-05) pdir = ntlVec3Gfx(-1.0 ,0.0 ,0.0); ntlVec3Gfx pos = (*mpTrafo) * pnew; gfxReal partsize = 0.0; if(debugParts) errMsg("DebugParts"," i"<<i<<" new"<<pnew<<" vel"<<pdir<<" pos="<<pos ); //if(i==0 &&(debugParts)) errMsg("DebugParts"," i"<<i<<" new"<<pnew[0]<<" pos="<<pos[0]<<" scale="<<scale[0]<<" t="<<trans[0] ); // value length scaling? if(mValueScale==1) { partsize = partscale * plen; } else if(mValueScale==2) { // cut off scaling if(plen > mValueCutoffTop) continue; if(plen < mValueCutoffBottom) continue; partsize = partscale * plen; } else { partsize = partscale; // no length scaling } //if(type&(PART_DROP|PART_BUBBLE)) partsize *= p->getSize()/5.0; ntlVec3Gfx pstart( mPartHeadDist *partsize, 0.0, 0.0 ); ntlVec3Gfx pend ( mPartTailDist *partsize, 0.0, 0.0 ); gfxReal phi = 0.0; gfxReal phiD = 2.0*M_PI / (gfxReal)segments; ntlMat4Gfx cvmat; cvmat.initId(); pdir *= -1.0; ntlVec3Gfx cv1 = pdir; ntlVec3Gfx cv2 = ntlVec3Gfx(pdir[1], -pdir[0], 0.0); ntlVec3Gfx cv3 = cross( cv1, cv2); //? for(int l=0; l<3; l++) { cvmat.value[l][0] = cv1[l]; cvmat.value[l][1] = cv2[l]; cvmat.value[l][2] = cv3[l]; } pstart = (cvmat * pstart); pend = (cvmat * pend); for(int s=0; s<segments; s++) { ntlVec3Gfx p1( 0.0 ); ntlVec3Gfx p2( 0.0 ); gfxReal radscale = partNormSize; radscale = (partsize+partNormSize)*0.5; p1[1] += cos(phi) * radscale; p1[2] += sin(phi) * radscale; p2[1] += cos(phi + phiD) * radscale; p2[2] += sin(phi + phiD) * radscale; ntlVec3Gfx n1 = ntlVec3Gfx( 0.0, cos(phi), sin(phi) ); ntlVec3Gfx n2 = ntlVec3Gfx( 0.0, cos(phi + phiD), sin(phi + phiD) ); ntlVec3Gfx ns = n1*0.5 + n2*0.5; p1 = (cvmat * p1); p2 = (cvmat * p2); sceneAddTriangle( pos+pstart, pos+p1, pos+p2, ns,n1,n2, ntlVec3Gfx(0.0), 1, triangles,vertices,normals ); sceneAddTriangle( pos+pend , pos+p2, pos+p1, ns,n2,n1, ntlVec3Gfx(0.0), 1, triangles,vertices,normals ); phi += phiD; tris += 2; } } } // t debMsgStd("ParticleTracer::getTriangles",DM_MSG,"Dumped "<<pcnt<<"/"<<mParts.size()<<" parts, tris:"<<tris<<", showonly:"<<mShowOnly,10); return; // DEBUG #endif // ELBEEM_PLUGIN }
int main() { char mem[4+1]; if(pend(mem).p != mem+4) abort (); }
string_view path::__filename() const { return empty() ? string_view{} : *--pend(*this); }
void QueryCvarProvider::InitCookie() { if (m_engine_cvar_cookie) return; DebugMessage("Trying to get g_iQueryCvarCookie ..."); basic_string modulename("engine"); #ifdef GNUC if (SourceSdk::InterfacesProxy::m_game != SourceSdk::CounterStrikeGlobalOffensive) { modulename.append("_srv"); } #endif #ifdef WIN32 modulename.append(".dll"); HMODULE engine_module_handle(GetModuleHandleA(modulename.c_str())); mem_byte * pstart(nullptr); mem_byte * pend(nullptr); if (engine_module_handle != NULL) { MODULEINFO modinfo; K32GetModuleInformation(GetCurrentProcess(), engine_module_handle, &modinfo, sizeof(MODULEINFO)); pstart = (mem_byte*)modinfo.lpBaseOfDll; pend = pstart + 0x44A400; mem_byte *sig_code(nullptr); mem_byte * sig_mask(nullptr); size_t sig_size(0); size_t sig_off(0); if (SourceSdk::InterfacesProxy::m_game == SourceSdk::CounterStrikeGlobalOffensive) { sig_code = new mem_byte[156] { 0x55, 0x8B, 0xEC, 0x83, 0xE4, 0xF8, 0x83, 0xEC, 0x3C, 0x56, 0x8B, 0x75, 0x08, 0x2B, 0x35, 0xD4, 0x12, 0x7B, 0x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xFE, 0xFF, 0xFF, 0x89, 0x85, 0xFC, 0xFE, 0xFF, 0xFF, 0x75, 0x08, 0xF7, 0xD9, 0x89, 0x8D, 0xF8, 0xFE, 0xFF, 0xFF, 0x8B, 0x4D, 0x08, 0x8D, 0x95, 0xE8, 0xFE, 0xFF, 0xFF, 0x6A, 0x00, 0x52, 0x8B, 0x01, 0xFF, 0x50, 0x74, 0x8B, 0x85, 0xF8, 0xFE, 0xFF, 0xFF, 0x8B, 0xE5, 0x5D, 0xC3 }; sig_mask = new mem_byte[105] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, //T 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, //T 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; sig_off = 0xA; sig_size = 105; } sig_ctx ctx(sig_code, sig_mask, sig_size, sig_off); #else modulename.append(".so"); basic_string relpath(Helpers::format("./bin/%s", modulename.c_str())); void ** modinfo = (void **)dlopen(relpath.c_str(), RTLD_NOW | RTLD_NOLOAD); void * engine_module_handle = nullptr; if (modinfo != NULL) { //mm_module_handle = dlsym(modinfo, ".init_proc"); // FIXME : Use link_map to get memory bounds of the module engine_module_handle = *modinfo; dlclose(modinfo); } if (engine_module_handle) { mem_byte * pstart = (mem_byte*)engine_module_handle; mem_byte * pend = pstart + 0x44A400; mem_byte *sig_code(nullptr); mem_byte * sig_mask(nullptr); size_t sig_size(0); size_t sig_off(0); if (SourceSdk::InterfacesProxy::m_game == SourceSdk::CounterStrikeGlobalOffensive) { sig_code = new mem_byte[234] { 0x55, 0x89, 0xE5, 0x57, 0x56, 0x8D, 0x75, 0xC4, 0x53, 0x83, 0xEC, 0x5C, 0xC7, 0x45, 0xC0, 0x68, 0x8A, 0x54, 0x00, 0x0F, 0xB6, 0x45, 0x10, 0x89, 0x34, 0x24, 0x8B, 0x7D, 0x0C, 0x88, 0x45, 0xB7, 0xE8, 0x0B, 0x4B, 0xF6, 0xFF, 0x8B, 0x15, 0x38, //T 0xD5, 0x72, 0x00, 0xC6, //T 0x45, 0xDC, 0x01, 0x8B, 0x5D, 0xCC, 0xC7, 0x45, 0xC0, 0x88, 0x91, 0x54, 0x00, 0xC7, 0x45, 0xC4, 0xCC, 0x91, 0x54, 0x00, 0xC7, 0x45, 0xE0, 0x9C, 0x4C, 0x7E, 0x00, 0x8D, 0x42, 0x01, 0x89, 0x55, 0xD0, 0xA3, 0x38, 0xD5, 0x72, 0x00, 0x8B, 0x45, 0xD8, 0x83, 0xC8, 0x03, 0x81, 0xFB, 0x00, 0x47, 0x7E, 0x00, 0x89, 0x45, 0xD8, 0x0F, 0x84, 0x89, 0x00, 0x00, 0x00, 0x89, 0x3C, 0x24, 0xE8, 0x75, 0xC9, 0x62, 0x00, 0x89, 0x1C, 0x24, 0x8D, 0x5D, 0xC0, 0x89, 0x44, 0x24, 0x08, 0x89, 0x7C, 0x24, 0x04, 0xE8, 0x42, 0x39, 0x36, 0x00, 0x80, 0x7D, 0xB7, 0x00, 0x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 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, }; sig_off = 0xA; sig_size = 116; } sig_ctx ctx(sig_code, sig_mask, sig_size, sig_off); #endif ScanMemoryRegion(pstart, pend, &ctx); if (ctx.m_out != nullptr) { m_engine_cvar_cookie = reinterpret_cast<SourceSdk::QueryCvarCookie_t *>(*(reinterpret_cast<size_t**>(ctx.m_out))); if (m_engine_cvar_cookie != nullptr) { DebugMessage(Helpers::format("g_iQueryCvarCookie = %d", *m_engine_cvar_cookie)); } else { g_Logger.Msg<MSG_ERROR>("Failed to get g_iQueryCvarCookie."); } } else { g_Logger.Msg<MSG_ERROR>("Sigscan failed for g_iQueryCvarCookie."); } if (sig_mask) delete[] sig_mask; if (sig_code) delete[] sig_code; } else { DebugMessage("engine module not found."); } } void QueryCvarProvider::FixQueryCvarCookie() { if (m_engine_cvar_cookie) { if (*m_engine_cvar_cookie < 1 || *m_engine_cvar_cookie == std::numeric_limits<SourceSdk::QueryCvarCookie_t>::max()) { *m_engine_cvar_cookie = 1; } } } SourceSdk::QueryCvarCookie_t QueryCvarProvider::StartQueryCvarValue(SourceSdk::edict_t * pEntity, const char * pName) { FixQueryCvarCookie(); return SourceSdk::InterfacesProxy::GetServerPluginHelpers()->StartQueryCvarValue(pEntity, pName); }
situation environment::analyze(const gns::point& robot_pose, const gns::point& goal_pose, const std::vector<gns::point>& points) const { if (points.empty()) return FREE; close_to ct(robot_pose, m_security_distance); bool too_close = std::count_if(points.begin(), points.end(), ct) > 0; std::vector<gns::point> hpoints = points; gns::vector vgoal = goal_pose - robot_pose; gns::frame wXh(robot_pose.x, robot_pose.y, vgoal.angle()); gns::frame hXw = ~wXh; //histogram points for (size_t i = 0; i < hpoints.size(); i++) hpoints[i] = hXw * points[i]; //compute histogram size double max = 0.0; double min = 0.0; for (std::vector<gns::point>::iterator p = hpoints.begin(); p != hpoints.end(); p++) { if (p->y < min) min = p->y; if (p->y > max) max = p->y; } const int SIZE = int(ceil((max - min) / m_scale)); gns::point hgoal = hXw * goal_pose; const int goalsector(int(round((hgoal.y - min) / m_scale))); //creating histogram std::vector<double> histogram(SIZE); std::fill(histogram.begin(), histogram.end(), -1); for (std::vector<gns::point>::iterator p = hpoints.begin(); p != hpoints.end(); p++) { int sector(int(floor((p->y - min) / m_scale))); if (p->x > 0 and p->x < hgoal.x and (histogram[sector] < 0 or p->x < histogram[sector])) //update the closest obstacle in the sector if it is closer than the goal histogram[sector] = p->x; } //fill small free spaces { int start = int(histogram.size()); int end = int(histogram.size()); for (int i = 0; i < int(histogram.size()); i++) { if (histogram[i] < 0 and start > i) //new free space start = i; //set start else if (histogram[i] > 0 and start < i) { //free space ended end = i; //set end if (start > 0) { gns::point pstart((start - 1) * m_scale, histogram[start - 1]), pend(end * m_scale, histogram[end]); if ((end - (start - 1)) * m_scale < m_width) { //is small //interpolate double a = (histogram[start - 1] - histogram[end]) / (start - 1 - end); double b = histogram[start - 1] - a * (start - 1); for (int j = start; j < end; j++) histogram[j] = a * j + b; } } start = int(histogram.size()); //unset start } } } //all freespaces in histogram are big enough for the robot to navigate if (histogram[goalsector] < 0) { //goalsector is in a free space int inicio = goalsector; while (inicio >= 0 and histogram[inicio] < 0) --inicio; if (inicio < 0) inicio = 0; else ++inicio; int fin(goalsector + 1); while (fin < SIZE and histogram[fin] < 0) ++fin; if (fin >= SIZE) fin = SIZE; if (fabs((goalsector - inicio) * m_scale) > m_security_distance and fabs((fin - goalsector) * m_scale) > m_security_distance and not too_close) { //there is enough free space to go through with no care return FREE; } else return AVOIDANCE; } //the goal is behind an obstacle { //compute starting point of the obstacle int inicio = goalsector; while (true) { if (inicio < 0) { inicio = 0; break; } //inicio >= 0 if (histogram[inicio] < 0) { inicio++; break; } //inicio >= 0 and histogram[inicio] >= 0 if (inicio == 0) { break; } //inicio > 0 and histogram[inicio] >= 0 if (histogram[inicio - 1] < 0) { break; } inicio--; } //compute end point of the obstacle int fin(goalsector + 1); while (true) { if (fin >= SIZE) { fin = SIZE; break; } //fin < SIZE if (histogram[fin] < 0) { break; } fin++; } //compute maxima and minima in the obstacle std::vector<int> maximun, minimun; { //all local maxima and minima candidates enum state { inc, dec, eq }; state s = eq; for (int i = inicio; i < fin - 1; i++) { double input = histogram[i + 1] - histogram[i]; if (input > 0) { if (s == dec) minimun.push_back(i); s = inc; } else if (input < 0) { if (s == inc) maximun.push_back(i); s = dec; } } //filter small neightbourhood and depth std::vector<int> tmp = maximun; maximun.clear(); for (std::vector<int>::iterator i = tmp.begin(); i != tmp.end(); i++) { //compute neighbourhood int n = 1; while (true) { if (*i - n < inicio) { n = *i - inicio; break; } if (*i + n >= fin) { n = fin - *i - 1; break; } if (histogram[*i - n] > histogram[*i] or histogram[*i + n] > histogram[*i]) { n--; break; } n++; } double depth = histogram[*i] - 0.5 * (histogram[*i - n] + histogram[*i + n - 1]); if (n * m_scale > m_width and depth > m_length) maximun.push_back(*i); } tmp = minimun; minimun.clear(); for (std::vector<int>::iterator i = tmp.begin(); i != tmp.end(); i++) { //compute neighbourhood int n = 1; while (true) { if (*i - n < inicio) { n = *i - inicio; break; } if (*i + n >= fin) { n = fin - *i - 1; break; } if (histogram[*i - n] < histogram[*i] or histogram[*i + n] < histogram[*i]) { n--; break; } n++; } if (n * m_scale > m_width) minimun.push_back(*i); } } if (not maximun.empty()) return TRAP; else return AVOIDANCE; } }