[Scummvm-git-logs] scummvm master -> bfc271a1351f4a78e59076545e06d03744c0a63f

elasota noreply at scummvm.org
Tue May 16 06:05:37 UTC 2023


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
f5704b87b5 MTROPOLIS: Fix uninitialized member
bfc271a135 VCRUISE: Rework room number lookup for script sets to fix crash after activating the ship in Schizm.


Commit: f5704b87b57da8998f6d630bdf96c08eae15ef08
    https://github.com/scummvm/scummvm/commit/f5704b87b57da8998f6d630bdf96c08eae15ef08
Author: elasota (ejlasota at gmail.com)
Date: 2023-05-15T20:50:36-04:00

Commit Message:
MTROPOLIS: Fix uninitialized member

Changed paths:
    engines/mtropolis/runtime.cpp


diff --git a/engines/mtropolis/runtime.cpp b/engines/mtropolis/runtime.cpp
index b59ab6e3b1b..faa645fad0d 100644
--- a/engines/mtropolis/runtime.cpp
+++ b/engines/mtropolis/runtime.cpp
@@ -6878,7 +6878,7 @@ Project::Segment::Segment() : weakStream(nullptr) {
 Project::StreamDesc::StreamDesc() : streamType(kStreamTypeUnknown), segmentIndex(0), size(0), pos(0) {
 }
 
-Project::AssetDesc::AssetDesc() : typeCode(0), id(0), streamID(0) {
+Project::AssetDesc::AssetDesc() : typeCode(0), id(0), streamID(0), filePosition(0) {
 }
 
 Project::Project(Runtime *runtime)


Commit: bfc271a1351f4a78e59076545e06d03744c0a63f
    https://github.com/scummvm/scummvm/commit/bfc271a1351f4a78e59076545e06d03744c0a63f
Author: elasota (ejlasota at gmail.com)
Date: 2023-05-16T02:05:08-04:00

Commit Message:
VCRUISE: Rework room number lookup for script sets to fix crash after activating the ship in Schizm.

Changed paths:
    engines/vcruise/runtime.cpp
    engines/vcruise/runtime.h
    engines/vcruise/script.cpp


diff --git a/engines/vcruise/runtime.cpp b/engines/vcruise/runtime.cpp
index 159e9c957bb..c933aae84a5 100644
--- a/engines/vcruise/runtime.cpp
+++ b/engines/vcruise/runtime.cpp
@@ -2221,6 +2221,21 @@ void Runtime::terminateScript() {
 	}
 }
 
+RoomScriptSet *Runtime::getRoomScriptSetForCurrentRoom() const {
+	if (!_scriptSet)
+		return nullptr;
+
+	uint roomNumber = _roomNumber;
+	if (roomNumber < _roomDuplicationOffsets.size())
+		roomNumber -= _roomDuplicationOffsets[roomNumber];
+
+	RoomScriptSetMap_t::const_iterator it = _scriptSet->roomScripts.find(roomNumber);
+	if (it == _scriptSet->roomScripts.end())
+		return nullptr;
+
+	return it->_value.get();
+}
+
 bool Runtime::checkCompletionConditions() {
 	bool succeeded = true;
 	for (uint i = 0; i < GyroState::kNumGyros; i++) {
@@ -2251,9 +2266,10 @@ bool Runtime::checkCompletionConditions() {
 
 	// Activate the corresponding failure or success interaction if present
 	if (_scriptSet) {
-		RoomScriptSetMap_t::const_iterator roomScriptIt = _scriptSet->roomScripts.find(_roomNumber);
-		if (roomScriptIt != _scriptSet->roomScripts.end()) {
-			const ScreenScriptSetMap_t &screenScriptsMap = roomScriptIt->_value->screenScripts;
+		RoomScriptSet *roomScriptSet = getRoomScriptSetForCurrentRoom();
+
+		if (roomScriptSet) {
+			const ScreenScriptSetMap_t &screenScriptsMap = roomScriptSet->screenScripts;
 			ScreenScriptSetMap_t::const_iterator screenScriptIt = screenScriptsMap.find(_screenNumber);
 			if (screenScriptIt != screenScriptsMap.end()) {
 				const ScreenScriptSet &screenScriptSet = *screenScriptIt->_value;
@@ -2790,9 +2806,10 @@ void Runtime::changeToScreen(uint roomNumber, uint screenNumber) {
 		_swapOutScreen = 0;
 
 		if (_scriptSet) {
-			RoomScriptSetMap_t::const_iterator roomScriptIt = _scriptSet->roomScripts.find(_roomNumber);
-			if (roomScriptIt != _scriptSet->roomScripts.end()) {
-				const ScreenScriptSetMap_t &screenScriptsMap = roomScriptIt->_value->screenScripts;
+			RoomScriptSet *roomScriptSet = getRoomScriptSetForCurrentRoom();
+
+			if (roomScriptSet) {
+				const ScreenScriptSetMap_t &screenScriptsMap = roomScriptSet->screenScripts;
 				ScreenScriptSetMap_t::const_iterator screenScriptIt = screenScriptsMap.find(_screenNumber);
 				if (screenScriptIt != screenScriptsMap.end()) {
 					const Common::SharedPtr<Script> &script = screenScriptIt->_value->entryScript;
@@ -4097,13 +4114,11 @@ void Runtime::drawDebugOverlay() {
 
 Common::SharedPtr<Script> Runtime::findScriptForInteraction(uint interactionID) const {
 	if (_scriptSet) {
-		RoomScriptSetMap_t::const_iterator roomScriptIt = _scriptSet->roomScripts.find(_roomNumber);
+		RoomScriptSet *roomScriptSet = getRoomScriptSetForCurrentRoom();
 
-		if (roomScriptIt != _scriptSet->roomScripts.end()) {
-			const RoomScriptSet &roomScriptSet = *roomScriptIt->_value;
-
-			ScreenScriptSetMap_t::const_iterator screenScriptIt = roomScriptSet.screenScripts.find(_screenNumber);
-			if (screenScriptIt != roomScriptSet.screenScripts.end()) {
+		if (roomScriptSet) {
+			ScreenScriptSetMap_t::const_iterator screenScriptIt = roomScriptSet->screenScripts.find(_screenNumber);
+			if (screenScriptIt != roomScriptSet->screenScripts.end()) {
 				const ScreenScriptSet &screenScriptSet = *screenScriptIt->_value;
 
 				ScriptMap_t::const_iterator interactionScriptIt = screenScriptSet.interactionScripts.find(interactionID);
@@ -6364,9 +6379,10 @@ void Runtime::scriptOpGoto(ScriptArg_t arg) {
 	Common::SharedPtr<Script> newScript = nullptr;
 
 	if (_scriptSet) {
-		RoomScriptSetMap_t::const_iterator roomScriptIt = _scriptSet->roomScripts.find(_roomNumber);
-		if (roomScriptIt != _scriptSet->roomScripts.end()) {
-			const ScreenScriptSetMap_t &screenScriptsMap = roomScriptIt->_value->screenScripts;
+		RoomScriptSet *roomScriptSet = getRoomScriptSetForCurrentRoom();
+
+		if (roomScriptSet) {
+			const ScreenScriptSetMap_t &screenScriptsMap = roomScriptSet->screenScripts;
 			ScreenScriptSetMap_t::const_iterator screenScriptIt = screenScriptsMap.find(_screenNumber);
 			if (screenScriptIt != screenScriptsMap.end()) {
 				const ScreenScriptSet &screenScriptSet = *screenScriptIt->_value;
@@ -6546,8 +6562,15 @@ void Runtime::scriptOpMusicPlayScore(ScriptArg_t arg) {
 	startScoreSection();
 }
 
-OPCODE_STUB(ScoreAlways)
-OPCODE_STUB(ScoreNormal)
+void Runtime::scriptOpScoreAlways(ScriptArg_t arg) {
+	// This op should temporarily disable music mute
+	warning("ScoreAlways opcode isn't implemented yet");
+}
+
+void Runtime::scriptOpScoreNormal(ScriptArg_t arg) {
+	// This op should re-enable music mute
+	warning("ScoreNormal opcode isn't implemented yet");
+}
 
 void Runtime::scriptOpSndPlay(ScriptArg_t arg) {
 	TAKE_STACK_STR_NAMED(1, sndNameArgs);
@@ -6615,10 +6638,24 @@ void Runtime::scriptOpSndStop(ScriptArg_t arg) {
 		stopSound(*cachedSound);
 }
 
-OPCODE_STUB(SndStopAll)
+void Runtime::scriptOpSndStopAll(ScriptArg_t arg) {
+	for (const Common::SharedPtr<SoundInstance> &snd : _activeSounds)
+		stopSound(*snd);
+}
+
 OPCODE_STUB(SndAddRandom)
 OPCODE_STUB(SndClearRandom)
-OPCODE_STUB(VolumeAdd)
+
+
+
+void Runtime::scriptOpVolumeAdd(ScriptArg_t arg) {
+	TAKE_STACK_INT(3);
+
+	SoundInstance *cachedSound = resolveSoundByID(static_cast<uint>(stackArgs[0]));
+
+	if (cachedSound)
+		triggerSoundRamp(*cachedSound, stackArgs[1] * 100, cachedSound->volume + stackArgs[2], false);
+}
 
 void Runtime::scriptOpVolumeChange(ScriptArg_t arg) {
 	TAKE_STACK_INT(3);
@@ -6650,11 +6687,10 @@ void Runtime::scriptOpAnimChange(ScriptArg_t arg) {
 
 void Runtime::scriptOpScreenName(ScriptArg_t arg) {
 	const Common::String &scrName = _scriptSet->strings[arg];
-	RoomScriptSetMap_t::const_iterator scriptSetIt = _scriptSet->roomScripts.find(_roomNumber);
-	if (scriptSetIt == _scriptSet->roomScripts.end())
-		error("Couldn't resolve room number to find screen name: '%s'", scrName.c_str());
 
-	const RoomScriptSet *rss = scriptSetIt->_value.get();
+	RoomScriptSet *rss = getRoomScriptSetForCurrentRoom();
+	if (!rss)
+		error("Couldn't resolve room number to find screen name: '%s'", scrName.c_str());
 
 	ScreenNameMap_t::const_iterator screenNameIt = rss->screenNames.find(scrName);
 	if (screenNameIt == rss->screenNames.end())
@@ -6669,7 +6705,20 @@ void Runtime::scriptOpExtractByte(ScriptArg_t arg) {
 	_scriptStack.push_back(StackValue(static_cast<StackInt_t>((stackArgs[0] >> (stackArgs[1] * 8) & 0xff))));
 }
 
-OPCODE_STUB(InsertByte)
+void Runtime::scriptOpInsertByte(ScriptArg_t arg) {
+	TAKE_STACK_INT(3);
+
+	StackInt_t value = stackArgs[0];
+	StackInt_t valueToInsert = (stackArgs[1] & 0xff);
+	int bytePos = stackArgs[2];
+
+	StackInt_t mask = static_cast<StackInt_t>(0xff) << (bytePos * 8);
+
+	value -= (value & mask);
+	value += (valueToInsert << (bytePos * 8));
+
+	_scriptStack.push_back(StackValue(value));
+}
 
 void Runtime::scriptOpString(ScriptArg_t arg) {
 	_scriptStack.push_back(StackValue(_scriptSet->strings[arg]));
@@ -6824,9 +6873,20 @@ void Runtime::scriptOpIsCDVersion(ScriptArg_t arg) {
 	_scriptStack.push_back(StackValue(_isCDVariant ? 1 : 0));
 }
 
-OPCODE_STUB(Disc)
+void Runtime::scriptOpDisc(ScriptArg_t arg) {
+	TAKE_STACK_INT(1);
+
+	(void)stackArgs;
+
+	// Always pass correct disc checks
+	_scriptStack.push_back(StackValue(1));
+}
+
 OPCODE_STUB(HidePanel)
-OPCODE_STUB(RotateUpdate)
+
+void Runtime::scriptOpRotateUpdate(ScriptArg_t arg) {
+	warning("RotateUpdate op not implemented yet");
+}
 
 void Runtime::scriptOpMul(ScriptArg_t arg) {
 	TAKE_STACK_INT(2);
diff --git a/engines/vcruise/runtime.h b/engines/vcruise/runtime.h
index ca095520852..5dc39cfd4a3 100644
--- a/engines/vcruise/runtime.h
+++ b/engines/vcruise/runtime.h
@@ -83,6 +83,7 @@ struct ScriptSet;
 struct Script;
 struct IScriptCompilerGlobalState;
 struct Instruction;
+struct RoomScriptSet;
 
 enum GameState {
 	kGameStateBoot,							// Booting the game
@@ -770,6 +771,7 @@ private:
 	void drawSectionToScreen(const RenderSection &section, const Common::Rect &rect);
 	void commitSectionToScreen(const RenderSection &section, const Common::Rect &rect);
 	void terminateScript();
+	RoomScriptSet *getRoomScriptSetForCurrentRoom() const;
 	bool checkCompletionConditions();
 
 	void startTerminatingHorizontalPan(bool isRight);
diff --git a/engines/vcruise/script.cpp b/engines/vcruise/script.cpp
index 339cf219bd0..54a50f9fa04 100644
--- a/engines/vcruise/script.cpp
+++ b/engines/vcruise/script.cpp
@@ -374,9 +374,6 @@ void ScriptCompiler::compileScriptSet(ScriptSet *ss) {
 					if (!parseNumber(token, roomNumber))
 						error("Error compiling script at line %i col %i: Expected number but found '%s'", static_cast<int>(state._lineNum), static_cast<int>(state._col), token.c_str());
 
-					if (_dialect == kScriptDialectSchizm && roomNumber == _fileRoom)
-						roomNumber = _loadAsRoom;
-
 					ss->roomScripts[roomNumber] = roomScript;
 				} else {
 					error("Error compiling script at line %i col %i: Expected number", static_cast<int>(state._lineNum), static_cast<int>(state._col));




More information about the Scummvm-git-logs mailing list