From 778a1474c79f1a538f64e561b0a2300d2bcbaec2 Mon Sep 17 00:00:00 2001 From: Tanasart Date: Wed, 25 Dec 2024 08:50:08 +0700 Subject: [PATCH] [ASE File In] Fix crash when loading aseprite file with mismatched palette data. --- scripts/ase_reader/ase_reader.gml | 24 +++++++-------- .../node_ase_file_read/node_ase_file_read.gml | 30 +++++++++++-------- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/scripts/ase_reader/ase_reader.gml b/scripts/ase_reader/ase_reader.gml index 0bbbc43bd..633956f20 100644 --- a/scripts/ase_reader/ase_reader.gml +++ b/scripts/ase_reader/ase_reader.gml @@ -156,8 +156,8 @@ globalvar __ase_format_chunk_color_profile; __ase_format_chunk_color_profile = [ [_BIN_TYPE.word, "Flag"], //1: Fix gamma [_BIN_TYPE.fixed, "Fixed gamma"], [_BIN_TYPE.byte, "Unused", 8], - [_BIN_TYPE.dword, "ICC Data length", 1, function(chunk) { return chunk[$ "Type"] == 2; }], - [_BIN_TYPE.byte, "ICC Data", "ICC Data length", function(chunk) { return chunk[$ "Type"] == 2; }], + [_BIN_TYPE.dword, "ICC Data length", 1, function(c) /*=>*/ {return c[$ "Type"] == 2}], + [_BIN_TYPE.byte, "ICC Data", "ICC Data length", function(c) /*=>*/ {return c[$ "Type"] == 2}], ]; globalvar __ase_format_chunk_file; __ase_format_chunk_file = [ @@ -201,16 +201,16 @@ globalvar __ase_format_chunk_palette_entry; __ase_format_chunk_palette_entry = [ [_BIN_TYPE.byte, "Green"], [_BIN_TYPE.byte, "Blue"], [_BIN_TYPE.byte, "Alpha"], - [_BIN_TYPE.string, "Name", 1, function(chunk) { return chunk[$ "Flag"] & (1 << 0); }], + [_BIN_TYPE.string, "Name", 1, function(c) /*=>*/ {return c[$ "Flag"] & (1 << 0)}], ]; globalvar __ase_format_chunk_user_data; __ase_format_chunk_user_data = [ [_BIN_TYPE.dword, "Flag"], //1: Text, 2: Color, 4: Properties - [_BIN_TYPE.string, "Name", 1, function(chunk) { return chunk[$ "Flag"] & (1 << 0); }], - [_BIN_TYPE.byte, "Red", 1, function(chunk) { return chunk[$ "Flag"] & (1 << 1); }], - [_BIN_TYPE.byte, "Green", 1, function(chunk) { return chunk[$ "Flag"] & (1 << 1); }], - [_BIN_TYPE.byte, "Blue", 1, function(chunk) { return chunk[$ "Flag"] & (1 << 1); }], - [_BIN_TYPE.byte, "Alpha", 1, function(chunk) { return chunk[$ "Flag"] & (1 << 1); }], + [_BIN_TYPE.string, "Name", 1, function(c) /*=>*/ {return c[$ "Flag"] & (1 << 0)} ], + [_BIN_TYPE.byte, "Red", 1, function(c) /*=>*/ {return c[$ "Flag"] & (1 << 1)} ], + [_BIN_TYPE.byte, "Green", 1, function(c) /*=>*/ {return c[$ "Flag"] & (1 << 1)} ], + [_BIN_TYPE.byte, "Blue", 1, function(c) /*=>*/ {return c[$ "Flag"] & (1 << 1)} ], + [_BIN_TYPE.byte, "Alpha", 1, function(c) /*=>*/ {return c[$ "Flag"] & (1 << 1)} ], ]; globalvar __ase_format_chunk_user_data_prop; __ase_format_chunk_user_data_prop = [ @@ -256,10 +256,10 @@ globalvar __ase_format_chunk_tileset; __ase_format_chunk_tileset = [ [_BIN_TYPE.short, "Base index"], [_BIN_TYPE.byte, "Reserved", 14], [_BIN_TYPE.string, "Name"], - [_BIN_TYPE.dword, "ID of external file", 1, function(chunk) { return chunk[$ "Flag"] & (1 << 1); }], - [_BIN_TYPE.dword, "Tileset ID", 1, function(chunk) { return chunk[$ "Flag"] & (1 << 1); }], - [_BIN_TYPE.dword, "Data length", 1, function(chunk) { return chunk[$ "Flag"] & (1 << 2); }], - [_BIN_TYPE.pixel, "Compressed image", "Data length", function(chunk) { return chunk[$ "Flag"] & (1 << 2); }], + [_BIN_TYPE.dword, "ID of external file", 1, function(c) /*=>*/ {return c[$ "Flag"] & (1 << 1)} ], + [_BIN_TYPE.dword, "Tileset ID", 1, function(c) /*=>*/ {return c[$ "Flag"] & (1 << 1)} ], + [_BIN_TYPE.dword, "Data length", 1, function(c) /*=>*/ {return c[$ "Flag"] & (1 << 2)} ], + [_BIN_TYPE.pixel, "Compressed image", "Data length", function(c) /*=>*/ {return c[$ "Flag"] & (1 << 2)} ], ]; function read_format_type(_bin, datType, outMap) { diff --git a/scripts/node_ase_file_read/node_ase_file_read.gml b/scripts/node_ase_file_read/node_ase_file_read.gml index 2ef8be58a..6b6682468 100644 --- a/scripts/node_ase_file_read/node_ase_file_read.gml +++ b/scripts/node_ase_file_read/node_ase_file_read.gml @@ -165,15 +165,13 @@ function Node_ASE_File_Read(_x, _y, _group = noone) : Node(_x, _y, _group) const edit_time = 0; attributes.file_checker = true; - array_push(attributeEditors, [ "File Watcher", function() { return attributes.file_checker; }, - new checkBox(function() { attributes.file_checker = !attributes.file_checker; }) ]); + array_push(attributeEditors, [ "File Watcher", function() /*=>*/ {return attributes.file_checker}, new checkBox(function() /*=>*/ { attributes.file_checker = !attributes.file_checker; }) ]); content = noone; layers = []; tags = []; _tag_delay = 0; path_current = ""; - first_update = false; on_drop_file = function(path) { @@ -252,24 +250,30 @@ function Node_ASE_File_Read(_x, _y, _group = noone) : Node(_x, _y, _group) const switch(chunk[$ "Type"]) { case 0x2019: //palette var pals = chunk[$ "Palette"]; - var plt = []; + var pamo = array_length(pals) + var plt = array_create(pamo); + var par = array_create(pamo); - for( var k = 0; k < array_length(pals); k++ ) - array_push(plt, [ pals[k][$ "Red"], pals[k][$ "Green"], pals[k][$ "Blue"], pals[k][$ "Alpha"] ]); + for( var k = 0; k < pamo; k++ ) { + var _clr = pals[k]; + var _r = _clr[$ "Red"] ?? 0; + var _g = _clr[$ "Green"] ?? 0; + var _b = _clr[$ "Blue"] ?? 0; + var _a = _clr[$ "Alpha"] ?? 0; + + plt[k] = [ _r, _g, _b, _a ]; + par[k] = make_color_rgba(_r, _g, _b, _a); + } content[$ "Palette"] = plt; - - var p_arr = []; - for( var k = 0; k < array_length(plt); k++ ) - array_push(p_arr, make_color_rgba(plt[k][0], plt[k][1], plt[k][2], plt[k][3])); - - outputs[3].setValue(p_arr); + outputs[3].setValue(par); break; case 0x2004: //layer var name = chunk[$ "Name"]; + var type = chunk[$ "Layer type"]; - array_push(layers, new ase_layer(name, chunk[$ "Layer type"])); + array_push(layers, new ase_layer(name, type)); array_push(vis, true); break;