When skin isn't actually a .png, also log first few bytes of downloaded data to allow identifying what was actually downloaded (Thanks stein38302)

This commit is contained in:
UnknownShadow200 2020-11-06 21:14:51 +11:00
parent 5c74425d79
commit 9f0f58efab

View File

@ -434,17 +434,20 @@ static cc_result Entity_EnsurePow2(struct Entity* e, struct Bitmap* bmp) {
return 0; return 0;
} }
static void LogInvalidPng(const cc_uint8* data, int size) { static void LogInvalidSkin(cc_result res, const cc_string* url, const cc_uint8* data, int size) {
cc_string str; char buffer[STRING_SIZE]; cc_string msg; char msgBuffer[256];
int i; int i;
String_InitArray(str, buffer); String_InitArray(msg, msgBuffer);
String_AppendConst(&str, " &c(expected \x89\x50\x4E\x47\x0D\x0A\x1A\x0A, but got "); Logger_FormatWarn2(&msg, res, "decoding", url, Platform_DescribeError);
if (res != PNG_ERR_INVALID_SIG) { Logger_WarnFunc(&msg); return; }
String_AppendConst(&msg, " (got ");
for (i = 0; i < min(size, 8); i++) { for (i = 0; i < min(size, 8); i++) {
String_Append(&str, data[i]); String_Append(&msg, data[i]);
} }
String_AppendConst(&str, ")"); String_AppendConst(&msg, ")");
Chat_Add(&str); Logger_WarnFunc(&msg);
} }
static void Entity_CheckSkin(struct Entity* e) { static void Entity_CheckSkin(struct Entity* e) {
@ -496,8 +499,7 @@ static void Entity_CheckSkin(struct Entity* e) {
failed: failed:
url = String_FromRawArray(item.url); url = String_FromRawArray(item.url);
Logger_SysWarn2(res, "decoding", &url); LogInvalidSkin(res, &url, item.data, item.size);
if (res == PNG_ERR_INVALID_SIG) LogInvalidPng(item.data, item.size);
Mem_Free(bmp.scan0); Mem_Free(bmp.scan0);
} }