From d4f31f85c1f6db632854a42df1d95bb19fe12516 Mon Sep 17 00:00:00 2001 From: XProger Date: Tue, 23 Oct 2018 03:46:24 +0300 Subject: [PATCH] add saveDir path for savegame.dat file --- src/core.h | 2 +- src/game.h | 8 ++--- src/gapi_gl.h | 2 +- src/lara.h | 7 ++-- .../android/app/src/main/cpp/main.cpp | 22 ++++++------- src/platform/clover/main.cpp | 31 ++++++++++-------- src/platform/ios/ViewController.mm | 9 ++---- src/platform/nix/main.cpp | 18 +++++------ src/platform/osx/main.cpp | 9 ++---- src/platform/psp/main.cpp | 5 ++- src/platform/rpi/main.cpp | 14 ++++---- src/platform/web/main.cpp | 7 ++-- src/platform/win/main.cpp | 12 +++---- src/sound.h | 2 +- src/utils.h | 32 ++++++++++++------- 15 files changed, 90 insertions(+), 90 deletions(-) diff --git a/src/core.h b/src/core.h index 19d536a..7238ea5 100644 --- a/src/core.h +++ b/src/core.h @@ -618,7 +618,7 @@ namespace Core { GAPI::init(); - LOG("cache : %s\n", Stream::cacheDir); + LOG("cache : %s\n", cacheDir); LOG("supports :\n"); LOG(" variyngs count : %d\n", support.maxVectors); LOG(" binary shaders : %s\n", support.shaderBinary ? "true" : "false"); diff --git a/src/game.h b/src/game.h index cab607a..f84d43c 100644 --- a/src/game.h +++ b/src/game.h @@ -9,11 +9,11 @@ #include "ui.h" #include "savegame.h" -namespace Game { - Level *level; - Stream *nextLevel; +#define MAX_CHEAT_SEQUENCE 8 - #define MAX_CHEAT_SEQUENCE 8 +namespace Game { + Level *level; + Stream *nextLevel; ControlKey cheatSeq[MAX_CHEAT_SEQUENCE]; void cheatControl(ControlKey key) { diff --git a/src/gapi_gl.h b/src/gapi_gl.h index ddd65df..688cd8c 100644 --- a/src/gapi_gl.h +++ b/src/gapi_gl.h @@ -475,7 +475,7 @@ namespace GAPI { bool linkBinary(const char *name) { // non-async code! char path[255]; - strcpy(path, Stream::cacheDir); + strcpy(path, cacheDir); strcat(path, name); if (!Stream::exists(path)) diff --git a/src/lara.h b/src/lara.h index 3bcffab..f02c013 100644 --- a/src/lara.h +++ b/src/lara.h @@ -629,15 +629,18 @@ struct Lara : Character { health = data.extra.lara.health; oxygen = data.extra.lara.oxygen; + if (level->isHome()) return; + layers[1].mask = layers[2].mask = layers[3].mask = 0; - wpnSet(TR::Entity::Type(data.extra.lara.itemWeapon)); + if (data.extra.lara.itemWeapon) + wpnSet(TR::Entity::Type(data.extra.lara.itemWeapon)); wpnCurrent = TR::Entity::Type(data.extra.lara.itemWeapon); itemHolster = TR::Entity::Type(data.extra.lara.itemHolster); wpnState = Weapon::IS_HIDDEN; - if (data.extra.lara.itemHands == data.extra.lara.itemWeapon) + if (data.extra.lara.itemHands && data.extra.lara.itemHands == data.extra.lara.itemWeapon) wpnDraw(true); if (itemHolster != TR::Entity::NONE) diff --git a/src/platform/android/app/src/main/cpp/main.cpp b/src/platform/android/app/src/main/cpp/main.cpp index 7e82ca0..d3f2ee2 100644 --- a/src/platform/android/app/src/main/cpp/main.cpp +++ b/src/platform/android/app/src/main/cpp/main.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "game.h" @@ -43,10 +44,7 @@ void osToggleVR(bool enable) { extern "C" { -char Stream::cacheDir[255]; -char Stream::contentDir[255]; - -JNI_METHOD(void, nativeInit)(JNIEnv* env, jobject obj, jstring contentDir, jstring cacheDir) { +JNI_METHOD(void, nativeInit)(JNIEnv* env, jobject obj, jstring jcontentDir, jstring jcacheDir) { env->GetJavaVM(&jvm); timeval t; @@ -55,15 +53,17 @@ JNI_METHOD(void, nativeInit)(JNIEnv* env, jobject obj, jstring contentDir, jstri const char* str; - Stream::contentDir[0] = Stream::cacheDir[0] = 0; + cacheDir[0] = saveDir[0] = contentDir[0] = 0; - str = env->GetStringUTFChars(contentDir, NULL); - strcat(Stream::contentDir, str); - env->ReleaseStringUTFChars(contentDir, str); + str = env->GetStringUTFChars(jcontentDir, NULL); + strcat(contentDir, str); + env->ReleaseStringUTFChars(jcontentDir, str); - str = env->GetStringUTFChars(cacheDir, NULL); - strcat(Stream::cacheDir, str); - env->ReleaseStringUTFChars(cacheDir, str); + str = env->GetStringUTFChars(jcacheDir, NULL); + strcat(cacheDir, str); + env->ReleaseStringUTFChars(jcacheDir, str); + + strcpy(saveDir, cacheDir); glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint*)&GAPI::defaultFBO); Game::init(); diff --git a/src/platform/clover/main.cpp b/src/platform/clover/main.cpp index f4a569b..cc1fa71 100644 --- a/src/platform/clover/main.cpp +++ b/src/platform/clover/main.cpp @@ -526,11 +526,7 @@ void inputUpdate() { } } -char Stream::cacheDir[255]; -char Stream::contentDir[255]; - int main(int argc, char **argv) { -LOG("start\n"); if (!eglInit()) { LOG("! can't initialize EGL context\n"); return -1; @@ -539,26 +535,33 @@ LOG("start\n"); Core::width = fb.width; Core::height = fb.height; - Stream::contentDir[0] = Stream::cacheDir[0] = 0; + cacheDir[0] = saveDir[0] = contentDir[0] = 0; - strcpy(Stream::contentDir, argv[0]); - int i = strlen(Stream::contentDir); + strcpy(contentDir, argv[0]); + int i = strlen(contentDir); while (--i >= 0) { - if (Stream::contentDir[i] == '/') { - Stream::contentDir[i + 1] = 0; + if (contentDir[i] == '/') { + contentDir[i + 1] = 0; break; } i--; } - strcpy(Stream::cacheDir, Stream::contentDir); - strcat(Stream::cacheDir, "cache/"); + strcpy(cacheDir, contentDir); + strcat(cacheDir, "cache/"); struct stat st = {0}; - if (stat(Stream::cacheDir, &st) == -1 && mkdir(Stream::cacheDir, 0777) == -1) - Stream::cacheDir[0] = 0; + if (stat(cacheDir, &st) == -1 && mkdir(cacheDir, 0777) == -1) + cacheDir[0] = 0; - LOG("cache dir %s\n", Stream::cacheDir); + const char *home; + if (!(home = getenv("HOME"))) + home = getpwuid(getuid())->pw_dir; + strcpy(saveDir, home); + strcat(saveDir, "/.openlara/"); + + if (stat(saveDir, &st) == -1 && mkdir(saveDir, 0777) == -1) + saveDir[0] = 0; timeval t; gettimeofday(&t, NULL); diff --git a/src/platform/ios/ViewController.mm b/src/platform/ios/ViewController.mm index 43ae924..dd23757 100644 --- a/src/platform/ios/ViewController.mm +++ b/src/platform/ios/ViewController.mm @@ -16,9 +16,6 @@ #include -char Stream::cacheDir[255]; -char Stream::contentDir[255]; - bool osJoyReady(int index) { return false; } @@ -112,11 +109,11 @@ void soundInit() { [EAGLContext setCurrentContext:self.context]; - Stream::contentDir[0] = Stream::cacheDir[0] = 0; + cacheDir[0] = saveDir[0] = contentDir[0] = 0; NSString *path = [[NSBundle mainBundle] resourcePath]; - strcat(Stream::contentDir, [path UTF8String]); - strcat(Stream::contentDir, "/"); + strcat(contentDir, [path UTF8String]); + strcat(contentDir, "/"); Game::init(); diff --git a/src/platform/nix/main.cpp b/src/platform/nix/main.cpp index a43ed15..0f52ce5 100644 --- a/src/platform/nix/main.cpp +++ b/src/platform/nix/main.cpp @@ -353,21 +353,19 @@ void WndProc(const XEvent &e,Display*dpy,Window wnd) { } } -char Stream::cacheDir[255]; -char Stream::contentDir[255]; - int main(int argc, char **argv) { - Stream::contentDir[0] = Stream::cacheDir[0] = 0; + cacheDir[0] = saveDir[0] = contentDir[0] = 0; const char *home; if (!(home = getenv("HOME"))) home = getpwuid(getuid())->pw_dir; - strcat(Stream::cacheDir, home); - strcat(Stream::cacheDir, "/.OpenLara/"); - - struct stat st = {0}; - if (stat(Stream::cacheDir, &st) == -1 && mkdir(Stream::cacheDir, 0777) == -1) - Stream::cacheDir[0] = 0; + strcat(cacheDir, home); + strcat(cacheDir, "/.openlara/"); + + struct stat st = {0}; + if (stat(cacheDir, &st) == -1 && mkdir(cacheDir, 0777) == -1) + cacheDir[0] = 0; + strcpy(saveDir, cacheDir); static int XGLAttr[] = { GLX_RGBA, diff --git a/src/platform/osx/main.cpp b/src/platform/osx/main.cpp index 17dcd49..8ff8564 100644 --- a/src/platform/osx/main.cpp +++ b/src/platform/osx/main.cpp @@ -153,18 +153,15 @@ int osGetTime() { return int(t / 1000); } -char Stream::contentDir[255]; -char Stream::cacheDir[255]; - int main() { - Stream::contentDir[0] = Stream::cacheDir[0] = 0; + cacheDir[0] = saveDir[0] = contentDir[0] = 0; // get path to game content CFBundleRef bundle = CFBundleGetMainBundle(); CFURLRef bundleURL = CFBundleCopyBundleURL(bundle); CFStringRef pathStr = CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle); - CFStringGetFileSystemRepresentation(pathStr, Stream::contentDir, 230); - strcat(Stream::contentDir, "/Contents/Resources/"); + CFStringGetFileSystemRepresentation(pathStr, contentDir, 230); + strcat(contentDir, "/Contents/Resources/"); // init window Rect rect = {0, 0, 720, 1280}; diff --git a/src/platform/psp/main.cpp b/src/platform/psp/main.cpp index c985603..1b30fe5 100644 --- a/src/platform/psp/main.cpp +++ b/src/platform/psp/main.cpp @@ -139,10 +139,9 @@ void sndInit() { pspAudioSetChannelCallback(0, sndFill, NULL); } -char Stream::cacheDir[255]; -char Stream::contentDir[255]; - int main() { + cacheDir[0] = saveDir[0] = contentDir[0] = 0; + scePowerSetClockFrequency(333, 333, 166); setupCallbacks(); diff --git a/src/platform/rpi/main.cpp b/src/platform/rpi/main.cpp index 555ea69..da2ee1e 100644 --- a/src/platform/rpi/main.cpp +++ b/src/platform/rpi/main.cpp @@ -467,9 +467,6 @@ void inputUpdate() { } } -char Stream::cacheDir[255]; -char Stream::contentDir[255]; - EGLDisplay display; int main(int argc, char **argv) { @@ -489,17 +486,18 @@ int main(int argc, char **argv) { return 1; } - Stream::contentDir[0] = Stream::cacheDir[0] = 0; + cacheDir[0] = saveDir[0] = contentDir[0] = 0; const char *home; if (!(home = getenv("HOME"))) home = getpwuid(getuid())->pw_dir; - strcat(Stream::cacheDir, home); - strcat(Stream::cacheDir, "/.OpenLara/"); + strcat(cacheDir, home); + strcat(cacheDir, "/.openlara/"); struct stat st = {0}; - if (stat(Stream::cacheDir, &st) == -1 && mkdir(Stream::cacheDir, 0777) == -1) - Stream::cacheDir[0] = 0; + if (stat(cacheDir, &st) == -1 && mkdir(cacheDir, 0777) == -1) + cacheDir[0] = 0; + strcpy(saveDir, cacheDir); timeval t; gettimeofday(&t, NULL); diff --git a/src/platform/web/main.cpp b/src/platform/web/main.cpp index c4570f1..65face9 100644 --- a/src/platform/web/main.cpp +++ b/src/platform/web/main.cpp @@ -312,12 +312,9 @@ EM_BOOL mouseCallback(int eventType, const EmscriptenMouseEvent *e, void *userDa return 1; } -char Stream::cacheDir[255]; -char Stream::contentDir[255]; - int main() { - Stream::contentDir[0] = Stream::cacheDir[0] = 0; - + cacheDir[0] = saveDir[0] = contentDir[0] = 0; + initGL(); emscripten_set_keydown_callback(0, 0, 1, keyCallback); diff --git a/src/platform/win/main.cpp b/src/platform/win/main.cpp index 30970c0..0dccb3a 100644 --- a/src/platform/win/main.cpp +++ b/src/platform/win/main.cpp @@ -667,9 +667,6 @@ void vrCompose() { } #endif // #ifdef VR_SUPPORT -char Stream::cacheDir[255]; -char Stream::contentDir[255]; - #ifdef _DEBUG int main(int argc, char** argv) { _CrtMemState _msBegin, _msEnd, _msDiff; @@ -682,11 +679,12 @@ int main(int argc, char** argv) { //#else //int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { #endif - Stream::contentDir[0] = Stream::cacheDir[0] = 0; + cacheDir[0] = saveDir[0] = contentDir[0] = 0; - strcat(Stream::cacheDir, getenv("APPDATA")); - strcat(Stream::cacheDir, "\\OpenLara\\"); - CreateDirectory(Stream::cacheDir, NULL); + strcat(cacheDir, getenv("APPDATA")); + strcat(cacheDir, "\\OpenLara\\"); + strcpy(saveDir, cacheDir); + CreateDirectory(cacheDir, NULL); RECT r = { 0, 0, 1280, 720 }; AdjustWindowRect(&r, WS_OVERLAPPEDWINDOW, false); diff --git a/src/sound.h b/src/sound.h index 4aa408f..157eea4 100644 --- a/src/sound.h +++ b/src/sound.h @@ -626,7 +626,7 @@ namespace Sound { OGG(Stream *stream, int channels) : Decoder(stream, channels, 0), ogg(NULL) { char buf[255]; - strcpy(buf, Stream::contentDir); + strcpy(buf, contentDir); strcat(buf, stream->name); alloc.alloc_buffer_length_in_bytes = 256 * 1024; diff --git a/src/utils.h b/src/utils.h index 7f8f904..2efa7f2 100644 --- a/src/utils.h +++ b/src/utils.h @@ -1189,10 +1189,11 @@ extern void osWriteSlot (Stream *stream); extern void osDownload (Stream *stream); #endif -struct Stream { - static char cacheDir[255]; - static char contentDir[255]; +char cacheDir[255]; +char saveDir[255]; +char contentDir[255]; +struct Stream { typedef void (Callback)(Stream *stream, void *userData); Callback *callback; void *userData; @@ -1284,7 +1285,7 @@ struct Stream { static bool existsContent(const char *name) { char fileName[1024]; - strcpy(fileName, Stream::contentDir); + strcpy(fileName, contentDir); strcat(fileName, name); return exists(fileName); } @@ -1337,9 +1338,9 @@ struct Stream { #ifdef OS_FILEIO_CACHE -void osCacheWrite(Stream *stream) { +void osDataWrite(Stream *stream, const char *dir) { char path[255]; - strcpy(path, Stream::cacheDir); + strcpy(path, dir); strcat(path, stream->name); FILE *f = fopen(path, "wb"); if (f) { @@ -1354,9 +1355,9 @@ void osCacheWrite(Stream *stream) { delete stream; } -void osCacheRead(Stream *stream) { +void osDataRead(Stream *stream, const char *dir) { char path[255]; - strcpy(path, Stream::cacheDir); + strcpy(path, dir); strcat(path, stream->name); FILE *f = fopen(path, "rb"); if (f) { @@ -1375,13 +1376,22 @@ void osCacheRead(Stream *stream) { delete stream; } -void osReadSlot(Stream *stream) { - return osCacheRead(stream); +void osCacheWrite(Stream *stream) { + osDataWrite(stream, cacheDir); +} + +void osCacheRead(Stream *stream) { + osDataRead(stream, cacheDir); } void osWriteSlot(Stream *stream) { - return osCacheWrite(stream); + osDataWrite(stream, saveDir); } + +void osReadSlot(Stream *stream) { + osDataRead(stream, saveDir); +} + #endif