Fix SSC (Server Side Characters) for Terraria 1.4.5#3164
Fix SSC (Server Side Characters) for Terraria 1.4.5#3164hakusaro merged 10 commits intoPryaxis:general-develfrom
Conversation
eb1dd84 to
fab8545
Compare
…adssc failed) Terraria 1.4.5 changed PlayerItemSlotID to reserve 200 slots per bank instead of 40. Use PlayerItemSlotID constants (Bank1_0, Bank2_0, etc.) for correct network slot indices.
…doutDyeSlots - 1 (989) instead of NetItem.MaxInventory (350) for the last slot check Slot validation: use PlayerItemSlotID.Count (990) instead of NetItem.MaxInventory (350)
64c061b to
bc224f4
Compare
|
conflicts solved |
Co-authored-by: Cai <13110818005@qq.com>
There was a problem hiding this comment.
These changes successfully solved at least the issue that players lose all of their items in Void Vault and Defender's Forge
TShockAPI/GetDataHandlers.cs
Outdated
| // Players send a slot update packet for each inventory slot right after they've joined. | ||
| bool bypassTrashCanCheck = false; | ||
| if (plr == args.Player.Index && !args.Player.HasSentInventory && slot == NetItem.MaxInventory) | ||
| if (plr == args.Player.Index && !args.Player.HasSentInventory && slot == PlayerItemSlotID.Count - 1) // equals to 989, avoid hardcoding |
There was a problem hiding this comment.
Can we derive this somehow in a way that makes it clear what -1 is?
There was a problem hiding this comment.
PlayerItemSlotID.Count (990) is the total number of slot IDs, slots range from 0 to 989, so Count - 1 is the last valid slot index. Would a descriptive comment or a local variable like const int lastSyncSlot = PlayerItemSlotID.Count - 1 be clearer
|
random thoughts screamed into the ether on the ssc changes in 1.4.5.0+ (not related to this PR per se, just something to note for future reference if anyone wants to make changes)
overall fix looks okay from experience making similar changes elsewhere but I cannot personally test tshock's version anytime soon. 👍 |
hakusaro
left a comment
There was a problem hiding this comment.
Most likely this can be merged if you wanna make a small comment or change on the magic number. Otherwise I’m reasonably satisfied!
|
@ACaiCat can you re-review and approve if you're good? |
|
@Nitori-Lab if you can review #3164 I would really appreciate it, but if you can't, nbd! |

ssc mode broken in 1.4.5
/uploadsscthrowingIndexOutOfRangeExceptionin logssc failed. Players can join an ssc-enabled server without being reset, but when they click on items in their inventory, those items turn into whatever ssc already has in that slot. Also, the items can't actually be picked up.
etc.
Root Cause:


1.4.5 source code:
1.4.4.9 source code:
They allocate 200 slots per bank instead of 40.
Changes:
Use
PlayerItemSlotIDconstants instead of sequential slot counter inRestoreCharacterAdd try-finally to ensure
IgnoreSSCPacketsis reset even if exception occursUpdate
HandlePlayerSlotslot validation to usePlayerItemSlotID.Count(990) instead ofNetItem.MaxInventory(350)