ID:2396588
 
Code:
    export_custom()

if(usr.isbusy) return

usr.isbusy = 1

if(usr.icon_state != "XXX")
usr << "<br><br><center><b>You can only download custom icons.</b></center></br><br>"

usr.isbusy = 0
return

var/icon/my_icon = icon(usr.icon)
var/icon/new_icon = new

for(var/state in my_icon.IconStates() - "BATTLE_XXX")
new_icon.Insert(icon(my_icon, state), state == "XXX" ? "" : state,,,1)

new_icon.Crop(1,1,32,32)

usr << ftp(new_icon,"[usr.name] Custom Icon.dmi")

usr.isbusy = 0

return


        var/F = input("Please select an icon file.","Choose a *.dmi") as icon
var/icon/I = icon(F)

if(!usr.IsAdmin() && !usr.IsMaster() && !usr.IsIC())

if(length(I) > ico_size)
alert(usr,"Icon is [(length(I)/1024)]Kb! It must be [ico_size/1024]Kb or below.","Upload Icon")
return

if(I.Width() != 32 || I.Height() != 32)
alert(usr,{"Icon is "[I.Width()] x [I.Height()]". It must be 32 x 32!"},"Upload Icon")
return


Problem description:

The first section of code above is a bit of code in place to allow players to download a custom icon created in my game. The icons created in-game have 2 states to them, a walking around state and a BATTLE state. (XXX and BATTLE_XXX). They're also 32x48 for other reasons. The download proc removes the BATTLE state, renames the normal state to a blank name, and crops it down to a 32x32 icon then lets the player download it.

The second section of code is from another proc and is used for players to upload their own hand made icons from their own PC to use. This section is a bit of security to prevent players from using icons larger than 32x32. The player selects their icon, the game checks if the user is a staff member, it checks the file size against the user's calculated max file size allowed (ico_size var. Can be increased in various ways), it checks the Width and Height of the icon to make sure they're not larger than 32.

Unfortunately, it seems like somewhere along the lines here somewhere the icon is getting damaged in some way?

When the icon gets downloaded by the first proc, everything seems fine. The icon is downloaded just fine. You can open it just fine. Everything in dreammaker looks ok. It says its a 32x32 in the dimension settings in the top right.

When you try to upload the icon however, the icon seems to get uploaded incorrectly and the Width() and Height() are giving me a null result and tripping that error message that's coded in. If a staff member who does not face this dimension check on the icon tries to upload one of the icons, the user's icon just becomes null and they turn invisible.

This is not the case for all icons, these ones created by the game specifically are causing issues. Although it has been an occasional issue in the past where an icon would give this same problem and the only way to resolve the issue would be to open the icon, make a new state in it with a few random pixels colored in and save it then re-upload the icon.

To clarify, when exporting the icon...
-A New icon is created.
-only 1 of 2 of the states in the original icon are inserted into the new icon using the Insert() proc
-the new icon is cropped down from 32x48 to 32x32 using the Crop() proc
-the user downloads the new icon that has had the state inserted and has been formatted to 32x32 using the ftp() proc.

When uploading an icon...
-The user selects a file on their own PC using input()
-The selected is assigned to an icon var using the icon() proc
-user is checked for staff position
-Assuming the user fails the staff check, the file size of the icon is checked using the length() proc
-Assuming the user passes the length() check, the dimensions of the icon are checked using Width() and Height().

I can't really seem to tell if the header information is damaged on the icons or one of these procs is screwing things up. Anyone notice anything that might be causing an issue here?

https://www.dropbox.com/s/5g2s08jw9zddi4r/ IceFire2050%20Custom%20Icon.dmi?dl=0

That's one of the icons created by the system if anyone has a way of testing it or checking the information on it?

(Also yes i know the icon is hideous. I just mashed some buttons and numbers in the system to make an icon to prove the point)
Well, this is a band-aid, but it would seem BYOND glitches when you create a completely null, new icon [as can be seen in your export custom script].

So, a slap together fix would be to crop nothing from the users current icon, then scale it up.

There are probably some unnecessary steps here, but oh well.

        var/icon/my_icon = icon(usr.icon)
var/icon/new_icon = icon(usr.icon,"")
new_icon.Crop(0,0,0,0)
new_icon.Scale(my_icon.Width(),my_icon.Height())



I did notice it makes the icon's mask color black, which could be problematic for someone not too familiar with how to change that back to grey. I'd suggest you make an icon with a blank state. Meaning, actually create an icon that has one state which has nothing drawn on it. By doing so, you can use it when creating new empty icons, and it'll preserve the icon mask color.


        var/icon/my_icon = icon(usr.icon)
var/icon/new_icon = icon('blank.dmi')
new_icon.Scale(my_icon.Width(),my_icon.Height())