Ejemplo n.º 1
0
ReplayViewer::ReplayViewer(const QString &file) : finished(false), paused(false), speeding(false), timerDiff(0), nextRead(quint32(-1))
{
    in = new QFile(file);

    if (!in->open(QFile::ReadOnly)) {
        QMessageBox::critical(nullptr, tr("Error when opening replay file"), tr("The replay file couldn't be opened: %1").arg(file));
        deleteLater();
        return;
    }

    QByteArray version = in->readLine().trimmed();

    if (version != "battle_logs_v2" && version != "battle_logs_v3") {
        QMessageBox::critical(nullptr, tr("Log format not supported"), tr("The replay version of the file isn't supported by this client."));
        deleteLater();
        return;
    }

    this->version = version.right(1).toInt();

    DataStream stream(in, this->version);

    stream >> conf;

    window = new SpectatorWindow(conf);

    QWidget *widget = new QWidget();
    QGridLayout *gl = new QGridLayout(widget);
    gl->addWidget(window->getSceneWidget(), 0, 0);
    gl->addWidget(window->getLogWidget(), 0, 1);

    bar.init();
    gl->addLayout(bar.getLayout(), 1, 0, 1, 2);
    connect(&bar, SIGNAL(paused()), SLOT(pause()));
    connect(&bar, SIGNAL(speedChange(bool)), SLOT(changeSpeed(bool)));
    connect(&bar, SIGNAL(play()), SLOT(play()));
    connect(&bar, SIGNAL(seekNext()), SLOT(seekNext()));

    widget->setWindowTitle(tr("Pok\303\251mon Online Replay"));

    widget->setObjectName("ReplayViewer");
    widget->show();
    //widget->setWindowFlags(Qt::Window);
    widget->setAttribute(Qt::WA_DeleteOnClose);

    connect(widget, SIGNAL(destroyed()), SLOT(deleteLater()));

    t.start();
    read();
}
Ejemplo n.º 2
0
//seek a particular instance
bool CLASS::seekInst(int inst){
  if(isEnd())
    return false;   //at end!
  //starting at outgoing instance pointer...
  while(seekNext()){
    if(inst==buf[index].inst)
      return true;
  }
  return false;
}
Ejemplo n.º 3
0
/// Reads the packet available at the current file position.
/// If the packet could not be read for any reason, the reason is printed.
/// Reading the packet means the file position is increased to the next packet.
void DTSC::File::seekNext() {
  if (!currentPositions.size()) {
    DEBUG_MSG(DLVL_WARN, "No seek positions set - returning empty packet.");
    myPack.null();
    return;
  }
  seekPos thisPos = *currentPositions.begin();
  fseek(F, thisPos.bytePos, SEEK_SET);
  if (reachedEOF()) {
    myPack.null();
    return;
  }
  clearerr(F);
  currentPositions.erase(currentPositions.begin());
  lastreadpos = ftell(F);
  if (fread(buffer, 4, 1, F) != 1) {
    if (feof(F)) {
      DEBUG_MSG(DLVL_DEVEL, "End of file reached while seeking @ %i", (int)lastreadpos);
    } else {
      DEBUG_MSG(DLVL_ERROR, "Could not seek to next @ %i", (int)lastreadpos);
    }
    myPack.null();
    return;
  }
  if (memcmp(buffer, DTSC::Magic_Header, 4) == 0) {
    seek_time(myPack.getTime(), myPack.getTrackId(), true);
    return seekNext();
  }
  long long unsigned int version = 0;
  if (memcmp(buffer, DTSC::Magic_Packet, 4) == 0) {
    version = 1;
  }
  if (memcmp(buffer, DTSC::Magic_Packet2, 4) == 0) {
    version = 2;
  }
  if (version == 0) {
    DEBUG_MSG(DLVL_ERROR, "Invalid packet header @ %#x - %.4s != %.4s @ %d", (unsigned int)lastreadpos, (char *)buffer, DTSC::Magic_Packet2, (int)lastreadpos);
    myPack.null();
    return;
  }
  if (fread(buffer, 4, 1, F) != 1) {
    DEBUG_MSG(DLVL_ERROR, "Could not read packet size @ %d", (int)lastreadpos);
    myPack.null();
    return;
  }
  long packSize = ntohl(((unsigned long *)buffer)[0]);
  char * packBuffer = (char *)malloc(packSize + 8);
  if (version == 1) {
    memcpy(packBuffer, "DTPD", 4);
  } else {
    memcpy(packBuffer, "DTP2", 4);
  }
  memcpy(packBuffer + 4, buffer, 4);
  if (fread((void *)(packBuffer + 8), packSize, 1, F) != 1) {
    DEBUG_MSG(DLVL_ERROR, "Could not read packet @ %d", (int)lastreadpos);
    myPack.null();
    free(packBuffer);
    return;
  }
  myPack.reInit(packBuffer, packSize + 8);
  free(packBuffer);
  if (metadata.merged) {
    int tempLoc = getBytePos();
    char newHeader[20];
    bool insert = false;
    seekPos tmpPos;
    if (fread((void *)newHeader, 20, 1, F) == 1) {
      if (memcmp(newHeader, DTSC::Magic_Packet2, 4) == 0) {
        tmpPos.bytePos = tempLoc;
        tmpPos.trackID = ntohl(((int *)newHeader)[2]);
        tmpPos.seekTime = 0;
        if (selectedTracks.find(tmpPos.trackID) != selectedTracks.end()) {
          tmpPos.seekTime = ((long long unsigned int)ntohl(((int *)newHeader)[3])) << 32;
          tmpPos.seekTime += ntohl(((int *)newHeader)[4]);
          insert = true;
        } else {
          long tid = myPack.getTrackId();
          for (unsigned int i = 0; i != metadata.tracks[tid].keys.size(); i++) {
            if ((unsigned long long)metadata.tracks[tid].keys[i].getTime() > myPack.getTime()) {
              tmpPos.seekTime = metadata.tracks[tid].keys[i].getTime();
              tmpPos.bytePos = metadata.tracks[tid].keys[i].getBpos();
              tmpPos.trackID = tid;
              insert = true;
              break;
            }
          }
        }
        if (currentPositions.size()) {
          for (std::set<seekPos>::iterator curPosIter = currentPositions.begin(); curPosIter != currentPositions.end(); curPosIter++) {
            if ((*curPosIter).trackID == tmpPos.trackID && (*curPosIter).seekTime >= tmpPos.seekTime) {
              insert = false;
              break;
            }
          }
        }
      }
    }
    if (insert){
      if (tmpPos.seekTime > 0xffffffffffffff00ll){
        tmpPos.seekTime = 0;
      }
      currentPositions.insert(tmpPos);
    } else {
      seek_time(myPack.getTime(), myPack.getTrackId(), true);
    }
    seek_bpos(tempLoc);
  }else{
    seek_time(thisPos.seekTime, thisPos.trackID);
    fseek(F, thisPos.bytePos, SEEK_SET);
  }
}