From 55e00f350bc4df3a3deea1aaef7227b73c26de85 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 1 Apr 2019 00:27:43 +0200 Subject: [PATCH] - 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. --- src/menu/playermenu.cpp | 40 ++++++++++----------- wadsrc/static/zscript/ui/menu/playermenu.zs | 20 +++++------ 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/menu/playermenu.cpp b/src/menu/playermenu.cpp index 973a49fdf..add7ed363 100644 --- a/src/menu/playermenu.cpp +++ b/src/menu/playermenu.cpp @@ -53,12 +53,12 @@ EXTERN_CVAR(Bool, cl_run) DEFINE_ACTION_FUNCTION(DPlayerMenu, ColorChanged) { - PARAM_SELF_PROLOGUE(DMenu); + PARAM_PROLOGUE; PARAM_INT(r); PARAM_INT(g); PARAM_INT(b); // only allow if the menu is active to prevent abuse. - if (self == CurrentMenu) + if (DMenu::InMenu) { char command[24]; players[consoleplayer].userinfo.ColorChanged(MAKERGB(r, g, b)); @@ -78,12 +78,12 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, ColorChanged) DEFINE_ACTION_FUNCTION(DPlayerMenu, PlayerNameChanged) { - PARAM_SELF_PROLOGUE(DMenu); + PARAM_PROLOGUE; PARAM_STRING(s); const char *pp = s; 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. for (auto p = pp; *p != '\0'; ++p) @@ -108,9 +108,9 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, PlayerNameChanged) DEFINE_ACTION_FUNCTION(DPlayerMenu, ColorSetChanged) { - PARAM_SELF_PROLOGUE(DMenu); + PARAM_PROLOGUE; PARAM_INT(sel); - if (self == CurrentMenu) + if (DMenu::InMenu) { players[consoleplayer].userinfo.ColorSetChanged(sel); char command[24]; @@ -128,10 +128,10 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, ColorSetChanged) DEFINE_ACTION_FUNCTION(DPlayerMenu, ClassChanged) { - PARAM_SELF_PROLOGUE(DMenu); + PARAM_PROLOGUE; PARAM_INT(sel); PARAM_POINTER(cls, FPlayerClass); - if (self == CurrentMenu) + if (DMenu::InMenu) { players[consoleplayer].userinfo.PlayerClassNumChanged(gameinfo.norandomplayerclass ? sel : sel - 1); 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) { - PARAM_SELF_PROLOGUE(DMenu); + PARAM_PROLOGUE; PARAM_INT(sel); - if (self == CurrentMenu) + if (DMenu::InMenu) { players[consoleplayer].userinfo.SkinNumChanged(sel); cvar_set("skin", Skins[sel].Name); @@ -166,10 +166,10 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, SkinChanged) DEFINE_ACTION_FUNCTION(DPlayerMenu, AutoaimChanged) { - PARAM_SELF_PROLOGUE(DMenu); + PARAM_PROLOGUE; PARAM_FLOAT(val); // only allow if the menu is active to prevent abuse. - if (self == CurrentMenu) + if (DMenu::InMenu) { autoaim = float(val); } @@ -184,10 +184,10 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, AutoaimChanged) DEFINE_ACTION_FUNCTION(DPlayerMenu, TeamChanged) { - PARAM_SELF_PROLOGUE(DMenu); + PARAM_PROLOGUE; PARAM_INT(val); // only allow if the menu is active to prevent abuse. - if (self == CurrentMenu) + if (DMenu::InMenu) { team = val == 0 ? TEAM_NONE : val - 1; } @@ -202,10 +202,10 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, TeamChanged) DEFINE_ACTION_FUNCTION(DPlayerMenu, GenderChanged) { - PARAM_SELF_PROLOGUE(DMenu); + PARAM_PROLOGUE; PARAM_INT(v); // only allow if the menu is active to prevent abuse. - if (self == CurrentMenu) + if (DMenu::InMenu) { switch(v) { @@ -226,10 +226,10 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, GenderChanged) DEFINE_ACTION_FUNCTION(DPlayerMenu, SwitchOnPickupChanged) { - PARAM_SELF_PROLOGUE(DMenu); + PARAM_PROLOGUE; PARAM_INT(v); // only allow if the menu is active to prevent abuse. - if (self == CurrentMenu) + if (DMenu::InMenu) { neverswitchonpickup = !!v; } @@ -244,10 +244,10 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, SwitchOnPickupChanged) DEFINE_ACTION_FUNCTION(DPlayerMenu, AlwaysRunChanged) { - PARAM_SELF_PROLOGUE(DMenu); + PARAM_PROLOGUE; PARAM_INT(v); // only allow if the menu is active to prevent abuse. - if (self == CurrentMenu) + if (DMenu::InMenu) { cl_run = !!v; } diff --git a/wadsrc/static/zscript/ui/menu/playermenu.zs b/wadsrc/static/zscript/ui/menu/playermenu.zs index 38c70353b..1aefb0ba0 100644 --- a/wadsrc/static/zscript/ui/menu/playermenu.zs +++ b/wadsrc/static/zscript/ui/menu/playermenu.zs @@ -42,16 +42,16 @@ class PlayerMenu : ListMenu Array mPlayerSkins; // All write function for the player config are native to prevent abuse. - protected native void AutoaimChanged(float val); - protected native void TeamChanged(int val); - protected native void AlwaysRunChanged(int val); - protected native void GenderChanged(int val); - protected native void SwitchOnPickupChanged(int val); - protected native void ColorChanged(int red, int green, int blue); - protected native void ColorSetChanged(int red); - protected native void PlayerNameChanged(String name); - protected native void SkinChanged (int val); - protected native void ClassChanged(int sel, PlayerClass cls); + protected static native void AutoaimChanged(float val); + protected static native void TeamChanged(int val); + protected static native void AlwaysRunChanged(int val); + protected static native void GenderChanged(int val); + protected static native void SwitchOnPickupChanged(int val); + protected static native void ColorChanged(int red, int green, int blue); + protected static native void ColorSetChanged(int red); + protected static native void PlayerNameChanged(String name); + protected static native void SkinChanged (int val); + protected static native void ClassChanged(int sel, PlayerClass cls); //============================================================================= //