SLUDGE: Improved script decompilation

This commit is contained in:
Eugene Sandulenko 2021-05-06 13:06:18 +02:00
parent 866a010880
commit 519b212f95
No known key found for this signature in database
GPG Key ID: 014D387312D34F08
5 changed files with 37 additions and 10 deletions

View File

@ -93,6 +93,7 @@ extern LoadedFunction *saverFunc;
typedef BuiltReturn (*builtInSludgeFunc)(int numParams, LoadedFunction *fun);
struct builtInFunctionData {
const char *name;
builtInSludgeFunc func;
int paramNum;
};
@ -2575,4 +2576,11 @@ BuiltReturn callBuiltIn(int whichFunc, int numParams, LoadedFunction *fun) {
return BR_ERROR;
}
const char *getBuiltInName(int num) {
if (num > NUM_FUNCS)
error("getBuiltInName: incorrect builtin number. %d > %d", num, NUM_FUNCS);
return builtInFunctionArray[num].name;
}
} // End of namespace Sludge

View File

@ -40,6 +40,7 @@ enum BuiltReturn {
bool failSecurityCheck(const Common::String &fn);
BuiltReturn callBuiltIn(int whichFunc, int numParams, LoadedFunction *fun);
const char *getBuiltInName(int num);
} // End of namespace Sludge

View File

@ -193,10 +193,7 @@ Common::String ResourceManager::convertString(const Common::String &s) {
}
Common::String ResourceManager::getNumberedString(int value) {
if (_sliceBusy) {
fatal("Can't read from data file", "I'm already reading something");
return NULL;
}
uint32 pos = _bigDataFile->pos();
_bigDataFile->seek((value << 2) + _startOfTextIndex, 0);
value = _bigDataFile->readUint32LE();
@ -209,6 +206,9 @@ Common::String ResourceManager::getNumberedString(int value) {
s = convertString(s);
}
if (_sliceBusy)
_bigDataFile->seek(pos);
return s;
}

View File

@ -164,6 +164,22 @@ void unfreezeSubs() {
}
}
Common::String getCommandParameter(int com, int param) {
switch(com) {
case SLU_LOAD_BUILT:
return getBuiltInName(param);
case SLU_SET_GLOBAL:
return Common::String::format("global%d", param);
case SLU_LOAD_STRING:
return Common::String::format("\"%s\"", g_sludge->_resMan->getNumberedString(param).c_str());
default:
return Common::String::format("%d", param);
}
}
bool continueFunction(LoadedFunction *fun) {
bool keepLooping = true;
bool advanceNow;
@ -177,9 +193,9 @@ bool continueFunction(LoadedFunction *fun) {
while (keepLooping) {
advanceNow = true;
debugC(1, kSludgeDebugStackMachine, "Executing command line %i : ", fun->runThisLine);
param = fun->compiledLines[fun->runThisLine].param;
com = fun->compiledLines[fun->runThisLine].theCommand;
debugC(1, kSludgeDebugStackMachine, "Executing command line %i : %s(%s)", fun->runThisLine, sludgeText[com], getCommandParameter(com, param).c_str());
if (numBIFNames) {
setFatalInfo((fun->originalNumber < numUserFunc) ? allUserFunc[fun->originalNumber] : "Unknown user function", (com < numSludgeCommands) ? sludgeText[com] : ERROR_UNKNOWN_MCODE);
@ -638,10 +654,12 @@ bool loadFunctionCode(LoadedFunction *newFunc) {
return false;
for (numLinesRead = 0; numLinesRead < numLines; numLinesRead++) {
newFunc->compiledLines[numLinesRead].theCommand = (SludgeCommand)readStream->readByte();
newFunc->compiledLines[numLinesRead].param = readStream->readUint16BE();
debugC(3, kSludgeDebugDataLoad, "command line %i: %i", numLinesRead,
newFunc->compiledLines[numLinesRead].theCommand);
byte com = readStream->readByte();
uint16 param = readStream->readUint16BE();
newFunc->compiledLines[numLinesRead].theCommand = (SludgeCommand)com;
newFunc->compiledLines[numLinesRead].param = param;
debugC(3, kSludgeDebugDataLoad, "command line %i: %s(%s)", numLinesRead,
sludgeText[com], getCommandParameter(com, param).c_str());
}
g_sludge->_resMan->finishAccess();

View File

@ -29,7 +29,7 @@
namespace Sludge {
#define FUNC(special,name,paramNum) {builtIn_ ## name, paramNum},
#define FUNC(special,name,paramNum) {#name, builtIn_ ## name, paramNum},
static builtInFunctionData builtInFunctionArray[] = {
FUNC(true, say, -1)
FUNC(true, skipSpeech, 0)