Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various non-Xbox-specific fixes from xbox-nxdk branch #4901

Merged
merged 8 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions 3rdParty/SDL_audiolib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ set(USE_RESAMP_SRC OFF)
# No need for the SOX resampler:
set(USE_RESAMP_SOXR OFF)

# Exceptions are only used for fatal errors which we can't handle anyway:
set(DISABLE_EXCEPTIONS ON)

# We do not need any of the audio formats except WAV and mp3:
set(USE_DEC_DRWAV ON)
set(USE_DEC_DRFLAC OFF)
Expand All @@ -35,8 +38,8 @@ set(USE_DEC_DRMP3 ON)

include(FetchContent)
FetchContent_Declare(SDL_audiolib
URL https://github.com/realnc/SDL_audiolib/archive/b66a66fedf8f65cacc5ce2ff8ed8d10649c6de31.tar.gz
URL_HASH MD5=0d8909cebd83fff19cbeceebc4b4577a)
URL https://github.com/realnc/SDL_audiolib/archive/2f85feb589f7b74f17a82ff18eb05b002df16cfd.tar.gz
URL_HASH MD5=3f9b64d6bcb8c3254e24d5c39e2147ee)
FetchContent_MakeAvailableExcludeFromAll(SDL_audiolib)

add_library(SDL_audiolib::SDL_audiolib ALIAS SDL_audiolib)
4 changes: 2 additions & 2 deletions 3rdParty/libmpq/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ include(functions/FetchContent_MakeAvailableExcludeFromAll)

include(FetchContent)
FetchContent_Declare(libmpq
URL https://github.com/diasurgical/libmpq/archive/94a32fcb26f98940485eed3cd775bf1a688022c6.tar.gz
URL_HASH MD5=80661a033ec2b33fb4fc56dd973c0fca
URL https://github.com/diasurgical/libmpq/archive/6a9fbdc7ed3032ff00eb069590da4629bd95da5f.tar.gz
URL_HASH MD5=5aa2add93b15c1823c18e95768195876
)
FetchContent_MakeAvailableExcludeFromAll(libmpq)

Expand Down
2 changes: 1 addition & 1 deletion Source/levels/drlg_l2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1599,7 +1599,7 @@ void PlaceMiniSetRandom(const Miniset &miniset, int rndper)

void PlaceMiniSetRandom1x1(uint8_t search, uint8_t replace, int rndper)
{
PlaceMiniSetRandom({ { 1, 1 }, { search }, { replace } }, rndper);
PlaceMiniSetRandom({ { 1, 1 }, { { search } }, { { replace } } }, rndper);
}

void LoadQuestSetPieces()
Expand Down
19 changes: 14 additions & 5 deletions Source/mpq/mpq_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,14 @@ bool IsUnallocatedBlock(const MpqBlockEntry *block)
MpqWriter::MpqWriter(const char *path)
{
LogVerbose("Opening {}", path);
std::string error;
bool exists = FileExists(path);
std::ios::openmode mode = std::ios::in | std::ios::out | std::ios::binary;
std::ios::openmode mode = std::ios::out | std::ios::binary;
if (exists) {
mode |= std::ios::in;
if (!GetFileSize(path, &size_)) {
Log(R"(GetFileSize("{}") failed with "{}")", path, std::strerror(errno));
error = R"(GetFileSize failed: "{}")";
LogError(error, path, std::strerror(errno));
goto on_error;
}
LogVerbose("GetFileSize(\"{}\") = {}", path, size_);
Expand All @@ -102,6 +105,7 @@ MpqWriter::MpqWriter(const char *path)
}
if (!stream_.Open(path, mode)) {
stream_.Close();
error = "Failed to open fstream";
goto on_error;
}

Expand All @@ -112,13 +116,16 @@ MpqWriter::MpqWriter(const char *path)
if (!exists) {
InitDefaultMpqHeader(&fhdr);
} else if (!ReadMPQHeader(&fhdr)) {
error = "Failed to read MPQ header";
goto on_error;
}
blockTable_ = std::make_unique<MpqBlockEntry[]>(BlockEntriesCount);
std::memset(blockTable_.get(), 0, BlockEntriesCount * sizeof(MpqBlockEntry));
if (fhdr.blockEntriesCount > 0) {
if (!stream_.Read(reinterpret_cast<char *>(blockTable_.get()), static_cast<std::streamsize>(fhdr.blockEntriesCount * sizeof(MpqBlockEntry))))
if (!stream_.Read(reinterpret_cast<char *>(blockTable_.get()), static_cast<std::streamsize>(fhdr.blockEntriesCount * sizeof(MpqBlockEntry)))) {
error = "Failed to read block table";
goto on_error;
}
uint32_t key = Hash("(block table)", 3);
Decrypt(reinterpret_cast<uint32_t *>(blockTable_.get()), fhdr.blockEntriesCount * sizeof(MpqBlockEntry), key);
}
Expand All @@ -128,8 +135,10 @@ MpqWriter::MpqWriter(const char *path)
std::memset(hashTable_.get(), 0xFF, HashEntriesCount * sizeof(MpqHashEntry));

if (fhdr.hashEntriesCount > 0) {
if (!stream_.Read(reinterpret_cast<char *>(hashTable_.get()), static_cast<std::streamsize>(fhdr.hashEntriesCount * sizeof(MpqHashEntry))))
if (!stream_.Read(reinterpret_cast<char *>(hashTable_.get()), static_cast<std::streamsize>(fhdr.hashEntriesCount * sizeof(MpqHashEntry)))) {
error = "Failed to read hash entries";
goto on_error;
}
uint32_t key = Hash("(hash table)", 3);
Decrypt(reinterpret_cast<uint32_t *>(hashTable_.get()), fhdr.hashEntriesCount * sizeof(MpqHashEntry), key);
}
Expand All @@ -150,7 +159,7 @@ MpqWriter::MpqWriter(const char *path)
}
return;
on_error:
app_fatal(_("Failed to open archive for writing."));
app_fatal(fmt::format("{}\n{}\n{}", _("Failed to open archive for writing."), path, error));
}

MpqWriter::~MpqWriter()
Expand Down
5 changes: 3 additions & 2 deletions Source/objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3232,8 +3232,9 @@ void OperateShrineSolar(Player &player)
if (&player != MyPlayer)
return;

time_t tm = time(nullptr);
int hour = localtime(&tm)->tm_hour;
time_t timeResult = time(nullptr);
const std::tm *localtimeResult = localtime(&timeResult);
int hour = localtimeResult != nullptr ? localtimeResult->tm_hour : 20;
if (hour >= 20 || hour < 4) {
InitDiabloMsg(EMSG_SHRINE_SOLAR4);
ModifyPlrVit(player, 2);
Expand Down
15 changes: 10 additions & 5 deletions Source/qol/chatlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ void ToggleChatLog()
void AddMessageToChatLog(string_view message, Player *player, UiFlags flags)
{
MessageCounter++;
time_t tm = time(nullptr);
std::string timestamp = fmt::format("[#{:d}] {:02}:{:02}:{:02}", MessageCounter, localtime(&tm)->tm_hour, localtime(&tm)->tm_min, localtime(&tm)->tm_sec);
time_t timeResult = time(nullptr);
const std::tm *localtimeResult = localtime(&timeResult);
std::string timestamp = localtimeResult != nullptr ? fmt::format("[#{:d}] {:02}:{:02}:{:02}", MessageCounter, localtimeResult->tm_hour, localtimeResult->tm_min, localtimeResult->tm_sec)
: fmt::format("[#{:d}] ", MessageCounter);
int oldSize = ChatLogLines.size();
ChatLogLines.emplace_back(MultiColoredText { "", { {} } });
if (player == nullptr) {
Expand Down Expand Up @@ -156,9 +158,12 @@ void DrawChatLog(const Surface &out)
{ { sx, sy + PaddingTop + blankLineHeight }, { ContentTextWidth, lineHeight } },
(UnreadFlag ? UiFlags::ColorRed : UiFlags::ColorWhitegold) | UiFlags::AlignCenter);

time_t tm = time(nullptr);
std::string timestamp = fmt::format("{:02}:{:02}:{:02}", localtime(&tm)->tm_hour, localtime(&tm)->tm_min, localtime(&tm)->tm_sec);
DrawString(out, timestamp, { { sx, sy + PaddingTop + blankLineHeight }, { ContentTextWidth, lineHeight } }, UiFlags::ColorWhitegold);
time_t timeResult = time(nullptr);
const std::tm *localtimeResult = localtime(&timeResult);
if (localtimeResult != nullptr) {
std::string timestamp = fmt::format("{:02}:{:02}:{:02}", localtimeResult->tm_hour, localtimeResult->tm_min, localtimeResult->tm_sec);
DrawString(out, timestamp, { { sx, sy + PaddingTop + blankLineHeight }, { ContentTextWidth, lineHeight } }, UiFlags::ColorWhitegold);
}

const int titleBottom = sy + HeaderHeight();
DrawSLine(out, titleBottom);
Expand Down
2 changes: 1 addition & 1 deletion Source/restrict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace devilution {
void ReadOnlyTest()
{
const std::string path = paths::PrefPath() + "Diablo1ReadOnlyTest.foo";
FILE *f = FOpen(path.c_str(), "wt");
FILE *f = FOpen(path.c_str(), "w");
if (f == nullptr) {
DirErrorDlg(paths::PrefPath());
}
Expand Down
2 changes: 1 addition & 1 deletion Source/utils/attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
#define DVL_REINITIALIZES
#endif

#if (defined(__GNUC__) && !defined(__EXCEPTIONS)) || FMT_MSC_VER && !_HAS_EXCEPTIONS
#if ((defined(__GNUC__) || defined(__clang__)) && !defined(__EXCEPTIONS)) || defined(_MSC_VER) && !_HAS_EXCEPTIONS
#define DVL_EXCEPTIONS 0
#else
#define DVL_EXCEPTIONS 1
Expand Down