diff --git a/scripts/HP_Compatibility.lua b/scripts/HP_Compatibility.lua index 943c584..9e1a695 100644 --- a/scripts/HP_Compatibility.lua +++ b/scripts/HP_Compatibility.lua @@ -40,7 +40,7 @@ local function modLooksActive(mod) if mod.isLoaded ~= nil then return mod.isLoaded == true end if mod.isActive ~= nil then return mod.isActive == true end if mod.isSelected ~= nil then return mod.isSelected == true end - return true + return false end local function scanLoadedModTable() diff --git a/scripts/HP_IntegrationAPI.lua b/scripts/HP_IntegrationAPI.lua index be49870..75e78f3 100644 --- a/scripts/HP_IntegrationAPI.lua +++ b/scripts/HP_IntegrationAPI.lua @@ -15,6 +15,10 @@ local function hpApiPrint(message) print(LOG .. tostring(message)) end +local function isCompatibilityBlocked() + return HP_Compatibility ~= nil and HP_Compatibility:isBlocked() +end + local function normalizeSlot(slot) if HP_SlotRegistry ~= nil and HP_SlotRegistry.normalise ~= nil then return HP_SlotRegistry:normalise(slot, HP_SlotRegistry.TARGET_COUNT) @@ -23,6 +27,7 @@ local function normalizeSlot(slot) end local function getProfiles() + if isCompatibilityBlocked() then return {} end if HelperProfiles == nil or type(HelperProfiles.getProfiles) ~= "function" then return {} end local ok, profiles = pcall(HelperProfiles.getProfiles, HelperProfiles) return ok and type(profiles) == "table" and profiles or {} @@ -194,7 +199,8 @@ local function buildApi() and HP_RosterExpansion:getStatus() or nil return { - available = true, + available = not isCompatibilityBlocked(), + disabledReason = isCompatibilityBlocked() and HP_Compatibility:getReason() or nil, apiVersion = self.apiVersion, modName = self.modName, modVersion = self.modVersion, @@ -256,6 +262,7 @@ local function buildApi() end function api:getSlots() + if isCompatibilityBlocked() then return {} end local profiles = getProfiles() local slots = {} for index = 1, getManagedSlotCount(profiles) do @@ -267,7 +274,21 @@ local function buildApi() return api end +function HP_IntegrationAPI:unpublish() + if g_currentMission ~= nil then + if g_currentMission.helperProfilesAPI == self.api then g_currentMission.helperProfilesAPI = nil end + if g_currentMission.fs25HelperProfilesAPI == self.api then g_currentMission.fs25HelperProfilesAPI = nil end + end + if rawget(_G, "FS25_HelperProfiles_API") == self.api then _G.FS25_HelperProfiles_API = nil end + if rawget(_G, "FS25_HelperProfilesAPI") == self.api then _G.FS25_HelperProfilesAPI = nil end + self.published = false +end + function HP_IntegrationAPI:publish(reason) + if isCompatibilityBlocked() then + self:unpublish() + return false + end if g_currentMission == nil then return false end self.api = self.api or buildApi() self.api.modVersion = self.modVersion @@ -294,6 +315,10 @@ end function HP_IntegrationAPI:loadMap() self:publish("loadMap") end function HP_IntegrationAPI:update() + if isCompatibilityBlocked() then + self:unpublish() + return + end if not self.published or g_currentMission == nil or g_currentMission.helperProfilesAPI ~= self.api or g_currentMission.fs25HelperProfilesAPI ~= self.api then @@ -302,13 +327,7 @@ function HP_IntegrationAPI:update() end function HP_IntegrationAPI:deleteMap() - if g_currentMission ~= nil then - if g_currentMission.helperProfilesAPI == self.api then g_currentMission.helperProfilesAPI = nil end - if g_currentMission.fs25HelperProfilesAPI == self.api then g_currentMission.fs25HelperProfilesAPI = nil end - end - if rawget(_G, "FS25_HelperProfiles_API") == self.api then _G.FS25_HelperProfiles_API = nil end - if rawget(_G, "FS25_HelperProfilesAPI") == self.api then _G.FS25_HelperProfilesAPI = nil end - self.published = false + self:unpublish() end addModEventListener(HP_IntegrationAPI) diff --git a/scripts/HP_UI.lua b/scripts/HP_UI.lua index 1d297a8..de828a8 100644 --- a/scripts/HP_UI.lua +++ b/scripts/HP_UI.lua @@ -604,6 +604,13 @@ end -- ===== Render ================================================================ function HP_UI:render(dtMillis) + if HP_Compatibility ~= nil and HP_Compatibility:isBlocked() then + self.visible = false + self.flashText = nil + self.flashTime = 0 + return + end + if self.flashTime ~= nil and self.flashTime > 0 then local dt = tonumber(dtMillis) or 16 self.flashTime = math.max(0, self.flashTime - dt * 0.001) @@ -720,6 +727,11 @@ end -- ===== Engine hooks ========================================================== function HP_UI:loadMap() + if HP_Compatibility ~= nil and HP_Compatibility:isBlocked() then + self.visible = false + return + end + if HP_Config ~= nil and HP_Config.read ~= nil and HP_Config.applyToUI ~= nil and HP_Config.init ~= nil then HP_Config:init() local config = HP_Config:read() diff --git a/scripts/RegisterPlayerActionEvents.lua b/scripts/RegisterPlayerActionEvents.lua index 63aaefe..53f04c0 100644 --- a/scripts/RegisterPlayerActionEvents.lua +++ b/scripts/RegisterPlayerActionEvents.lua @@ -44,8 +44,13 @@ local function _isHpModifierDown() or _isPhysicalKeyPressed("KEY_ralt") end +local function _isCompatibilityBlocked() + return HP_Compatibility ~= nil and HP_Compatibility:isBlocked() +end + local function _onCycle(_, actionName, inputValue, callbackState, isAnalog) if not _isPress(inputValue, callbackState) then return end + if _isCompatibilityBlocked() then return end -- GIANTS action bindings are not exclusive: KEY_semicolon can still fire -- when KEY_shift/KEY_ctrl/KEY_alt + KEY_semicolon is pressed. @@ -63,6 +68,7 @@ local function _onCycle(_, actionName, inputValue, callbackState, isAnalog) end local function _onToggle(_, actionName, inputValue, callbackState, isAnalog) + if _isCompatibilityBlocked() then return end if HP_UI and HP_UI.onToggleAction then HP_UI:onToggleAction(actionName, inputValue, callbackState, isAnalog) end @@ -70,6 +76,7 @@ end local function _onMode(_, actionName, inputValue, callbackState, isAnalog) if not _isPress(inputValue, callbackState) then return end + if _isCompatibilityBlocked() then return end if HelperProfiles and HelperProfiles.togglePickMode then HelperProfiles:togglePickMode() end @@ -77,6 +84,7 @@ end local function _onAppearanceMenu(_, actionName, inputValue, callbackState, isAnalog) if not _isPress(inputValue, callbackState) then return end + if _isCompatibilityBlocked() then return end if HP_AppearanceBindingsGui ~= nil and HP_AppearanceBindingsGui.open ~= nil then HP_AppearanceBindingsGui:open() elseif HP_AppearanceMenu ~= nil and HP_AppearanceMenu.toggle ~= nil then @@ -120,6 +128,7 @@ local function _unregisterPlayerAction(field, label) end local function _registerPlayerActions() + if _isCompatibilityBlocked() then return end _registerPlayerAction("_playerCycleId", InputAction.OPEN_HELPER_MENU, HelperProfiles, _onCycle, "OPEN_HELPER_MENU") _registerPlayerAction("_playerToggleId", InputAction.HP_TOGGLE_OVERLAY, HP_UI, _onToggle, "HP_TOGGLE_OVERLAY") _registerPlayerAction("_playerModeId", InputAction.HP_TOGGLE_MODE, HelperProfiles, _onMode, "HP_TOGGLE_MODE") @@ -186,6 +195,7 @@ local function _addVehicleAction(vehicle, spec, inputAction, target, callback, l end local function _registerVehicleActions(vehicle, isActiveForInput) + if _isCompatibilityBlocked() then return end if not isActiveForInput or vehicle == nil or vehicle.addActionEvent == nil then return end local spec = _ensureVehicleSpec(vehicle)