Jump to content

Event not being removed for some users


ethanwdp

Recommended Posts

For Cheat Menu V2.5, I've seen numerous reports that the menu creates 50+ context menus instead of 1. I've come to understand that this is because of my code used to check if a player is admin. Here's the code in question:

 

CheatCoreCM.isAdmin = function() -- stops pesky cheaters. good luck trying to modify this, it won't work :^)
	if isClient() == true and isAdmin() == true or isClient() == false and isAdmin() == false then
		return true
	else
		return false
	end
end

CheatCoreCM.shouldStart = function()
	if CheatCoreCM.isAdmin() then
		print("[CHEAT MENU] User "..getOnlineUsername().." is authorized! This message will appear the next time the client connects.")
		Events.OnPlayerUpdate.Add(CheatCoreCM.DoCheats);
		Events.OnTick.Add(CheatCoreCM.DoTickCheats);
		Events.OnMouseDown.Add(CheatCoreCM.SpawnZombieNow);
		Events.OnKeyKeepPressed.Add(CheatCoreCM.OnKeyKeepPressed);
		Events.OnKeyPressed.Add(CheatCoreCM.OnKeyPressed);
		Events.OnPlayerMove.Add(CheatCoreCM.updateCoords);
		Events.OnFillWorldObjectContextMenu.Add(ISUICheatMenu.createMenuEntries);
		Events.OnMouseMove.Add(CheatCoreCM.highlightSquare);
		Events.OnTick.Remove(CheatCoreCM.shouldStart);
	elseif not CheatCoreCM.isAdmin() and CheatCoreCM.doNotWarn ~= true then
		print("[CHEAT MENU] User "..getOnlineUsername().." is not authorized! This message will appear the next time the client connects.")
		CheatCoreCM.doNotWarn = true
	end
end

Events.OnTick.Add(CheatCoreCM.shouldStart);

 

What it does is that it checks if the player is an admin, then it creates the rest of the events that Cheat Menu's various cheat functions use. It also creates the menu. Theoretically, it won't fire at all for non-admins.

 

But what if the player has been made an admin after the check has been performed? Since otherwise it would require the player to exit & re-enter the server, I decided to hook the function to an OnTick event.

 

Now, this is where the problem is. What's happening is that the admin check is passed, but for whatever reason Events.OnTick.Remove(CheatCoreCM.shouldStart) refuses to fire.

 

Here's an error log that one of my afflicted users have given me:

Spoiler

I am still having issues with the meun showing multiple times.  Tried on a laptop (i7 gt555m) and desktop (i7 gtx660).  I have GOG version 33.20.

 

I do not know who lemmy101 is

The console is also spammed with:

-----------------------------------------
STACK TRACE
-----------------------------------------
function: shouldStart -- file: CheatCoreForCheatMenu.lua line # 1126
[CHEAT MENU] User lemmy101 is authorized! This message will appear the next time
 the client connects.
-----------------------------------------
STACK TRACE
-----------------------------------------
function: shouldStart -- file: CheatCoreForCheatMenu.lua line # 1126
java.lang.RuntimeException: Object tried to call nil in shouldStart
        at se.krka.kahlua.vm.KahluaUtil.fail(KahluaUtil.java:91)
        at se.krka.kahlua.vm.KahluaThread.luaMainloop(KahluaThread.java:949)
        at se.krka.kahlua.vm.KahluaThread.call(KahluaThread.java:163)
        at se.krka.kahlua.vm.KahluaThread.pcall(KahluaThread.java:1727)
        at se.krka.kahlua.vm.KahluaThread.pcallvoid(KahluaThread.java:1672)
        at se.krka.kahlua.integration.LuaCaller.pcallvoid(LuaCaller.java:53)
        at se.krka.kahlua.integration.LuaCaller.protectedCallVoid(LuaCaller.java
:81)
        at zombie.Lua.Event.trigger(Event.java:37)
        at zombie.Lua.LuaEventManager.triggerEvent(LuaEventManager.java:82)
        at zombie.gameStates.IngameState.update(IngameState.java:1252)
        at zombie.gameStates.GameStateMachine.update(GameStateMachine.java:101)
        at zombie.GameWindow.logic(GameWindow.java:619)
        at zombie.GameWindow.run(GameWindow.java:1173)
        at zombie.GameWindow.maina(GameWindow.java:974)
        at zombie.gameStates.MainScreenState.main(MainScreenState.java:173)

Line # 1126 is where I called Events.OnTick.Remove(CheatCoreCM.shouldStart). Cheat Menu successfully printed the success message to the console, curiously with Lenny101 as the username (I assume that's just the default username for singleplayer. Either that, or Lenny101 is a wizard and is bending spacetime to break my mod.)

 

So the function successfully fires, the isAdmin() check passes, and for whatever reason Events.OnTick.Remove is no longer a thing. Because of this, Cheat Menu is now cloning itself on every tick event since the OnTick check is still there.

 

 

The logical conclusion would have been that I messed up and I could at least close the loop through another way. However, this bug does not happen to me. It does not happen to my friends, it doesn't even happen if I install PZ onto another computer and test the mod on that.

 

 

The numerous reports I have received confirm that this bug is present. It's happening to multiple people, and I cannot figure out why. Some of the reporters had also said they are using Windows 10, the same operating system I am using. The specs also range wildly. Previously I had just used a global variable that, if set to true (which it is when the check passes), the function does nothing. Then, in the current version, I made the function straight up remove the event after completing the setup (as seen above). Same issue, same users.

 

 

I am very, very confused as to why this is happening. It only happens to some people, sometimes, for some reason, and I cannot figure out why. There's always a reason as to why a problem occurs in programming, so this simply isn't random. There is a reason for this, but I cannot figure it out. And thus, I request for help from the kind folks here.

 

 

 

EDIT: Okay, it turns out that ISUICheatMenu loaded after CheatCoreForCheatMenu was loaded. CheatCoreForCheatMenu was trying to hook a non-existent function to an event. I simply cut and paste CheatCoreCM.shouldStart() to ISUICheatMenu.lua. I'm an idiot.

 

Edit 2: MMnnnnnope. Still doesn't work for a select few users, with the same error as before, despite moving the admin checking code over to ISUICheatMenu. Again, it still works fine for me, but not for some users. Why is this?

 

Edited by ethanwdp
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...