diff options
author | Filippos Karapetis | 2009-05-10 13:47:38 +0000 |
---|---|---|
committer | Filippos Karapetis | 2009-05-10 13:47:38 +0000 |
commit | 53f24f3e43f78e974367dfe2c87951e7d2589689 (patch) | |
tree | bf114ab85c20f8626d4d712b233d1f2710543360 /engines/sci | |
parent | dd84aaf648b57220180b84a9aa0825d16bcea5bc (diff) | |
download | scummvm-rg350-53f24f3e43f78e974367dfe2c87951e7d2589689.tar.gz scummvm-rg350-53f24f3e43f78e974367dfe2c87951e7d2589689.tar.bz2 scummvm-rg350-53f24f3e43f78e974367dfe2c87951e7d2589689.zip |
Applied patch by waltervn to remove the length parameter from getText() and fixed a silly bug in getLength()
svn-id: r40421
Diffstat (limited to 'engines/sci')
-rw-r--r-- | engines/sci/engine/kstring.cpp | 68 | ||||
-rw-r--r-- | engines/sci/engine/message.cpp | 18 | ||||
-rw-r--r-- | engines/sci/engine/message.h | 4 |
3 files changed, 40 insertions, 50 deletions
diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp index 36a3f992f3..827f2c4bc1 100644 --- a/engines/sci/engine/kstring.cpp +++ b/engines/sci/engine/kstring.cpp @@ -727,56 +727,49 @@ reg_t kGetFarText(EngineState *s, int funct_nr, int argc, reg_t *argv) { static MessageState state; reg_t kMessage(EngineState *s, int funct_nr, int argc, reg_t *argv) { + MessageTuple tuple; + if (!state.isInitialized()) message_state_initialize(s->resmgr, &state); switch (UKPV(0)) { - case 0 : { - char *buffer = argc == 7 ? kernel_dereference_char_pointer(s, argv[6], 0) : NULL; - MessageTuple tuple; - int module = UKPV(1); + case 0: + case 2: + case 3: + case 4: + case 5: + if (!state.loadRes(UKPV(1))) + return NULL_REG; tuple.noun = UKPV(2); tuple.verb = UKPV(3); tuple.cond = UKPV(4); tuple.seq = UKPV(5); + } + + switch (UKPV(0)) { + case 0 : + case 1 : + if (UKPV(0) == 0 ? state.getSpecific(&tuple) : state.getNext()) { + char *buffer = argc == 7 ? kernel_dereference_char_pointer(s, argv[6], state.getLength() + 1) : NULL; - if (state.loadRes(module) && state.getSpecific(&tuple)) { if (buffer) - state.getText(buffer, 100); + state.getText(buffer); // Talker id return make_reg(0, state.getTalker()); } else { - if (buffer) strcpy(buffer, DUMMY_MESSAGE); - return NULL_REG; - } - } - case 1 : { - char *buffer = argc == 7 ? kernel_dereference_char_pointer(s, argv[6], 0) : NULL; + char *buffer = argc == 7 ? kernel_dereference_char_pointer(s, argv[6], 0) : NULL; - if (state.getNext()) { if (buffer) - state.getText(buffer, 100); - // Talker id - return make_reg(0, state.getTalker()); - } else { - if (buffer) strcpy(buffer, DUMMY_MESSAGE); + strcpy(buffer, DUMMY_MESSAGE); + return NULL_REG; } - } - case 2 : { - MessageTuple tuple; - int module = UKPV(1); - tuple.noun = UKPV(2); - tuple.verb = UKPV(3); - tuple.cond = UKPV(4); - tuple.seq = UKPV(5); - - if (state.loadRes(module) && state.getSpecific(&tuple)) + case 2: + if (state.getSpecific(&tuple)) return make_reg(0, state.getLength() + 1); else return NULL_REG; } - } return NULL_REG; } @@ -785,8 +778,6 @@ reg_t kGetMessage(EngineState *s, int funct_nr, int argc, reg_t *argv) { if (!state.isInitialized()) message_state_initialize(s->resmgr, &state); - char *buffer = kernel_dereference_char_pointer(s, argv[3], 0); - MessageTuple tuple; tuple.noun = UKPV(0); int module = UKPV(1); @@ -794,12 +785,17 @@ reg_t kGetMessage(EngineState *s, int funct_nr, int argc, reg_t *argv) { tuple.cond = 0; tuple.seq = 0; - if (buffer && state.loadRes(module) && state.getSpecific(&tuple)) { - state.getText(buffer, 255); - return argv[3]; - } else { - return NULL_REG; + if (state.loadRes(module) && state.getSpecific(&tuple)) { + int len = state.getLength(); + char *buffer = kernel_dereference_char_pointer(s, argv[3], len + 1); + + if (buffer) { + state.getText(buffer); + return argv[3]; + } } + + return NULL_REG; } } // End of namespace Sci diff --git a/engines/sci/engine/message.cpp b/engines/sci/engine/message.cpp index 6766224247..2bed850a31 100644 --- a/engines/sci/engine/message.cpp +++ b/engines/sci/engine/message.cpp @@ -93,22 +93,16 @@ int MessageState::getTalker() { return *(_engineCursor.index_record + 4); } -int MessageState::getText(char *buffer, int length) { - int offset; - if (_version == 2101) - offset = READ_LE_UINT16(_engineCursor.index_record + 2); - else - offset = READ_LE_UINT16(_engineCursor.index_record + 5); - +void MessageState::getText(char *buffer) { + int offset = READ_LE_UINT16(_engineCursor.index_record + ((_version == 2101) ? 2 : 5)); char *stringptr = (char *)_engineCursor.resource_beginning + offset; - strncpy(buffer, stringptr, length); - - return strlen(buffer); + strcpy(buffer, stringptr); } int MessageState::getLength() { - char buffer[500]; - return getText(buffer, sizeof(buffer)); + int offset = READ_LE_UINT16(_engineCursor.index_record + ((_version == 2101) ? 2 : 5)); + char *stringptr = (char *)_engineCursor.resource_beginning + offset; + return strlen(stringptr); } int MessageState::loadRes(int module) { diff --git a/engines/sci/engine/message.h b/engines/sci/engine/message.h index 9f5b04cf7e..c125d1b898 100644 --- a/engines/sci/engine/message.h +++ b/engines/sci/engine/message.h @@ -46,7 +46,7 @@ struct IndexRecordCursor { //typedef int index_record_size_t(); typedef void parse_index_record_t(IndexRecordCursor *index_record, MessageTuple *t); typedef int get_talker_t(IndexRecordCursor *cursor); -typedef void get_text_t(IndexRecordCursor *cursor, char *buffer, int buffer_size); +typedef void get_text_t(IndexRecordCursor *cursor); typedef int index_record_count_t(byte *header); class MessageState { @@ -55,7 +55,7 @@ public: int getNext(); int getTalker(); int getLength(); - int getText(char *buffer, int length); + void getText(char *buffer); int loadRes(int module); int isInitialized() { return _initialized; } void initialize(ResourceManager *resmgr); |