Skip to content

Commit

Permalink
Fixes playing cards (#5337)
Browse files Browse the repository at this point in the history
# About the pull request

<!-- Remove this text and explain what the purpose of your PR is.

Mention if you have tested your changes. If you changed a map, make sure
you used the mapmerge tool.
If this is an Issue Correction, you can type "Fixes Issue #169420" to
link the PR to the corresponding Issue number #169420.

Remember: something that is self-evident to you might not be to others.
Explain your rationale fully, even if you feel it goes without saying.
-->

3 layers of fixes for a pretty bad bug with playing cards you might have
seen recently.


# Changelog
:cl:
fix: Fixed an exploit involving playing cards.
/:cl:
  • Loading branch information
fira committed Jan 23, 2024
1 parent bb9dd5a commit 0e0a86a
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions code/game/objects/items/toys/cards.dm
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
. = ..()
populate_deck()

/obj/item/toy/deck/Destroy(force)
. = ..()
QDEL_NULL_LIST(cards)

/obj/item/toy/deck/get_examine_text(mob/user)
. = ..()
. += SPAN_NOTICE("There are <b>[length(cards)]</b> cards remaining in the deck.")
Expand Down Expand Up @@ -75,6 +79,7 @@
var/obj/item/toy/handcard/H = O
for(var/datum/playing_card/P as anything in H.cards)
cards += P
H.cards -= P
update_icon()
qdel(O)
user.visible_message(SPAN_NOTICE("<b>[user]</b> places their cards on the bottom of \the [src]."), SPAN_NOTICE("You place your cards on the bottom of the deck."))
Expand Down Expand Up @@ -271,6 +276,10 @@
if(!concealed)
. += " ([length(cards)] card\s)"

/obj/item/toy/handcard/Destroy(force)
. = ..()
QDEL_NULL_LIST(cards)

/obj/item/toy/handcard/aceofspades
icon_state = "spades_ace"
desc = "An Ace of Spades"
Expand Down Expand Up @@ -315,6 +324,9 @@

//fuck any qsorts and merge sorts. This needs to be brutally easy
var/cards_length = length(cards)
if(cards_length >= 200)
to_chat(usr, SPAN_WARNING("Your hand is too big to sort. Remove some cards."))
return
for(var/i = 1 to cards_length)
for(var/k = 2 to cards_length)
if(cards[i].sort_index > cards[k].sort_index)
Expand All @@ -331,6 +343,7 @@
var/cards_length = length(H.cards)
for(var/datum/playing_card/P in H.cards)
cards += P
H.cards -= P
qdel(O)
if(pile_state)
if(concealed)
Expand Down Expand Up @@ -390,6 +403,8 @@
/obj/item/toy/handcard/MouseDrop(atom/over)
if(usr != over || !Adjacent(usr))
return
if(ismob(loc))
return
usr.put_in_hands(src)

/obj/item/toy/handcard/get_examine_text(mob/user)
Expand Down Expand Up @@ -423,6 +438,12 @@
name = "a playing card"
desc = "A playing card."

if(length(cards) >= 200)
// BYOND will flat out choke when using thousands of cards for some unknown reason,
// possibly due to the transformed overlay stacking below. Nobody's gonna see the
// difference past 40 or so anyway.
return

overlays.Cut()

if(!cards_length)
Expand Down

0 comments on commit 0e0a86a

Please sign in to comment.