[Scummvm-git-logs] scummvm-tools master -> 86ebc2b4852f8fb4e7a374b9b9d408d4cbf32dc7

sev- noreply at scummvm.org
Sun Nov 20 15:58:21 UTC 2022


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm-tools' repo located at https://github.com/scummvm/scummvm-tools .

Summary:
49b12d9134 SAGA: A tool for unpacking Amiga resource archive
86ebc2b485 SAGA: Add a tool for decompressing resources other than amiga


Commit: 49b12d9134392b655bedb99932d788e6b2241651
    https://github.com/scummvm/scummvm-tools/commit/49b12d9134392b655bedb99932d788e6b2241651
Author: Vladimir Serbinenko (phcoder at gmail.com)
Date: 2022-11-20T16:58:18+01:00

Commit Message:
SAGA: A tool for unpacking Amiga resource archive

Changed paths:
  A engines/saga/unpack_amiga.cpp
    Makefile.common


diff --git a/Makefile.common b/Makefile.common
index c97a0723..91be2680 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -57,7 +57,8 @@ PROGRAMS = \
 	grim_sklb2txt \
 	grim_til2bmp \
 	grim_unlab \
-	grim_vima
+	grim_vima \
+	saga_unpack_amiga
 
 ifdef USE_BOOST
 PROGRAMS += \
@@ -151,6 +152,10 @@ extract_hadesch_OBJS := \
 	engines/hadesch/extract_hadesch.o \
 	$(UTILS)
 
+saga_unpack_amiga_OBJS := \
+	engines/saga/unpack_amiga.o \
+	$(UTILS)
+
 extract_hadesch_img_OBJS := \
 	engines/hadesch/extract_hadesch_img.o \
 	$(UTILS)
diff --git a/engines/saga/unpack_amiga.cpp b/engines/saga/unpack_amiga.cpp
new file mode 100644
index 00000000..581dd882
--- /dev/null
+++ b/engines/saga/unpack_amiga.cpp
@@ -0,0 +1,91 @@
+/* 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.
+ *
+ * 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.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "common/endian.h"
+#include "common/str.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+int main (int argc, char **argv) {
+	unsigned char *rtnbuf;
+	size_t sz;
+	FILE *rtnfin;
+
+	if (argc < 3) {
+		fprintf (stderr, "USAGE: %s BASEFILE OUTDIR\n", argv[0]);
+		return -1;
+	}
+
+	rtnfin = fopen (Common::String::format("%s.rtn", argv[1]).c_str(), "rb");
+	if (rtnfin == NULL) {
+		fprintf (stderr, "Unable to open %s: %s.rtn\n", argv[1], strerror(errno));
+		return -2;
+	}
+	fseek (rtnfin, 0, SEEK_END);
+	sz = ftell (rtnfin);
+	fseek (rtnfin, 0, SEEK_SET);
+
+	rtnbuf = (unsigned char *) malloc (sz);
+
+	fread (rtnbuf, 1, sz, rtnfin);
+	fclose (rtnfin);
+
+	int rescnt = READ_BE_UINT16(rtnbuf);
+	int scriptcnt = READ_BE_UINT16(rtnbuf + 2);
+
+	int ctr = 0;
+
+	fprintf (stderr, "%d resource files, %d script files\n", rescnt, scriptcnt);
+      
+	for (ctr = 0; ctr < rescnt + scriptcnt; ctr++) {
+		unsigned char * headptr = rtnbuf + 4 + 10 * ctr;
+		uint32 off = READ_BE_UINT32(headptr);
+		uint32 len = READ_BE_UINT32(headptr + 4);
+		uint16 vol = READ_BE_UINT16(headptr + 8);
+		Common::String finName = Common::String::format("%s.%03d", argv[1], vol);
+		Common::String foutName = Common::String::format("%s/%s_%d.bin", argv[2], ctr < rescnt ? "res" : "scr", ctr < rescnt ? ctr : ctr - rescnt);
+		FILE *finH = fopen(finName.c_str(), "rb");
+		if (!finH) {
+			fprintf(stderr, "Can't open %s.%03d", argv[1], vol);
+			continue;
+		}
+		FILE *foutH = fopen(foutName.c_str(), "wb");
+		if (!foutH) {
+			fprintf(stderr, "Can't open %s.%03d", argv[1], vol);
+			continue;
+		}
+		fseek(finH, off, SEEK_SET);
+		char buf[0x400];
+		size_t resSz = len;
+		while (resSz) {
+			int csz = resSz < sizeof(buf) ? resSz : sizeof(buf);
+			fread(buf, csz, 1, finH);
+			fwrite(buf, csz, 1, foutH);
+			resSz -= csz;
+		}
+		fclose(finH);
+		fclose(foutH);
+	}
+
+	return 0;
+}


Commit: 86ebc2b4852f8fb4e7a374b9b9d408d4cbf32dc7
    https://github.com/scummvm/scummvm-tools/commit/86ebc2b4852f8fb4e7a374b9b9d408d4cbf32dc7
Author: Vladimir Serbinenko (phcoder at gmail.com)
Date: 2022-11-20T16:58:18+01:00

Commit Message:
SAGA: Add a tool for decompressing resources other than amiga

Changed paths:
  A engines/saga/unpack_saga.cpp
    Makefile.common


diff --git a/Makefile.common b/Makefile.common
index 91be2680..2d069fd5 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -58,7 +58,8 @@ PROGRAMS = \
 	grim_til2bmp \
 	grim_unlab \
 	grim_vima \
-	saga_unpack_amiga
+	saga_unpack_amiga \
+	saga_unpack
 
 ifdef USE_BOOST
 PROGRAMS += \
@@ -152,6 +153,10 @@ extract_hadesch_OBJS := \
 	engines/hadesch/extract_hadesch.o \
 	$(UTILS)
 
+saga_unpack_OBJS := \
+	engines/saga/unpack_saga.o \
+	$(UTILS)
+
 saga_unpack_amiga_OBJS := \
 	engines/saga/unpack_amiga.o \
 	$(UTILS)
diff --git a/engines/saga/unpack_saga.cpp b/engines/saga/unpack_saga.cpp
new file mode 100644
index 00000000..97c30475
--- /dev/null
+++ b/engines/saga/unpack_saga.cpp
@@ -0,0 +1,113 @@
+/* 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.
+ *
+ * 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.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "common/file.h"
+#include "common/str.h"
+#include "common/util.h"
+
+#define RSC_TABLEINFO_SIZE 8
+#define RSC_TABLEENTRY_SIZE 8
+
+typedef struct  {
+	uint32 offset;
+	uint32 size;
+} Record;
+
+void unpack(Common::String inputName, Common::String outDirName, bool isBe = false) {
+	Common::File inputFile;
+	Common::File outputFile;
+	uint32 inputFileSize;
+	uint32 resTableOffset;
+	uint32 resTableCount;
+	uint32 i;
+
+	Record *inputTable;
+
+	inputFile.open(inputName, "rb");
+	inputFileSize = inputFile.size();
+	fprintf(stderr, "Filesize: %ul\n", inputFileSize);
+	/*
+	 * At the end of the resource file there are 2 values: one points to the
+	 * beginning of the resource table the other gives the number of
+	 * records in the table
+	 */
+	inputFile.seek(inputFileSize - RSC_TABLEINFO_SIZE, SEEK_SET);
+
+	if (!isBe) {
+		resTableOffset = inputFile.readUint32LE();
+		resTableCount = inputFile.readUint32LE();
+	} else {
+		resTableOffset = inputFile.readUint32BE();
+		resTableCount = inputFile.readUint32BE();
+	}
+
+	fprintf(stderr, "Table offset: %ul\nnumber of records: %ul\n", resTableOffset, resTableCount);
+	if (resTableOffset != inputFileSize - RSC_TABLEINFO_SIZE - RSC_TABLEENTRY_SIZE * resTableCount) {
+		error("Something's wrong with your resource file");
+	}
+
+	// Go to beginning of the table
+	inputFile.seek(resTableOffset, SEEK_SET);
+
+	inputTable = (Record*)malloc(resTableCount * sizeof(Record));
+
+	// Put offsets of all the records in a table
+	for (i = 0; i < resTableCount; i++) {
+
+		if (!isBe) {
+			inputTable[i].offset = inputFile.readUint32LE();
+			inputTable[i].size = inputFile.readUint32LE();
+		} else {
+			inputTable[i].offset = inputFile.readUint32BE();
+			inputTable[i].size = inputFile.readUint32BE();
+		}
+
+		fprintf(stderr, "Record: %ul, offset: %ul, size: %ul\n", i, inputTable[i].offset, inputTable[i].size);
+
+		if ((inputTable[i].offset > inputFileSize) ||
+			(inputTable[i].offset + inputTable[i].size > inputFileSize)) {
+			error("The offset points outside the file");
+		}
+
+	}
+
+	for (i = 0; i < resTableCount; i++) {
+		outputFile.open(Common::String::format("%s/%d.bin", outDirName.c_str(), i), "wb");
+		inputFile.seek(inputTable[i].offset, SEEK_SET);
+		byte *buf = new byte[inputTable[i].size];
+		inputFile.read_throwsOnError(buf, inputTable[i].size);
+		outputFile.write(buf, inputTable[i].size);
+		delete[]buf;
+	}
+	inputFile.close();
+
+	fprintf(stderr, "Done!\n");
+}
+
+int main(int argc, char *argv[]) {
+	unpack(argv[1], argv[2]);
+}
+
+




More information about the Scummvm-git-logs mailing list