Skip to content

Commit

Permalink
don't opt crc magic
Browse files Browse the repository at this point in the history
  • Loading branch information
liberize committed Dec 5, 2024
1 parent 54015ab commit 74db1cb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ enum ScriptFormat {
LUA,
};

#ifdef VERIFY_CHECKSUM
DISABLE_OPTIMIZATION FORCE_INLINE uint32_t* get_cksum_data() {
static uint32_t cksum_data[2];
memcpy(cksum_data, "ssccksum", 8);
return cksum_data;
}
#endif

int main(int argc, char* argv[]) {
#ifdef UNTRACEABLE
check_debugger(true);
Expand All @@ -50,8 +58,7 @@ int main(int argc, char* argv[]) {
std::string exe_path = get_exe_path();

#ifdef VERIFY_CHECKSUM
static uint32_t cksum_data[2]; // use static to prevent compiler from optimizing
memcpy(cksum_data, "ssccksum", 8);
auto cksum_data = get_cksum_data();
if (is_big_endian()) {
cksum_data[0] = byteswap32(cksum_data[0]);
cksum_data[1] = byteswap32(cksum_data[1]);
Expand Down
8 changes: 8 additions & 0 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@

#define FORCE_INLINE __attribute__((always_inline)) inline

#if defined(__GNUC__)
#define DISABLE_OPTIMIZATION __attribute__((optimize("O0")))
#elif defined(__clang__)
#define DISABLE_OPTIMIZATION [[clang::optnone]]
#else
#define DISABLE_OPTIMIZATION
#endif

#define LOGD(fmt, ...) /* fprintf(stdout, OBF(fmt "\n"), ##__VA_ARGS__) */
#define LOGE(fmt, ...) fprintf(stderr, OBF(fmt "\n"), ##__VA_ARGS__)

Expand Down

0 comments on commit 74db1cb

Please sign in to comment.