Skip to content

Commit

Permalink
fix DC spawn malloc issue
Browse files Browse the repository at this point in the history
  • Loading branch information
whitedragon0000 committed Dec 31, 2017
1 parent 46cd157 commit a0177b6
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions engine/openbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -9715,7 +9715,7 @@ s_model *load_cached_model(char *name, char *owner, char unload)

// Command title for log. Details will be added blow accordingly.
// Forced character length is to line up with Alternatepal logs.
printf("\t\t\tPalette - \t");
//printf("\t\t\tPalette: \t");

// Get argument.
value = GET_ARG(1);
Expand All @@ -9728,7 +9728,7 @@ s_model *load_cached_model(char *name, char *owner, char unload)
{
nopalette = 1;

printf("%s\n", "'None' option active. All sprites for this model will be loaded with independent color tables.");
//printf("%s\n", "'None' option active. All sprites for this model will be loaded with independent color tables.");
}
else
{
Expand All @@ -9753,20 +9753,20 @@ s_model *load_cached_model(char *name, char *owner, char unload)
{
if(load_palette(newchar->palette, value) == 0)
{
printf("%s%s\n", "Failed to load color table from .act file: ", value);
//printf("%s%s\n", "Failed to load color table from .act file: ", value);
goto lCleanup;
}
}
else
{
if(loadimagepalette(value, packfile, newchar->palette) == 0)
{
printf("%s%s\n", "Failed to load color table from image: ", value);
//printf("%s%s\n", "Failed to load color table from image: ", value);
goto lCleanup;
}
}

printf("%s%s\n", "Loaded color selection 0: ", value);
//printf("%s%s\n", "Loaded color selection 0: ", value);
}
}

Expand Down Expand Up @@ -14117,7 +14117,7 @@ void load_level(char *filename)
s_model *tempmodel, *cached_model;

int i = 0, j = 0, crlf = 0;
int player_max;
int player_max = MAX_PLAYERS;
int usemap[MAX_BLENDINGS];
char bgPath[128] = {""}, fnbuf[128];
s_loadingbar bgPosi = {0, 0, {0,0}, {0,0}, 0, 0};
Expand Down Expand Up @@ -14196,21 +14196,15 @@ void load_level(char *filename)
strcpy(level->name, filename);

// Allocate memory for player spawn - only as much as we need.
player_max = levelsets[current_set].maxplayers;
level->spawn = malloc(sizeof(*level->spawn) * player_max);
//player_max = levelsets[current_set].maxplayers;
level->spawn = malloc( (sizeof(*level->spawn) * player_max) );

if(buffer_pakfile(filename, &buf, &size) != 1)
{
errormessage = "Unable to load level file!";
goto lCleanup;
}

// Default player spawn Y position just above the screen top.
for(i=0; i < player_max; i++)
{
level->spawn[i].y = videomodes.vRes + 60;
}

level->settime = 100; // Feb 25, 2005 - Default time limit set to 100
level->nospecial = 0; // Default set to specials can be used during bonus levels
level->nohurt = DAMAGE_FROM_ENEMY_ON;
Expand All @@ -14235,7 +14229,13 @@ void load_level(char *filename)
noscreenshot = 0;
panel_width = panel_height = frontpanels_loaded = 0;

//reset_playable_list(1);
//reset_playable_list(1);

// Default player spawn Y position just above the screen top.
for(i = 0; i < player_max; i++)
{
level->spawn[i].y = videomodes.vRes + 60;
}

// Now interpret the contents of buf line by line
pos = 0;
Expand Down Expand Up @@ -14645,11 +14645,13 @@ void load_level(char *filename)

// Verify specified player index exists,
// then set values.
if(i <= player_max)
if(i < player_max)
{
level->spawn[i].x = GET_INT_ARG(1);
level->spawn[i].z = GET_INT_ARG(2);
level->spawn[i].y = GET_INT_ARG(3);
level->spawn[i].y = GET_INT_ARG(3);

if(level->spawn[i].y < 0) level->spawn[i].y = videomodes.vRes + 60;
}

break;
Expand Down Expand Up @@ -17045,11 +17047,14 @@ void ent_default_init(entity *e)
e->takeaction = common_spawn;
}
else if(!e->animation)
{
if(time && level->spawn[(int)e->playerindex].y > e->position.y)
{
int player_index = (int)e->playerindex;
//int max_players = levelsets[current_set].maxplayers;

if(time && level->spawn[player_index].y > e->position.y)//player_index < max_players &&
{
e->takeaction = common_drop;
e->position.y = (float)level->spawn[(int)e->playerindex].y;
e->position.y = (float)level->spawn[player_index].y;
if(validanim(e, ANI_JUMP))
{
ent_set_anim(e, ANI_JUMP, 0);
Expand Down Expand Up @@ -30497,7 +30502,8 @@ void spawnplayer(int index)
p.position.x = (float)(20 + 30 * index);
}
p.flip = 1;
}
}

if(level->spawn[index].z)
{
if(level->scrolldir & (SCROLL_INWARD | SCROLL_OUTWARD))
Expand All @@ -30516,15 +30522,17 @@ void spawnplayer(int index)
else
{
p.position.z = (float)PLAYER_MIN_Z;
}
}

if(p.position.z < PLAYER_MIN_Z)
{
p.position.z = PLAYER_MIN_Z;
}
else if(p.position.z > PLAYER_MAX_Z)
{
p.position.z = PLAYER_MAX_Z;
}
}

//////////////////checking holes/ walls///////////////////////////////////
for(xc = 0; xc < videomodes.hRes / 4; xc++)
{
Expand Down

0 comments on commit a0177b6

Please sign in to comment.