Unpack various structures
Prohibit conversion to void* to avoid accidental use with memcpy
This commit is contained in:
parent
78143eb045
commit
f6631ce742
|
@ -31,6 +31,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|||
#include "palette.h"
|
||||
#include "dxxsconf.h"
|
||||
#include "fmtcheck.h"
|
||||
#include "pack.h"
|
||||
|
||||
#ifdef DXX_BUILD_DESCENT_I
|
||||
extern int HiresGFXAvailable;
|
||||
|
@ -120,7 +121,7 @@ struct grs_bitmap
|
|||
};
|
||||
|
||||
//font structure
|
||||
struct grs_font
|
||||
struct grs_font : public prohibit_void_ptr<grs_font>
|
||||
{
|
||||
short ft_w; // Width in pixels
|
||||
short ft_h; // Height in pixels
|
||||
|
@ -142,7 +143,7 @@ struct grs_font
|
|||
|
||||
#define GRS_FONT_SIZE 28 // how much space it takes up on disk
|
||||
|
||||
struct grs_canvas
|
||||
struct grs_canvas : public prohibit_void_ptr<grs_canvas>
|
||||
{
|
||||
grs_bitmap cv_bitmap; // the bitmap for this canvas
|
||||
short cv_color; // current color
|
||||
|
@ -154,7 +155,7 @@ struct grs_canvas
|
|||
short cv_font_bg_color; // current font background color (-1==Invisible)
|
||||
};
|
||||
|
||||
struct grs_screen
|
||||
struct grs_screen : public prohibit_void_ptr<grs_screen>
|
||||
{ // This is a video screen
|
||||
grs_canvas sc_canvas; // Represents the entire screen
|
||||
u_int32_t sc_mode; // Video mode number
|
||||
|
|
46
common/include/pack.h
Normal file
46
common/include/pack.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
#pragma once
|
||||
|
||||
#include "dxxsconf.h"
|
||||
#include "compiler-type_traits.h"
|
||||
|
||||
template <typename T>
|
||||
class exact_type
|
||||
{
|
||||
T *p;
|
||||
public:
|
||||
// Conversion to void* variants is prohibited
|
||||
operator void *() const DXX_CXX11_EXPLICIT_DELETE;
|
||||
operator volatile void *() const DXX_CXX11_EXPLICIT_DELETE;
|
||||
operator const void *() const DXX_CXX11_EXPLICIT_DELETE;
|
||||
operator const volatile void *() const DXX_CXX11_EXPLICIT_DELETE;
|
||||
bool operator<(exact_type<T>) const DXX_CXX11_EXPLICIT_DELETE;
|
||||
bool operator<=(exact_type<T>) const DXX_CXX11_EXPLICIT_DELETE;
|
||||
bool operator>(exact_type<T>) const DXX_CXX11_EXPLICIT_DELETE;
|
||||
bool operator>=(exact_type<T>) const DXX_CXX11_EXPLICIT_DELETE;
|
||||
exact_type(T *t) : p(t) {}
|
||||
// Conversion to the exact type is permitted
|
||||
operator T *() const { return p; }
|
||||
bool operator==(exact_type<T> rhs) const { return p == rhs.p; }
|
||||
bool operator!=(exact_type<T> rhs) const { return p != rhs.p; }
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class prohibit_void_ptr
|
||||
{
|
||||
public:
|
||||
// Return a proxy when the address is taken
|
||||
exact_type<T> operator&() { return static_cast<T*>(this); }
|
||||
exact_type<T const> operator&() const { return static_cast<T const*>(this); }
|
||||
};
|
||||
|
||||
struct allow_void_ptr {};
|
||||
|
||||
template <typename T>
|
||||
struct has_prohibit_void_ptr : tt::is_base_of<prohibit_void_ptr<T>, T> {};
|
||||
|
||||
template <typename T>
|
||||
struct has_prohibit_void_ptr<T[]> {};
|
||||
|
||||
template <typename T, typename D>
|
||||
struct inherit_void_ptr_handler : public
|
||||
tt::conditional<has_prohibit_void_ptr<T>::value, prohibit_void_ptr<D>, allow_void_ptr> {};
|
|
@ -32,6 +32,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|||
#include "polyobj.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include "pack.h"
|
||||
|
||||
#define GREEN_GUY 1
|
||||
|
||||
|
@ -165,7 +166,7 @@ enum player_awareness_type_t
|
|||
// This is the stuff that is permanent for an AI object.
|
||||
#if defined(DXX_BUILD_DESCENT_I) || defined(DXX_BUILD_DESCENT_II)
|
||||
// Rather temporal AI stuff.
|
||||
struct ai_local
|
||||
struct ai_local : public prohibit_void_ptr<ai_local>
|
||||
{
|
||||
// These used to be bytes, changed to ints so I could set watchpoints on them.
|
||||
#if defined(DXX_BUILD_DESCENT_I)
|
||||
|
@ -202,7 +203,7 @@ struct ai_local
|
|||
sbyte achieved_state[MAX_SUBMODELS]; // Last achieved state
|
||||
};
|
||||
|
||||
struct ai_static
|
||||
struct ai_static : public prohibit_void_ptr<ai_static>
|
||||
{
|
||||
ubyte behavior; //
|
||||
sbyte flags[MAX_AI_FLAGS]; // various flags, meaning defined by constants
|
||||
|
@ -287,7 +288,7 @@ struct ai_local_rw
|
|||
sbyte achieved_state[MAX_SUBMODELS]; // Last achieved state
|
||||
};
|
||||
|
||||
struct ai_cloak_info
|
||||
struct ai_cloak_info : public prohibit_void_ptr<ai_cloak_info>
|
||||
{
|
||||
fix64 last_time;
|
||||
#if defined(DXX_BUILD_DESCENT_II)
|
||||
|
|
|
@ -32,10 +32,11 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|||
#include "switch.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include "pack.h"
|
||||
|
||||
#define MAX_CONTROLCEN_LINKS 10
|
||||
|
||||
struct control_center_triggers
|
||||
struct control_center_triggers : public prohibit_void_ptr<control_center_triggers>
|
||||
{
|
||||
short num_links;
|
||||
array<short, MAX_CONTROLCEN_LINKS> seg;
|
||||
|
|
|
@ -31,8 +31,9 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|||
#include "mission.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include "pack.h"
|
||||
|
||||
struct Cfg
|
||||
struct Cfg : public prohibit_void_ptr<Cfg>
|
||||
{
|
||||
ubyte DigiVolume;
|
||||
ubyte MusicVolume;
|
||||
|
@ -60,7 +61,7 @@ struct Cfg
|
|||
int MovieTexFilt;
|
||||
int MovieSubtitles;
|
||||
#endif
|
||||
} __pack__;
|
||||
};
|
||||
|
||||
extern struct Cfg GameCfg;
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|||
#ifdef __cplusplus
|
||||
#include "dxxsconf.h"
|
||||
#include "compiler-array.h"
|
||||
#include "pack.h"
|
||||
|
||||
#if defined(DXX_BUILD_DESCENT_I)
|
||||
#define MAX_EFFECTS 60
|
||||
|
@ -51,7 +52,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|||
#define ECLIP_NUM_FORCE_FIELD 78
|
||||
#endif
|
||||
|
||||
struct eclip
|
||||
struct eclip : public prohibit_void_ptr<eclip>
|
||||
{
|
||||
vclip vc; //imbedded vclip
|
||||
fix time_left; //for sequencing
|
||||
|
|
|
@ -30,6 +30,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|||
#include "object.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include "pack.h"
|
||||
|
||||
//------------------------------------------------------------
|
||||
// A refueling center is one segment... to identify it in the
|
||||
|
@ -103,7 +104,7 @@ fix repaircen_give_shields(segment *segp, fix MaxAmountCanTake );
|
|||
//--repair-- abort_repair_center();
|
||||
|
||||
// An array of pointers to segments with fuel centers.
|
||||
struct FuelCenter
|
||||
struct FuelCenter : public prohibit_void_ptr<FuelCenter>
|
||||
{
|
||||
int Type;
|
||||
int segnum;
|
||||
|
@ -119,7 +120,7 @@ struct FuelCenter
|
|||
// The max number of robot centers per mine.
|
||||
#define MAX_ROBOT_CENTERS 20
|
||||
|
||||
struct d1_matcen_info
|
||||
struct d1_matcen_info : public prohibit_void_ptr<d1_matcen_info>
|
||||
{
|
||||
array<int, 1> robot_flags; // Up to 32 different robots
|
||||
fix hit_points; // How hard it is to destroy this particular matcen
|
||||
|
@ -133,7 +134,7 @@ struct d1_matcen_info
|
|||
typedef d1_matcen_info matcen_info;
|
||||
void matcen_info_read(PHYSFS_file *fp, matcen_info &ps, int version);
|
||||
#elif defined(DXX_BUILD_DESCENT_II)
|
||||
struct matcen_info
|
||||
struct matcen_info : public prohibit_void_ptr<matcen_info>
|
||||
{
|
||||
array<int, 2> robot_flags; // Up to 64 different robots
|
||||
fix hit_points; // How hard it is to destroy this particular matcen
|
||||
|
|
|
@ -98,7 +98,7 @@ void net_udp_send_netgame_update();
|
|||
#endif
|
||||
|
||||
// Structure keeping lite game infos (for netlist, etc.)
|
||||
struct UDP_netgame_info_lite
|
||||
struct UDP_netgame_info_lite : public prohibit_void_ptr<UDP_netgame_info_lite>
|
||||
{
|
||||
struct _sockaddr game_addr;
|
||||
short program_iver[3];
|
||||
|
@ -114,7 +114,7 @@ struct UDP_netgame_info_lite
|
|||
ubyte numconnected;
|
||||
ubyte max_numplayers;
|
||||
bit_game_flags game_flag;
|
||||
} __pack__;
|
||||
};
|
||||
|
||||
struct UDP_sequence_packet
|
||||
{
|
||||
|
@ -155,10 +155,10 @@ struct UDP_mdata_store
|
|||
} __pack__;
|
||||
|
||||
// structure to keep track of MDATA packets we've already got
|
||||
struct UDP_mdata_recv
|
||||
struct UDP_mdata_recv : public prohibit_void_ptr<UDP_mdata_recv>
|
||||
{
|
||||
int pkt_num[UDP_MDATA_STOR_QUEUE_SIZE];
|
||||
int cur_slot; // index we can use for a new pkt_num
|
||||
} __pack__;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -211,7 +211,7 @@ struct quaternionpos
|
|||
#define MATRIX_MAX 0x7f // This is based on MATRIX_PRECISION, 9 => 0x7f
|
||||
|
||||
// information for physics sim for an object
|
||||
struct physics_info
|
||||
struct physics_info : public prohibit_void_ptr<physics_info>
|
||||
{
|
||||
vms_vector velocity; // velocity vector of this object
|
||||
vms_vector thrust; // constant force applied to this object
|
||||
|
@ -238,9 +238,9 @@ struct physics_info_rw
|
|||
|
||||
// stuctures for different kinds of simulation
|
||||
|
||||
struct laser_info
|
||||
struct laser_info : public prohibit_void_ptr<laser_info>
|
||||
{
|
||||
struct hitobj_list_t
|
||||
struct hitobj_list_t : public prohibit_void_ptr<hitobj_list_t>
|
||||
{
|
||||
typedef unsigned objnum_t;
|
||||
template <typename T>
|
||||
|
@ -325,7 +325,7 @@ struct laser_info_rw
|
|||
fix multiplier; // Power if this is a fusion bolt (or other super weapon to be added).
|
||||
} __pack__;
|
||||
|
||||
struct explosion_info
|
||||
struct explosion_info : public prohibit_void_ptr<explosion_info>
|
||||
{
|
||||
fix spawn_time; // when lifeleft is < this, spawn another
|
||||
fix delete_time; // when to delete object
|
||||
|
@ -345,7 +345,7 @@ struct explosion_info_rw
|
|||
short next_attach; // next explosion in attach list
|
||||
} __pack__;
|
||||
|
||||
struct light_info
|
||||
struct light_info : public prohibit_void_ptr<light_info>
|
||||
{
|
||||
fix intensity; // how bright the light is
|
||||
};
|
||||
|
@ -355,14 +355,14 @@ struct light_info_rw
|
|||
fix intensity; // how bright the light is
|
||||
} __pack__;
|
||||
|
||||
struct powerup_info
|
||||
struct powerup_info : public prohibit_void_ptr<powerup_info>
|
||||
{
|
||||
int count; // how many/much we pick up (vulcan cannon only?)
|
||||
#if defined(DXX_BUILD_DESCENT_II)
|
||||
int flags; // spat by player?
|
||||
fix64 creation_time; // Absolute time of creation.
|
||||
#endif
|
||||
} __pack__;
|
||||
};
|
||||
|
||||
struct powerup_info_rw
|
||||
{
|
||||
|
@ -374,7 +374,7 @@ struct powerup_info_rw
|
|||
#endif
|
||||
} __pack__;
|
||||
|
||||
struct vclip_info
|
||||
struct vclip_info : public prohibit_void_ptr<vclip_info>
|
||||
{
|
||||
int vclip_num;
|
||||
fix frametime;
|
||||
|
@ -390,7 +390,7 @@ struct vclip_info_rw
|
|||
|
||||
// structures for different kinds of rendering
|
||||
|
||||
struct polyobj_info
|
||||
struct polyobj_info : public prohibit_void_ptr<polyobj_info>
|
||||
{
|
||||
int model_num; // which polygon model
|
||||
vms_angvec anim_angles[MAX_SUBMODELS]; // angles for each subobject
|
||||
|
|
|
@ -33,6 +33,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include "pack.h"
|
||||
|
||||
#define MAX_PLAYERS 8
|
||||
#define MAX_MULTI_PLAYERS MAX_PLAYERS+3
|
||||
|
@ -87,7 +88,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|||
#if defined(DXX_BUILD_DESCENT_I) || defined(DXX_BUILD_DESCENT_II)
|
||||
// When this structure changes, increment the constant
|
||||
// SAVE_FILE_VERSION in playsave.c
|
||||
struct player
|
||||
struct player : public prohibit_void_ptr<player>
|
||||
{
|
||||
// Who am I data
|
||||
char callsign[CALLSIGN_LEN+1]; // The callsign of this player, for net purposes.
|
||||
|
|
|
@ -117,7 +117,7 @@ enum powerup_type_t
|
|||
#define POWERUP_NAME_LENGTH 16 // Length of a robot or powerup name.
|
||||
extern char Powerup_names[MAX_POWERUP_TYPES][POWERUP_NAME_LENGTH];
|
||||
|
||||
struct powerup_type_info
|
||||
struct powerup_type_info : public prohibit_void_ptr<powerup_type_info>
|
||||
{
|
||||
int vclip_num;
|
||||
int hit_sound;
|
||||
|
|
|
@ -27,6 +27,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|||
#define _SWITCH_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include "pack.h"
|
||||
|
||||
struct segment;
|
||||
|
||||
|
@ -108,7 +109,7 @@ struct v30_trigger
|
|||
//the trigger really should have both a type & a flags, since most of the
|
||||
//flags bits are exclusive of the others.
|
||||
#if defined(DXX_BUILD_DESCENT_I) || defined(DXX_BUILD_DESCENT_II)
|
||||
struct trigger
|
||||
struct trigger : public prohibit_void_ptr<trigger>
|
||||
{
|
||||
#if defined(DXX_BUILD_DESCENT_I)
|
||||
short flags;
|
||||
|
|
|
@ -58,7 +58,7 @@ struct objptridx_t;
|
|||
// vclip flags
|
||||
#define VF_ROD 1 // draw as a rod, not a blob
|
||||
|
||||
struct vclip
|
||||
struct vclip : public prohibit_void_ptr<vclip>
|
||||
{
|
||||
fix play_time; // total time (in seconds) of clip
|
||||
unsigned num_frames;
|
||||
|
|
|
@ -32,6 +32,7 @@ struct object;
|
|||
struct objptridx_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include "pack.h"
|
||||
|
||||
#if defined(DXX_BUILD_DESCENT_I)
|
||||
#define MAX_WALLS 175u // Maximum number of walls
|
||||
|
@ -117,7 +118,7 @@ struct objptridx_t;
|
|||
|
||||
#define MAX_STUCK_OBJECTS 32
|
||||
|
||||
struct stuckobj
|
||||
struct stuckobj : public prohibit_void_ptr<stuckobj>
|
||||
{
|
||||
short objnum, wallnum;
|
||||
int signature;
|
||||
|
@ -135,7 +136,7 @@ struct v16_wall
|
|||
sbyte keys;
|
||||
};
|
||||
|
||||
struct v19_wall
|
||||
struct v19_wall : public prohibit_void_ptr<v19_wall>
|
||||
{
|
||||
int segnum,sidenum; // Seg & side for this wall
|
||||
sbyte type; // What kind of special wall.
|
||||
|
@ -150,7 +151,7 @@ struct v19_wall
|
|||
//End old wall structures
|
||||
|
||||
#if defined(DXX_BUILD_DESCENT_I) || defined(DXX_BUILD_DESCENT_II)
|
||||
struct wall
|
||||
struct wall : public prohibit_void_ptr<wall>
|
||||
{
|
||||
short segnum;
|
||||
int sidenum; // Seg & side for this wall
|
||||
|
@ -172,7 +173,7 @@ struct wall
|
|||
};
|
||||
#endif
|
||||
|
||||
struct active_door
|
||||
struct active_door : public prohibit_void_ptr<active_door>
|
||||
{
|
||||
int n_parts; // for linked walls
|
||||
array<short, 2> front_wallnum; // front wall numbers for this door
|
||||
|
@ -181,7 +182,7 @@ struct active_door
|
|||
};
|
||||
|
||||
#if defined(DXX_BUILD_DESCENT_II)
|
||||
struct cloaking_wall
|
||||
struct cloaking_wall : public prohibit_void_ptr<cloaking_wall>
|
||||
{
|
||||
short front_wallnum; // front wall numbers for this door
|
||||
short back_wallnum; // back wall numbers for this door
|
||||
|
@ -200,7 +201,8 @@ struct cloaking_wall
|
|||
#if defined(DXX_BUILD_DESCENT_I) || defined(DXX_BUILD_DESCENT_II)
|
||||
#define MAX_CLIP_FRAMES_D1 20
|
||||
|
||||
struct wclip {
|
||||
struct wclip : public prohibit_void_ptr<wclip>
|
||||
{
|
||||
fix play_time;
|
||||
short num_frames;
|
||||
union {
|
||||
|
|
|
@ -1096,7 +1096,10 @@ static void bm_read_robot(int skip)
|
|||
|
||||
n_textures = first_bitmap_num[i+1] - first_bitmap_num[i];
|
||||
|
||||
model_num = load_polygon_model(model_name[i],n_textures,first_bitmap_num[i],(i==0)?&Robot_info[N_robot_types]:NULL);
|
||||
robot_info *ri = NULL;
|
||||
if (i == 0)
|
||||
ri = &Robot_info[N_robot_types];
|
||||
model_num = load_polygon_model(model_name[i],n_textures,first_bitmap_num[i],ri);
|
||||
|
||||
if (i==0)
|
||||
Robot_info[N_robot_types].model_num = model_num;
|
||||
|
@ -1317,7 +1320,10 @@ void bm_read_player_ship(int skip)
|
|||
|
||||
n_textures = first_bitmap_num[i+1] - first_bitmap_num[i];
|
||||
|
||||
model_num = load_polygon_model(model_name[i],n_textures,first_bitmap_num[i],(i==0)?&ri:NULL);
|
||||
robot_info *pri = NULL;
|
||||
if (i == 0)
|
||||
pri = &ri;
|
||||
model_num = load_polygon_model(model_name[i],n_textures,first_bitmap_num[i],pri);
|
||||
|
||||
if (i==0)
|
||||
Player_ship->model_num = model_num;
|
||||
|
|
Loading…
Reference in a new issue