diff --git a/code/__HELPERS/files.dm b/code/__HELPERS/files.dm index 8b4f8d5b54..aad5b4cab1 100644 --- a/code/__HELPERS/files.dm +++ b/code/__HELPERS/files.dm @@ -71,3 +71,18 @@ /proc/pathflatten(path) return replacetext(path, "/", "_") + +/// Returns the md5 of a file at a given path. +/proc/md5filepath(path) + . = md5(file(path)) + +/// Save file as an external file then md5 it. +/// Used because md5ing files stored in the rsc sometimes gives incorrect md5 results. +/proc/md5asfile(file) + var/static/notch = 0 + // its importaint this code can handle md5filepath sleeping instead of hard blocking, if it's converted to use rust_g. + var/filename = "tmp/md5asfile.[world.realtime].[world.timeofday].[world.time].[world.tick_usage].[notch]" + notch = WRAP(notch+1, 0, 2^15) + fcopy(file, filename) + . = md5filepath(filename) + fdel(filename) diff --git a/code/__HELPERS/icons.dm b/code/__HELPERS/icons.dm index 11332863f5..2bd477d98c 100644 --- a/code/__HELPERS/icons.dm +++ b/code/__HELPERS/icons.dm @@ -1126,12 +1126,13 @@ GLOBAL_DATUM_INIT(dummySave, /savefile, new("tmp/dummySave.sav")) //Cache of ico var/list/partial = splittext(iconData, "{") return replacetext(copytext_char(partial[2], 3, -5), "\n", "") -/proc/icon2html(thing, target, icon_state, dir, frame = 1, moving = FALSE) +/proc/icon2html(thing, target, icon_state, dir = SOUTH, frame = 1, moving = FALSE, sourceonly = FALSE) if (!thing) return var/key var/icon/I = thing + if (!target) return if (target == world) @@ -1147,17 +1148,26 @@ GLOBAL_DATUM_INIT(dummySave, /savefile, new("tmp/dummySave.sav")) //Cache of ico if (!isicon(I)) if (isfile(thing)) //special snowflake var/name = sanitize_filename("[generate_asset_name(thing)].png") - if(!SSassets.cache[name]) + if (!SSassets.cache[name]) SSassets.transport.register_asset(name, thing) for (var/thing2 in targets) SSassets.transport.send_assets(thing2, name) + if(sourceonly) + return SSassets.transport.get_asset_url(name) return "" var/atom/A = thing - if (isnull(dir)) - dir = A.dir + + I = A.icon if (isnull(icon_state)) icon_state = A.icon_state - I = A.icon + if (!(icon_state in icon_states(I, 1))) + icon_state = initial(A.icon_state) + if (isnull(dir)) + dir = initial(A.dir) + + if (isnull(dir)) + dir = A.dir + if (ishuman(thing)) // Shitty workaround for a BYOND issue. var/icon/temp = I I = icon() diff --git a/code/modules/asset_cache/asset_cache_item.dm b/code/modules/asset_cache/asset_cache_item.dm index 41cee06db1..72d976bf11 100644 --- a/code/modules/asset_cache/asset_cache_item.dm +++ b/code/modules/asset_cache/asset_cache_item.dm @@ -24,12 +24,10 @@ /datum/asset_cache_item/New(name, file) if (!isfile(file)) file = fcopy_rsc(file) - hash = md5(file) + + hash = md5asfile(file) //icons sent to the rsc sometimes md5 incorrectly if (!hash) - hash = md5(fcopy_rsc(file)) - if (!hash) - CRASH("invalid asset sent to asset cache") - debug_world_log("asset cache unexpected success of second fcopy_rsc") + CRASH("invalid asset sent to asset cache") src.name = name var/extstart = findlasttext(name, ".") if (extstart)