maximegmd / CyberEngineTweaks

Cyberpunk 2077 tweaks, hacks and scripting framework
MIT License
4.48k stars 285 forks source link

CET crashes when a mod with a number/period in the name and uses the `registerHotkey` or `registerInput` is reloaded #946

Open Norviah opened 4 months ago

Norviah commented 4 months ago

Bug

Operating system: Windows 10 Game version: v2.12a CET version: v1.32.2 GPU: RTX 3090 Founders Edition

Description

The title is quite a mouthful, so to be clear, CET crashes when a mod that has these conditions is reloaded:

It looks like whenever CET reloads a mod with the above conditions, it will crash and prevent CET menu from working for future launches, forcing the user to delete bindings.json to cause CET to re-prompt for a menu key.

I'm certain that the issue is with these functions as I reloaded the mod many times yesterday and nothing happened, but the second I reload while using these functions the game crashes.

I'm not sure if this is important but may be some pointer to the problem, when the mod has 2.0 in the folder, the mod appears first in the keybindings menu, without 2.0 it normally appears alphabetically.

Expected behaviour

The expected behavior when reloading a mod that has the mentioned conditions is for it to reload normally to reflect any new changes in the file.

Reproduction

init.lua

registerInput('walk_by_default', 'Toggle Walking', function(keypress)
  if not keypress then
    Game.GetPlayer():ProcessToggleWalkInput()
  end
end)

registerForEvent('onInit', function()
  ObserveAfter('activityLogGameController', 'OnInitialize', function()
    Game.GetPlayer():ProcessToggleWalkInput()
  end)

  ObserveAfter('PlayerPuppet', 'OnGameAttached', function()
    Game.GetPlayer():ProcessToggleWalkInput()
  end)
end)
-- registerInput('walk_by_default', 'Toggle Walking', function(keypress)
--   if not keypress then
--     Game.GetPlayer():ProcessToggleWalkInput()
--   end
-- end)

registerForEvent('onInit', function()
  ObserveAfter('activityLogGameController', 'OnInitialize', function()
    Game.GetPlayer():ProcessToggleWalkInput()
  end)

  ObserveAfter('PlayerPuppet', 'OnGameAttached', function()
    Game.GetPlayer():ProcessToggleWalkInput()
  end)
end)
WSSDude commented 3 months ago

Problem is the dot specifically, we use it as a delimiter for IDs. Number shouldn't be an issue I believe. Unsure what could be done atm, bindings.json structure would have to be updated in some way.