From 67ef3655050e63d679086a3547b6fa1069727ec0 Mon Sep 17 00:00:00 2001 From: Taylor Stephensen Date: Sun, 24 Sep 2023 23:06:23 -0400 Subject: [PATCH] Rewrite asset file loading for new toolchain Old implementation throws null dereference errors on new toolchain. New implementation has not been fully stress-tested but should be mostly operational. --- mods/src/misc/misc.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mods/src/misc/misc.cpp b/mods/src/misc/misc.cpp index 44d312892..79c8825db 100644 --- a/mods/src/misc/misc.cpp +++ b/mods/src/misc/misc.cpp @@ -14,10 +14,11 @@ // Read Asset File static AppPlatform_readAssetFile_return_value AppPlatform_readAssetFile_injection(__attribute__((unused)) unsigned char *app_platform, std::string const& path) { // Read File - std::string full_path("data/"); - full_path.append(path); - std::ifstream stream(full_path); - std::string str((std::istreambuf_iterator(stream)), std::istreambuf_iterator()); + std::ifstream stream("data/" + path, std::ios_base::binary | std::ios_base::ate); + long len = stream.tellg(); + char *buf = new char[len]; + stream.seekg(0, stream.beg); + stream.read(buf, len); // Return String AppPlatform_readAssetFile_return_value ret; ret.length = str.length();