Ticket #7547: iqpoints.diff
File iqpoints.diff, 4.8 KB (added by , 18 years ago) |
---|
-
script_v5.cpp
871 871 void ScummEngine_v5::saveVars() { 872 872 int a, b; 873 873 874 // FIXME: This opcode is currently a stub. It is needed for at least two things: 874 // This opcode is a stub, on purpose. As far as we know it is used 875 // for precisely two things. 875 876 // * storing save game names in Indy 3 (and maybe others) 876 877 // * storing the global IQ (Indy Quotient) in Indy 3 877 878 // The former is not so important as we have our own save system, but the 878 879 // latter one of course is a desirable feature. 879 // So implementing this would be nice indeed. Not sure what the filename 880 // should be -- either base it on the target name, or base it on the gameid. 881 // Both approaches have their merits, though. 880 // However, there are at least two problems: First off, it's questionable 881 // whether using the filename passed to this opcode is a good idea. 882 // It might clash with others, and is neither target nor gameid specific, 883 // which could lead to conflicts. 884 // Secondly, the scripts calling this opcode are only run when using the 885 // built-in save/load dialog of Indy3, which we don't. 886 // 887 // Hence, instead of all this, we store the relevant strings (7 resp. 9) 888 // ourselves with custom code in ScummEngine::saveOrLoad(). 882 889 883 890 while ((_opcode = fetchScriptByte()) != 0) { 884 891 switch (_opcode & 0x1F) { … … 911 918 void ScummEngine_v5::loadVars() { 912 919 int a, b; 913 920 914 // FIXME: See ScummEngine_v5::saveVars 921 // See ScummEngine_v5::saveVars for an explanation of this opcode and 922 // why it is only a stub. 915 923 916 // Common::hexdump(_scriptPointer, 64); 924 { 925 printf("loadVars()\n"); 926 int i; 927 char iqPointsFilename[32]; 928 sprintf(iqPointsFilename, "%s.___", _targetName.c_str()); 929 930 Common::InSaveFile *file = _saveFileMan->openForLoading(iqPointsFilename); 931 if (file != NULL) { 932 int len = file->size(); 933 byte *ptr9 = (byte *)malloc(len); 934 len = file->read(ptr9, len); // Read the future content of string 9 935 loadPtrToResource(rtString, 9, ptr9); 936 937 byte *ptr7 = getResourceAddress(rtString, 7); 938 939 int seriesIQ = 0; 940 for (i = 0; i <= 73; ++i) { 941 if (ptr9[i]) 942 ptr7[i] = ptr9[i]; 943 seriesIQ += ptr7[i]; 944 } 945 // TODO: Set var 245 to seriesIQ ??? 946 947 948 free(ptr9); 949 delete file; 950 } 951 } 952 917 953 while ((_opcode = fetchScriptByte()) != 0) { 918 954 switch (_opcode & 0x1F) { 919 955 case 0x01: // read a range of variables … … 1985 2021 file = _saveFileMan->openForLoading(filename); 1986 2022 if (file != NULL) { 1987 2023 byte *ptr; 1988 int len = 256, cnt = 0;2024 int len = file->size(); 1989 2025 ptr = (byte *)malloc(len); 1990 while (ptr) { 1991 int r = file->read(ptr + cnt, len - cnt); 1992 cnt += r; 1993 if (cnt < len) 1994 break; 1995 len *= 2; 1996 ptr = (byte *)realloc(ptr, len); 1997 } 1998 ptr[cnt] = '\0'; 2026 len = file->read(ptr, len); 1999 2027 loadPtrToResource(rtString, a, ptr); 2000 2028 free(ptr); 2001 2029 delete file; … … 2303 2331 _opcode = fetchScriptByte(); 2304 2332 switch (_opcode & 0x1F) { 2305 2333 case 1: /* loadstring */ 2306 loadPtrToResource(rtString, getVarOrDirectByte(PARAM_1), NULL); 2334 a = getVarOrDirectByte(PARAM_1); 2335 loadPtrToResource(rtString, a, NULL); 2307 2336 break; 2308 2337 case 2: /* copystring */ 2309 2338 a = getVarOrDirectByte(PARAM_1); -
saveload.cpp
1108 1108 1109 1109 s->saveLoadArrayOf(_bitVars, _numBitVariables >> 3, 1, sleByte); 1110 1110 1111 if (_game.id == GID_INDY3) { 1112 // Save/load the "series" IQ points for Indy3. See FR #1666521 for 1113 // some explanations as to why/how this code works. 1114 // We store string 7, but load string 9 (this is on purpose). 1115 char iqPointsFilename[32]; 1116 sprintf(iqPointsFilename, "%s.___", _targetName.c_str()); 1111 1117 1118 if (s->isSaving()) { 1119 Common::OutSaveFile *file = _saveFileMan->openForSaving(iqPointsFilename); 1120 if (file != NULL) { 1121 int size = getResourceSize(rtString, 7); 1122 byte *ptr = getResourceAddress(rtString, 7); 1123 file->write(ptr, size); 1124 delete file; 1125 } 1126 } else { 1127 Common::InSaveFile *file = _saveFileMan->openForLoading(iqPointsFilename); 1128 if (file != NULL) { 1129 int len = file->size(); 1130 byte *ptr9 = (byte *)malloc(len); 1131 len = file->read(ptr9, len); // Read the future content of string 9 1132 loadPtrToResource(rtString, 9, ptr9); 1133 1134 byte *ptr7 = getResourceAddress(rtString, 7); 1135 1136 int seriesIQ = 0; 1137 for (i = 0; i <= 73; ++i) { 1138 if (ptr9[i]) 1139 ptr7[i] = ptr9[i]; 1140 seriesIQ += ptr7[i]; 1141 } 1142 // TODO: Set var 245 to seriesIQ ??? 1143 1144 1145 free(ptr9); 1146 delete file; 1147 } 1148 } 1149 } 1150 1112 1151 // 1113 1152 // Save/load a list of the locked objects 1114 1153 //