From cf9c856c4d2e8c62d17c3709c8615899f2087de1 Mon Sep 17 00:00:00 2001 From: Jari van der Kaap Date: Thu, 4 May 2023 23:23:42 +0200 Subject: [PATCH 1/3] fix: only load the gsc files with the right magic --- src/client/component/script.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/component/script.cpp b/src/client/component/script.cpp index 4a9e3eb6..345b507e 100644 --- a/src/client/component/script.cpp +++ b/src/client/component/script.cpp @@ -69,7 +69,7 @@ namespace script { std::string data; auto script_file = script.generic_string(); - if (!std::filesystem::is_directory(script) && utils::io::read_file(script_file, &data)) + if (!std::filesystem::is_directory(script) && utils::io::read_file(script_file, &data) && *(int*)data.c_str() == 0x43534780) { print_loading_script(script_file); load_script(script_file, data); From a73b0e21d34c6b6cfbcef9296d67aade56b542ba Mon Sep 17 00:00:00 2001 From: Jari van der Kaap Date: Thu, 4 May 2023 23:48:41 +0200 Subject: [PATCH 2/3] fix: use int64 for gsc magic --- src/client/component/script.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/component/script.cpp b/src/client/component/script.cpp index 345b507e..bab1d7b8 100644 --- a/src/client/component/script.cpp +++ b/src/client/component/script.cpp @@ -69,7 +69,7 @@ namespace script { std::string data; auto script_file = script.generic_string(); - if (!std::filesystem::is_directory(script) && utils::io::read_file(script_file, &data) && *(int*)data.c_str() == 0x43534780) + if (!std::filesystem::is_directory(script) && utils::io::read_file(script_file, &data) && *(uint64_t*)data.c_str() == 0x1C000A0D43534780) { print_loading_script(script_file); load_script(script_file, data); From 7942e360beb9e5dfd3a0ffcff1c10c71758019a2 Mon Sep 17 00:00:00 2001 From: Jari van der Kaap Date: Sat, 6 May 2023 11:54:42 +0200 Subject: [PATCH 3/3] change gsc to const, check file size and use memcmp --- src/client/component/script.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/client/component/script.cpp b/src/client/component/script.cpp index bab1d7b8..2958dae6 100644 --- a/src/client/component/script.cpp +++ b/src/client/component/script.cpp @@ -12,6 +12,8 @@ namespace script { namespace { + constexpr size_t GSC_MAGIC = 0x1C000A0D43534780; + utils::hook::detour db_findxassetheader_hook; utils::hook::detour gscr_get_bgb_remaining_hook; @@ -69,10 +71,13 @@ namespace script { std::string data; auto script_file = script.generic_string(); - if (!std::filesystem::is_directory(script) && utils::io::read_file(script_file, &data) && *(uint64_t*)data.c_str() == 0x1C000A0D43534780) + if (!std::filesystem::is_directory(script) && utils::io::read_file(script_file, &data)) { - print_loading_script(script_file); - load_script(script_file, data); + if (data.size() >= sizeof(GSC_MAGIC) && !std::memcmp(data.data(), &GSC_MAGIC, sizeof(GSC_MAGIC))) + { + print_loading_script(script_file); + load_script(script_file, data); + } } else if (std::filesystem::is_directory(script)) {