Added a method to the resource manager, to limit the places where script exports are accessed, since for SCI11 and newer exports can be functions and objects (first step in removing scriptRelocateExportsSci11(), which is a gross hack and it fails in QFG1VGA)
svn-id: r49308
This commit is contained in:
parent
928eafcccf
commit
6f056c6c98
4 changed files with 31 additions and 20 deletions
|
@ -127,9 +127,7 @@ int game_init(EngineState *s) {
|
|||
|
||||
srand(g_system->getMillis()); // Initialize random number generator
|
||||
|
||||
// script_dissect(0, s->_selectorNames);
|
||||
// The first entry in the export table of script 0 points to the game object
|
||||
s->_gameObj = s->_segMan->lookupScriptExport(0, 0);
|
||||
s->_gameObj = g_sci->getResMan()->findGameObject();
|
||||
|
||||
#ifdef USE_OLD_MUSIC_FUNCTIONS
|
||||
if (s->sfx_init_flags & SFX_STATE_FLAG_NOSOUND)
|
||||
|
|
|
@ -111,12 +111,6 @@ public:
|
|||
*/
|
||||
SegmentId getScriptSegment(int script_nr, ScriptLoadType load);
|
||||
|
||||
// TODO: document this
|
||||
reg_t lookupScriptExport(int script_nr, int export_index) {
|
||||
SegmentId seg = getScriptSegment(script_nr, SCRIPT_GET_DONT_LOAD);
|
||||
return make_reg(seg, getScript(seg)->validateExportFunc(export_index));
|
||||
}
|
||||
|
||||
// TODO: document this
|
||||
reg_t getClassAddress(int classnr, ScriptLoadType lock, reg_t caller);
|
||||
|
||||
|
|
|
@ -1913,26 +1913,37 @@ bool ResourceManager::hasSci1Voc900() {
|
|||
|
||||
#define READ_UINT16(ptr) (!isSci11Mac() ? READ_LE_UINT16(ptr) : READ_BE_UINT16(ptr))
|
||||
|
||||
Common::String ResourceManager::findSierraGameId() {
|
||||
reg_t ResourceManager::findGameObject(bool addSci11ScriptOffset) {
|
||||
Resource *script = findResource(ResourceId(kResourceTypeScript, 0), false);
|
||||
// In SCI0-SCI1, the heap is embedded in the script. In SCI1.1+, it's separated
|
||||
Resource *heap = 0;
|
||||
byte *seeker = 0;
|
||||
Common::String sierraId;
|
||||
int extraBytes = 0;
|
||||
if (getSciVersion() == SCI_VERSION_0_EARLY || getSciVersion() >= SCI_VERSION_1_1)
|
||||
extraBytes = 2;
|
||||
|
||||
// Seek to the name selector of the first export
|
||||
if (getSciVersion() < SCI_VERSION_1_1) {
|
||||
const int nameSelector = 3;
|
||||
int extraSci0EarlyBytes = (getSciVersion() == SCI_VERSION_0_EARLY) ? 2 : 0;
|
||||
byte *exportPtr = script->data + extraSci0EarlyBytes + 4 + 2;
|
||||
seeker = script->data + READ_UINT16(script->data + READ_UINT16(exportPtr) + nameSelector * 2);
|
||||
} else {
|
||||
const int nameSelector = 5 + 3;
|
||||
heap = findResource(ResourceId(kResourceTypeHeap, 0), false);
|
||||
byte *exportPtr = script->data + 4 + 2 + 2;
|
||||
seeker = heap->data + READ_UINT16(heap->data + READ_UINT16(exportPtr) + nameSelector * 2);
|
||||
int16 offset = READ_UINT16(script->data + extraBytes + 4 + 2);
|
||||
|
||||
// In SCI1.1 and newer, the heap is appended at the end of the script,
|
||||
// so adjust the offset accordingly
|
||||
if (getSciVersion() >= SCI_VERSION_1_1 && addSci11ScriptOffset)
|
||||
offset += script->size;
|
||||
|
||||
return make_reg(1, offset);
|
||||
}
|
||||
|
||||
Common::String ResourceManager::findSierraGameId() {
|
||||
// In SCI0-SCI1, the heap is embedded in the script. In SCI1.1+, it's separated
|
||||
Resource *heap = 0;
|
||||
int nameSelector = 3;
|
||||
|
||||
if (getSciVersion() < SCI_VERSION_1_1) {
|
||||
heap = findResource(ResourceId(kResourceTypeScript, 0), false);
|
||||
} else {
|
||||
heap = findResource(ResourceId(kResourceTypeHeap, 0), false);
|
||||
nameSelector += 5;
|
||||
}
|
||||
|
||||
// Seek to the name selector of the first export
|
||||
byte *seeker = heap->data + READ_UINT16(heap->data + findGameObject(false).offset + nameSelector * 2);
|
||||
Common::String sierraId;
|
||||
sierraId += (const char *)seeker;
|
||||
|
||||
return sierraId;
|
||||
|
|
|
@ -296,6 +296,14 @@ public:
|
|||
*/
|
||||
Common::String findSierraGameId();
|
||||
|
||||
/**
|
||||
* Finds the location of the game object from script 0
|
||||
* @param addSci11ScriptOffset: Adjust the return value for SCI1.1 and newer
|
||||
* games. Needs to be false when the heap is accessed directly inside
|
||||
* findSierraGameId().
|
||||
*/
|
||||
reg_t findGameObject(bool addSci11ScriptOffset = true);
|
||||
|
||||
protected:
|
||||
// Maximum number of bytes to allow being allocated for resources
|
||||
// Note: maxMemory will not be interpreted as a hard limit, only as a restriction
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue