Made find_unique_script_block() a member of the Script class

svn-id: r49241
This commit is contained in:
Filippos Karapetis 2010-05-26 14:25:51 +00:00
parent d502bdf982
commit bfaba64c6a
3 changed files with 31 additions and 22 deletions

View file

@ -748,26 +748,6 @@ int gamestate_save(EngineState *s, Common::WriteStream *fh, const char* savename
return 0;
}
static byte *find_unique_script_block(EngineState *s, byte *buf, int type) {
bool oldScriptHeader = (getSciVersion() == SCI_VERSION_0_EARLY);
if (oldScriptHeader)
buf += 2;
do {
int seeker_type = READ_LE_UINT16(buf);
if (seeker_type == 0) break;
if (seeker_type == type) return buf;
int seeker_size = READ_LE_UINT16(buf + 2);
assert(seeker_size > 0);
buf += seeker_size;
} while (1);
return NULL;
}
// TODO: This should probably be turned into an EngineState or DataStack method.
static void reconstruct_stack(EngineState *retval) {
SegmentId stack_seg = retval->_segMan->findSegmentByType(SEG_TYPE_STACK);
@ -821,8 +801,8 @@ void SegManager::reconstructScripts(EngineState *s) {
s->_segMan->scriptRelocateExportsSci11(i);
}
} else {
scr->_exportTable = (uint16 *) find_unique_script_block(s, scr->_buf, SCI_OBJ_EXPORTS);
scr->_synonyms = find_unique_script_block(s, scr->_buf, SCI_OBJ_SYNONYMS);
scr->_exportTable = (uint16 *) scr->findBlock(SCI_OBJ_EXPORTS);
scr->_synonyms = scr->findBlock(SCI_OBJ_SYNONYMS);
scr->_exportTable += 3;
}
scr->_codeBlocks.clear();

View file

@ -395,6 +395,30 @@ int Script::getSynonymsNr() const {
return _numSynonyms;
}
byte *Script::findBlock(int type) {
byte *buf = _buf;
bool oldScriptHeader = (getSciVersion() == SCI_VERSION_0_EARLY);
if (oldScriptHeader)
buf += 2;
do {
int seekerType = READ_LE_UINT16(buf);
if (seekerType == 0)
break;
if (seekerType == type)
return buf;
int seekerSize = READ_LE_UINT16(buf + 2);
assert(seekerSize > 0);
buf += seekerSize;
} while (1);
return NULL;
}
// memory operations
void Script::mcpyInOut(int dst, const void *src, size_t n) {

View file

@ -498,6 +498,11 @@ public:
*/
int16 getHeap(uint16 offset) const;
/**
* Finds the pointer where a block of a specific type starts from
*/
byte *Script::findBlock(int type);
private:
void setScriptSize(int script_nr, ResourceManager *resMan);
};