[Scummvm-cvs-logs] CVS: scummvm/scumm intern.h,2.455,2.456 script_v72he.cpp,2.270,2.271 script_v80he.cpp,2.98,2.99
kirben
kirben at users.sourceforge.net
Fri Apr 22 00:13:02 CEST 2005
Update of /cvsroot/scummvm/scummvm/scumm
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26178/scumm
Modified Files:
intern.h script_v72he.cpp script_v80he.cpp
Log Message:
Add support for reading/writing to external config file in HE games.
Index: intern.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/intern.h,v
retrieving revision 2.455
retrieving revision 2.456
diff -u -d -r2.455 -r2.456
--- intern.h 21 Apr 2005 19:27:13 -0000 2.455
+++ intern.h 22 Apr 2005 07:12:27 -0000 2.456
@@ -823,6 +823,7 @@
virtual void decodeParseString(int a, int b);
void decodeScriptString(byte *dst, bool scriptString = false);
void copyScriptString(byte *dst, int dstSize);
+ void convertFilePath(byte *dst);
byte *heFindResourceData(uint32 tag, byte *ptr);
byte *heFindResource(uint32 tag, byte *ptr);
Index: script_v72he.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/script_v72he.cpp,v
retrieving revision 2.270
retrieving revision 2.271
diff -u -d -r2.270 -r2.271
--- script_v72he.cpp 21 Apr 2005 10:24:13 -0000 2.270
+++ script_v72he.cpp 22 Apr 2005 07:12:28 -0000 2.271
@@ -518,6 +518,42 @@
}
}
+void ScummEngine_v72he::convertFilePath(byte *dst) {
+ // Switch all \ to / for portablity
+ int len = resStrLen(dst) + 1;
+ for (int i = 0; i < len; i++) {
+ if (dst[i] == '\\')
+ dst[i] = '/';
+ }
+
+ // Strip path
+ int r = 0;
+ if (dst[0] == '.' && dst[1] == '/') {
+ r = 2;
+ } else if (dst[0] == 'c' && dst[1] == ':') {
+ for (r = len; r != 0; r--) {
+ if (dst[r - 1] == '/')
+ break;
+ }
+ }
+
+ File f;
+ char filePath[256], newFilePath[256];
+
+ sprintf(filePath, "%s%s", _gameDataPath.c_str(), dst + r);
+ if (f.exists(filePath)) {
+ sprintf(newFilePath, "%s%s", _gameDataPath.c_str(), dst + r);
+ } else {
+ sprintf(newFilePath, "%s%s", _saveFileMan->getSavePath(), dst + r);
+ }
+
+ len = resStrLen((const byte *)newFilePath);
+ memcpy(dst, newFilePath, len);
+ dst[len] = 0;
+
+ debug(0, "convertFilePath: newFilePath is %s", newFilePath);
+}
+
void ScummEngine_v72he::copyScriptString(byte *dst, int dstSize) {
byte string[1024];
byte chr;
@@ -1506,7 +1542,7 @@
c = pop();
id = readVar(array);
if (id == 0) {
- defineArray(array, kDwordArray, 0, 0, 0, b + c);
+ defineArray(array, kDwordArray, 0, 0, 0, b + c - 1);
}
while (c--) {
writeArray(array, 0, b + c, pop());
@@ -1670,7 +1706,7 @@
}
void ScummEngine_v72he::o72_openFile() {
- int mode, slot, len, i;
+ int mode, slot, i;
byte filename[256];
mode = pop();
@@ -1686,22 +1722,8 @@
strcpy((char *)filename, buf1);
}
- int r = 0;
- if (filename[0] == 'c' && filename[1] == ':') {
- // Strip path
- for (r = strlen((char*)filename); r != 0; r--) {
- if (filename[r - 1] == '\\')
- break;
- }
- } else {
- // Switch all \ to / for portablity
- len = resStrLen(filename) + 1;
- for (i = 0; i < len; i++) {
- if (filename[i] == '\\')
- filename[i] = '/';
- }
- }
- debug(0,"Final filename to %s", filename + r);
+ convertFilePath(filename);
+ debug(0,"Final filename to %s", filename);
slot = -1;
for (i = 0; i < 17; i++) {
@@ -1714,12 +1736,10 @@
if (slot != -1) {
switch(mode) {
case 1:
- _hFileTable[slot].open((char*)filename + r, File::kFileReadMode, _saveFileMan->getSavePath());
- if (_hFileTable[slot].isOpen() == false)
- _hFileTable[slot].open((char*)filename + r, File::kFileReadMode);
+ _hFileTable[slot].open((char*)filename, File::kFileReadMode);
break;
case 2:
- _hFileTable[slot].open((char*)filename + r, File::kFileWriteMode, _saveFileMan->getSavePath());
+ _hFileTable[slot].open((char*)filename, File::kFileWriteMode);
break;
default:
error("o72_openFile(): wrong open file mode %d", mode);
Index: script_v80he.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/script_v80he.cpp,v
retrieving revision 2.98
retrieving revision 2.99
diff -u -d -r2.98 -r2.99
--- script_v80he.cpp 18 Apr 2005 11:44:01 -0000 2.98
+++ script_v80he.cpp 22 Apr 2005 07:12:29 -0000 2.99
@@ -449,35 +449,47 @@
}
void ScummEngine_v80he::o80_readConfigFile() {
- byte name[128], section[128], filename[256];
- int type;
+ byte option[128], section[128], filename[256];
+ ArrayHeader *ah;
+ const char *entry;
+ int len, type;
// we pretend that we don't have .ini file
+ copyScriptString(option, sizeof(option));
copyScriptString(section, sizeof(section));
- copyScriptString(name, sizeof(name));
copyScriptString(filename, sizeof(filename));
+ convertFilePath(filename);
type = fetchScriptByte();
+ ConfMan.loadConfigFile((const char *)filename);
+
switch (type) {
case 43: // HE 100
case 6: // number
- push(0);
+ push(ConfMan.getInt((char *)option, (char *)section));
break;
case 77: // HE 100
case 7: // string
+ entry = (ConfMan.get((char *)option, (char *)section).c_str());
+
writeVar(0, 0);
- defineArray(0, kStringArray, 0, 0, 0, 0);
- writeArray(0, 0, 0, 0);
- push(readVar(0)); // var ID string
+ len = resStrLen((const byte *)entry);
+ ah = defineArray(0, kStringArray, 0, 0, 0, len);
+ memcpy(ah->data, entry, len);
+
+ push(readVar(0));
break;
default:
error("o80_readConfigFile: default type %d", type);
}
- debug(0, "o80_readConfigFile: Filename %s Section %s Name %s", filename, section, name);
+
+ ConfMan.loadDefaultConfigFile();
+
+ debug(0, "o80_readConfigFile: Filename %s Section %s Option %s", filename, section, option);
}
void ScummEngine_v80he::o80_writeConfigFile() {
- byte filename[256], section[256], name[256], string[1024];
+ byte filename[256], section[256], option[256], string[1024];
int type, value;
// we pretend that we don't have .ini file
@@ -487,22 +499,33 @@
case 43: // HE 100
case 6: // number
value = pop();
+ copyScriptString(option, sizeof(option));
copyScriptString(section, sizeof(section));
- copyScriptString(name, sizeof(name));
copyScriptString(filename, sizeof(filename));
- debug(1,"o80_writeConfigFile: Filename %s Section %s Name %s Value %d", filename, section, name, value);
+ convertFilePath(filename);
+
+ ConfMan.loadConfigFile((const char *)filename);
+ ConfMan.set((char *)option, value, (char *)section);
+ debug(0,"o80_writeConfigFile: Filename %s Section %s Option %s Value %d", filename, section, option, value);
break;
case 77: // HE 100
case 7: // string
copyScriptString(string, sizeof(string));
+ copyScriptString(option, sizeof(option));
copyScriptString(section, sizeof(section));
- copyScriptString(name, sizeof(name));
copyScriptString(filename, sizeof(filename));
- debug(1,"o80_writeConfigFile: Filename %s Section %s Name %s String %s", filename, section, name, string);
+ convertFilePath(filename);
+
+ ConfMan.loadConfigFile((const char *)filename);
+ ConfMan.set((char *)option, (char *)string, (char *)section);
+ debug(0,"o80_writeConfigFile: Filename %s Section %s Option %s String %s", filename, section, option, string);
break;
default:
error("o80_writeConfigFile: default type %d", type);
}
+
+ ConfMan.flushToDisk();
+ ConfMan.loadDefaultConfigFile();
}
void ScummEngine_v80he::o80_cursorCommand() {
More information about the Scummvm-git-logs
mailing list