diff --git a/assets/Changelog.md b/assets/Changelog.md index 50959b79f..843246e43 100644 --- a/assets/Changelog.md +++ b/assets/Changelog.md @@ -100,6 +100,10 @@ The callback of `NotifyOnNewObject` can now optionally return `true` to unregist ### BPModLoader BPModLoader now supports loading mods from subdirectories within the `LogicMods` folder ([UE4SS #412](https://github.com/UE4SS-RE/RE-UE4SS/pull/412)) - Ethan Green +### ConsoleEnablerMod +Added additional console key **~** (Tilde) ([UE4SS #687](https://github.com/UE4SS-RE/RE-UE4SS/pull/687)) +The console keys **F10** and **~** are now added by the mod in addition to the existing keys instead of replacing them ([UE4SS #687](https://github.com/UE4SS-RE/RE-UE4SS/pull/687)) + ### Repo & Build Process Switch to xmake from cmake which makes building much more streamlined ([UE4SS #377](https://github.com/UE4SS-RE/RE-UE4SS/pull/377), [UEPseudo #81](https://github.com/Re-UE4SS/UEPseudo/pull/81)) - localcc diff --git a/assets/Mods/ConsoleEnablerMod/Scripts/main.lua b/assets/Mods/ConsoleEnablerMod/Scripts/main.lua index f78e7d469..c29c7115a 100644 --- a/assets/Mods/ConsoleEnablerMod/Scripts/main.lua +++ b/assets/Mods/ConsoleEnablerMod/Scripts/main.lua @@ -1,42 +1,54 @@ -local Engine = FindFirstOf("Engine") +local UEHelpers = require("UEHelpers") + local PlayerControllerHookActive = false local WasFirstConsoleCreated = false local function RemapConsoleKeys() -- Change console key - local InputSettings = StaticFindObject("/Script/Engine.Default__InputSettings") + local InputSettings = StaticFindObject("/Script/Engine.Default__InputSettings") ---@cast InputSettings UInputSettings if not InputSettings:IsValid() then print("[ConsoleEnabler] InputSettings not found, could not change console key\n") return end - + local ConsoleKeys = InputSettings.ConsoleKeys - - -- This sets the first console key to F10 - ConsoleKeys[1].KeyName = FName("F10", EFindName.FNAME_Find) - - ConsoleKeys:ForEach(function(index, elem_wrapper) - local KeyStruct = elem_wrapper:get() - local KeyFName = KeyStruct.KeyName - -- The ToString() call here will go bad if the FName is not ansi - print(string.format("[ConsoleEnabler] ConsoleKey[%d]: %s\n", index, KeyFName:ToString())) - end) + + local KeysToAdd = { + UEHelpers.FindFName("Tilde"), + UEHelpers.FindFName("F10") + } + + for _, KeyName in ipairs(KeysToAdd) do + if KeyName ~= NAME_None then + local KeyIsAlreadySet = false + for i = 1, #ConsoleKeys do + if ConsoleKeys[i].KeyName == KeyName then + KeyIsAlreadySet = true + end + end + if not KeyIsAlreadySet then + ConsoleKeys[#ConsoleKeys + 1].KeyName = KeyName + end + end + end + + for i = 1, #ConsoleKeys do + print(string.format("[ConsoleEnabler] ConsoleKey[%d]: %s\n", i, ConsoleKeys[i].KeyName:ToString())) + end end local function CreateConsole() - if not Engine:IsValid() then - Engine = FindFirstOf("Engine") - end - + local Engine = UEHelpers.GetEngine() if not Engine:IsValid() then print("[ConsoleEnabler] Was unable to find an instance of UEngine\n") return end - - local ConsoleClass = Engine.ConsoleClass + + local ConsoleClass = Engine.ConsoleClass ---@type UClass local GameViewport = Engine.GameViewport - - if GameViewport.ViewportConsole:IsValid() then + + if GameViewport:IsValid() and GameViewport.ViewportConsole:IsValid() then -- Console already exists, let's just remap the keys RemapConsoleKeys() elseif ConsoleClass:IsValid() and GameViewport:IsValid() then - local CreatedConsole = StaticConstructObject(ConsoleClass, GameViewport, 0, 0, 0, nil, false, false, nil) + local CreatedConsole = StaticConstructObject(ConsoleClass, GameViewport) ---@cast CreatedConsole UConsole + if not CreatedConsole:IsValid() then print("[CreateConsole] Was unable to construct an UConsole object\n") return end + GameViewport.ViewportConsole = CreatedConsole - PlayerControllerHookActive = true WasFirstConsoleCreated = true @@ -48,7 +60,7 @@ end CreateConsole() -NotifyOnNewObject("/Script/Engine.PlayerController", function(CreatedObject) +NotifyOnNewObject("/Script/Engine.PlayerController", function() if PlayerControllerHookActive or not WasFirstConsoleCreated then CreateConsole() end