- use a more reliable menu check for the player menu items.

This needs to ensure that it only allows modification from within a menu's event handlers and nowhere else.
This commit is contained in:
Christoph Oelckers 2019-04-01 00:27:43 +02:00
parent a6593e1400
commit 55e00f350b
2 changed files with 30 additions and 30 deletions

View file

@ -53,12 +53,12 @@ EXTERN_CVAR(Bool, cl_run)
DEFINE_ACTION_FUNCTION(DPlayerMenu, ColorChanged) DEFINE_ACTION_FUNCTION(DPlayerMenu, ColorChanged)
{ {
PARAM_SELF_PROLOGUE(DMenu); PARAM_PROLOGUE;
PARAM_INT(r); PARAM_INT(r);
PARAM_INT(g); PARAM_INT(g);
PARAM_INT(b); PARAM_INT(b);
// only allow if the menu is active to prevent abuse. // only allow if the menu is active to prevent abuse.
if (self == CurrentMenu) if (DMenu::InMenu)
{ {
char command[24]; char command[24];
players[consoleplayer].userinfo.ColorChanged(MAKERGB(r, g, b)); players[consoleplayer].userinfo.ColorChanged(MAKERGB(r, g, b));
@ -78,12 +78,12 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, ColorChanged)
DEFINE_ACTION_FUNCTION(DPlayerMenu, PlayerNameChanged) DEFINE_ACTION_FUNCTION(DPlayerMenu, PlayerNameChanged)
{ {
PARAM_SELF_PROLOGUE(DMenu); PARAM_PROLOGUE;
PARAM_STRING(s); PARAM_STRING(s);
const char *pp = s; const char *pp = s;
FString command("name \""); FString command("name \"");
if (self == CurrentMenu || self == CurrentMenu->mParentMenu) if (DMenu::InMenu)
{ {
// Escape any backslashes or quotation marks before sending the name to the console. // Escape any backslashes or quotation marks before sending the name to the console.
for (auto p = pp; *p != '\0'; ++p) for (auto p = pp; *p != '\0'; ++p)
@ -108,9 +108,9 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, PlayerNameChanged)
DEFINE_ACTION_FUNCTION(DPlayerMenu, ColorSetChanged) DEFINE_ACTION_FUNCTION(DPlayerMenu, ColorSetChanged)
{ {
PARAM_SELF_PROLOGUE(DMenu); PARAM_PROLOGUE;
PARAM_INT(sel); PARAM_INT(sel);
if (self == CurrentMenu) if (DMenu::InMenu)
{ {
players[consoleplayer].userinfo.ColorSetChanged(sel); players[consoleplayer].userinfo.ColorSetChanged(sel);
char command[24]; char command[24];
@ -128,10 +128,10 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, ColorSetChanged)
DEFINE_ACTION_FUNCTION(DPlayerMenu, ClassChanged) DEFINE_ACTION_FUNCTION(DPlayerMenu, ClassChanged)
{ {
PARAM_SELF_PROLOGUE(DMenu); PARAM_PROLOGUE;
PARAM_INT(sel); PARAM_INT(sel);
PARAM_POINTER(cls, FPlayerClass); PARAM_POINTER(cls, FPlayerClass);
if (self == CurrentMenu) if (DMenu::InMenu)
{ {
players[consoleplayer].userinfo.PlayerClassNumChanged(gameinfo.norandomplayerclass ? sel : sel - 1); players[consoleplayer].userinfo.PlayerClassNumChanged(gameinfo.norandomplayerclass ? sel : sel - 1);
cvar_set("playerclass", sel == 0 && !gameinfo.norandomplayerclass ? "Random" : GetPrintableDisplayName(cls->Type).GetChars()); cvar_set("playerclass", sel == 0 && !gameinfo.norandomplayerclass ? "Random" : GetPrintableDisplayName(cls->Type).GetChars());
@ -148,9 +148,9 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, ClassChanged)
DEFINE_ACTION_FUNCTION(DPlayerMenu, SkinChanged) DEFINE_ACTION_FUNCTION(DPlayerMenu, SkinChanged)
{ {
PARAM_SELF_PROLOGUE(DMenu); PARAM_PROLOGUE;
PARAM_INT(sel); PARAM_INT(sel);
if (self == CurrentMenu) if (DMenu::InMenu)
{ {
players[consoleplayer].userinfo.SkinNumChanged(sel); players[consoleplayer].userinfo.SkinNumChanged(sel);
cvar_set("skin", Skins[sel].Name); cvar_set("skin", Skins[sel].Name);
@ -166,10 +166,10 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, SkinChanged)
DEFINE_ACTION_FUNCTION(DPlayerMenu, AutoaimChanged) DEFINE_ACTION_FUNCTION(DPlayerMenu, AutoaimChanged)
{ {
PARAM_SELF_PROLOGUE(DMenu); PARAM_PROLOGUE;
PARAM_FLOAT(val); PARAM_FLOAT(val);
// only allow if the menu is active to prevent abuse. // only allow if the menu is active to prevent abuse.
if (self == CurrentMenu) if (DMenu::InMenu)
{ {
autoaim = float(val); autoaim = float(val);
} }
@ -184,10 +184,10 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, AutoaimChanged)
DEFINE_ACTION_FUNCTION(DPlayerMenu, TeamChanged) DEFINE_ACTION_FUNCTION(DPlayerMenu, TeamChanged)
{ {
PARAM_SELF_PROLOGUE(DMenu); PARAM_PROLOGUE;
PARAM_INT(val); PARAM_INT(val);
// only allow if the menu is active to prevent abuse. // only allow if the menu is active to prevent abuse.
if (self == CurrentMenu) if (DMenu::InMenu)
{ {
team = val == 0 ? TEAM_NONE : val - 1; team = val == 0 ? TEAM_NONE : val - 1;
} }
@ -202,10 +202,10 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, TeamChanged)
DEFINE_ACTION_FUNCTION(DPlayerMenu, GenderChanged) DEFINE_ACTION_FUNCTION(DPlayerMenu, GenderChanged)
{ {
PARAM_SELF_PROLOGUE(DMenu); PARAM_PROLOGUE;
PARAM_INT(v); PARAM_INT(v);
// only allow if the menu is active to prevent abuse. // only allow if the menu is active to prevent abuse.
if (self == CurrentMenu) if (DMenu::InMenu)
{ {
switch(v) switch(v)
{ {
@ -226,10 +226,10 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, GenderChanged)
DEFINE_ACTION_FUNCTION(DPlayerMenu, SwitchOnPickupChanged) DEFINE_ACTION_FUNCTION(DPlayerMenu, SwitchOnPickupChanged)
{ {
PARAM_SELF_PROLOGUE(DMenu); PARAM_PROLOGUE;
PARAM_INT(v); PARAM_INT(v);
// only allow if the menu is active to prevent abuse. // only allow if the menu is active to prevent abuse.
if (self == CurrentMenu) if (DMenu::InMenu)
{ {
neverswitchonpickup = !!v; neverswitchonpickup = !!v;
} }
@ -244,10 +244,10 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, SwitchOnPickupChanged)
DEFINE_ACTION_FUNCTION(DPlayerMenu, AlwaysRunChanged) DEFINE_ACTION_FUNCTION(DPlayerMenu, AlwaysRunChanged)
{ {
PARAM_SELF_PROLOGUE(DMenu); PARAM_PROLOGUE;
PARAM_INT(v); PARAM_INT(v);
// only allow if the menu is active to prevent abuse. // only allow if the menu is active to prevent abuse.
if (self == CurrentMenu) if (DMenu::InMenu)
{ {
cl_run = !!v; cl_run = !!v;
} }

View file

@ -42,16 +42,16 @@ class PlayerMenu : ListMenu
Array<int> mPlayerSkins; Array<int> mPlayerSkins;
// All write function for the player config are native to prevent abuse. // All write function for the player config are native to prevent abuse.
protected native void AutoaimChanged(float val); protected static native void AutoaimChanged(float val);
protected native void TeamChanged(int val); protected static native void TeamChanged(int val);
protected native void AlwaysRunChanged(int val); protected static native void AlwaysRunChanged(int val);
protected native void GenderChanged(int val); protected static native void GenderChanged(int val);
protected native void SwitchOnPickupChanged(int val); protected static native void SwitchOnPickupChanged(int val);
protected native void ColorChanged(int red, int green, int blue); protected static native void ColorChanged(int red, int green, int blue);
protected native void ColorSetChanged(int red); protected static native void ColorSetChanged(int red);
protected native void PlayerNameChanged(String name); protected static native void PlayerNameChanged(String name);
protected native void SkinChanged (int val); protected static native void SkinChanged (int val);
protected native void ClassChanged(int sel, PlayerClass cls); protected static native void ClassChanged(int sel, PlayerClass cls);
//============================================================================= //=============================================================================
// //