Commit graph

5105 commits

Author SHA1 Message Date
Kp bcf06623a5 Disable morph processing in demo files
It reads uninitialized values, so it was barely functional before
morph_data became a dynamic allocation, and it is broken now.  Disable
it to avoid crashing the game.  The demo code should have initialized
the morph_data structure properly, but does not.

Reported-by: tycho <https://github.com/dxx-rebirth/dxx-rebirth/issues/496>
Fixes: cac5f1da56 ("Move morph_data into dynamic allocations")
2020-02-06 03:22:45 +00:00
Kp f1c6177338 Poison morph_data on allocation
Require the caller to provide sane values later.
2020-02-06 03:22:45 +00:00
Kp edc8819409 Add hint about range of bitmap indices
When building with AddressSanitizer, gcc warns that `i` may not fit,
because the compiler fails to adequately constrain the possible values
for `i`.  Add a control-flow hint to inform gcc about valid values.
2020-02-06 03:22:45 +00:00
Kp 74271443ed Add definition of d_level_shared_boss_state::D1_Boss_*_interval
These variables are used, but optimized builds eliminate all reference
to their address, so the build normally succeeds.  Unoptimized builds
retain references to the address, so a definition is required for them.

Reported-by: tycho <https://github.com/dxx-rebirth/dxx-rebirth/issues/496>
Fixes: 595c3ca086 ("Move Boss_cloak_interval to d_level_shared_boss_state")
Fixes: c61dee7e6a ("Move Boss_teleport_interval to d_level_shared_boss_state")
2020-02-06 03:22:45 +00:00
Kp 8ebb66c5c9 Remember player's hostages_on_board across secret level return
Returning from a secret level clears the player's `hostages_on_board` to
0 as part of initializing a "new" ship, but this is not desirable
behavior.  Copy the counter out before and back afterward.

    ```
    Thread 1 "d2x-rebirth-edi" hit Hardware watchpoint 1: -location d2x::LevelUniqueObjectState.Objects._M_elems[0].ctype.player_info.mission.hostages_on_board

    Old value = 5 '\005'
    New value = 0 '\000'

    #0  d2x::init_player_stats_ship (GameTime64=<optimized out>, plrobj=...) at similar/main/gameseq.cpp:613
    #1  d2x::init_player_stats_level (secret_flag=d2x::secret_restore::survived, plrobj=..., plr=...) at similar/main/gameseq.cpp:615
    #2  d2x::StartNewLevelSub (level_num=level_num@entry=3, page_in_textures=page_in_textures@entry=1, secret_flag=secret_flag@entry=d2x::secret_restore::survived) at similar/main/gameseq.cpp:1901
    #3  d2x::state_restore_all_sub (LevelSharedDestructibleLightState=..., secret=d2x::secret_restore::survived, filename=<optimized out>) at similar/main/state.cpp:1670
    #4  d2x::state_restore_all (in_game=in_game@entry=1, secret=secret@entry=d2x::secret_restore::survived, filename_override=<optimized out>, blind=blind@entry=dcx::blind_save::no) at similar/main/state.cpp:1490
    #5  d2x::ExitSecretLevel ()
    ```

Reported-by: teratorn <https://github.com/dxx-rebirth/dxx-rebirth/issues/495>
2020-02-01 22:33:31 +00:00
Kp 0ea0a5ff31 Avoid scaling morph vector by length 0 2020-02-01 22:33:31 +00:00
Kp 7c9b8d61b8 Zip morph elements for traversal
This generates code that increments a group of pointers, instead of
incrementing an index and repeatedly multiplying it to compute each
index.
2020-02-01 22:33:31 +00:00
Kp 2bbda9d92c Factor out morph bounding box setup 2020-02-01 22:33:31 +00:00
Kp 669c341147 Move d_level_unique_morph_object_state to d_level_unique_object_state 2020-02-01 22:33:31 +00:00
Kp cac5f1da56 Move morph_data into dynamic allocations
This improves poison detection, and eliminates some large static
allocations (MAX_VECS * ((2 * vms_vector) + fix)).
2020-02-01 22:33:31 +00:00
Kp c55c7d1bd6 Move morph_data to dcx
Only one member was part of dsx, and it could be dcx instead.
2020-02-01 22:33:31 +00:00
Kp ab55d26051 Zip ranges passed to rotate_point_list
This gains a range check on the output, and makes the relation of input
and output parameters clear in the function signature.
2020-02-01 22:33:31 +00:00
Kp 0db0230689 Use enumerate to manage morph index/pointer 2020-02-01 22:33:31 +00:00
Kp 25d782812c Make some update_points variables const 2020-02-01 22:33:31 +00:00
Kp f65ce8bbe4 Make some init_points variables const 2020-02-01 22:33:31 +00:00
Kp 7eaa8f03d7 Hold polymodel data const in morph code 2020-02-01 22:33:31 +00:00
Kp 0aaa263adf Use enum class for morph_data submodel_state
Name the state members, instead of using magic constants.  Also, switch
from `int` to `uint8_t`, since there are only 3 valid values.
2020-02-01 22:33:31 +00:00
Kp 5653124a43 Move MAX_VECS into morph_data 2020-02-01 22:33:31 +00:00
AlumiuN 915172478f Initial fix for doors with linked walls other than their connected side 2020-01-24 14:12:43 +13:00
Kp 4b48e0cd14 Fix Windows build break
Commit d879fc7f6b changed the type of `newpath` and updated all uses
in common code.  A Windows-only block was skipped.  Update that now.

Fixes: d879fc7f6b ("Convert file selection to use array<char, N>, not char[N]")
2020-01-19 00:33:47 +00:00
Kp 19c5f4064e Fix bogus unused variable warning from clang in inferno.cpp
Fixes: 59b94a4dcb ("Call arch_close before atexit hooks begin")
2020-01-18 22:43:19 +00:00
Kp 81e0b95e1b Merge 'thief-suppress-fix' into master 2020-01-18 21:57:47 +00:00
Kp 844e5f92b2 Fix stack buffer overruns in newdemo code
When presented with an overlong string, throw std::runtime_error instead
of corrupting memory.  Either way, the result is a crash, but this crash
is safe, deterministic, and probably easier to debug.
2020-01-18 21:57:39 +00:00
Kp 1a2cfa35ba Fix saving/loading games for missions in subdirectories
The historical savegame format cannot support finding a mission in a
subdirectory.  Add a backwards-incompatible modification to store the
full path in the savegame, and store it in a way that old versions will
fail gracefully.[1]  When loading demos, or legacy savegames, search for
the mission in all available directories.  Demos are still written with
an unqualified path because the demo loading code would crash if given
an oversized path.  Mission names sent over the network as part of
multiplayer use the guess logic now, so that guests do not need to have
the mission in the same path as the host.

[1] Versions affected by issue #486 may fail ungracefully.

Reported-by: AlumiuN <https://github.com/dxx-rebirth/dxx-rebirth/issues/491>
2020-01-18 21:57:39 +00:00
Kp 3e2d47f879 Track mission type correctly when loading mission list
- In D2X, do not accept Descent2-specific directives from Descent 1
  `.msn` files.
- Set the descent_version field correctly in the `mle`.  Previously,
  `.msn` was set to descent1 and all `.mn2` were set to descent2,
  regardless of whether the `.mn2` used `name`, `xname`, `zname`, or
  `!name`.
- Avoid rewinding the file and rereading the same line while checking
  the possible name types.
- Avoid recomputing end-of-string when it is already known.
- Avoid re-reading the mission file's version when the mission is
  chosen.  Instead, use the version that was recorded when the mission
  was loaded into the mission list.  This also fixes a bug where Descent
  1 `.msn` files would be classified as descent_version_type::descent2
  since both use `name =`, but that string has a different meaning
  depending on whether the file is `.msn` or `.mn2`.
2020-01-18 21:57:39 +00:00
Kp 3d09f4544b Remove macro Current_mission_filename 2020-01-18 21:57:39 +00:00
Kp 99356e0cdb Use enum for include/exclude anarchy mode 2020-01-18 21:57:39 +00:00
Kp d879fc7f6b Convert file selection to use array<char, N>, not char[N]
Eliminate some uses of strncpy as part of the conversion.
2020-01-18 21:57:39 +00:00
AlumiuN f98d8caea1 Make thief bot drop any map-specified items if option to suppress it is enabled 2020-01-10 19:58:54 +13:00
Kp 47a3df9fab Clean invalid robot joint data on load
Some levels have robots with n_joints=0 and an invalid offset.  If the
number of joints is zero, the offset is irrelevant.  Reset it to 0, so
that a later call to partial_range will not trap.

Reported-by: kakhome1 <https://github.com/dxx-rebirth/dxx-rebirth/issues/485>
2020-01-08 04:32:39 +00:00
Kp b0185e44ad Fix displacing players when synthesizing player start positions
TORRaven reported an issue where `Descent: First Strike` level 4 in
cooperative games would cause the player 0 ship to be unable to move.
On investigation, this occurs when the host has enabled extra player
starts, and the resulting synthesis of new player start positions moves
the player 0 start out of its origin segment.  The physics engine reacts
poorly to this situation, causing the object to be unable to move and to
report HIT_BAD_P0 in debug builds.  Add a test to cancel the
displacement if get_seg_masks reports that the center point would move
outside the origin segment.  More clever logic might be appropriate, but
since this is the first report of problems with the feature since its
introduction in 5a64ee5132, this commit just eliminates the
immediate problem.  Possible future improvements if the existing
displacement causes collisions:

- Reduce the magnitude of the existing displacement, instead of
  abandoning it entirely.
- Move the player start to the segment's center before displacing it.
- Add logic to move the player into a nearby logically connected
  segment.

Reported-by: TORRaven <https://github.com/dxx-rebirth/dxx-rebirth/issues/483>
Fixes: 5a64ee5132 ("Add experimental support for larger cooperative games")
2020-01-06 01:25:35 +00:00
Kp ffb4240710 Report failure when a mission is not found in the mission list
AlumiuN reported a crash when a save game is unable to load the
underlying mission.  The crash is because the game proceeds to load the
savegame onto whatever level was loaded before this mission, which will
usually result in fatal inconsistencies in the data.

This commit does not fix the cause of the inability to load the mission,
but instead fixes the logic so that the user gets a reasonable error
message advising that the mission failed to load.  This was
unintentionally broken in db80a88ad2 when the sense of the return
value was inverted, and the fallthrough case was not adjusted.  This
impacts all uses of `load_mission_by_name`, though in practice restoring
from a savegame is the most obvious way to hit the problem.

Reported-by: AlumiuN <https://github.com/dxx-rebirth/dxx-rebirth/issues/486> (indirectly)
Fixes: db80a88ad2 ("Improve error message on failure to load mission")
2020-01-06 01:25:35 +00:00
Kp 59b94a4dcb Call arch_close before atexit hooks begin
arch_close calls various library shutdown routines, some of which may
not be in good order after atexit hooks begin executing.  Call it before
returning from main, so that the libraries are still fully initialized.
2020-01-06 01:25:35 +00:00
Kp e2a108bbf5 Use base32 instead of base64+extended-identifiers
Extended identifiers have proved to cause more problems than they solve.
Switch to base32 which, while less commonly supported, is available in
Python and uses an alphabet that is almost a subset of the C identifier
alphabet.  Padding characters are still a problem, but can be remapped
to a valid C identifier that is not a valid base32 character.
2019-12-29 22:24:20 +00:00
Kp 05a54ef7c1 Merge pull #479 into master 2019-12-27 02:08:58 +00:00
Kp ce906560ab Use susegment for segment2_read 2019-12-27 02:02:23 +00:00
Kp 34366d84c2 Use susegment for dumpmine iteration 2019-12-27 02:02:23 +00:00
Kp c9b1b5b1ec Use susegment for WALL_IS_DOORWAY 2019-12-27 02:02:23 +00:00
ziplantil 398d9013ef Merge remote-tracking branch 'upstream/master' into vertigo-exit-fix 2019-12-24 01:49:11 +02:00
Kp dfae1c7203 Split object_move_all for game/endlevel
endlevel wants to freeze the console player's last in-mine position.
Instead of copying the position out and back, refactor the flow to let
endlevel skip the update of the position.
2019-12-22 05:34:08 +00:00
Kp 36873ec12d Simplify maybe_ai_do_actual_firing_stuff
The second parameter always points to a substructure in the first
parameter.  Remove the second parameter.
2019-12-22 05:34:08 +00:00
Kp 5dfd62c4f6 Use susegment for references introduced by valptridx conversion 2019-12-22 05:34:08 +00:00
Kp c93e7f44c3 Move object::last_pos to LevelUniqueObjectState
Only the console player's last position needs to be remembered across
frames.  Copy the console player's position out before processsing
object movement.  For all other objects, retain a temporary for use by
the position recovery code.
2019-12-22 05:34:08 +00:00
Kp 30091902af Simplify valptridx types where possible
Switch valptridx::ptr to a reference type.
Switch valptridx::ptridx to a reference type or to ::ptr.

Fix up uses of operator-> accordingly.
2019-12-22 05:34:08 +00:00
Kp c3265f6b90 Convert segment & to susegment where possible 2019-12-22 05:34:08 +00:00
Kp 00d09b2bdb Move free_object_slots predicates to dcx 2019-12-22 05:34:08 +00:00
Kp cc144647b5 Make kconfig.ui-table.cpp compile when freestanding
Special macros are used to pass information to
`generate-kconfig-udlr.py`.  Provide default definitions for these
macros in `kconfig.ui-table.cpp`, and override them in the one build
where they need to be special.  This enables `kconfig.ui-table.cpp` to
build cleanly when invoked from the command line in the compilation
database.
2019-12-22 05:34:08 +00:00
Kp f26d91bbe2 Change kconfig type/state fields to enums 2019-12-22 05:34:08 +00:00
Kp d2f2f98850 Use symbolic STATE_NONE for kconfig entries with no state bit 2019-12-22 05:34:08 +00:00
ziplantil 4cb06c43f7 revert to old load behavior when emulating D1 2019-12-21 23:42:04 +02:00