diff -rN -u old-freesci-0.6.4/src/engine/kmovement.c new-freesci-0.6.4/src/engine/kmovement.c --- old-freesci-0.6.4/src/engine/kmovement.c 2008-05-29 23:42:30.000000000 +0200 +++ new-freesci-0.6.4/src/engine/kmovement.c 2008-05-29 23:42:31.000000000 +0200 @@ -245,6 +245,50 @@ #define MOVING_ON_X (((axis == _K_BRESEN_AXIS_X)&&bi1) || dx) #define MOVING_ON_Y (((axis == _K_BRESEN_AXIS_Y)&&bi1) || dy) +static enum { + IGNORE_MOVECNT, + INCREMENT_MOVECNT, + UNINITIALIZED +} handle_movecnt = UNINITIALIZED; + +int parse_reg_t(state_t *s, char *str, reg_t *dest); /* In scriptconsole.c */ + +static void +bresenham_autodetect(state_t *s) +{ + reg_t motion_class; + + if (!parse_reg_t(s, "?Motion", &motion_class)) + { + object_t *obj = obj_get(s, motion_class); + reg_t fptr; + byte *buf; + static byte signature[] = {0x3f, 0x06, 0x78, 0x7c, 0x43, 0x50, 0x02, 0x48}; + + if (obj == NULL) + { + SCIkwarn(SCIkWARNING,"bresenham_autodetect failed!"); + handle_movecnt = INCREMENT_MOVECNT; /* Most games do this, so best guess */ + return; + } + + if (lookup_selector(s, motion_class, s->selector_map.doit, NULL, &fptr) != SELECTOR_METHOD) + { + SCIkwarn(SCIkWARNING,"bresenham_autodetect failed!"); + handle_movecnt = INCREMENT_MOVECNT; /* Most games do this, so best guess */ + return; + } + + buf = s->seg_manager.heap[fptr.segment]->data.script.buf + fptr.offset; + handle_movecnt = (SCI_VERSION_MAJOR(s->version) == 0 || + memcmp(buf, signature, sizeof(signature)) == 0); + } else + { + SCIkwarn(SCIkWARNING,"bresenham_autodetect failed!"); + handle_movecnt = INCREMENT_MOVECNT; /* Most games do this, so best guess */ + } +} + reg_t kDoBresen(state_t *s, int funct_nr, int argc, reg_t *argv) { @@ -261,6 +305,9 @@ if (SCI_VERSION_MAJOR(s->version)>0) signal&=~_K_VIEW_SIG_FLAG_HIT_OBSTACLE; + if (handle_movecnt == UNINITIALIZED) + bresenham_autodetect(s); + PUT_SEL32(client, signal, make_reg(0, signal)); /* This is a NOP for SCI0 */ oldx = x; oldy = y; @@ -285,12 +332,26 @@ } PUT_SEL32V(mover, b_di, bdi); -/* PUT_SELECTOR(mover, b_movCnt, movcnt - 1); *//* Needed for HQ1/Ogre? */ x += dx; y += dy; +// sciprintf("movecnt %d, move speed %d\n", movcnt, max_movcnt); + if (handle_movecnt) + { + if (max_movcnt > movcnt) + { + ++movcnt; + PUT_SEL32V(mover, b_movCnt, movcnt); /* Needed for HQ1/Ogre? */ + return NULL_REG; + } + else + { + movcnt = 0; + PUT_SEL32V(mover, b_movCnt, movcnt); /* Needed for HQ1/Ogre? */ + } + } if ((MOVING_ON_X && (((x < destx) && (oldx >= destx)) /* Moving left, exceeded? */ || @@ -342,12 +403,6 @@ SCIkdebug(SCIkBRESEN, "Finished mover "PREG" by collision\n", PRINT_REG(mover)); completed = 1; - } else { - ++movcnt; - if (movcnt > max_movcnt) - movcnt = 0; - - PUT_SEL32V(mover, b_movCnt, movcnt); /* Needed for HQ1/Ogre? */ } if (SCI_VERSION_MAJOR(s->version)>0) diff -rN -u old-freesci-0.6.4/src/scicore/resource.c new-freesci-0.6.4/src/scicore/resource.c --- old-freesci-0.6.4/src/scicore/resource.c 2008-05-29 23:42:31.000000000 +0200 +++ new-freesci-0.6.4/src/scicore/resource.c 2008-05-29 23:42:31.000000000 +0200 @@ -298,6 +298,8 @@ res->data = NULL; res->status = SCI_STATUS_NOMALLOC; res->size = 0; + chdir(save_cwd); + free(save_cwd); return; } @@ -328,6 +330,8 @@ res->data = NULL; res->status = SCI_STATUS_NOMALLOC; res->size = 0; + chdir(save_cwd); + free(save_cwd); return; } }