-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
inventory: limit max item quantities to prevent crashing #2554
Conversation
f513750
to
2ae8a17
Compare
Download the built assets for this pull request: |
This linter will be the death of me. Why does it prefer this 💀
|
Inv_InsertItem refers to inserting an item to the inventory ring. I think a more appropriate name for InsertAmmo would be AddAmmo. WDYT? Maybe we could support /give max shotgun ammo for some syntax sugar? |
Good idea on the function name. Ya I will look into supporting the displayed max quantity of shotgun ammo instead of the underlying ammo. I will also try to look into TR1 hiding the ammo count outside of NG+. |
a7737a7
to
66250eb
Compare
I believe all issues are resolved. I fixed the ammo string not displaying for large quantities in TR1. I made a |
@aredfan I will wait for your approval before merging. Take as long as you need, no rush. |
src/libtrx/game/inventory.c
Outdated
{ | ||
weapon_ammo->ammo += qty; | ||
// TODO Check for shotgun_ammo when merged to libtrx and clamp to MAX_QTY | ||
// * 6. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this can be already done using Lara_GetInfo().
@walkawayy no problem and thank you. The only issue I found happens if Lara doesn't have weapons in her inventory. If I use the give command for ammo such as |
Oops I fixed a TR2 bug where I had copied Uzi clip constants into the Magnum functions. @aredfan maybe @lahm86 can correct me, but I don't think it's a bug actually. The way the ammo works underneath the hood is a little odd. Uzis for example:
The main purpose of the PR is to set a realistic cap that will never be reached in normal gameplay and avoid crashes, so the exact number isn't that important imo. |
66250eb
to
d09e1ea
Compare
d09e1ea
to
c55f256
Compare
@lahm86 is it ok if I merge? |
It LGTM. Maybe hang on for rr's approval? |
Checklist
Description
int32_t
since it seems everywhere else that's the quantity type.Inv_InsertAmmo
helper function similar toInv_InsertItem
. This allows us to clamp to the max quantity ofMAX_QTY 999999
(open to suggestions on this).MAX_QTY
prevents thegive
command from causing an overflow which can crash the game, overflow the item quantity, etc. This number seemed big enough to be avoided during normal gameplay, but also give a massive amount if desired. Also allows you to type something likegive 1000000000 shotgun shells
to max out the item for testing without worrying about crashing the game.At first I tried experimenting with checking max
int32_t
values on scan and then checking to make sure the scanned value + the current quantity fit in anint32_t
size, but I think just capping it like this makes the code much simpler. You will only ever hit this max quantity with cheats anyway, so it's just a theoretical cap to prevent crashes.Requires testing all sorts of
give x
ammo commands, picking up normal pickups while at max value, NG+, etc. I don't see any issues but I did notice 2 quirks for feedback:999,999
shotgun ammo is maxed out as166,666
because of the shotgun technically having 6x the pellets per ammo. I don't think it's an issue but I wanted to note it.