From 3ab0a2a430fdbac5ac0cdc7e09a3c519c378b51c Mon Sep 17 00:00:00 2001 From: Inori Date: Mon, 5 Aug 2019 16:24:16 -0400 Subject: [PATCH] Fix files in archives not loading for no good reason --- binding/filesystem-binding.cpp | 8 +++++++- src/filesystem.cpp | 11 ++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/binding/filesystem-binding.cpp b/binding/filesystem-binding.cpp index 277c0d3..1dbe144 100644 --- a/binding/filesystem-binding.cpp +++ b/binding/filesystem-binding.cpp @@ -79,7 +79,7 @@ RB_METHOD(fileIntRead) { int length = -1; - rb_get_args(argc, argv, "i", &length RB_ARG_END); + rb_get_args(argc, argv, "|i", &length RB_ARG_END); SDL_RWops *ops = getPrivateData(self); @@ -87,6 +87,12 @@ RB_METHOD(fileIntRead) { Sint64 cur = SDL_RWtell(ops); Sint64 end = SDL_RWseek(ops, 0, SEEK_END); + + // Sometimes SDL_RWseek will fail for no reason + // with encrypted archives, so let's just ask + // for the size up front + if (end < 0) end = ops->size(ops); + length = end - cur; SDL_RWseek(ops, cur, SEEK_SET); } diff --git a/src/filesystem.cpp b/src/filesystem.cpp index b3615ac..8f20b59 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -689,7 +689,16 @@ void FileSystem::openReadRaw(SDL_RWops &ops, bool freeOnClose) { PHYSFS_File *handle = PHYSFS_openRead(filename); - // assert(handle); // Ruby exceptions are a little more helpful + + // Not sure what to do with this assert, I feel like + // I should throw an exception for the binding but + // Essentials pings for files that don't exist + + // I'll have to look at it later, but it works fine + // like this so I'll leave it commented out for now + + // assert(handle); + initReadOps(handle, ops, freeOnClose); }