// //////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////// void displayRequestOption(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset) { LEVEL_DATASET *mapData = (LEVEL_DATASET *)psWidget->pUserData; int x = xOffset + psWidget->x(); int y = yOffset + psWidget->y(); char butString[255]; sstrcpy(butString, ((W_BUTTON *)psWidget)->pTip.toUtf8().constData()); drawBlueBox(x, y, psWidget->width(), psWidget->height()); iV_SetFont(font_regular); // font iV_SetTextColour(WZCOL_TEXT_BRIGHT); while (iV_GetTextWidth(butString) > psWidget->width() - 10) { butString[strlen(butString)-1]='\0'; } iV_DrawText(butString, x + 6, y + 12); //draw text if (mapData != NULL) { // Display map hash, so we can see the difference between identically named maps. Sha256 hash = mapData->realFileHash; // levGetFileHash can be slightly expensive. static uint32_t lastHashTime = 0; if (lastHashTime != realTime && hash.isZero()) { hash = levGetFileHash(mapData); if (!hash.isZero()) { lastHashTime = realTime; // We just calculated a hash. Don't calculate any more hashes this frame. } } if (!hash.isZero()) { iV_SetFont(font_small); iV_SetTextColour(WZCOL_TEXT_DARK); sstrcpy(butString, hash.toString().c_str()); while (iV_GetTextWidth(butString) > psWidget->width() - 10 - (8 + mapData->players*6)) { butString[strlen(butString) - 1] = '\0'; } iV_DrawText(butString, x + 6 + 8 + mapData->players*6, y + 26); iV_SetFont(font_regular); } // if map, then draw no. of players. for (int count = 0; count < mapData->players; ++count) { iV_DrawImage(FrontImages, IMAGE_WEE_GUY, x + 6*count + 6, y + 16); } } }
Sha256 levGetMapNameHash(char const *mapName) { LEVEL_DATASET *level = levFindDataSet(mapName, NULL); if (level == NULL) { debug(LOG_WARNING, "Couldn't find map \"%s\" to hash.", mapName); Sha256 zero; zero.setZero(); return zero; } return levGetFileHash(level); }
/** Find a level dataset with the given name. * @param name the name of the dataset to search for. * @return a dataset with associated with the given @c name, or NULL if none * could be found. */ LEVEL_DATASET *levFindDataSet(char const *name, Sha256 const *hash) { if (hash != NULL && hash->isZero()) { hash = NULL; // Don't check hash if it's just 0000000000000000000000000000000000000000000000000000000000000000. Assuming real map files probably won't have that particular SHA-256 hash. } for (LEVEL_DATASET *psNewLevel = psLevels; psNewLevel != NULL; psNewLevel = psNewLevel->psNext) { if (psNewLevel->pName != NULL && strcmp(psNewLevel->pName, name) == 0) { if (hash == NULL || levGetFileHash(psNewLevel) == *hash) { return psNewLevel; } } } return NULL; }
/** Find a level dataset with the given name. * @param name the name of the dataset to search for. * @return a dataset with associated with the given @c name, or NULL if none * could be found. */ LEVEL_DATASET *levFindDataSet(char const *name, Sha256 const *hash) { if (hash != nullptr && hash->isZero()) { hash = nullptr; // Don't check hash if it's just 0000000000000000000000000000000000000000000000000000000000000000. Assuming real map files probably won't have that particular SHA-256 hash. } for (auto psNewLevel : psLevels) { if (psNewLevel->pName && strcmp(psNewLevel->pName, name) == 0) { if (hash == nullptr || levGetFileHash(psNewLevel) == *hash) { return psNewLevel; } } } return nullptr; }