Skip to content

Commit

Permalink
DIRECTOR: Lingo: Fix codeString() method
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Aug 3, 2016
1 parent 53dceb9 commit 6d2a7aa
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions engines/director/lingo/lingo.cpp
Expand Up @@ -82,16 +82,18 @@ Lingo::~Lingo() {

int Lingo::codeString(const char *str) {
int instLen = sizeof(inst);
int numInsts = (strlen(str) + 1 + instLen - 1) % instLen;
int numInsts = strlen(str) / instLen + (strlen(str) + 1 + instLen - 1) % instLen;

// Allocate needed space in script
_currentScript->push_back(0);
char *start = (char *)(&_currentScript->back());
// Where we copy the string over
int pos = _currentScript->size();

for (int i = 0; i < numInsts - 1; i++)
// Allocate needed space in script
for (int i = 0; i < numInsts; i++)
_currentScript->push_back(0);

Common::strlcpy(start, str, numInsts * instLen);
byte *dst = (byte *)&_currentScript->front() + pos * sizeof(inst);

memcpy(dst, str, strlen(str) + 1);

return _currentScript->size();
}
Expand All @@ -107,6 +109,8 @@ void Lingo::addCode(Common::String code, ScriptType type, uint16 id) {
_scripts[type][id] = _currentScript;

parse(code.c_str());

Common::hexdump((byte *)&_currentScript->front(), _currentScript->size() * sizeof(inst));
}

void Lingo::processEvent(LEvent event, int entityId) {
Expand Down

0 comments on commit 6d2a7aa

Please sign in to comment.