2019-05-21 00:49:40 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file debug_sl.cpp Code handling saving and loading of debugging information */
|
|
|
|
|
|
|
|
#include "../stdafx.h"
|
|
|
|
|
|
|
|
#include "../debug.h"
|
|
|
|
#include "saveload.h"
|
|
|
|
#include "saveload_buffer.h"
|
2019-09-14 21:00:13 +00:00
|
|
|
#include "../fios.h"
|
2019-05-21 00:49:40 +00:00
|
|
|
|
|
|
|
#include "../safeguards.h"
|
|
|
|
|
|
|
|
static void Save_DBGL()
|
|
|
|
{
|
|
|
|
if (_savegame_DBGL_data != nullptr) {
|
|
|
|
size_t length = strlen(_savegame_DBGL_data);
|
|
|
|
SlSetLength(length);
|
|
|
|
MemoryDumper::GetCurrent()->CopyBytes(reinterpret_cast<const byte *>(_savegame_DBGL_data), length);
|
|
|
|
} else {
|
|
|
|
SlSetLength(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Load_DBGL()
|
|
|
|
{
|
|
|
|
size_t length = SlGetFieldLength();
|
|
|
|
if (length) {
|
|
|
|
_loadgame_DBGL_data.resize(length);
|
2021-03-11 01:08:33 +00:00
|
|
|
ReadBuffer::GetCurrent()->CopyBytes(reinterpret_cast<byte *>(_loadgame_DBGL_data.data()), length);
|
2019-05-21 00:49:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-14 21:00:13 +00:00
|
|
|
static void Check_DBGL()
|
|
|
|
{
|
2020-04-21 17:17:13 +00:00
|
|
|
if (!_load_check_data.want_debug_data) {
|
2019-09-14 21:00:13 +00:00
|
|
|
SlSkipBytes(SlGetFieldLength());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
size_t length = SlGetFieldLength();
|
|
|
|
if (length) {
|
|
|
|
_load_check_data.debug_log_data.resize(length);
|
2021-03-11 01:08:33 +00:00
|
|
|
ReadBuffer::GetCurrent()->CopyBytes(reinterpret_cast<byte *>(_load_check_data.debug_log_data.data()), length);
|
2019-09-14 21:00:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-21 17:17:13 +00:00
|
|
|
static void Save_DBGC()
|
|
|
|
{
|
|
|
|
extern std::string _config_file_text;
|
|
|
|
const char header[] = "*** openttd.cfg start ***\n";
|
|
|
|
const char footer[] = "*** openttd.cfg end ***\n";
|
|
|
|
if (_save_DBGC_data) {
|
|
|
|
SlSetLength(lengthof(header) + _config_file_text.size() + lengthof(footer) - 2);
|
|
|
|
MemoryDumper::GetCurrent()->CopyBytes(reinterpret_cast<const byte *>(header), lengthof(header) - 1);
|
|
|
|
MemoryDumper::GetCurrent()->CopyBytes(reinterpret_cast<const byte *>(_config_file_text.data()), _config_file_text.size());
|
|
|
|
MemoryDumper::GetCurrent()->CopyBytes(reinterpret_cast<const byte *>(footer), lengthof(footer) - 1);
|
|
|
|
} else {
|
|
|
|
SlSetLength(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Load_DBGC()
|
|
|
|
{
|
|
|
|
size_t length = SlGetFieldLength();
|
|
|
|
if (length) {
|
|
|
|
_loadgame_DBGC_data.resize(length);
|
2021-03-11 01:08:33 +00:00
|
|
|
ReadBuffer::GetCurrent()->CopyBytes(reinterpret_cast<byte *>(_loadgame_DBGC_data.data()), length);
|
2020-04-21 17:17:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Check_DBGC()
|
|
|
|
{
|
|
|
|
if (!_load_check_data.want_debug_data) {
|
|
|
|
SlSkipBytes(SlGetFieldLength());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
size_t length = SlGetFieldLength();
|
|
|
|
if (length) {
|
|
|
|
_load_check_data.debug_config_data.resize(length);
|
2021-03-11 01:08:33 +00:00
|
|
|
ReadBuffer::GetCurrent()->CopyBytes(reinterpret_cast<byte *>(_load_check_data.debug_config_data.data()), length);
|
2020-04-21 17:17:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-21 00:49:40 +00:00
|
|
|
extern const ChunkHandler _debug_chunk_handlers[] = {
|
2020-04-21 17:17:13 +00:00
|
|
|
{ 'DBGL', Save_DBGL, Load_DBGL, nullptr, Check_DBGL, CH_RIFF},
|
|
|
|
{ 'DBGC', Save_DBGC, Load_DBGC, nullptr, Check_DBGC, CH_RIFF | CH_LAST},
|
2019-05-21 00:49:40 +00:00
|
|
|
};
|