diff --git a/Makefile.mingw32ce b/Makefile.mingw32ce
index ffce590..49f214b 100644
--- a/Makefile.mingw32ce
+++ b/Makefile.mingw32ce
@@ -1,4 +1,4 @@
-VERSION := 1.2.1
+VERSION := 1.2.2
PREFIX=./
DESTDIR=
diff --git a/PKGBUILD.in b/PKGBUILD.in
index 7f0a512..a2bdff2 100644
--- a/PKGBUILD.in
+++ b/PKGBUILD.in
@@ -1,6 +1,6 @@
# Contributor: Peter Kosyh
pkgname=instead
-pkgver=1.2.1
+pkgver=1.2.2
pkgrel=1
pkgdesc="instead quest interpreter"
arch=('i686' 'x86_64')
diff --git a/Rules.make.macosx b/Rules.make.macosx
index 384807b..5773ad8 100644
--- a/Rules.make.macosx
+++ b/Rules.make.macosx
@@ -1,4 +1,4 @@
-VERSION := 1.2.1
+VERSION := 1.2.2
DESTDIR=
BIN=
diff --git a/Rules.make.standalone b/Rules.make.standalone
index 2713ef7..e44692a 100644
--- a/Rules.make.standalone
+++ b/Rules.make.standalone
@@ -1,4 +1,4 @@
-VERSION := 1.2.1
+VERSION := 1.2.2
DESTDIR=
BIN=
diff --git a/Rules.make.system b/Rules.make.system
index 1fcbbc4..9d632ba 100644
--- a/Rules.make.system
+++ b/Rules.make.system
@@ -1,4 +1,4 @@
-VERSION := 1.2.1
+VERSION := 1.2.2
PREFIX=/usr/local
DESTDIR=
diff --git a/Rules.mingw b/Rules.mingw
index d7ea0ae..d1fe517 100644
--- a/Rules.mingw
+++ b/Rules.mingw
@@ -1,4 +1,4 @@
-VERSION := 1.2.1
+VERSION := 1.2.2
PREFIX=./
DESTDIR=
diff --git a/Rules.windows b/Rules.windows
index 64bc084..8f3b0d5 100644
--- a/Rules.windows
+++ b/Rules.windows
@@ -1,4 +1,4 @@
-VERSION := 1.2.1
+VERSION := 1.2.2
PREFIX=
DESTDIR=
diff --git a/desktop/instead.desktop.in b/desktop/instead.desktop.in
index 0555cbe..3806a96 100644
--- a/desktop/instead.desktop.in
+++ b/desktop/instead.desktop.in
@@ -1,6 +1,6 @@
[Desktop Entry]
Encoding=UTF-8
-Version=1.2.1
+Version=1.2.2
Type=Application
Name=INSTEAD
Name[ru]=INSTEAD
diff --git a/doc/index.html b/doc/index.html
index ab29be9..d405b8d 100644
--- a/doc/index.html
+++ b/doc/index.html
@@ -13,7 +13,7 @@ body { font-family: Verdana, Arial, Helvetica, sans-serif;
INSTEAD -- interpreter of simple text adventures for Unix and Windows
-INSTEAD 1.2.1
+INSTEAD 1.2.2
INSTEAD -- interpreter of simple text adventures for Unix and Windows.
INSTEAD was designed to interpret the games that are the mix of visual novels, text quests and classical 90'ss quests.
diff --git a/doc/instead.6 b/doc/instead.6
index 0356392..c6d415d 100644
--- a/doc/instead.6
+++ b/doc/instead.6
@@ -1,4 +1,4 @@
-.TH INSTEAD 6 "Version 1.2.1" Instead GAMES
+.TH INSTEAD 6 "Version 1.2.2" Instead GAMES
.SH NAME
diff --git a/readme.txt b/readme.txt
index 3ad5677..34f1ae7 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,4 +1,4 @@
-INSTEAD 1.2.1
+INSTEAD 1.2.2
=============
WARNING! For successfull building you must install these development packages (names may vary in your distribution):
diff --git a/setup-kit.iss b/setup-kit.iss
index 4cd6106..cfaf765 100644
--- a/setup-kit.iss
+++ b/setup-kit.iss
@@ -1,11 +1,11 @@
[Setup]
AppName=INSTEAD-KIT
-AppVerName=INSTEAD 1.2.1
+AppVerName=INSTEAD 1.2.2
DefaultDirName={pf}\Pinebrush games\INSTEAD
DefaultGroupName=Pinebrush games
UninstallDisplayIcon={app}\sdl-instead.exe
OutputDir=.
-OutputBaseFilename=instead-kit-1.2.1
+OutputBaseFilename=instead-kit-1.2.2
AllowNoIcons=true
[Languages]
diff --git a/setup.iss b/setup.iss
index 37b2c80..4973045 100644
--- a/setup.iss
+++ b/setup.iss
@@ -1,11 +1,11 @@
[Setup]
AppName=INSTEAD
-AppVerName=INSTEAD 1.2.1
+AppVerName=INSTEAD 1.2.2
DefaultDirName={pf}\Pinebrush games\INSTEAD
DefaultGroupName=Pinebrush games
UninstallDisplayIcon={app}\sdl-instead.exe
OutputDir=.
-OutputBaseFilename=instead-1.2.1
+OutputBaseFilename=instead-1.2.2
AllowNoIcons=true
[Languages]
diff --git a/src/sdl-instead/game.c b/src/sdl-instead/game.c
index aff7536..6b386c3 100644
--- a/src/sdl-instead/game.c
+++ b/src/sdl-instead/game.c
@@ -86,7 +86,7 @@ int game_select(const char *name)
g = game_lookup(name);
if ((!name || !*name) && !g)
return 0;
- if (chdir(game_cwd))
+ if (setdir(game_cwd))
return -1;
if (g) {
char *oldgame = curgame_dir;
@@ -96,11 +96,11 @@ int game_select(const char *name)
curgame_dir = oldgame;
return -1;
}
- if (chdir(g->path)) {
+ if (setdir(g->path)) {
curgame_dir = oldgame;
return -1;
}
- if (instead_load(MAIN_FILE)) {
+ if (instead_load(dirpath(MAIN_FILE))) {
curgame_dir = oldgame;
return -1;
}
@@ -128,13 +128,13 @@ int games_rename(void)
{
int i;
char cwd[PATH_MAX];
- getcwd(cwd, sizeof(cwd));
- chdir(game_cwd);
+ getdir(cwd, sizeof(cwd));
+ setdir(game_cwd);
for (i = 0; i < games_nr; i++) {
FREE(games[i].name);
- games[i].name = game_name(games[i].path, games[i].dir);
+ games[i].name = game_name(dirpath(games[i].path), games[i].dir);
}
- chdir(cwd);
+ setdir(cwd);
return 0;
}
@@ -670,7 +670,7 @@ int counter_fn(int interval, void *p)
int game_init(const char *name)
{
- getcwd(game_cwd, sizeof(game_cwd));
+ getdir(game_cwd, sizeof(game_cwd));
unix_path(game_cwd);
if (name)
@@ -690,12 +690,12 @@ int game_init(const char *name)
if (game_select(name))
return -1;
- if (curgame_dir && !access(THEME_FILE, R_OK)) {
+ if (curgame_dir && !access(dirpath(THEME_FILE), R_OK)) {
game_own_theme = 1;
}
if (game_own_theme && opt_owntheme) {
- if (theme_load(THEME_FILE))
+ if (theme_load(dirpath(THEME_FILE)))
return -1;
} else if (curtheme_dir && strcmp(DEFAULT_THEME, curtheme_dir)) {
game_theme_load(curtheme_dir);
@@ -753,7 +753,7 @@ void game_done(int err)
if (opt_autosave && curgame_dir && !err)
game_save(0);
- chdir(game_cwd);
+ setdir(game_cwd);
// cfg_save();
if (menu_shown)
@@ -1238,11 +1238,11 @@ void game_music_player(void)
} else if (!last_music && mus) {
game_stop_mus(500);
last_music = mus;
- snd_play_mus(mus, 0, loop - 1);
+ snd_play_mus(dirpath(mus), 0, loop - 1);
} else if (strcmp(last_music, mus)) {
game_stop_mus(500);
last_music = mus;
- snd_play_mus(mus, 0, loop - 1);
+ snd_play_mus(dirpath(mus), 0, loop - 1);
} else
free(mus);
}
@@ -1264,7 +1264,7 @@ static int wavs_pos = 0;
static wav_t sound_add(const char *fname)
{
wav_t w;
- w = snd_load_wav(fname);
+ w = snd_load_wav(dirpath(fname));
if (!w)
return NULL;
snd_free_wav(wavs[wavs_pos].wav);
@@ -1486,7 +1486,7 @@ int game_cmd(char *cmd)
img_t img;
if (new_pict) {
- img = gfx_load_image(pict);
+ img = gfx_load_image(dirpath(pict));
if (el_img(el_spic))
gfx_free_image(el_img(el_spic));
el(el_spic)->p.p = NULL;
diff --git a/src/sdl-instead/graphics.c b/src/sdl-instead/graphics.c
index 2ae0372..fa80920 100644
--- a/src/sdl-instead/graphics.c
+++ b/src/sdl-instead/graphics.c
@@ -708,7 +708,7 @@ static img_t _gfx_load_combined_image(char *filename)
} else if (*ep) {
goto err;
}
- img = _gfx_load_image(strip(p));
+ img = _gfx_load_image(dirpath(strip(p)));
if (img)
img = gfx_display_alpha(img);
if (img) {
@@ -1032,8 +1032,11 @@ int gfx_set_mode(int w, int h, int fs)
screen = SDL_SetVideoMode(gfx_width, gfx_height, 16, SDL_DOUBLEBUF | SDL_HWSURFACE | ( ( fs ) ? SDL_FULLSCREEN : 0 ) );
#endif
if (screen == NULL) {
- fprintf(stderr, "Unable to set %dx%d video: %s\n", w, h, SDL_GetError());
- return -1;
+ screen = SDL_SetVideoMode(0, 0, 0, SDL_ANYFORMAT | SDL_HWSURFACE | ( ( fs ) ? SDL_FULLSCREEN : 0 ) );
+ if (!screen) {
+ fprintf(stderr, "Unable to set %dx%d video: %s\n", w, h, SDL_GetError());
+ return -1;
+ }
}
gfx_clear(0, 0, gfx_width, gfx_height);
return 0;
@@ -2550,7 +2553,7 @@ img_t get_img(struct layout *layout, char *p)
img = cache_get(layout->img_cache, p);
if (!img) {
unix_path(p);
- if (!(img = gfx_load_image(p)))
+ if (!(img = gfx_load_image(dirpath(p))))
goto out;
theme_img_scale(&img); /* bad style, no gfx layer :( */
}
diff --git a/src/sdl-instead/instead.c b/src/sdl-instead/instead.c
index 70012d7..61dd060 100644
--- a/src/sdl-instead/instead.c
+++ b/src/sdl-instead/instead.c
@@ -257,6 +257,7 @@ typedef struct LoadF {
int extraline;
unsigned char byte;
FILE *f;
+ int enc;
unsigned char buff[4096];
} LoadF;
@@ -271,11 +272,13 @@ static const char *getF (lua_State *L, void *ud, size_t *size) {
}
if (feof(lf->f)) return NULL;
*size = fread(lf->buff, 1, sizeof(lf->buff), lf->f);
- for (i = 0; i < *size; i ++) {
- unsigned char b = lf->buff[i];
- lf->buff[i] ^= lf->byte;
- lf->buff[i] = (lf->buff[i] >> 3) | (lf->buff[i] << 5);
- lf->byte = b;
+ if (lf->enc) {
+ for (i = 0; i < *size; i ++) {
+ unsigned char b = lf->buff[i];
+ lf->buff[i] ^= lf->byte;
+ lf->buff[i] = (lf->buff[i] >> 3) | (lf->buff[i] << 5);
+ lf->byte = b;
+ }
}
return (*size > 0) ? (char*)lf->buff : NULL;
}
@@ -288,7 +291,7 @@ static int errfile (lua_State *L, const char *what, int fnameindex) {
return LUA_ERRFILE;
}
-static int loadfile (lua_State *L, const char *filename) {
+static int loadfile (lua_State *L, const char *filename, int enc) {
LoadF lf;
int status, readstatus;
int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */
@@ -296,6 +299,7 @@ static int loadfile (lua_State *L, const char *filename) {
lua_pushfstring(L, "@%s", filename);
lf.f = fopen(filename, "rb");
lf.byte = 0xcc;
+ lf.enc = enc;
if (lf.f == NULL) return errfile(L, "open", fnameindex);
status = lua_load(L, getF, &lf, lua_tostring(L, -1));
readstatus = ferror(lf.f);
@@ -312,7 +316,15 @@ static int loadfile (lua_State *L, const char *filename) {
static int luaB_doencfile (lua_State *L) {
const char *fname = luaL_optstring(L, 1, NULL);
int n = lua_gettop(L);
- if (loadfile(L, fname) != 0) lua_error(L);
+ if (loadfile(L, dirpath(fname), 1) != 0) lua_error(L);
+ lua_call(L, 0, LUA_MULTRET);
+ return lua_gettop(L) - n;
+}
+
+static int luaB_dofile (lua_State *L) {
+ const char *fname = luaL_optstring(L, 1, NULL);
+ int n = lua_gettop(L);
+ if (loadfile(L, dirpath(fname), 0) != 0) lua_error(L);
lua_call(L, 0, LUA_MULTRET);
return lua_gettop(L) - n;
}
@@ -404,6 +416,7 @@ static int luaB_set_timer(lua_State *L) {
static const luaL_Reg base_funcs[] = {
{"doencfile", luaB_doencfile},
+ {"dofile", luaB_dofile},
{"print", luaB_print}, /* for some mystic, it is needed in win version (with -debug) */
{"is_sound", luaB_is_sound},
{"get_savepath", luaB_get_savepath},
@@ -467,11 +480,11 @@ int instead_init(void)
instead_package();
instead_lang();
- if (dofile(L,STEAD_PATH"/stead.lua")) {
+ if (dofile(L, dirpath(STEAD_PATH"/stead.lua"))) {
return -1;
}
- if (dofile(L,STEAD_PATH"/gui.lua")) {
+ if (dofile(L, dirpath(STEAD_PATH"/gui.lua"))) {
instead_clear();
return -1;
}
diff --git a/src/sdl-instead/macosx.m b/src/sdl-instead/macosx.m
index 81a1745..428f733 100644
--- a/src/sdl-instead/macosx.m
+++ b/src/sdl-instead/macosx.m
@@ -194,3 +194,18 @@ char *open_file_dialog(void)
}
return NULL;
}
+
+int setdir(const char *path)
+{
+ return chdir(path);
+}
+
+char *getdir(char *path, size_t size)
+{
+ return getcwd(path, size);
+}
+
+char *dirpath(const char *path)
+{
+ return (char*)path;
+}
diff --git a/src/sdl-instead/main.c b/src/sdl-instead/main.c
index ca20cad..5d6ebe8 100644
--- a/src/sdl-instead/main.c
+++ b/src/sdl-instead/main.c
@@ -69,6 +69,29 @@ void macosx_init(void) {
}
#endif
+#ifdef _WIN32_WCE
+char *getcurdir(char *path)
+{
+ char *p;
+ if (path == NULL || *path == '\0')
+ return ".";
+ p = path + strlen(path) - 1;
+ while (*p == '/') {
+ if (p == path)
+ return path;
+ *p-- = '\0';
+ }
+ while (p >= path && *p != '/')
+ p--;
+ return p < path ? "." : p == path ? "/" : (*p = '\0', path);
+}
+void wince_init(char *path)
+{
+ unix_path(path);
+ strcpy(game_cwd, getcurdir(path));
+}
+#endif
+
int main(int argc, char *argv[])
{
int clean_tmp = 0;
@@ -81,8 +104,13 @@ int main(int argc, char *argv[])
gtk_init(&argc, &argv);
#endif
putenv("SDL_MOUSE_RELATIVE=0"); /* test this! */
+#ifdef _WIN32_WCE
+ wince_init(argv[0]);
+#else
getcwd(game_cwd, sizeof(game_cwd));
+#endif
unix_path(game_cwd);
+ setdir(game_cwd);
for (i = 1; i < argc; i++) {
if (!strcmp(argv[i],"-alsa"))
alsa_sw = 1;
@@ -100,7 +128,7 @@ int main(int argc, char *argv[])
else if (!strcmp(argv[i], "-debug"))
debug_sw = 1;
else if (!strcmp(argv[i], "-noautosave"))
- noauto_sw = 1;
+ noauto_sw = 1;
else if (!strcmp(argv[i], "-game")) {
if ((i + 1) < argc)
game_sw = argv[++i];
@@ -187,7 +215,7 @@ int main(int argc, char *argv[])
goto out;
}
- menu_langs_lookup(LANG_PATH);
+ menu_langs_lookup(dirpath(LANG_PATH));
if (!langs_nr) {
fprintf(stderr, "No languages found in: %s.\n", LANG_PATH);
@@ -207,14 +235,14 @@ int main(int argc, char *argv[])
if (games_sw)
games_lookup(games_sw);
- if (!nostdgames_sw && games_lookup(GAMES_PATH))
+ if (!nostdgames_sw && games_lookup(dirpath(GAMES_PATH)))
fprintf(stderr, "No games found in: %s.\n", GAMES_PATH);
if (themes_sw)
themes_lookup(themes_sw);
if (!nostdthemes_sw) {
- themes_lookup(THEMES_PATH);
+ themes_lookup(dirpath(THEMES_PATH));
themes_lookup(game_local_themes_path());
}
diff --git a/src/sdl-instead/menu.c b/src/sdl-instead/menu.c
index be07e1b..abd7e0f 100644
--- a/src/sdl-instead/menu.c
+++ b/src/sdl-instead/menu.c
@@ -819,22 +819,22 @@ int menu_lang_select(const char *name)
char cwd[PATH_MAX];
if (!name)
return -1;
- getcwd(cwd, sizeof(cwd));
- chdir(game_cwd);
+ getdir(cwd, sizeof(cwd));
+ setdir(game_cwd);
for (i = 0; ipath) || theme_load(THEME_FILE)) {
- chdir(cwd);
+ if (!theme || setdir(theme->path) || theme_load(dirpath(THEME_FILE))) {
+ setdir(cwd);
return -1;
}
- chdir(cwd);
+ setdir(cwd);
return 0;
}
diff --git a/src/sdl-instead/unix.c b/src/sdl-instead/unix.c
index 5e70917..6a28efc 100644
--- a/src/sdl-instead/unix.c
+++ b/src/sdl-instead/unix.c
@@ -302,3 +302,18 @@ char *sdl_path(char *p)
unix_path(p);
return p;
}
+
+int setdir(const char *path)
+{
+ return chdir(path);
+}
+
+char *getdir(char *path, size_t size)
+{
+ return getcwd(path, size);
+}
+
+char *dirpath(const char *path)
+{
+ return (char*)path;
+}
diff --git a/src/sdl-instead/util.c b/src/sdl-instead/util.c
index 69ea021..1fa53be 100644
--- a/src/sdl-instead/util.c
+++ b/src/sdl-instead/util.c
@@ -266,7 +266,7 @@ int parse_full_path(const char *v, void *data)
char **p = ((char **)data);
if (*p)
free(*p);
- getcwd(cwd, sizeof(cwd));
+ getdir(cwd, sizeof(cwd));
*p = malloc(strlen(v) + strlen(cwd) + 2);
if (!*p)
return -1;
diff --git a/src/sdl-instead/util.h b/src/sdl-instead/util.h
index 8ad7543..0698cf7 100644
--- a/src/sdl-instead/util.h
+++ b/src/sdl-instead/util.h
@@ -31,6 +31,9 @@ extern char *decode(iconv_t hiconv, const char *s);
extern void unix_path(char *path);
extern char *sdl_path(char *path);
+extern int setdir(const char *path);
+extern char *getdir(char *path, size_t size);
+extern char *dirpath(const char *path);
extern char *parse_tag(char *line, const char *tag, const char *comm, int *brk);
extern int remove_dir(const char *path);
diff --git a/src/sdl-instead/wince.c b/src/sdl-instead/wince.c
index ff627a9..212f768 100644
--- a/src/sdl-instead/wince.c
+++ b/src/sdl-instead/wince.c
@@ -102,7 +102,7 @@ char *game_tmp_path(void)
return NULL;
}
strcat((char*)lpTempPathBuffer, "/instead-games");
- if (mkdir((char*)lpTempPathBuffer) && errno != EEXIST)
+ if (mkdir((char*)lpTempPathBuffer) && access((char*)lpTempPathBuffer, W_OK))
return NULL;
unix_path((char*)lpTempPathBuffer);
return (char*)lpTempPathBuffer;
@@ -115,12 +115,12 @@ char *game_local_games_path(int cr)
return NULL;
snprintf(local_games_path, sizeof(local_games_path) - 1 , "%s/", app);
if (cr) {
- if (mkdir(local_games_path) && errno != EEXIST)
+ if (mkdir(local_games_path) && access(local_games_path, W_OK))
return NULL;
}
strcat(local_games_path,"/games");
if (cr) {
- if (mkdir(local_games_path) && errno != EEXIST)
+ if (mkdir(local_games_path) && access(local_games_path, W_OK))
return NULL;
}
return local_games_path;
@@ -182,7 +182,7 @@ char *game_cfg_path( void )
return cfg_path;
/* no at home? Try in dir */
snprintf(cfg_path, sizeof(cfg_path) - 1 , "%s", p);
- if (mkdir(cfg_path) && errno != EEXIST) {
+ if (mkdir(cfg_path) && access(cfg_path, W_OK)) {
snprintf(cfg_path, sizeof(cfg_path) - 1 , "%src", p); /* appdir/insteadrc ;) */
return cfg_path;
}
@@ -205,21 +205,21 @@ char *game_save_path( int cr, int nr )
snprintf(save_path, sizeof(save_path) - 1, "saves/autosave");
return save_path;
}
- if (!p)
+ if (!p)
return NULL;
strcpy( appdir, p );
- if (cr && mkdir(appdir) && errno != EEXIST)
+ if (cr && mkdir(appdir) && access(appdir, W_OK))
return NULL;
snprintf(save_path, sizeof(save_path) - 1 , "%s/saves", appdir);
- if (cr && mkdir(save_path) && errno != EEXIST)
+ if (cr && mkdir(save_path) && access(save_path, W_OK))
return NULL;
snprintf(save_path, sizeof(save_path) - 1, "%s/saves/%s", appdir, curgame_dir);
- if (cr && mkdir(save_path) && errno != EEXIST)
+ if (cr && mkdir(save_path) && access(save_path, W_OK))
return NULL;
if (nr)
diff --git a/stead/stead.lua b/stead/stead.lua
index bacaa6b..5208814 100644
--- a/stead/stead.lua
+++ b/stead/stead.lua
@@ -1,5 +1,5 @@
stead = {
- version = "1.2.1",
+ version = "1.2.2",
api_version = "1.1.6", -- last version before 1.2.0
table = table,
delim = ',',