[Scummvm-git-logs] scummvm-tools master -> 6ab94bec82fe871fdd73ee6392ac61723f446b70
aquadran
noreply at scummvm.org
Tue Nov 16 07:07:02 UTC 2021
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm-tools' repo located at https://github.com/scummvm/scummvm-tools .
Summary:
6ab94bec82 GRIM: Integrate grim engine tools
Commit: 6ab94bec82fe871fdd73ee6392ac61723f446b70
https://github.com/scummvm/scummvm-tools/commit/6ab94bec82fe871fdd73ee6392ac61723f446b70
Author: PaweÅ KoÅodziejski (aquadran at gmail.com)
Date: 2021-11-16T08:06:58+01:00
Commit Message:
GRIM: Integrate grim engine tools
Changed paths:
A common/zlib.cpp
A common/zlib.h
R engines/grim/lua/module.mk
R engines/grim/luac/module.mk
R engines/grim/module.mk
.gitignore
Makefile.common
common/endian.h
engines/grim/delua.cpp
engines/grim/diffr.cpp
engines/grim/emi/animb2txt.cpp
engines/grim/emi/filetools.h
engines/grim/emi/meshb2obj.cpp
engines/grim/emi/renderModel.cpp
engines/grim/emi/renderTil.cpp
engines/grim/emi/setb2set.cpp
engines/grim/emi/sklb2txt.cpp
engines/grim/emi/til2bmp.cpp
engines/grim/luac/luac.cpp
engines/grim/luac/luac.h
engines/grim/luac/opt.cpp
engines/grim/luac/rebase.cpp
engines/grim/patchex/cab.h
engines/grim/patchex/cabd.cpp
engines/grim/patchex/mszip.h
engines/grim/patchex/mszipd.cpp
engines/grim/patchex/patchex.cpp
engines/grim/patchr.cpp
diff --git a/.gitignore b/.gitignore
index c96619c..69e8dfa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,6 +19,7 @@
/extract_gob_cdi
/extract_ngi
/gob_loadcalc
+/grim_*
/msn_convert_mod
/pegasus_save_types
/ScummVM Tools.app
diff --git a/Makefile.common b/Makefile.common
index ea99c99..d0dfa53 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -37,7 +37,25 @@ PROGRAMS = \
msn_convert_mod \
scummvm-tools-cli \
extract_hadesch \
- extract_lokalizator
+ extract_lokalizator \
+ grim_animb2txt \
+ grim_bm2bmp \
+ grim_cosb2cos \
+ grim_delua \
+ grim_diffr \
+ grim_imc2wav \
+ grim_int2flt \
+ grim_luac \
+ grim_meshb2obj \
+ grim_mklab \
+ grim_patchex \
+ grim_patchr \
+ grim_set2fig \
+ grim_setb2set \
+ grim_sklb2txt \
+ grim_til2bmp \
+ grim_unlab \
+ grim_vima
ifdef USE_BOOST
PROGRAMS += \
@@ -80,6 +98,30 @@ UTILS := \
sound/voc.o \
sound/wave.o
+GRIM_LUA := \
+ engines/grim/lua/lapi.o \
+ engines/grim/lua/lauxlib.o \
+ engines/grim/lua/lbuffer.o \
+ engines/grim/lua/lbuiltin.o \
+ engines/grim/lua/ldo.o \
+ engines/grim/lua/lfunc.o \
+ engines/grim/lua/lgc.o \
+ engines/grim/lua/liolib.o \
+ engines/grim/lua/llex.o \
+ engines/grim/lua/lmathlib.o \
+ engines/grim/lua/lmem.o \
+ engines/grim/lua/lobject.o \
+ engines/grim/lua/lparser.o \
+ engines/grim/lua/lstate.o \
+ engines/grim/lua/lstring.o \
+ engines/grim/lua/lstrlib.o \
+ engines/grim/lua/ltable.o \
+ engines/grim/lua/ltask.o \
+ engines/grim/lua/ltm.o \
+ engines/grim/lua/lundump.o \
+ engines/grim/lua/lvm.o \
+ engines/grim/lua/lzio.o
+
decine_OBJS := engines/cine/decine.o
degob_OBJS := \
@@ -174,6 +216,89 @@ msn_convert_mod_OBJS := \
common/util.o \
engines/supernova/convert_mod.o
+grim_animb2txt_OBJS := \
+ engines/grim/emi/animb2txt.o \
+ engines/grim/lab.o
+
+grim_bm2bmp_OBJS := \
+ engines/grim/bm2bmp.o \
+ engines/grim/lab.o
+
+grim_cosb2cos_OBJS := \
+ engines/grim/emi/cosb2cos.o
+
+grim_delua_OBJS := \
+ engines/grim/delua.o \
+ $(GRIM_LUA)
+
+ifdef USE_ZLIB
+grim_diffr_OBJS := \
+ engines/grim/diffr.o \
+ $(UTILS) \
+ common/zlib.o
+grim_diffr_LIBS := $(LIBS)
+endif
+
+grim_imc2wav_OBJS := \
+ engines/grim/imc2wav.o
+
+grim_int2flt_OBJS := \
+ engines/grim/int2flt.o
+
+grim_luac_OBJS := \
+ engines/grim/luac/dump.o \
+ engines/grim/luac/luac.o \
+ engines/grim/luac/opcode.o \
+ engines/grim/luac/opt.o \
+ engines/grim/luac/print.o \
+ engines/grim/luac/rebase.o \
+ $(GRIM_LUA)
+
+grim_meshb2obj_OBJS := \
+ engines/grim/emi/meshb2obj.o \
+ engines/grim/lab.o
+
+grim_mklab_OBJS := \
+ engines/grim/mklab.o
+
+grim_patchex_OBJS := \
+ engines/grim/patchex/patchex.o \
+ engines/grim/patchex/mszipd.o \
+ engines/grim/patchex/cabd.o
+
+ifdef USE_ZLIB
+grim_patchr_OBJS := \
+ engines/grim/patchr.o \
+ $(UTILS) \
+ common/zlib.o
+grim_patchr_LIBS := $(LIBS)
+endif
+
+grim_set2fig_OBJS := \
+ engines/grim/set2fig.o
+
+grim_setb2set_OBJS := \
+ engines/grim/emi/setb2set.o \
+ engines/grim/lab.o
+
+grim_sklb2txt_OBJS := \
+ engines/grim/emi/sklb2txt.o \
+ engines/grim/lab.o
+
+ifdef USE_ZLIB
+grim_til2bmp_OBJS := \
+ engines/grim/emi/til2bmp.o \
+ engines/grim/lab.o
+grim_til2bmp_LIBS := $(LIBS)
+endif
+
+grim_unlab_OBJS := \
+ engines/grim/unlab.o \
+ engines/grim/lab.o
+
+grim_vima_OBJS := \
+ engines/grim/vima.o
+
pegasus_save_types_OBJS := \
engines/pegasus/pegasus_save_types.o \
$(UTILS)
diff --git a/common/endian.h b/common/endian.h
index 20ab962..5eb2c25 100644
--- a/common/endian.h
+++ b/common/endian.h
@@ -29,6 +29,8 @@
#include "common/scummsys.h"
+#define MKTAG(a0,a1,a2,a3) ((uint32)((a3) | ((a2) << 8) | ((a1) << 16) | ((a0) << 24)))
+
#if defined(INVERSE_MKID)
#define MKID_BE(a) ((uint32) \
(((a) >> 24) & 0x000000FF) | \
@@ -52,6 +54,17 @@ static inline uint16 SWAP_16(uint16 a) {
return uint16(((a >> 8) & 0xFF) | ((a << 8) & 0xFF00));
}
+#if defined(SCUMM_BIG_ENDIAN)
+ #define FROM_LE_32(a) SWAP_32(a)
+ #define FROM_LE_16(a) SWAP_16(a)
+ #define TO_LE_32(a) SWAP_32(a)
+ #define TO_LE_16(a) SWAP_16(a)
+#else
+ #define FROM_LE_32(a) ((uint32)(a))
+ #define FROM_LE_16(a) ((uint16)(a))
+ #define TO_LE_32(a) ((uint32)(a))
+ #define TO_LE_16(a) ((uint16)(a))
+#endif
FORCEINLINE uint16 READ_LE_UINT16(const void *ptr) {
const byte *b = (const byte *)ptr;
diff --git a/common/zlib.cpp b/common/zlib.cpp
new file mode 100644
index 0000000..28af7ed
--- /dev/null
+++ b/common/zlib.cpp
@@ -0,0 +1,251 @@
+/* ScummVM Tools
+ *
+ * ScummVM Tools is the legal property of its developers, whose
+ * names are too numerous to list here. Please refer to the
+ * COPYRIGHT file distributed with this source distribution.
+ *
+ * Additionally this file is based on the ScummVM source code.
+ * Copyright information for the ScummVM source code is
+ * available in the COPYRIGHT file of the ScummVM source
+ * distribution.
+ *
+ * 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 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include <iostream>
+#include <fstream>
+
+#include "common/scummsys.h"
+#include "common/endian.h"
+#include "common/zlib.h"
+
+#define MIN(x,y) (((x)<(y)) ? (x) : (y))
+
+#if defined(USE_ZLIB)
+
+GZipReadStream::GZipReadStream(std::ifstream *w, uint32 start, uint32 size_p) : _wrapped(w), _stream(), _start(start), _size(size_p) {
+ char buf[4];
+ assert(w != 0);
+
+ // Verify file header is correct
+ w->seekg(_start, std::ios::beg);
+ w->read(buf, 2);
+ uint16 header = READ_BE_UINT16(buf);
+ assert(header == 0x1F8B ||
+ ((header & 0x0F00) == 0x0800 && header % 31 == 0));
+
+ if (header == 0x1F8B && _size > 0) {
+ // Retrieve the original file size
+ w->seekg(_start + _size - 4, std::ios::beg);
+ w->read(buf, 4);
+ _origSize = READ_LE_UINT32(buf);
+ } else {
+ // Original size not available in zlib format
+ _origSize = 0;
+ }
+ _pos = 0;
+ w->seekg(_start, std::ios::beg);
+ _eos = false;
+
+ // Adding 32 to windowBits indicates to zlib that it is supposed to
+ // automatically detect whether gzip or zlib headers are used for
+ // the compressed file. This feature was added in zlib 1.2.0.4,
+ // released 10 August 2003.
+ // Note: This is *crucial* for savegame compatibility, do *not* remove!
+ _zlibErr = inflateInit2(&_stream, MAX_WBITS + 32);
+ if (_zlibErr != Z_OK)
+ return;
+
+ // Setup input buffer
+ _stream.next_in = _buf;
+ _stream.avail_in = 0;
+}
+
+GZipReadStream::~GZipReadStream() {
+ inflateEnd(&_stream);
+}
+
+bool GZipReadStream::err() const { return (_zlibErr != Z_OK) && (_zlibErr != Z_STREAM_END); }
+void GZipReadStream::clearErr() {
+ // only reset _eos; I/O errors are not recoverable
+ _eos = false;
+}
+
+uint32 GZipReadStream::read(void *dataPtr, uint32 dataSize) {
+ _stream.next_out = (byte *)dataPtr;
+ _stream.avail_out = dataSize;
+
+ // Keep going while we get no error
+ while (_zlibErr == Z_OK && _stream.avail_out) {
+ if (_stream.avail_in == 0 && !_wrapped->eof()) {
+ // If we are out of input data: Read more data, if available.
+ _wrapped->read((char*)_buf, BUFSIZE);
+ _stream.next_in = _buf;
+ _stream.avail_in = _wrapped->gcount();
+ }
+ _zlibErr = inflate(&_stream, Z_NO_FLUSH);
+ }
+
+ // Update the position counter
+ _pos += dataSize - _stream.avail_out;
+
+ if (_zlibErr == Z_STREAM_END && _stream.avail_out > 0)
+ _eos = true;
+
+ return dataSize - _stream.avail_out;
+}
+
+bool GZipReadStream::eos() const {
+ return _eos;
+}
+
+int32 GZipReadStream::pos() const {
+ return _pos;
+}
+
+int32 GZipReadStream::size() const {
+ return _origSize;
+}
+
+bool GZipReadStream::seek(int32 offset, std::ios::seekdir whence) {
+ int32 newPos = 0;
+ assert(whence != std::ios::end); // std::ios::end not supported
+ switch (whence) {
+ case std::ios::beg:
+ newPos = offset;
+ break;
+ case std::ios::cur:
+ newPos = _pos + offset;
+ default:
+ assert(false);
+ }
+
+ assert(newPos >= 0);
+
+ if ((uint32)newPos < _pos) {
+ // To search backward, we have to restart the whole decompression
+ // from the start of the file. A rather wasteful operation, best
+ // to avoid it. :/
+#if DEBUG
+ warning("Backward seeking in GZipReadStream detected");
+#endif
+ _pos = 0;
+ _wrapped->seekg(_start, std::ios_base::beg);
+ _zlibErr = inflateReset(&_stream);
+ if (_zlibErr != Z_OK)
+ return false; // FIXME: STREAM REWRITE
+ _stream.next_in = _buf;
+ _stream.avail_in = 0;
+ }
+
+ offset = newPos - _pos;
+
+ // Skip the given amount of data (very inefficient if one tries to skip
+ // huge amounts of data, but usually client code will only skip a few
+ // bytes, so this should be fine.
+ byte tmpBuf[1024];
+ while (!err() && offset > 0) {
+ offset -= read(tmpBuf, MIN((int32)sizeof(tmpBuf), offset));
+ }
+
+ _eos = false;
+ return true; // FIXME: STREAM REWRITE
+}
+
+void GZipWriteStream::processData(int flushType) {
+ // This function is called by both write() and finalize().
+ while (_zlibErr == Z_OK && (_stream.avail_in || flushType == Z_FINISH)) {
+ if (_stream.avail_out == 0) {
+ _wrapped->write((char*)_buf, BUFSIZE);
+ if (_wrapped->bad()) {
+ _zlibErr = Z_ERRNO;
+ break;
+ }
+
+ _stream.next_out = _buf;
+ _stream.avail_out = BUFSIZE;
+ }
+ _zlibErr = deflate(&_stream, flushType);
+ }
+}
+
+GZipWriteStream::GZipWriteStream(std::ofstream *w) : _wrapped(w), _stream() {
+ assert(w != 0);
+
+ // Adding 16 to windowBits indicates to zlib that it is supposed to
+ // write gzip headers. This feature was added in zlib 1.2.0.4,
+ // released 10 August 2003.
+ // Note: This is *crucial* for savegame compatibility, do *not* remove!
+ _zlibErr = deflateInit2(&_stream,
+ Z_DEFAULT_COMPRESSION,
+ Z_DEFLATED,
+ MAX_WBITS + 16,
+ 8,
+ Z_DEFAULT_STRATEGY);
+ assert(_zlibErr == Z_OK);
+
+ _stream.next_out = _buf;
+ _stream.avail_out = BUFSIZE;
+ _stream.avail_in = 0;
+ _stream.next_in = 0;
+}
+
+GZipWriteStream::~GZipWriteStream() {
+ finalize();
+ deflateEnd(&_stream);
+}
+
+bool GZipWriteStream::err() const {
+ // CHECKME: does Z_STREAM_END make sense here?
+ return (_zlibErr != Z_OK && _zlibErr != Z_STREAM_END) || _wrapped->bad();
+}
+
+void GZipWriteStream::finalize() {
+ if (_zlibErr != Z_OK)
+ return;
+
+ // Process whatever remaining data there is.
+ processData(Z_FINISH);
+
+ // Since processData only writes out blocks of size BUFSIZE,
+ // we may have to flush some stragglers.
+ uint remainder = BUFSIZE - _stream.avail_out;
+ if (remainder > 0) {
+ _wrapped->write((char*)_buf, remainder);
+ if (_wrapped->bad())
+ _zlibErr = Z_ERRNO;
+ }
+
+ // Finalize the wrapped savefile, too
+ _wrapped->flush();
+}
+
+uint32 GZipWriteStream::write(const void *dataPtr, uint32 dataSize) {
+ if (err())
+ return 0;
+
+ // Hook in the new data ...
+ // Note: We need to make a const_cast here, as zlib is not aware
+ // of the const keyword.
+ _stream.next_in = const_cast<byte *>((const byte *)dataPtr);
+ _stream.avail_in = dataSize;
+
+ // ... and flush it to disk
+ processData(Z_NO_FLUSH);
+
+ return dataSize - _stream.avail_in;
+}
+
+#endif
diff --git a/common/zlib.h b/common/zlib.h
new file mode 100644
index 0000000..6f3c4c6
--- /dev/null
+++ b/common/zlib.h
@@ -0,0 +1,106 @@
+/* ScummVM Tools
+ *
+ * ScummVM Tools is the legal property of its developers, whose
+ * names are too numerous to list here. Please refer to the
+ * COPYRIGHT file distributed with this source distribution.
+ *
+ * Additionally this file is based on the ScummVM source code.
+ * Copyright information for the ScummVM source code is
+ * available in the COPYRIGHT file of the ScummVM source
+ * distribution.
+ *
+ * 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 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef COMMON_ZLIB_H
+#define COMMON_ZLIB_H
+
+#if defined(USE_ZLIB)
+ #ifdef __SYMBIAN32__
+ #include <zlib\zlib.h>
+ #else
+ #include <zlib.h>
+ #endif
+
+ #if ZLIB_VERNUM < 0x1204
+ #error Version 1.2.0.4 or newer of zlib is required for this code
+ #endif
+
+/**
+ * A simple wrapper class which can be used to wrap around an arbitrary
+ * other std::ifstream and will then provide on-the-fly decompression support.
+ * Assumes the compressed data to be in gzip format.
+ */
+class GZipReadStream {
+protected:
+ enum {
+ BUFSIZE = 16384 // 1 << MAX_WBITS
+ };
+
+ byte _buf[BUFSIZE];
+
+ std::ifstream *_wrapped;
+ z_stream _stream;
+ int _zlibErr;
+ uint32 _pos;
+ uint32 _origSize;
+ bool _eos;
+ uint32 _start, _size;
+
+public:
+ GZipReadStream(std::ifstream *w, uint32 start, uint32 size = 0);
+ ~GZipReadStream();
+ bool err() const;
+ void clearErr();
+
+ uint32 read(void *dataPtr, uint32 dataSize);
+
+ bool eos() const;
+ int32 pos() const;
+ int32 size() const;
+ bool seek(int32 offset, std::ios::seekdir whence = std::ios::beg);
+};
+
+/**
+ * A simple wrapper class which can be used to wrap around an arbitrary
+ * other std::ofstream and will then provide on-the-fly compression support.
+ * The compressed data is written in the gzip format.
+ */
+class GZipWriteStream {
+protected:
+ enum {
+ BUFSIZE = 16384 // 1 << MAX_WBITS
+ };
+
+ byte _buf[BUFSIZE];
+ std::ofstream *_wrapped;
+ z_stream _stream;
+ int _zlibErr;
+
+ void processData(int flushType);
+
+public:
+ GZipWriteStream(std::ofstream *w);
+ ~GZipWriteStream();
+
+ bool err() const;
+ void finalize();
+
+ uint32 write(const void *dataPtr, uint32 dataSize);
+};
+
+#endif
+
+#endif
diff --git a/engines/grim/delua.cpp b/engines/grim/delua.cpp
index bcdf03e..c529dad 100644
--- a/engines/grim/delua.cpp
+++ b/engines/grim/delua.cpp
@@ -20,10 +20,10 @@
*
*/
-#include <tools/lua/lua.h>
-#include <tools/lua/lundump.h>
-#include <tools/lua/lopcodes.h>
-#include <tools/lua/lzio.h>
+#include <engines/grim/lua/lua.h>
+#include <engines/grim/lua/lundump.h>
+#include <engines/grim/lua/lopcodes.h>
+#include <engines/grim/lua/lzio.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/engines/grim/diffr.cpp b/engines/grim/diffr.cpp
index d22f6b2..e3e1f72 100644
--- a/engines/grim/diffr.cpp
+++ b/engines/grim/diffr.cpp
@@ -49,10 +49,10 @@
#include <iostream>
#include <fstream>
+#include <algorithm>
#include "common/endian.h"
#include "common/zlib.h"
#include "common/md5.h"
-#include "common/getopt.h"
#define MIN(x,y) (((x)<(y)) ? (x) : (y))
@@ -239,49 +239,15 @@ static int32 search(int32 *I, byte *old, int32 oldsize,
}
typedef struct {
- char *oldfile;
- char *newfile;
- char *patchfile;
+ const char *oldfile;
+ const char *newfile;
+ const char *patchfile;
bool mix;
bool comp_ctrl;
} arguments;
void show_usage(char *name) {
- printf("usage: %s [-m][-n] oldfile newfile patchfile\n", name);
-}
-
-arguments parse_args(int argc, char *argv[]) {
- arguments arg;
- arg.comp_ctrl = true;
- arg.mix = false;
-
- int c;
- while ((c = getopt(argc, argv, "nm")) != -1)
- switch (c) {
- case 'n':
- arg.comp_ctrl = false;
- break;
- case 'm':
- arg.mix = true;
- break;
- case '?':
- show_usage(argv[0]);
- exit(0);
- default:
- fprintf(stderr, "Internal error\n");
- exit(1);
- }
-
- if (argc - optind < 3) {
- show_usage(argv[0]);
- exit(0);
- }
-
- arg.oldfile = argv[optind++];
- arg.newfile = argv[optind++];
- arg.patchfile = argv[optind++];
-
- return arg;
+ printf("usage: %s [-m] [-n] oldfile newfile patchfile\n", name);
}
int main(int argc, char *argv[]) {
@@ -302,8 +268,35 @@ int main(int argc, char *argv[]) {
std::ofstream patch;
std::ifstream in;
arguments args;
+ args.comp_ctrl = true;
+ args.mix = false;
+
+ std::deque<std::string> arg;
+ for (int a = 1; a < argc; a++)
+ arg.push_back(argv[a]);
+ if (argc < 2) {
+ show_usage(argv[0]);
+ return 1;
+ }
+
+ std::string option = arg.front();
+ if (option == "-n") {
+ arg.pop_front();
+ args.comp_ctrl = false;
+ }
+ option = arg.front();
+ if (option == "-n") {
+ arg.pop_front();
+ args.mix = true;
+ }
+ if (arg.size() < 3) {
+ show_usage(argv[0]);
+ return 1;
+ }
- args = parse_args(argc, argv);
+ args.oldfile = arg[0].c_str();
+ args.newfile = arg[1].c_str();
+ args.patchfile = arg[2].c_str();
//Set flags
if (args.mix) {
diff --git a/engines/grim/emi/animb2txt.cpp b/engines/grim/emi/animb2txt.cpp
index 67c387a..adb8a0d 100644
--- a/engines/grim/emi/animb2txt.cpp
+++ b/engines/grim/emi/animb2txt.cpp
@@ -26,7 +26,7 @@
#include <string>
#include <iostream>
#include "filetools.h"
-#include "tools/lab.h"
+#include "engines/grim/lab.h"
using namespace std;
diff --git a/engines/grim/emi/filetools.h b/engines/grim/emi/filetools.h
index 8deaa84..a70552a 100644
--- a/engines/grim/emi/filetools.h
+++ b/engines/grim/emi/filetools.h
@@ -28,6 +28,26 @@
#include <sstream>
#include "common/endian.h"
+#if defined(SCUMM_BIG_ENDIAN)
+
+inline float get_float(const char *data) {
+ const unsigned char *udata = reinterpret_cast<const unsigned char *>(data);
+ unsigned char fdata[4];
+ fdata[0] = udata[3];
+ fdata[1] = udata[2];
+ fdata[2] = udata[1];
+ fdata[3] = udata[0];
+ return *(reinterpret_cast<const float *>(fdata));
+}
+
+#else
+
+inline float get_float(const char *data) {
+ return *(reinterpret_cast<const float *>(data));
+}
+
+#endif
+
template<typename T>
struct Vector3 {
T _x;
@@ -104,7 +124,7 @@ std::string readString(std::istream &file) {
file.read(readString, strLength);
std::string retVal(readString);
- delete readString;
+ delete[] readString;
return retVal;
}
diff --git a/engines/grim/emi/meshb2obj.cpp b/engines/grim/emi/meshb2obj.cpp
index 0bce143..86fc2f2 100644
--- a/engines/grim/emi/meshb2obj.cpp
+++ b/engines/grim/emi/meshb2obj.cpp
@@ -24,7 +24,7 @@
#include <string>
#include <iostream>
#include "filetools.h"
-#include "tools/lab.h"
+#include "engines/grim/lab.h"
int main(int argc, char **argv) {
if (argc < 2) {
diff --git a/engines/grim/emi/renderModel.cpp b/engines/grim/emi/renderModel.cpp
index ee372ed..76d33f7 100644
--- a/engines/grim/emi/renderModel.cpp
+++ b/engines/grim/emi/renderModel.cpp
@@ -31,7 +31,7 @@
#include <GL/glfw.h>
#include "filetools.h"
#include "model.h"
-#include "lab.h"
+#include "engines/grim/lab.h"
using namespace std;
diff --git a/engines/grim/emi/renderTil.cpp b/engines/grim/emi/renderTil.cpp
index 235bddb..905524e 100644
--- a/engines/grim/emi/renderTil.cpp
+++ b/engines/grim/emi/renderTil.cpp
@@ -31,8 +31,8 @@
#include <cstdio>
#include <cstring>
#include "common/endian.h"
-#include "tools/lab.h"
-#include "tools/emi/filetools.h"
+#include "engines/grim/lab.h"
+#include "engines/grim/emi/filetools.h"
#include <GLFW/glfw3.h>
/*
diff --git a/engines/grim/emi/setb2set.cpp b/engines/grim/emi/setb2set.cpp
index b5043b5..6d88ec4 100644
--- a/engines/grim/emi/setb2set.cpp
+++ b/engines/grim/emi/setb2set.cpp
@@ -28,7 +28,7 @@
#include <fstream>
#include <vector>
#include <sstream>
-#include "tools/lab.h"
+#include "engines/grim/lab.h"
using namespace std;
@@ -470,6 +470,6 @@ int main(int argc, char **argv) {
Data *data = new Data(buf);
Set *ourSet = new Set(data);
delete data;
- delete buf;
+ delete[] buf;
cout << ourSet->ToString();
}
diff --git a/engines/grim/emi/sklb2txt.cpp b/engines/grim/emi/sklb2txt.cpp
index bd20f55..9b1fde5 100644
--- a/engines/grim/emi/sklb2txt.cpp
+++ b/engines/grim/emi/sklb2txt.cpp
@@ -26,7 +26,7 @@
#include <string>
#include <iostream>
#include "filetools.h"
-#include "tools/lab.h"
+#include "engines/grim/lab.h"
using namespace std;
diff --git a/engines/grim/emi/til2bmp.cpp b/engines/grim/emi/til2bmp.cpp
index 797cd9c..0f12355 100644
--- a/engines/grim/emi/til2bmp.cpp
+++ b/engines/grim/emi/til2bmp.cpp
@@ -31,7 +31,7 @@
#include <cstdio>
#include <cstring>
#include "common/endian.h"
-#include "tools/lab.h"
+#include "engines/grim/lab.h"
/*
This tool converts EMI-TILEs into BMP-files, and supports both the format used in the Windows
diff --git a/engines/grim/lua/module.mk b/engines/grim/lua/module.mk
deleted file mode 100644
index 4e80862..0000000
--- a/engines/grim/lua/module.mk
+++ /dev/null
@@ -1,28 +0,0 @@
-MODULE := tools/lua
-
-MODULE_OBJS := \
- lapi.o \
- lauxlib.o \
- lbuffer.o \
- lbuiltin.o \
- ldo.o \
- lfunc.o \
- lgc.o \
- liolib.o \
- llex.o \
- lmathlib.o \
- lmem.o \
- lobject.o \
- lparser.o \
- lstate.o \
- lstring.o \
- lstrlib.o \
- ltable.o \
- ltask.o \
- ltm.o \
- lundump.o \
- lvm.o \
- lzio.o
-
-# Include common rules
-include $(srcdir)/rules.mk
diff --git a/engines/grim/luac/luac.cpp b/engines/grim/luac/luac.cpp
index 6afb9a2..ec73f7e 100644
--- a/engines/grim/luac/luac.cpp
+++ b/engines/grim/luac/luac.cpp
@@ -8,9 +8,9 @@
#include <stdlib.h>
#include <string.h>
#include "luac.h"
-#include "tools/lua/lparser.h"
-#include "tools/lua/lzio.h"
-#include "tools/lua/luadebug.h"
+#include "engines/grim/lua/lparser.h"
+#include "engines/grim/lua/lzio.h"
+#include "engines/grim/lua/luadebug.h"
#define OUTPUT "luac.out" /* default output file */
diff --git a/engines/grim/luac/luac.h b/engines/grim/luac/luac.h
index 77f3eb1..ca5316b 100644
--- a/engines/grim/luac/luac.h
+++ b/engines/grim/luac/luac.h
@@ -4,12 +4,12 @@
** See Copyright Notice in lua.h
*/
-#include "tools/lua/lauxlib.h"
-#include "tools/lua/lfunc.h"
-#include "tools/lua/lobject.h"
-#include "tools/lua/lopcodes.h"
-#include "tools/lua/lstring.h"
-#include "tools/lua/lundump.h"
+#include "engines/grim/lua/lauxlib.h"
+#include "engines/grim/lua/lfunc.h"
+#include "engines/grim/lua/lobject.h"
+#include "engines/grim/lua/lopcodes.h"
+#include "engines/grim/lua/lstring.h"
+#include "engines/grim/lua/lundump.h"
#include "common/endian.h"
typedef struct
diff --git a/engines/grim/luac/module.mk b/engines/grim/luac/module.mk
deleted file mode 100644
index 02d38e8..0000000
--- a/engines/grim/luac/module.mk
+++ /dev/null
@@ -1,20 +0,0 @@
-MODULE := tools/luac
-
-TOOL_OBJS := \
- dump.o \
- luac.o \
- opcode.o \
- opt.o \
- print.o \
- rebase.o
-
-TOOL_LDFLAGS := tools/lua/liblua.a
-
-TOOL := luac
-TOOL_DEPS := tools/lua
-
-MAKE := luac
-
-# Include common rules
-include $(srcdir)/rules.mk
-
diff --git a/engines/grim/luac/opt.cpp b/engines/grim/luac/opt.cpp
index c0e13e4..4d0b21e 100644
--- a/engines/grim/luac/opt.cpp
+++ b/engines/grim/luac/opt.cpp
@@ -7,7 +7,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "luac.h"
-#include "tools/lua/lmem.h"
+#include "engines/grim/lua/lmem.h"
static void FixConstants(TProtoFunc* tf, int* C)
{
diff --git a/engines/grim/luac/rebase.cpp b/engines/grim/luac/rebase.cpp
index 71cc730..17b8d29 100644
--- a/engines/grim/luac/rebase.cpp
+++ b/engines/grim/luac/rebase.cpp
@@ -2,8 +2,8 @@
#include <stdlib.h>
#include <string.h>
#include "luac.h"
-#include "tools/lua/lmem.h"
-#include "tools/lua/lstring.h"
+#include "engines/grim/lua/lmem.h"
+#include "engines/grim/lua/lstring.h"
static const Opcode Info[]= /* ORDER lopcodes.h */
{
diff --git a/engines/grim/module.mk b/engines/grim/module.mk
deleted file mode 100644
index 4bedd51..0000000
--- a/engines/grim/module.mk
+++ /dev/null
@@ -1,122 +0,0 @@
-
-MODULE := tools
-
-#######################################################################
-# Tools directory
-#######################################################################
-
-MAKE := \
- delua \
- imc2wav \
- int2flt \
- cosb2cos \
- meshb2obj \
- sklb2txt \
- animb2txt \
- setb2set \
- set2fig \
- til2bmp \
- unlab \
- mklab \
- vima \
- luac \
- patchex \
- diffr \
- patchr \
- bm2bmp
-
-# these below are not added because they depend on the ppm and bpm libraries
-# mat2ppm
-# bm2ppm
-
-
-#
-# Build rules for the tools
-#
-
-TOOL := diffr
-TOOL_OBJS := diffr.o
-TOOL_LDFLAGS := -lcommon -lz
-include $(srcdir)/rules.mk
-
-TOOL := patchr
-TOOL_OBJS := patchr.o
-TOOL_LDFLAGS := -lcommon -lz
-include $(srcdir)/rules.mk
-
-TOOL := delua
-TOOL_OBJS := delua.o lua/liblua.a
-include $(srcdir)/rules.mk
-
-TOOL := mat2ppm
-TOOL_OBJS := mat2ppm.o
-TOOL_LDFLAGS := -lppm -lpbm
-include $(srcdir)/rules.mk
-
-TOOL := bmtoppm
-TOOL_OBJS := bmtoppm.o
-TOOL_LDFLAGS := -lppm -lpbm
-include $(srcdir)/rules.mk
-
-TOOL := imc2wav
-TOOL_OBJS := imc2wav.o
-include $(srcdir)/rules.mk
-
-TOOL := int2flt
-TOOL_OBJS := int2flt.o
-include $(srcdir)/rules.mk
-
-TOOL := cosb2cos
-TOOL_OBJS := emi/cosb2cos.o
-include $(srcdir)/rules.mk
-
-TOOL := meshb2obj
-TOOL_OBJS := emi/meshb2obj.o lab.o
-include $(srcdir)/rules.mk
-
-TOOL := animb2txt
-TOOL_OBJS := emi/animb2txt.o lab.o
-include $(srcdir)/rules.mk
-
-TOOL := setb2set
-TOOL_OBJS := emi/setb2set.o lab.o
-include $(srcdir)/rules.mk
-
-TOOL := sklb2txt
-TOOL_OBJS := emi/sklb2txt.o lab.o
-include $(srcdir)/rules.mk
-
-TOOL := set2fig
-TOOL_OBJS := set2fig.o
-include $(srcdir)/rules.mk
-
-TOOL := til2bmp
-TOOL_OBJS := emi/til2bmp.o lab.o
-TOOL_LDFLAGS := -lz
-include $(srcdir)/rules.mk
-
-TOOL := unlab
-TOOL_OBJS := unlab.o lab.o
-include $(srcdir)/rules.mk
-
-TOOL := mklab
-TOOL_OBJS := mklab.o
-include $(srcdir)/rules.mk
-
-TOOL := vima
-TOOL_OBJS := vima.o
-include $(srcdir)/rules.mk
-
-TOOL := labcopy
-TOOL_OBJS := labcopy.o
-include $(srcdir)/rules.mk
-
-TOOL := patchex
-TOOL_OBJS := patchex/patchex.o patchex/mszipd.o patchex/cabd.o
-include $(srcdir)/rules.mk
-
-TOOL := bm2bmp
-TOOL_OBJS := bm2bmp.o lab.o
-include $(srcdir)/rules.mk
-
-.PHONY: clean-tools tools
diff --git a/engines/grim/patchex/cab.h b/engines/grim/patchex/cab.h
index e548299..841d845 100644
--- a/engines/grim/patchex/cab.h
+++ b/engines/grim/patchex/cab.h
@@ -34,7 +34,7 @@
#ifndef MSPACK_CAB_H
#define MSPACK_CAB_H
-#include "tools/patchex/mszip.h"
+#include "engines/grim/patchex/mszip.h"
#define cfhead_Signature (0x00)
#define cfhead_CabinetSize (0x08)
diff --git a/engines/grim/patchex/cabd.cpp b/engines/grim/patchex/cabd.cpp
index 65ce046..9433507 100644
--- a/engines/grim/patchex/cabd.cpp
+++ b/engines/grim/patchex/cabd.cpp
@@ -31,7 +31,7 @@
* For further details, see the file COPYING.LIB distributed with libmspack
*/
-#include "tools/patchex/cab.h"
+#include "engines/grim/patchex/cab.h"
static struct mscabd_cabinet * cabd_open(
struct mscab_decompressor *base, char *filename);
diff --git a/engines/grim/patchex/mszip.h b/engines/grim/patchex/mszip.h
index 3a4962e..1953b53 100644
--- a/engines/grim/patchex/mszip.h
+++ b/engines/grim/patchex/mszip.h
@@ -37,7 +37,7 @@
#ifndef MSPACK_MSZIP_H
#define MSPACK_MSZIP_H 1
-#include "tools/patchex/mspack.h"
+#include "engines/grim/patchex/mspack.h"
#define MSZIP_FRAME_SIZE (32768)
#define MSZIP_MAX_HUFFBITS (16)
diff --git a/engines/grim/patchex/mszipd.cpp b/engines/grim/patchex/mszipd.cpp
index 0cced00..78d89e9 100644
--- a/engines/grim/patchex/mszipd.cpp
+++ b/engines/grim/patchex/mszipd.cpp
@@ -34,7 +34,7 @@
* For further details, see the file COPYING.LIB distributed with libmspack
*/
-#include "tools/patchex/mszip.h"
+#include "engines/grim/patchex/mszip.h"
static const unsigned short lit_lengths[29] = {
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27,
diff --git a/engines/grim/patchex/patchex.cpp b/engines/grim/patchex/patchex.cpp
index c4b9893..3518956 100644
--- a/engines/grim/patchex/patchex.cpp
+++ b/engines/grim/patchex/patchex.cpp
@@ -40,7 +40,7 @@
#include <stdarg.h>
#include <sys/types.h>
-#include "tools/patchex/mspack.h"
+#include "engines/grim/patchex/mspack.h"
#include "common/endian.h"
// Languages codes
diff --git a/engines/grim/patchr.cpp b/engines/grim/patchr.cpp
index 4185042..2a5811b 100644
--- a/engines/grim/patchr.cpp
+++ b/engines/grim/patchr.cpp
@@ -53,7 +53,6 @@
#include "common/endian.h"
#include "common/zlib.h"
#include "common/md5.h"
-#include "common/getopt.h"
uint8 *old_block, *new_block;
GZipReadStream *ctrlDec, *diffDec, *extraDec;
@@ -95,9 +94,9 @@ void show_header_info(uint8 *header) {
}
typedef struct {
- char *oldfile;
- char *newfile;
- char *patchfile;
+ const char *oldfile;
+ const char *newfile;
+ const char *patchfile;
bool show_info;
} arguments;
@@ -105,36 +104,6 @@ void show_usage(char *name) {
printf("usage: %s [-a] oldfile newfile patchfile\n", name);
}
-arguments parse_args(int argc, char *argv[]) {
- arguments arg;
- arg.show_info = false;
-
- int c;
- while ((c = getopt(argc, argv, "a")) != -1)
- switch (c) {
- case 'a':
- arg.show_info = true;
- break;
- case '?':
- show_usage(argv[0]);
- exit(0);
- default:
- fprintf(stderr, "Internal error\n");
- exit(1);
- }
-
- if (argc - optind < 3) {
- show_usage(argv[0]);
- exit(0);
- }
-
- arg.oldfile = argv[optind++];
- arg.newfile = argv[optind++];
- arg.patchfile = argv[optind++];
-
- return arg;
-}
-
int main(int argc, char *argv[]) {
uint32 oldsize, newsize;
uint32 zctrllen, zdatalen, zextralen;
@@ -148,12 +117,33 @@ int main(int argc, char *argv[]) {
std::ofstream newfile;
bool comp_ctrl, mix;
arguments args;
+ args.show_info = false;
old_block = 0;
new_block = 0;
atexit(free_memory);
- args = parse_args(argc, argv);
+ std::deque<std::string> arg;
+ for (int a = 1; a < argc; a++)
+ arg.push_back(argv[a]);
+ if (argc < 2) {
+ show_usage(argv[0]);
+ return 1;
+ }
+
+ std::string option = arg.front();
+ if (option == "-a") {
+ arg.pop_front();
+ args.show_info = true;
+ }
+ if (arg.size() < 3) {
+ show_usage(argv[0]);
+ return 1;
+ }
+
+ args.oldfile = arg[0].c_str();
+ args.newfile = arg[1].c_str();
+ args.patchfile = arg[2].c_str();
/* Opens the old file */
oldfile.open(args.oldfile, std::ios::in | std::ios::binary);
More information about the Scummvm-git-logs
mailing list