2016-03-01 15:47:10 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
2017-04-17 11:33:19 +00:00
|
|
|
// Copyright 1993-1996 id Software
|
|
|
|
// Copyright 1999-2016 Randy Heit
|
|
|
|
// Copyright 2002-2016 Christoph Oelckers
|
2016-03-01 15:47:10 +00:00
|
|
|
//
|
2017-04-17 11:33:19 +00:00
|
|
|
// This program 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, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
2016-03-01 15:47:10 +00:00
|
|
|
//
|
2017-04-17 11:33:19 +00:00
|
|
|
// This program is distributed in the hope that it will be useful,
|
2016-03-01 15:47:10 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2017-04-17 11:33:19 +00:00
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
2016-03-01 15:47:10 +00:00
|
|
|
//
|
2017-04-17 11:33:19 +00:00
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see http://www.gnu.org/licenses/
|
2016-03-01 15:47:10 +00:00
|
|
|
//
|
2017-04-17 11:33:19 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2016-03-01 15:47:10 +00:00
|
|
|
//
|
|
|
|
// DESCRIPTION:
|
|
|
|
// Default Config File.
|
|
|
|
// Screenshots.
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2017-03-10 01:22:42 +00:00
|
|
|
#include "r_defs.h"
|
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
#include "version.h"
|
|
|
|
|
|
|
|
#if defined(_WIN32)
|
|
|
|
#include <io.h>
|
|
|
|
#else
|
|
|
|
#endif
|
|
|
|
|
2017-03-10 01:22:42 +00:00
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
#include "m_swap.h"
|
|
|
|
#include "m_argv.h"
|
|
|
|
|
2020-04-11 11:36:23 +00:00
|
|
|
#include "filesystem.h"
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
#include "c_cvars.h"
|
|
|
|
#include "c_dispatch.h"
|
|
|
|
#include "c_bind.h"
|
|
|
|
|
|
|
|
#include "i_video.h"
|
|
|
|
#include "v_video.h"
|
2019-01-31 18:38:04 +00:00
|
|
|
#include "i_system.h"
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
// Data.
|
|
|
|
#include "m_misc.h"
|
|
|
|
#include "m_png.h"
|
|
|
|
|
|
|
|
#include "cmdlib.h"
|
|
|
|
|
|
|
|
#include "g_game.h"
|
|
|
|
#include "gi.h"
|
|
|
|
|
|
|
|
#include "gameconfigfile.h"
|
2019-03-18 23:37:43 +00:00
|
|
|
#include "gstrings.h"
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
FGameConfigFile *GameConfig;
|
|
|
|
|
|
|
|
CVAR(Bool, screenshot_quiet, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG);
|
|
|
|
CVAR(String, screenshot_type, "png", CVAR_ARCHIVE|CVAR_GLOBALCONFIG);
|
|
|
|
CVAR(String, screenshot_dir, "", CVAR_ARCHIVE|CVAR_GLOBALCONFIG);
|
|
|
|
EXTERN_CVAR(Bool, longsavemessages);
|
|
|
|
|
2023-03-26 07:49:40 +00:00
|
|
|
static size_t ParseCommandLine (const char *args, int *argc, char **argv);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// PROC M_FindResponseFile
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void M_FindResponseFile (void)
|
|
|
|
{
|
|
|
|
const int limit = 100; // avoid infinite recursion
|
|
|
|
int added_stuff = 0;
|
|
|
|
int i = 1;
|
|
|
|
|
|
|
|
while (i < Args->NumArgs())
|
|
|
|
{
|
|
|
|
if (Args->GetArg(i)[0] != '@')
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char **argv;
|
2023-08-19 14:16:56 +00:00
|
|
|
std::vector<uint8_t> file;
|
2016-03-01 15:47:10 +00:00
|
|
|
int argc = 0;
|
|
|
|
int size;
|
2023-03-26 07:49:40 +00:00
|
|
|
size_t argsize = 0;
|
2016-03-01 15:47:10 +00:00
|
|
|
int index;
|
|
|
|
|
|
|
|
// Any more response files after the limit will be removed from the
|
|
|
|
// command line.
|
|
|
|
if (added_stuff < limit)
|
|
|
|
{
|
|
|
|
// READ THE RESPONSE FILE INTO MEMORY
|
2018-03-11 17:32:00 +00:00
|
|
|
FileReader fr;
|
2018-03-10 19:33:49 +00:00
|
|
|
if (!fr.OpenFile(Args->GetArg(i) + 1))
|
2016-03-01 15:47:10 +00:00
|
|
|
{ // [RH] Make this a warning, not an error.
|
|
|
|
Printf ("No such response file (%s)!\n", Args->GetArg(i) + 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Printf ("Found response file %s!\n", Args->GetArg(i) + 1);
|
2018-03-10 19:33:49 +00:00
|
|
|
size = (int)fr.GetLength();
|
2018-12-21 08:21:40 +00:00
|
|
|
file = fr.Read (size);
|
2023-08-19 14:16:56 +00:00
|
|
|
file.push_back(0);
|
|
|
|
argsize = ParseCommandLine ((char*)file.data(), &argc, NULL);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Printf ("Ignored response file %s.\n", Args->GetArg(i) + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc != 0)
|
|
|
|
{
|
|
|
|
argv = (char **)M_Malloc (argc*sizeof(char *) + argsize);
|
|
|
|
argv[0] = (char *)argv + argc*sizeof(char *);
|
2023-08-19 14:16:56 +00:00
|
|
|
ParseCommandLine ((char*)file.data(), NULL, argv);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
// Create a new argument vector
|
2017-04-14 11:31:58 +00:00
|
|
|
FArgs *newargs = new FArgs;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
// Copy parameters before response file.
|
|
|
|
for (index = 0; index < i; ++index)
|
|
|
|
newargs->AppendArg(Args->GetArg(index));
|
|
|
|
|
|
|
|
// Copy parameters from response file.
|
|
|
|
for (index = 0; index < argc; ++index)
|
|
|
|
newargs->AppendArg(argv[index]);
|
|
|
|
|
|
|
|
// Copy parameters after response file.
|
|
|
|
for (index = i + 1; index < Args->NumArgs(); ++index)
|
|
|
|
newargs->AppendArg(Args->GetArg(index));
|
|
|
|
|
|
|
|
// Use the new argument vector as the global Args object.
|
2017-04-14 11:31:58 +00:00
|
|
|
delete Args;
|
2016-03-01 15:47:10 +00:00
|
|
|
Args = newargs;
|
|
|
|
if (++added_stuff == limit)
|
|
|
|
{
|
|
|
|
Printf("Response file limit of %d hit.\n", limit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Remove the response file from the Args object
|
|
|
|
Args->RemoveArg(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (added_stuff > 0)
|
|
|
|
{
|
|
|
|
// DISPLAY ARGS
|
|
|
|
Printf ("Added %d response file%s, now have %d command-line args:\n",
|
|
|
|
added_stuff, added_stuff > 1 ? "s" : "", Args->NumArgs ());
|
|
|
|
for (int k = 1; k < Args->NumArgs (); k++)
|
|
|
|
Printf ("%s\n", Args->GetArg (k));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ParseCommandLine
|
|
|
|
//
|
|
|
|
// This is just like the version in c_dispatch.cpp, except it does not
|
|
|
|
// do cvar expansion.
|
|
|
|
|
2023-03-26 07:49:40 +00:00
|
|
|
static size_t ParseCommandLine (const char *args, int *argc, char **argv)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
int count;
|
2023-03-26 07:49:40 +00:00
|
|
|
char* buffstart;
|
2016-03-01 15:47:10 +00:00
|
|
|
char *buffplace;
|
|
|
|
|
|
|
|
count = 0;
|
2023-03-26 07:49:40 +00:00
|
|
|
buffstart = NULL;
|
2016-03-01 15:47:10 +00:00
|
|
|
if (argv != NULL)
|
|
|
|
{
|
2023-03-26 07:49:40 +00:00
|
|
|
buffstart = argv[0];
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
2023-03-26 07:49:40 +00:00
|
|
|
buffplace = buffstart;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
while (*args <= ' ' && *args)
|
|
|
|
{ // skip white space
|
|
|
|
args++;
|
|
|
|
}
|
|
|
|
if (*args == 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (*args == '\"')
|
|
|
|
{ // read quoted string
|
|
|
|
char stuff;
|
|
|
|
if (argv != NULL)
|
|
|
|
{
|
|
|
|
argv[count] = buffplace;
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
args++;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
stuff = *args++;
|
|
|
|
if (stuff == '\\' && *args == '\"')
|
|
|
|
{
|
|
|
|
stuff = '\"', args++;
|
|
|
|
}
|
|
|
|
else if (stuff == '\"')
|
|
|
|
{
|
|
|
|
stuff = 0;
|
|
|
|
}
|
|
|
|
else if (stuff == 0)
|
|
|
|
{
|
|
|
|
args--;
|
|
|
|
}
|
|
|
|
if (argv != NULL)
|
|
|
|
{
|
|
|
|
*buffplace = stuff;
|
|
|
|
}
|
|
|
|
buffplace++;
|
|
|
|
} while (stuff);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // read unquoted string
|
|
|
|
const char *start = args++, *end;
|
|
|
|
|
|
|
|
while (*args && *args > ' ' && *args != '\"')
|
|
|
|
args++;
|
|
|
|
end = args;
|
|
|
|
if (argv != NULL)
|
|
|
|
{
|
|
|
|
argv[count] = buffplace;
|
|
|
|
while (start < end)
|
|
|
|
*buffplace++ = *start++;
|
|
|
|
*buffplace++ = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buffplace += end - start + 1;
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (argc != NULL)
|
|
|
|
{
|
|
|
|
*argc = count;
|
|
|
|
}
|
2023-03-26 07:49:40 +00:00
|
|
|
return (buffplace - buffstart);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// M_SaveDefaults
|
|
|
|
//
|
|
|
|
|
|
|
|
bool M_SaveDefaults (const char *filename)
|
|
|
|
{
|
|
|
|
FString oldpath;
|
|
|
|
bool success;
|
|
|
|
|
2019-10-07 18:28:55 +00:00
|
|
|
if (GameConfig == nullptr) return true;
|
|
|
|
if (filename != nullptr)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
oldpath = GameConfig->GetPathName();
|
|
|
|
GameConfig->ChangePathName (filename);
|
|
|
|
}
|
|
|
|
GameConfig->ArchiveGlobalData ();
|
|
|
|
if (gameinfo.ConfigName.IsNotEmpty())
|
|
|
|
{
|
|
|
|
GameConfig->ArchiveGameData (gameinfo.ConfigName);
|
|
|
|
}
|
|
|
|
success = GameConfig->WriteConfigFile ();
|
2019-10-07 18:28:55 +00:00
|
|
|
if (filename != nullptr)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
GameConfig->ChangePathName (filename);
|
|
|
|
}
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
void M_SaveDefaultsFinal ()
|
|
|
|
{
|
2019-10-07 18:28:55 +00:00
|
|
|
if (GameConfig == nullptr) return;
|
2022-10-02 12:08:07 +00:00
|
|
|
while (!M_SaveDefaults (nullptr) && I_WriteIniFailed (GameConfig->GetPathName()))
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
/* Loop until the config saves or I_WriteIniFailed() returns false */
|
|
|
|
}
|
|
|
|
delete GameConfig;
|
2019-10-07 18:28:55 +00:00
|
|
|
GameConfig = nullptr;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
2018-01-07 13:03:49 +00:00
|
|
|
UNSAFE_CCMD (writeini)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
const char *filename = (argv.argc() == 1) ? NULL : argv[1];
|
|
|
|
if (!M_SaveDefaults (filename))
|
|
|
|
{
|
|
|
|
Printf ("Writing config failed: %s\n", strerror(errno));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Printf ("Config saved.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-14 19:03:20 +00:00
|
|
|
CCMD(openconfig)
|
|
|
|
{
|
|
|
|
M_SaveDefaults(nullptr);
|
2022-08-16 22:31:22 +00:00
|
|
|
I_OpenShellFolder(ExtractFilePath(GameConfig->GetPathName()));
|
2022-08-14 19:03:20 +00:00
|
|
|
}
|
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
//
|
|
|
|
// M_LoadDefaults
|
|
|
|
//
|
|
|
|
|
|
|
|
void M_LoadDefaults ()
|
|
|
|
{
|
|
|
|
GameConfig = new FGameConfigFile;
|
|
|
|
GameConfig->DoGlobalSetup ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// SCREEN SHOTS
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
struct pcx_t
|
|
|
|
{
|
2017-07-15 07:01:02 +00:00
|
|
|
int8_t manufacturer;
|
|
|
|
int8_t version;
|
|
|
|
int8_t encoding;
|
|
|
|
int8_t bits_per_pixel;
|
|
|
|
|
|
|
|
uint16_t xmin;
|
|
|
|
uint16_t ymin;
|
|
|
|
uint16_t xmax;
|
|
|
|
uint16_t ymax;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2017-07-15 07:01:02 +00:00
|
|
|
uint16_t hdpi;
|
|
|
|
uint16_t vdpi;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2017-07-15 07:01:02 +00:00
|
|
|
uint8_t palette[48];
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2017-07-15 07:01:02 +00:00
|
|
|
int8_t reserved;
|
|
|
|
int8_t color_planes;
|
|
|
|
uint16_t bytes_per_line;
|
|
|
|
uint16_t palette_type;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2017-07-15 07:01:02 +00:00
|
|
|
int8_t filler[58];
|
2016-03-01 15:47:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-09-21 10:19:13 +00:00
|
|
|
inline void putc(unsigned char chr, FileWriter *file)
|
2016-09-21 07:01:12 +00:00
|
|
|
{
|
|
|
|
file->Write(&chr, 1);
|
|
|
|
}
|
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
//
|
|
|
|
// WritePCXfile
|
|
|
|
//
|
2017-03-08 17:47:52 +00:00
|
|
|
void WritePCXfile (FileWriter *file, const uint8_t *buffer, const PalEntry *palette,
|
2016-03-01 15:47:10 +00:00
|
|
|
ESSType color_type, int width, int height, int pitch)
|
|
|
|
{
|
2019-10-24 07:42:39 +00:00
|
|
|
TArray<uint8_t> temprow_storage(width * 3, true);
|
|
|
|
uint8_t *temprow = &temprow_storage[0];
|
2017-03-08 17:47:52 +00:00
|
|
|
const uint8_t *data;
|
2016-03-01 15:47:10 +00:00
|
|
|
int x, y;
|
|
|
|
int runlen;
|
|
|
|
int bytes_per_row_minus_one;
|
2017-03-08 17:47:52 +00:00
|
|
|
uint8_t color;
|
2016-03-01 15:47:10 +00:00
|
|
|
pcx_t pcx;
|
|
|
|
|
|
|
|
pcx.manufacturer = 10; // PCX id
|
|
|
|
pcx.version = 5; // 256 (or more) colors
|
|
|
|
pcx.encoding = 1;
|
|
|
|
pcx.bits_per_pixel = 8; // 256 (or more) colors
|
|
|
|
pcx.xmin = 0;
|
|
|
|
pcx.ymin = 0;
|
|
|
|
pcx.xmax = LittleShort((unsigned short)(width-1));
|
|
|
|
pcx.ymax = LittleShort((unsigned short)(height-1));
|
|
|
|
pcx.hdpi = LittleShort((unsigned short)75);
|
|
|
|
pcx.vdpi = LittleShort((unsigned short)75);
|
|
|
|
memset (pcx.palette, 0, sizeof(pcx.palette));
|
|
|
|
pcx.reserved = 0;
|
|
|
|
pcx.color_planes = (color_type == SS_PAL) ? 1 : 3; // chunky image
|
|
|
|
pcx.bytes_per_line = width + (width & 1);
|
|
|
|
pcx.palette_type = 1; // not a grey scale
|
|
|
|
memset (pcx.filler, 0, sizeof(pcx.filler));
|
|
|
|
|
2016-09-21 07:01:12 +00:00
|
|
|
file->Write(&pcx, 128);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
bytes_per_row_minus_one = ((color_type == SS_PAL) ? width : width * 3) - 1;
|
|
|
|
|
|
|
|
// pack the image
|
|
|
|
for (y = height; y > 0; y--)
|
|
|
|
{
|
|
|
|
switch (color_type)
|
|
|
|
{
|
|
|
|
case SS_PAL:
|
|
|
|
data = buffer;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SS_RGB:
|
|
|
|
// Unpack RGB into separate planes.
|
|
|
|
for (int i = 0; i < width; ++i)
|
|
|
|
{
|
|
|
|
temprow[i ] = buffer[i*3];
|
|
|
|
temprow[i + width ] = buffer[i*3 + 1];
|
|
|
|
temprow[i + width * 2] = buffer[i*3 + 2];
|
|
|
|
}
|
|
|
|
data = temprow;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SS_BGRA:
|
|
|
|
// Unpack RGB into separate planes, discarding A.
|
|
|
|
for (int i = 0; i < width; ++i)
|
|
|
|
{
|
|
|
|
temprow[i ] = buffer[i*4 + 2];
|
|
|
|
temprow[i + width ] = buffer[i*4 + 1];
|
|
|
|
temprow[i + width * 2] = buffer[i*4];
|
|
|
|
}
|
|
|
|
data = temprow;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// Should never happen.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
buffer += pitch;
|
|
|
|
|
|
|
|
color = *data++;
|
|
|
|
runlen = 1;
|
|
|
|
|
|
|
|
for (x = bytes_per_row_minus_one; x > 0; x--)
|
|
|
|
{
|
|
|
|
if (*data == color)
|
|
|
|
{
|
|
|
|
runlen++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (runlen > 1 || color >= 0xc0)
|
|
|
|
{
|
|
|
|
while (runlen > 63)
|
|
|
|
{
|
|
|
|
putc (0xff, file);
|
|
|
|
putc (color, file);
|
|
|
|
runlen -= 63;
|
|
|
|
}
|
|
|
|
if (runlen > 0)
|
|
|
|
{
|
|
|
|
putc (0xc0 + runlen, file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (runlen > 0)
|
|
|
|
{
|
|
|
|
putc (color, file);
|
|
|
|
}
|
|
|
|
runlen = 1;
|
|
|
|
color = *data;
|
|
|
|
}
|
|
|
|
data++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (runlen > 1 || color >= 0xc0)
|
|
|
|
{
|
|
|
|
while (runlen > 63)
|
|
|
|
{
|
|
|
|
putc (0xff, file);
|
|
|
|
putc (color, file);
|
|
|
|
runlen -= 63;
|
|
|
|
}
|
|
|
|
if (runlen > 0)
|
|
|
|
{
|
|
|
|
putc (0xc0 + runlen, file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (runlen > 0)
|
|
|
|
{
|
|
|
|
putc (color, file);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (width & 1)
|
|
|
|
putc (0, file);
|
|
|
|
}
|
|
|
|
|
|
|
|
// write the palette
|
|
|
|
if (color_type == SS_PAL)
|
|
|
|
{
|
|
|
|
putc (12, file); // palette ID byte
|
|
|
|
for (x = 0; x < 256; x++, palette++)
|
|
|
|
{
|
|
|
|
putc (palette->r, file);
|
|
|
|
putc (palette->g, file);
|
|
|
|
putc (palette->b, file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// WritePNGfile
|
|
|
|
//
|
2017-03-08 17:47:52 +00:00
|
|
|
void WritePNGfile (FileWriter *file, const uint8_t *buffer, const PalEntry *palette,
|
2017-12-06 08:59:20 +00:00
|
|
|
ESSType color_type, int width, int height, int pitch, float gamma)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
char software[100];
|
|
|
|
mysnprintf(software, countof(software), GAMENAME " %s", GetVersionString());
|
2017-12-06 08:59:20 +00:00
|
|
|
if (!M_CreatePNG (file, buffer, palette, color_type, width, height, pitch, gamma) ||
|
2016-03-01 15:47:10 +00:00
|
|
|
!M_AppendPNGText (file, "Software", software) ||
|
|
|
|
!M_FinishPNG (file))
|
|
|
|
{
|
2019-03-18 23:37:43 +00:00
|
|
|
Printf ("%s\n", GStrings("TXT_SCREENSHOTERR"));
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// M_ScreenShot
|
|
|
|
//
|
|
|
|
static bool FindFreeName (FString &fullname, const char *extension)
|
|
|
|
{
|
|
|
|
FString lbmname;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i <= 9999; i++)
|
|
|
|
{
|
|
|
|
const char *gamename = gameinfo.ConfigName;
|
|
|
|
|
|
|
|
time_t now;
|
|
|
|
tm *tm;
|
|
|
|
|
|
|
|
time(&now);
|
|
|
|
tm = localtime(&now);
|
|
|
|
|
|
|
|
if (tm == NULL)
|
|
|
|
{
|
|
|
|
lbmname.Format ("%sScreenshot_%s_%04d.%s", fullname.GetChars(), gamename, i, extension);
|
|
|
|
}
|
|
|
|
else if (i == 0)
|
|
|
|
{
|
|
|
|
lbmname.Format ("%sScreenshot_%s_%04d%02d%02d_%02d%02d%02d.%s", fullname.GetChars(), gamename,
|
|
|
|
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
|
|
|
|
tm->tm_hour, tm->tm_min, tm->tm_sec,
|
|
|
|
extension);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lbmname.Format ("%sScreenshot_%s_%04d%02d%02d_%02d%02d%02d_%02d.%s", fullname.GetChars(), gamename,
|
|
|
|
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
|
|
|
|
tm->tm_hour, tm->tm_min, tm->tm_sec,
|
|
|
|
i, extension);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!FileExists (lbmname.GetChars()))
|
|
|
|
{
|
|
|
|
fullname = lbmname;
|
|
|
|
return true; // file doesn't exist
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void M_ScreenShot (const char *filename)
|
|
|
|
{
|
2016-09-21 07:01:12 +00:00
|
|
|
FileWriter *file;
|
2016-03-01 15:47:10 +00:00
|
|
|
FString autoname;
|
|
|
|
bool writepcx = (stricmp (screenshot_type, "pcx") == 0); // PNG is the default
|
|
|
|
|
|
|
|
// find a file name to save it to
|
|
|
|
if (filename == NULL || filename[0] == '\0')
|
|
|
|
{
|
|
|
|
size_t dirlen;
|
|
|
|
autoname = Args->CheckValue("-shotdir");
|
|
|
|
if (autoname.IsEmpty())
|
|
|
|
{
|
|
|
|
autoname = screenshot_dir;
|
|
|
|
}
|
|
|
|
dirlen = autoname.Len();
|
|
|
|
if (dirlen == 0)
|
|
|
|
{
|
|
|
|
autoname = M_GetScreenshotsPath();
|
|
|
|
dirlen = autoname.Len();
|
|
|
|
}
|
|
|
|
if (dirlen > 0)
|
|
|
|
{
|
|
|
|
if (autoname[dirlen-1] != '/' && autoname[dirlen-1] != '\\')
|
|
|
|
{
|
|
|
|
autoname += '/';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
autoname = NicePath(autoname);
|
|
|
|
CreatePath(autoname);
|
|
|
|
if (!FindFreeName (autoname, writepcx ? "pcx" : "png"))
|
|
|
|
{
|
|
|
|
Printf ("M_ScreenShot: Delete some screenshots\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
autoname = filename;
|
|
|
|
DefaultExtension (autoname, writepcx ? ".pcx" : ".png");
|
|
|
|
}
|
|
|
|
|
|
|
|
// save the screenshot
|
|
|
|
int pitch;
|
|
|
|
ESSType color_type;
|
2017-12-06 08:59:20 +00:00
|
|
|
float gamma;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2018-12-21 08:21:40 +00:00
|
|
|
auto buffer = screen->GetScreenshotBuffer(pitch, color_type, gamma);
|
|
|
|
if (buffer.Size() > 0)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-09-21 07:01:12 +00:00
|
|
|
file = FileWriter::Open(autoname);
|
2016-03-01 15:47:10 +00:00
|
|
|
if (file == NULL)
|
|
|
|
{
|
|
|
|
Printf ("Could not open %s\n", autoname.GetChars());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (writepcx)
|
|
|
|
{
|
2019-03-09 13:48:14 +00:00
|
|
|
WritePCXfile(file, buffer.Data(), nullptr, color_type,
|
2016-03-01 15:47:10 +00:00
|
|
|
screen->GetWidth(), screen->GetHeight(), pitch);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-09 13:48:14 +00:00
|
|
|
WritePNGfile(file, buffer.Data(), nullptr, color_type,
|
2017-12-06 08:59:20 +00:00
|
|
|
screen->GetWidth(), screen->GetHeight(), pitch, gamma);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
2016-09-21 07:01:12 +00:00
|
|
|
delete file;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
if (!screenshot_quiet)
|
|
|
|
{
|
2021-08-11 22:45:59 +00:00
|
|
|
ptrdiff_t slash = -1;
|
2016-03-01 15:47:10 +00:00
|
|
|
if (!longsavemessages) slash = autoname.LastIndexOfAny(":/\\");
|
|
|
|
Printf ("Captured %s\n", autoname.GetChars()+slash+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!screenshot_quiet)
|
|
|
|
{
|
|
|
|
Printf ("Could not create screenshot.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-29 11:30:36 +00:00
|
|
|
UNSAFE_CCMD (screenshot)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
if (argv.argc() == 1)
|
|
|
|
G_ScreenShot (NULL);
|
|
|
|
else
|
|
|
|
G_ScreenShot (argv[1]);
|
|
|
|
}
|
|
|
|
|
2022-08-14 19:03:20 +00:00
|
|
|
CCMD(openscreenshots)
|
|
|
|
{
|
|
|
|
size_t dirlen;
|
|
|
|
FString autoname;
|
|
|
|
autoname = Args->CheckValue("-shotdir");
|
|
|
|
if (autoname.IsEmpty())
|
|
|
|
{
|
|
|
|
autoname = screenshot_dir;
|
|
|
|
}
|
|
|
|
dirlen = autoname.Len();
|
|
|
|
if (dirlen == 0)
|
|
|
|
{
|
|
|
|
autoname = M_GetScreenshotsPath();
|
|
|
|
dirlen = autoname.Len();
|
|
|
|
}
|
|
|
|
if (dirlen > 0)
|
|
|
|
{
|
|
|
|
if (autoname[dirlen-1] != '/' && autoname[dirlen-1] != '\\')
|
|
|
|
{
|
|
|
|
autoname += '/';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
autoname = NicePath(autoname);
|
|
|
|
|
|
|
|
CreatePath(autoname);
|
|
|
|
|
|
|
|
I_OpenShellFolder(autoname.GetChars());
|
|
|
|
}
|
|
|
|
|