Ejemplo n.º 1
0
bool CSurface8::Save(const char *szFilename, CStdPalette *bpPalette)
{
	C4BMP256Info BitmapInfo;
	BitmapInfo.Set(Wdt,Hgt, bpPalette ? bpPalette : pPal);

	// Create file & write info
	CStdFile hFile;

	if ( !hFile.Create(szFilename)
	     || !hFile.Write(&BitmapInfo,sizeof(BitmapInfo)) )
		{ return false; }

	// Write lines
	char bpEmpty[4]; ZeroMem(bpEmpty, 4);
	const int iEmpty = DWordAligned(Wdt)-Wdt;
	for (int cnt=Hgt-1; cnt>=0; cnt--)
	{
		if (!hFile.Write(Bits+(Pitch*cnt),Wdt))
			{ return false; }
		if (iEmpty)
			if (!hFile.Write(bpEmpty,iEmpty))
				{ return false; }
	}

	// Close file
	hFile.Close();

	// Success
	return true;
}
Ejemplo n.º 2
0
bool CSurface8::Save(const char *szFilename, BYTE *bpPalette) {
  CBitmap256Info BitmapInfo;
  BitmapInfo.Set(Wdt, Hgt, bpPalette ? bpPalette : pPal->Colors);

  // Create file & write info
  CStdFile hFile;

  if (!hFile.Create(szFilename) ||
      !hFile.Write(&BitmapInfo, sizeof(BitmapInfo))) {
    return FALSE;
  }

  // Write lines
  char bpEmpty[4];
  int iEmpty = DWordAligned(Wdt) - Wdt;
  for (int cnt = Hgt - 1; cnt >= 0; cnt--) {
    if (!hFile.Write(Bits + (Pitch * cnt), Wdt)) {
      return FALSE;
    }
    if (iEmpty)
      if (!hFile.Write(bpEmpty, iEmpty)) {
        return FALSE;
      }
  }

  // Close file
  hFile.Close();

  // Success
  return TRUE;
}
Ejemplo n.º 3
0
BOOL CStdBitmap::Save(const char *szFileName) {
  CStdFile hFile;
  if (!Bits) return FALSE;
  int savesize = sizeof(Head) + sizeof(Info);
  if (Info.biBitCount == 8) savesize += 256 * sizeof(RGBQUAD);
  if (!hFile.Create(szFileName, FALSE) || !hFile.Write(this, savesize) ||
      !hFile.Write(Bits, Info.biSizeImage) || !hFile.Close())
    return FALSE;
  return TRUE;
}
Ejemplo n.º 4
0
void C4Playback::Check(C4RecordChunkType eType, const uint8_t *pData,
                       int iSize) {
  // only if enabled
  if (DoNoDebugRec > 0) return;
  if (Game.FrameCounter < DEBUGREC_START_FRAME) return;

  C4PktDebugRec PktInReplay;
  bool fHasPacketFromHead = false;
#ifdef DEBUGREC_EXTFILE
#ifdef DEBUGREC_EXTFILE_WRITE
  // writing of external debugrec file
  DbgRecFile.Write(&eType, sizeof eType);
  int32_t iSize32 = iSize;
  DbgRecFile.Write(&iSize32, sizeof iSize32);
  DbgRecFile.Write(pData, iSize);
  return;
#else
  int32_t iSize32 = 0;
  C4RecordChunkType eTypeRec = RCT_Undefined;
  DbgRecFile.Read(&eTypeRec, sizeof eTypeRec);
  DbgRecFile.Read(&iSize32, sizeof iSize32);
  if (iSize32) {
    StdBuf buf;
    buf.SetSize(iSize32);
    DbgRecFile.Read(buf.getMData(), iSize32);
    PktInReplay = C4PktDebugRec(eTypeRec, buf);
  }
#endif
#else
  // check debug rec in list
  C4IDPacket *pkt;
  if (pkt = DebugRec.firstPkt()) {
    // copy from list
    PktInReplay = *static_cast<C4PktDebugRec *>(pkt->getPkt());
    DebugRec.Delete(pkt);
  } else {
    // special sync check skip...
    while (currChunk != chunks.end() && currChunk->Type == RCT_CtrlPkt) {
      C4IDPacket Packet(*currChunk->pPkt);
      C4ControlPacket *pCtrlPck =
          static_cast<C4ControlPacket *>(Packet.getPkt());
      assert(!pCtrlPck->Sync());
      Game.Control.ExecControlPacket(Packet.getPktType(), pCtrlPck);
      NextChunk();
    }
    // record end?
    if (currChunk == chunks.end() || currChunk->Type == RCT_End || Finished) {
      Log("DebugRec end: All in sync!");
      ++DoNoDebugRec;
      return;
    }
    // unpack directly from head
    if (currChunk->Type != eType) {
      DebugRecError(FormatString("Playback type %x, this type %x",
                                 currChunk->Type, eType).getData());
      return;
    }
    PktInReplay = *currChunk->pDbg;
    fHasPacketFromHead = true;
  }
#endif  // DEBUGREC_EXTFILE
  // record end?
  if (PktInReplay.getType() == RCT_End) {
    Log("DebugRec end: All in sync (2)!");
    ++DoNoDebugRec;
    return;
  }
  // replay packet is unpacked to PktInReplay now; check it
  if (PktInReplay.getType() != eType) {
    DebugRecError(FormatString("Type %s != %s",
                               GetRecordChunkTypeName(PktInReplay.getType()),
                               GetRecordChunkTypeName(eType)).getData());
    return;
  }
  if (PktInReplay.getSize() != iSize) {
    DebugRecError(FormatString("Size %d != %d", (int)PktInReplay.getSize(),
                               (int)iSize).getData());
  }
  // check packet data
  if (memcmp(PktInReplay.getData(), pData, iSize)) {
    StdStrBuf sErr;
    sErr.Format("DbgRecPkt Type %s, size %d", GetRecordChunkTypeName(eType),
                iSize);
    sErr.Append(" Replay: ");
    StdBuf replay(PktInReplay.getData(), PktInReplay.getSize());
    sErr.Append(GetDbgRecPktData(eType, replay));
    sErr.Append(" Here: ");
    StdBuf here(pData, iSize);
    sErr.Append(GetDbgRecPktData(eType, here));
    DebugRecError(sErr.getData());
  }
  // packet is fine, jump over it
  if (fHasPacketFromHead) NextChunk();
}
Ejemplo n.º 5
0
BOOL C4UpdatePackage::MakeUpdate(const char *strFile1, const char *strFile2,
                                 const char *strUpdateFile,
                                 const char *strName) {
#ifdef UPDATE_DEBUG
    char *pData;
    int iSize;
    CStdFile MyFile;
    MyFile.Load(strFile2, (BYTE **)&pData, &iSize, 0, TRUE);
    MyFile.Create("SoIstRichtig.txt", FALSE);
    MyFile.Write(pData, iSize, FALSE);
    MyFile.Close();
    MemScramble((BYTE *)pData, iSize);
    MyFile.Create("UndSoAuch.txt", FALSE);
    MyFile.Write(pData, iSize, FALSE);
    MyFile.Close();
#endif

    // open Log
    if (!Log.Create("Update.log")) return FALSE;

    // begin message
    WriteLog("Source: %s\nTarget: %s\nOutput: %s\n\n", strFile1, strFile2,
             strUpdateFile);

    // open both groups
    C4Group Group1, Group2;
    if (!Group1.Open(strFile1)) {
        WriteLog("Error: could not open %s!\n", strFile1);
        return FALSE;
    }
    if (!Group2.Open(strFile2)) {
        WriteLog("Error: could not open %s!\n", strFile2);
        return FALSE;
    }

    // All groups to be compared need to be packed
    if (!Group1.IsPacked()) {
        WriteLog("Error: source group %s not packed!\n", strFile1);
        return FALSE;
    }
    if (!Group2.IsPacked()) {
        WriteLog("Error: target group %s not packed!\n", strFile2);
        return FALSE;
    }
    if (Group1.HasPackedMother()) {
        WriteLog("Error: source group %s must not have a packed mother group!\n",
                 strFile1);
        return FALSE;
    }
    if (Group2.HasPackedMother()) {
        WriteLog("Error: target group %s must not have a packed mother group!\n",
                 strFile2);
        return FALSE;
    }

    // create/open update-group
    C4GroupEx UpGroup;
    if (!UpGroup.Open(strUpdateFile, TRUE)) {
        WriteLog("Error: could not open %s!\n", strUpdateFile);
        return FALSE;
    }

    // may be continued update-file -> try to load core
    UpGrpCnt = 0;
    BOOL fContinued = C4UpdatePackageCore::Load(UpGroup);

    // save crc2 for later check
    unsigned int iOldChks2 = GrpChks2;

    // create core info
    if (strName)
        SCopy(strName, Name, C4MaxName);
    else
        sprintf(Name, "%s Update", GetFilename(strFile1));
    SCopy(strFile1, DestPath, _MAX_PATH);
    GrpUpdate = TRUE;
    if (!C4Group_GetFileCRC(strFile1, &GrpChks1[UpGrpCnt])) {
        WriteLog("Error: could not calc checksum for %s!\n", strFile1);
        return FALSE;
    }
    if (!C4Group_GetFileCRC(strFile2, &GrpChks2)) {
        WriteLog("Error: could not calc checksum for %s!\n", strFile2);
        return FALSE;
    }
    if (fContinued) {
        // continuation check: GrpChks2 matches?
        if (GrpChks2 != iOldChks2)
            // that would mess up the update result...
        {
            WriteLog(
                "Error: could not add to update package - target groups don't match "
                "(checksum error)\n");
            return FALSE;
        }
        // already supported by this update?
        int i = 0;
        for (; i < UpGrpCnt; i++)
            if (GrpChks1[UpGrpCnt] == GrpChks1[i]) break;
        if (i < UpGrpCnt) {
            WriteLog(
                "This update already supports the version of the source file.\n");
            return FALSE;
        }
    }

    UpGrpCnt++;

    // save core
    if (!C4UpdatePackageCore::Save(UpGroup)) {
        WriteLog("Could not save update package core!\n");
        return FALSE;
    }

    // compare groups, create update
    BOOL fModified = FALSE;
    BOOL fSuccess = MkUp(&Group1, &Group2, &UpGroup, &fModified);
    // close (save) it
    UpGroup.Close(FALSE);
    // error?
    if (!fSuccess) {
        WriteLog("Update package not created.\n");
        remove(strUpdateFile);
        return FALSE;
    }

    WriteLog("Update package created.\n");
    return TRUE;
}
Ejemplo n.º 6
0
BOOL C4UpdatePackage::Execute(C4Group *pGroup) {
    // search target
    C4GroupEx TargetGrp;
    char strTarget[_MAX_PATH];
    SCopy(DestPath, strTarget, _MAX_PATH);
    char *p = strTarget, *lp = strTarget;
    while (p = strchr(p + 1, '\\')) {
        *p = 0;
        if (!*(p + 1)) break;
        if (!SEqual(lp, ".."))
            if (TargetGrp.Open(strTarget)) {
                // packed?
                bool fPacked = TargetGrp.IsPacked();
                // maker check (someone might try to unpack directories w/o asking user)
                if (fPacked)
                    if (!SEqual(TargetGrp.GetMaker(), pGroup->GetMaker())) return FALSE;
                // Close Group
                TargetGrp.Close(TRUE);
                if (fPacked)
                    // Unpack
                    C4Group_UnpackDirectory(strTarget);
            } else {
                // GrpUpdate -> file must exist
                if (GrpUpdate) return FALSE;
                // create dir
                CreateDirectory(strTarget, NULL);
            }
        *p = '\\';
        lp = p + 1;
    }

    // try to open it
    if (!TargetGrp.Open(strTarget, !GrpUpdate)) return FALSE;

    // check if the update is allowed
    if (GrpUpdate) {
        // maker must match
        /*if(!SEqual(TargetGrp.GetMaker(), pGroup->GetMaker())) - now allowing
           updates from different makers
                return FALSE;*/
        // check checksum
        uint32_t iCRC32;
        if (!C4Group_GetFileCRC(TargetGrp.GetFullName().getData(), &iCRC32))
            return FALSE;
        int i = 0;
        for (; i < UpGrpCnt; i++)
            if (iCRC32 == GrpChks1[i]) break;
        if (i >= UpGrpCnt) return FALSE;
    } else {
        // only allow Extra.c4g-Updates
        if (!SEqual2(DestPath, "Extra.c4g")) return FALSE;
    }

    // update children
    char ItemFileName[_MAX_PATH];
    pGroup->ResetSearch();
    while (pGroup->FindNextEntry("*", ItemFileName))
        if (!SEqual(ItemFileName, C4CFN_UpdateCore) &&
                !SEqual(ItemFileName, C4CFN_UpdateEntries))
            DoUpdate(pGroup, &TargetGrp, ItemFileName);

    // do GrpUpdate
    if (GrpUpdate) DoGrpUpdate(pGroup, &TargetGrp);

    // close the group
    TargetGrp.Close(FALSE);

    if (GrpUpdate) {
        // check the result
        uint32_t iResChks;
        if (!C4Group_GetFileCRC(strTarget, &iResChks)) return FALSE;
        if (iResChks != GrpChks2) {
#ifdef UPDATE_DEBUG
            char *pData;
            int iSize;
            CStdFile MyFile;
            MyFile.Load(strTarget, (BYTE **)&pData, &iSize, 0, TRUE);
            MyFile.Create("DiesesDingIstMist.txt", FALSE);
            MyFile.Write(pData, iSize, FALSE);
            MyFile.Close();
#endif
            return FALSE;
        }
    }

    return TRUE;
}