Skip to content

Commit

Permalink
Crash/desync logs: Include non-default settings section
Browse files Browse the repository at this point in the history
  • Loading branch information
JGRennison committed Jan 10, 2024
1 parent 2ec4b2a commit 7dd820f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/crashlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include "event_logs.h"
#include "scope.h"
#include "progress.h"
#include "settings_type.h"
#include "settings_internal.h"

#include "ai/ai_info.hpp"
#include "game/game.hpp"
Expand Down Expand Up @@ -508,6 +510,31 @@ char *CrashLog::LogCommandLog(char *buffer, const char *last) const
return buffer;
}

/**
* Writes the non-default settings to the buffer.
* @param buffer The begin where to write at.
* @param last The last position in the buffer to write to.
* @return the position of the \c '\0' character after the buffer.
*/
char *CrashLog::LogSettings(char *buffer, const char *last) const
{
buffer += seprintf(buffer, last, "Non-default settings:");

IterateSettingsTables([&](const SettingTable &table, void *object) {
for (auto &sd : table) {
/* Skip any old settings we no longer save/load. */
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to, sd->save.ext_feature_test)) continue;

if (sd->IsDefaultValue(object)) continue;
buffer += seprintf(buffer, last, "\n %s: ", sd->name);
buffer = sd->FormatValue(buffer, last, object);
}
});

buffer += seprintf(buffer, last, "\n\n");
return buffer;
}

/**
* Fill the crash log buffer with all data of a crash log.
* @param buffer The begin where to write at.
Expand Down Expand Up @@ -618,6 +645,9 @@ char *CrashLog::FillCrashLog(char *buffer, const char *last)
buffer = this->TryCrashLogFaultSection(buffer, last, "command log", [](CrashLog *self, char *buffer, const char *last) -> char * {
return self->LogCommandLog(buffer, last);
});
buffer = this->TryCrashLogFaultSection(buffer, last, "settings", [](CrashLog *self, char *buffer, const char *last) -> char * {
return self->LogSettings(buffer, last);
});

buffer += seprintf(buffer, last, "*** End of OpenTTD Crash Report ***\n");
this->StopCrashLogFaultHandler();
Expand Down Expand Up @@ -682,6 +712,7 @@ char *CrashLog::FillDesyncCrashLog(char *buffer, const char *last, const DesyncE
buffer = this->LogGamelog(buffer, last);
buffer = this->LogRecentNews(buffer, last);
buffer = this->LogCommandLog(buffer, last);
buffer = this->LogSettings(buffer, last);
buffer = DumpDesyncMsgLog(buffer, last);

bool have_cache_log = false;
Expand Down Expand Up @@ -744,6 +775,7 @@ char *CrashLog::FillInconsistencyLog(char *buffer, const char *last, const Incon
buffer = this->LogGamelog(buffer, last);
buffer = this->LogRecentNews(buffer, last);
buffer = this->LogCommandLog(buffer, last);
buffer = this->LogSettings(buffer, last);
buffer = DumpDesyncMsgLog(buffer, last);

if (!info.check_caches_result.empty()) {
Expand Down
1 change: 1 addition & 0 deletions src/crashlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class CrashLog {
char *LogGamelog(char *buffer, const char *last) const;
char *LogRecentNews(char *buffer, const char *list) const;
char *LogCommandLog(char *buffer, const char *last) const;
char *LogSettings(char *buffer, const char *last) const;

virtual void StartCrashLogFaultHandler();
virtual void StopCrashLogFaultHandler();
Expand Down

0 comments on commit 7dd820f

Please sign in to comment.