From e35e4529a2637a6a3e789bc3b20af6214d4fe0f2 Mon Sep 17 00:00:00 2001 From: Agent X <44549182+AgentXLP@users.noreply.github.com> Date: Sun, 19 May 2024 12:31:12 -0400 Subject: [PATCH] Fix overflow, hex codes not working, and add dev prints --- src/game/player_palette.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/game/player_palette.c b/src/game/player_palette.c index 78f1b1b35..e005b34a3 100644 --- a/src/game/player_palette.c +++ b/src/game/player_palette.c @@ -1,4 +1,5 @@ #include +#include #include "pc/ini.h" #include "pc/mods/mods.h" #include "pc/mods/mods_utils.h" @@ -43,13 +44,14 @@ void player_palettes_reset(void) { static u8 read_value(const char* data) { if (data == NULL) { return 0; } + data = sys_strlwr((char*)data); for (size_t i = 0; i < strlen(data); i++) { char c = data[i]; if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || c == 'x')) { return 0; } } - return strtol(data, NULL, 0); + return MIN(strtol(data, NULL, 0), 255); } void player_palettes_read(const char* palettesPath) { @@ -82,7 +84,12 @@ void player_palettes_read(const char* palettesPath) { } if (strlen(path) == 0) { continue; } - if (!player_palette_init(palettesPath, path)) { continue; } + if (!player_palette_init(palettesPath, path)) { +#ifdef DEVELOPMENT + printf("Failed to load palette '%s.ini'\n", path); +#endif + continue; + } struct PlayerPalette palette = {{ { read_value(ini_get(sPalette, "PALETTE", "PANTS_R")), read_value(ini_get(sPalette, "PALETTE", "PANTS_G")), read_value(ini_get(sPalette, "PALETTE", "PANTS_B")) }, @@ -100,6 +107,9 @@ void player_palettes_read(const char* palettesPath) { strncpy(gPresetPalettes[gPresetPaletteCount].name, path, 4096); gPresetPalettes[gPresetPaletteCount].palette = palette; gPresetPaletteCount++; +#ifdef DEVELOPMENT + printf("Loaded palette '%s.ini'\n", path); +#endif if (gPresetPaletteCount >= MAX_PRESET_PALETTES) { break; } }