limit the range of certain entity attributes
For example, direction angle values can be reduced to +- 360 degree. (0..360 would be sufficient, but some people like their angles negative) This is not a reduction of functionality or a security measure - it's for convenience only: values now wrap around at the borders of their useful ranges.
This commit is contained in:
@@ -662,3 +662,22 @@ void syncentchanges(bool force)
|
||||
changedents.setsize(0);
|
||||
lastentsync = lastmillis;
|
||||
}
|
||||
|
||||
void clampentityattributes(persistent_entity &e)
|
||||
{
|
||||
if(e.type < MAXENTTYPES)
|
||||
{
|
||||
int c;
|
||||
#define CLAMPATTR(x) \
|
||||
c = entwraparound[e.type][x - 1]; \
|
||||
if(c > 0) e.attr##x = (e.attr##x % c + c) % c; /* fold value into range 0..c */ \
|
||||
else if(c < 0) e.attr##x = e.attr##x % (-c) /* fold value into range -c..c */
|
||||
CLAMPATTR(1);
|
||||
CLAMPATTR(2);
|
||||
CLAMPATTR(3);
|
||||
CLAMPATTR(4);
|
||||
CLAMPATTR(5);
|
||||
CLAMPATTR(6);
|
||||
CLAMPATTR(7);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -788,6 +788,7 @@ extern void setspawn(int i, bool on);
|
||||
extern void checkitems(playerent *d);
|
||||
extern vector<int> changedents;
|
||||
extern void syncentchanges(bool force = false);
|
||||
extern void clampentityattributes(persistent_entity &e);
|
||||
|
||||
// rndmap
|
||||
extern void perlinarea(block &b, int scale, int seed, int psize);
|
||||
|
||||
+2
-2
@@ -464,10 +464,10 @@ short entwraparound[MAXENTTYPES][7] =
|
||||
{ 0, 0, 0, 0, 0, 0, 0 }, // helmet
|
||||
{ 0, 0, 0, 0, 0, 0, 0 }, // armour
|
||||
{ 0, 0, 0, 0, 0, 0, 0 }, // akimbo
|
||||
{ 3600, 0, 0, 0, 3600, 0, 0 }, // mapmodel
|
||||
{ -3600, 0, 0, 0, -3600, 0, 0 }, // mapmodel
|
||||
{ 0, 0, 0, 0, 0, 0, 0 }, // trigger
|
||||
{ 0, 0, 0, 0, 0, 0, 0 }, // ladder
|
||||
{ 3600, 0, 0, 0, 0, 0, 0 }, // ctf-flag
|
||||
{ -3600, 0, 0, 0, 0, 0, 0 }, // ctf-flag
|
||||
{ 256, 0, 0, 0, 0, 0, 0 }, // sound
|
||||
{ 0, 0, 0, 0, 0, 0, 0 }, // clip
|
||||
{ 0, 0, 0, 0, 0, 0, 0 } // plclip
|
||||
|
||||
@@ -185,6 +185,7 @@ void entproperty(int prop, int amount)
|
||||
case 12: e.y += amount; break;
|
||||
case 13: e.z += amount; break;
|
||||
}
|
||||
clampentityattributes(e);
|
||||
switch(e.type)
|
||||
{
|
||||
case LIGHT: calclight(); break;
|
||||
@@ -301,6 +302,7 @@ entity *newentity(int index, int x, int y, int z, char *what, int v1, int v2, in
|
||||
if(type != PLAYERSTART) e.attr1 = e.attr1 + 70 - (e.attr1 + 70) % 150;
|
||||
break;
|
||||
}
|
||||
clampentityattributes(e);
|
||||
syncentchanges(true);
|
||||
addmsg(SV_EDITENT, "ri9i3", index<0 ? ents.length() : index, type, e.x, e.y, e.z, e.attr1, e.attr2, e.attr3, e.attr4, e.attr5, e.attr6, e.attr7);
|
||||
e.spawned = true;
|
||||
@@ -404,6 +406,7 @@ void editentity(char **args, int numargs) // index x y z a1 a2 a3 a4 ...
|
||||
case 7: e.attr4 = v; break;
|
||||
}
|
||||
}
|
||||
clampentityattributes(e);
|
||||
switch(e.type)
|
||||
{
|
||||
case LIGHT: calclight(); break;
|
||||
|
||||
@@ -568,6 +568,7 @@ void save_world(char *mname, bool skipoptimise, bool addcomfort)
|
||||
{
|
||||
if(!ne--) break;
|
||||
persistent_entity tmp = ents[i];
|
||||
clampentityattributes(tmp);
|
||||
lilswap((short *)&tmp, 4);
|
||||
lilswap(&tmp.attr5, 1);
|
||||
f->write(&tmp, sizeof(persistent_entity));
|
||||
@@ -716,7 +717,7 @@ bool load_world(char *mname) // still supports all map formats that have
|
||||
if(e.type == LIGHT && e.attr1 < 0) e.attr1 = 0; // negative lights had no meaning before version 10
|
||||
int ov, ss;
|
||||
#define SCALEATTR(x) \
|
||||
if((ss = entwraparound[e.type][x - 1] / entscale[e.type][x - 1])) e.attr##x = (int(e.attr##x) % ss + ss) % ss; \
|
||||
if((ss = abs(entwraparound[e.type][x - 1] / entscale[e.type][x - 1]))) e.attr##x = (int(e.attr##x) % ss + ss) % ss; \
|
||||
e.attr##x = ov = e.attr##x * entscale[e.type][x - 1]; \
|
||||
if(ov != e.attr##x) conoutf("overflow during conversion of attr%d of entity #%d (%s) - pls check before saving the map", x, i, entnames[e.type]);
|
||||
SCALEATTR(1);
|
||||
|
||||
Reference in New Issue
Block a user