systemshock icon indicating copy to clipboard operation
systemshock copied to clipboard

Weapon cheating is working incorrectly.

Open shamazmazum opened this issue 5 years ago • 5 comments

As discovered in #360, cheating for weapons (CTRL+2) results in some problems. These problems are:

  • Weapons obtained with cheating cannot be removed from the inventory.
  • They use ammo clips of inappropriate type (see screenshot. Rail gun + Mag carts. What?)
  • Sometimes it can crash the game (#265). It was fixed, but the fix affects normal gameplay (as reported in #360).

20200421_09h10m57s_grim

The code which causes problems is in src/GameSrc/hkeyfunc.c in toggle_giveall_func().

Is there any ideas how to fix it?

shamazmazum avatar Apr 21 '20 06:04 shamazmazum

Items can't be spawned, the cheat command is simply writing over the inventory structure. This is a hard problem; we'd have to load the level where a certain weapon is, put it in the inventory, save the level, then return to the original level.

donnierussellii avatar Apr 21 '20 09:04 donnierussellii

Do you have any ideas how to avoid both #360 and #265? Because 70371bb actually reverts your work. Also, why HUD shows incorrect ammo type for rail gun? Isn't it dangerous?

BTW, I still do not understand how to reproduce #265.

shamazmazum avatar Apr 21 '20 11:04 shamazmazum

Since weapons acquired with the cheat command are not "world" objects, they aren't handled properly in some obscure ways.

I think what's causing the strange ammo type behavior is that, for example, a projectile weapon in slot 4 with these values: player_struct.weapons[4].ammo = 50; player_struct.weapons[4].ammo_type = 0;

is later modified with data for an energy weapon: player_struct.weapons[4].heat = 0; //union'd with ammo player_struct.weapons[4].setting = 40; //union'ed with ammo_type

causing the ammo type to now have a crazy value way out of bounds.

I think one thing to do would be to try to modify any held weapons so that they change into cheat weapons. But if one such weapon was then dropped, I don't know if the world object would be correct.

donnierussellii avatar Apr 21 '20 21:04 donnierussellii

As a quick solution, can the cheat weapon set be replaced with non-energy weapons?

shamazmazum avatar Apr 22 '20 04:04 shamazmazum

Maybe I'm wrong (it's been a long time since I went digging into the code), but I don't think that would fix it, since an energy weapon can be in a slot before the cheat is applied. When the weapon inventory is overwritten by the cheat, the world objects that were there are caught in limbo and confuse the game in peculiar ways. The cheats were probably just quick, quite broken hacks, and aren't like the ones you see in, for example, DOOM. I recall fixing another that crashed when cycling through levels.

donnierussellii avatar Apr 23 '20 19:04 donnierussellii