From 768c61cffe223bad4de011bc73593cc09e08314f Mon Sep 17 00:00:00 2001 From: Remy Raes Date: Fri, 1 Nov 2024 01:23:55 +0100 Subject: [PATCH 01/12] build: update CI method signatures --- .github/nativefuncs.json | 132 ++------------------------------------- 1 file changed, 6 insertions(+), 126 deletions(-) diff --git a/.github/nativefuncs.json b/.github/nativefuncs.json index 110429031..89eb54d1e 100644 --- a/.github/nativefuncs.json +++ b/.github/nativefuncs.json @@ -6,6 +6,12 @@ "returnTypeString":"array", "argTypes":"" }, + { + "name":"NSGetModsInformation", + "helpText":"", + "returnTypeString":"array", + "argTypes":"" + }, { "name":"NSIsModEnabled", "helpText":"", @@ -18,48 +24,6 @@ "returnTypeString":"void", "argTypes":"string modName, bool enabled" }, - { - "name":"NSIsModRemote", - "helpText":"", - "returnTypeString":"bool", - "argTypes":"string modName" - }, - { - "name":"NSGetModDescriptionByModName", - "helpText":"", - "returnTypeString":"string", - "argTypes":"string modName" - }, - { - "name":"NSGetModVersionByModName", - "helpText":"", - "returnTypeString":"string", - "argTypes":"string modName" - }, - { - "name":"NSGetModDownloadLinkByModName", - "helpText":"", - "returnTypeString":"string", - "argTypes":"string modName" - }, - { - "name":"NSGetModLoadPriority", - "helpText":"", - "returnTypeString":"int", - "argTypes":"string modName" - }, - { - "name":"NSIsModRequiredOnClient", - "helpText":"", - "returnTypeString":"bool", - "argTypes":"string modName" - }, - { - "name":"NSGetModConvarsByModName", - "helpText":"", - "returnTypeString":"array", - "argTypes":"string modName" - }, { "name":"DecodeJSON", "helpText":"converts a json string to a squirrel table", @@ -272,48 +236,6 @@ "returnTypeString":"void", "argTypes":"string modName, bool enabled" }, - { - "name":"NSIsModRemote", - "helpText":"", - "returnTypeString":"bool", - "argTypes":"string modName" - }, - { - "name":"NSGetModDescriptionByModName", - "helpText":"", - "returnTypeString":"string", - "argTypes":"string modName" - }, - { - "name":"NSGetModVersionByModName", - "helpText":"", - "returnTypeString":"string", - "argTypes":"string modName" - }, - { - "name":"NSGetModDownloadLinkByModName", - "helpText":"", - "returnTypeString":"string", - "argTypes":"string modName" - }, - { - "name":"NSGetModLoadPriority", - "helpText":"", - "returnTypeString":"int", - "argTypes":"string modName" - }, - { - "name":"NSIsModRequiredOnClient", - "helpText":"", - "returnTypeString":"bool", - "argTypes":"string modName" - }, - { - "name":"NSGetModConvarsByModName", - "helpText":"", - "returnTypeString":"array", - "argTypes":"string modName" - }, { "name":"DecodeJSON", "helpText":"converts a json string to a squirrel table", @@ -478,48 +400,6 @@ "returnTypeString":"void", "argTypes":"string modName, bool enabled" }, - { - "name":"NSIsModRemote", - "helpText":"", - "returnTypeString":"bool", - "argTypes":"string modName" - }, - { - "name":"NSGetModDescriptionByModName", - "helpText":"", - "returnTypeString":"string", - "argTypes":"string modName" - }, - { - "name":"NSGetModVersionByModName", - "helpText":"", - "returnTypeString":"string", - "argTypes":"string modName" - }, - { - "name":"NSGetModDownloadLinkByModName", - "helpText":"", - "returnTypeString":"string", - "argTypes":"string modName" - }, - { - "name":"NSGetModLoadPriority", - "helpText":"", - "returnTypeString":"int", - "argTypes":"string modName" - }, - { - "name":"NSIsModRequiredOnClient", - "helpText":"", - "returnTypeString":"bool", - "argTypes":"string modName" - }, - { - "name":"NSGetModConvarsByModName", - "helpText":"", - "returnTypeString":"array", - "argTypes":"string modName" - }, { "name": "NSFetchVerifiedModsManifesto", "helpText": "Retrieves the verified mods list from the central authority (GitHub).", From c1401b048e20cbf05c9eb253930244d3dbacaacf Mon Sep 17 00:00:00 2001 From: Remy Raes Date: Fri, 1 Nov 2024 01:25:54 +0100 Subject: [PATCH 02/12] feat: add ModInfo structure --- .../scripts/vscripts/cl_northstar_client_init.nut | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Northstar.Client/mod/scripts/vscripts/cl_northstar_client_init.nut b/Northstar.Client/mod/scripts/vscripts/cl_northstar_client_init.nut index 9e683a869..e4e44d51e 100644 --- a/Northstar.Client/mod/scripts/vscripts/cl_northstar_client_init.nut +++ b/Northstar.Client/mod/scripts/vscripts/cl_northstar_client_init.nut @@ -29,6 +29,19 @@ global struct UIPresenceStruct { int gameState } +global struct ModInfo +{ + string name = "" + string description = "" + string version = "" + string downloadLink = "" + int loadPriority = 0 + bool enabled = false + bool requiredOnClient = false + bool isRemote + array conVars = [] +} + global struct RequiredModInfo { string name From cc383071c771c3d903940dcdc8250927a7e5e648 Mon Sep 17 00:00:00 2001 From: Remy Raes Date: Fri, 1 Nov 2024 02:12:12 +0100 Subject: [PATCH 03/12] build: add NSGetModVersions to CI signatures --- .github/nativefuncs.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/nativefuncs.json b/.github/nativefuncs.json index 89eb54d1e..3658fc8e0 100644 --- a/.github/nativefuncs.json +++ b/.github/nativefuncs.json @@ -12,6 +12,12 @@ "returnTypeString":"array", "argTypes":"" }, + { + "name":"NSGetModVersions", + "helpText":"", + "returnTypeString":"array", + "argTypes":"string modName" + }, { "name":"NSIsModEnabled", "helpText":"", From b9aedb200afa98bb2f99ac86fb34821a450d0ad9 Mon Sep 17 00:00:00 2001 From: Remy Raes Date: Fri, 1 Nov 2024 02:12:37 +0100 Subject: [PATCH 04/12] refactor: adapt mod architecture to new mod API --- .../scripts/vscripts/ui/menu_ns_modmenu.nut | 108 +++++++++--------- .../vscripts/ui/menu_ns_serverbrowser.nut | 100 ++++++++-------- .../vscripts/ui/menu_ns_setversionlabel.nut | 2 +- .../scripts/vscripts/ui/panel_mainmenu.nut | 4 +- 4 files changed, 107 insertions(+), 107 deletions(-) diff --git a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_modmenu.nut b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_modmenu.nut index f08d69a72..5f938bced 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_modmenu.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_modmenu.nut @@ -5,17 +5,8 @@ global function AddNorthstarModMenu_MainMenuFooter global function ReloadMods -struct modData { - string name = "" - string version = "" - string link = "" - int loadPriority = 0 - bool enabled = false - array conVars = [] -} - struct panelContent { - modData& mod + ModInfo& mod bool isHeader = false } @@ -37,10 +28,10 @@ struct { var menu array panels int scrollOffset = 0 - array enabledMods + array enabledMods var currentButton string searchTerm - modData& lastMod + ModInfo& lastMod } file const int PANELS_LEN = 15 @@ -150,11 +141,22 @@ void function OnModMenuClosed() } catch ( ex ) {} - array current = GetEnabledModsArray() + array current = GetEnabledModsArray() bool reload - foreach ( string mod in current ) + foreach ( ModInfo mod in current ) { - if ( file.enabledMods.find(mod) == -1 ) + bool notFound = true + + foreach ( ModInfo enMod in file.enabledMods ) + { + if ( mod.name == enMod.name ) + { + notFound = false + break + } + } + + if ( notFound ) { reload = true break @@ -176,10 +178,10 @@ void function OnModButtonFocused( var button ) RuiSetGameTime( rui, "startTime", -99999.99 ) // make sure it skips the whole animation for showing this RuiSetString( rui, "headerText", modName ) - RuiSetString( rui, "messageText", FormatModDescription( modName ) ) + RuiSetString( rui, "messageText", FormatModDescription() ) // Add a button to open the link with if required - string link = NSGetModDownloadLinkByModName( modName ) + string link = file.lastMod.downloadLink var linkButton = Hud_GetChild( file.menu, "ModPageButton" ) if ( link.len() ) { @@ -195,14 +197,15 @@ void function OnModButtonFocused( var button ) SetControlBarColor( modName ) - bool required = NSIsModRequiredOnClient( modName ) + bool required = file.lastMod.requiredOnClient Hud_SetVisible( Hud_GetChild( file.menu, "WarningLegendLabel" ), required ) Hud_SetVisible( Hud_GetChild( file.menu, "WarningLegendImage" ), required ) } void function OnModButtonPressed( var button ) { - string modName = file.mods[ int ( Hud_GetScriptID( Hud_GetParent( button ) ) ) + file.scrollOffset - 1 ].mod.name + ModInfo mod = file.mods[ int ( Hud_GetScriptID( Hud_GetParent( button ) ) ) + file.scrollOffset - 1 ].mod + string modName = mod.name if ( StaticFind( modName ) && NSIsModEnabled( modName ) ) CoreModToggleDialog( modName ) else @@ -230,8 +233,8 @@ void function OnAuthenticationAgreementButtonPressed( var button ) void function OnModLinkButtonPressed( var button ) { - string modName = file.mods[ int ( Hud_GetScriptID( Hud_GetParent( file.currentButton ) ) ) + file.scrollOffset - 1 ].mod.name - string link = NSGetModDownloadLinkByModName( modName ) + ModInfo mod = file.mods[ int ( Hud_GetScriptID( Hud_GetParent( file.currentButton ) ) ) + file.scrollOffset - 1 ].mod + string link = mod.downloadLink if ( link.find("http://") != 0 && link.find("https://") != 0 ) link = "http://" + link // links without the http or https protocol get opened in the internal browser LaunchExternalWebBrowser( link, WEBBROWSER_FLAG_FORCEEXTERNAL ) @@ -261,7 +264,7 @@ void function OnHideConVarsChange( var n ) if ( modName == "" ) return var rui = Hud_GetRui( Hud_GetChild( file.menu, "LabelDetails" ) ) - RuiSetString( rui, "messageText", FormatModDescription( modName ) ) + RuiSetString( rui, "messageText", FormatModDescription() ) } // LIST LOGIC @@ -284,7 +287,8 @@ void function CoreModToggleDialog( string mod ) void function DisableMod() { - string modName = file.mods[ int ( Hud_GetScriptID( Hud_GetParent( file.currentButton ) ) ) + file.scrollOffset - 1 ].mod.name + ModInfo mod = file.mods[ int ( Hud_GetScriptID( Hud_GetParent( file.currentButton ) ) ) + file.scrollOffset - 1 ].mod + string modName = mod.name NSSetModEnabled( modName, false ) var panel = file.panels[ int ( Hud_GetScriptID( Hud_GetParent( file.currentButton ) ) ) - 1] @@ -295,12 +299,12 @@ void function DisableMod() RefreshMods() } -array function GetEnabledModsArray() +array function GetEnabledModsArray() { - array enabledMods - foreach ( string mod in NSGetModNames() ) + array enabledMods + foreach ( ModInfo mod in NSGetModsInformation() ) { - if ( NSIsModEnabled( mod ) ) + if ( mod.enabled ) enabledMods.append( mod ) } return enabledMods @@ -324,29 +328,30 @@ void function UpdateList() void function RefreshMods() { - array modNames = NSGetModNames() + array mods = NSGetModsInformation() file.mods.clear() bool reverse = GetConVarBool( "modlist_reverse" ) - int lastLoadPriority = reverse ? NSGetModLoadPriority( modNames[ modNames.len() - 1 ] ) + 1 : -1 + int lastLoadPriority = reverse ? mods.top().loadPriority + 1 : -1 string searchTerm = Hud_GetUTF8Text( Hud_GetChild( file.menu, "BtnModsSearch" ) ).tolower() - for ( int i = reverse ? modNames.len() - 1 : 0; - reverse ? ( i >= 0 ) : ( i < modNames.len() ); + for ( int i = reverse ? mods.len() - 1 : 0; + reverse ? ( i >= 0 ) : ( i < mods.len() ); i += ( reverse ? -1 : 1) ) { - string mod = modNames[i] + ModInfo mod = mods[i] + string modName = mod.name // Do not display remote mods - if ( NSIsModRemote( mod ) ) + if ( mod.isRemote ) continue - if ( searchTerm.len() && mod.tolower().find( searchTerm ) == null ) + if ( searchTerm.len() && modName.tolower().find( searchTerm ) == null ) continue - bool enabled = NSIsModEnabled( mod ) - bool required = NSIsModRequiredOnClient( mod ) + bool enabled = mod.enabled + bool required = mod.requiredOnClient switch ( GetConVarInt( "filter_mods" ) ) { case filterShow.ONLY_ENABLED: @@ -367,11 +372,11 @@ void function RefreshMods() break } - int pr = NSGetModLoadPriority( mod ) + int pr = mod.loadPriority if ( reverse ? pr < lastLoadPriority : pr > lastLoadPriority ) { - modData m + ModInfo m m.name = pr.tostring() panelContent c @@ -381,16 +386,8 @@ void function RefreshMods() lastLoadPriority = pr } - modData m - m.name = mod - m.version = NSGetModVersionByModName( mod ) - m.link = NSGetModDownloadLinkByModName( mod ) - m.loadPriority = NSGetModLoadPriority( mod ) - m.enabled = enabled - m.conVars = NSGetModConvarsByModName( mod ) - panelContent c - c.mod = m + c.mod = mod file.mods.append( c ) } @@ -404,7 +401,7 @@ void function DisplayModPanels() break panelContent c = file.mods[ file.scrollOffset + i ] - modData mod = c.mod + ModInfo mod = c.mod var btn = Hud_GetChild( panel, "BtnMod" ) var headerLabel = Hud_GetChild( panel, "Header" ) var box = Hud_GetChild( panel, "ControlBox" ) @@ -438,7 +435,7 @@ void function DisplayModPanels() Hud_SetVisible( box, true ) Hud_SetVisible( line, false ) - Hud_SetVisible( warning, NSIsModRequiredOnClient( c.mod.name ) ) + Hud_SetVisible( warning, mod.requiredOnClient ) SetModEnabledHelperImageAsset( enabledImage, c.mod.name ) } @@ -502,17 +499,20 @@ vector function GetControlColorForMod( string modName ) unreachable } -string function FormatModDescription( string modName ) +string function FormatModDescription() { + ModInfo mod = file.lastMod + string modName = mod.name + string ret // version - ret += format( "Version %s\n", NSGetModVersionByModName( modName ) ) + ret += format( "Version %s\n", mod.version ) // load priority - ret += format( "Load Priority: %i\n", NSGetModLoadPriority( modName ) ) + ret += format( "Load Priority: %i\n", mod.loadPriority ) // convars - array modCvars = NSGetModConvarsByModName( modName ) + array modCvars = mod.conVars if ( modCvars.len() != 0 && GetConVarBool( "modlist_show_convars" ) ) { ret += "ConVars: " @@ -529,7 +529,7 @@ string function FormatModDescription( string modName ) } // description - ret += format( "\n%s\n", NSGetModDescriptionByModName( modName ) ) + ret += format( "\n%s\n", mod.description ) return ret } diff --git a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut index cdeb8b3e0..ffbc1a306 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut @@ -973,18 +973,26 @@ void function OnServerSelected_Threaded( var button ) foreach ( requiredModInfo in server.requiredMods ) { // Tolerate core mods having different versions - if ( requiredModInfo.name.len() > 10 && requiredModInfo.name.slice(0, 10) == "Northstar." ) + if ( IsCoreMod( requiredModInfo.name ) ) continue if ( !modNames.contains( requiredModInfo.name ) ) { - print( format ( "\"%s\" was not found locally, triggering manifesto fetching.", requiredModInfo.name ) ) - uninstalledModFound = true - break - } else if ( NSGetModVersionByModName( requiredModInfo.name ) != requiredModInfo.version ) { - print( format ( "\"%s\" was found locally but has version \"%s\" while server requires \"%s\", triggering manifesto fetching.", requiredModInfo.name, NSGetModVersionByModName( requiredModInfo.name ), requiredModInfo.version ) ) + print( format ( "\"%s\" was not found locally" + ( autoDownloadAllowed ? ", triggering manifesto fetching." : "." ), requiredModInfo.name ) ) uninstalledModFound = true break + } else { + array modVersions = NSGetModVersions( requiredModInfo.name ) + if ( !modVersions.contains( requiredModInfo.version ) ) { + print( format ( "\"%s\" was found locally but has versions:", requiredModInfo.name ) ) + foreach ( string version in modVersions ) + { + print(" - " + version) + } + print( format ( "while server requires \"%s\"" + ( autoDownloadAllowed ? ", triggering manifesto fetching." : "." ), requiredModInfo.version ) ) + uninstalledModFound = true + break + } } } @@ -992,17 +1000,16 @@ void function OnServerSelected_Threaded( var button ) // mods can be installed through auto-download if ( uninstalledModFound && autoDownloadAllowed ) { - print("Auto-download is allowed, checking if missing mods can be installed automatically.") FetchVerifiedModsManifesto() } foreach ( RequiredModInfo mod in server.requiredMods ) { // Tolerate core mods having different versions - if ( mod.name.len() > 10 && mod.name.slice(0, 10) == "Northstar." ) + if ( IsCoreMod( mod.name ) ) continue - if ( !NSGetModNames().contains( mod.name ) || NSGetModVersionByModName( mod.name ) != mod.version ) + if ( !NSGetModNames().contains( mod.name ) || !NSGetModVersions( mod.name ).contains( mod.version ) ) { // Auto-download mod if ( autoDownloadAllowed ) @@ -1055,43 +1062,8 @@ void function OnServerSelected_Threaded( var button ) return } } - else - { - // this uses semver https://semver.org - array serverModVersion = split( mod.name, "." ) - array clientModVersion = split( NSGetModVersionByModName( mod.name ), "." ) - - bool semverFail = false - // if server has invalid semver don't bother checking - if ( serverModVersion.len() == 3 ) - { - // bad client semver - if ( clientModVersion.len() != serverModVersion.len() ) - semverFail = true - // major version, don't think we should need to check other versions - else if ( clientModVersion[ 0 ] != serverModVersion[ 0 ] ) - semverFail = true - } - if ( semverFail ) - { - DialogData dialogData - dialogData.header = "#ERROR" - dialogData.message = Localize( "#WRONG_MOD_VERSION", mod.name, mod.version, NSGetModVersionByModName( mod.name ) ) - dialogData.image = $"ui/menu/common/dialog_error" - - #if PC_PROG - AddDialogButton( dialogData, "#DISMISS" ) - - AddDialogFooter( dialogData, "#A_BUTTON_SELECT" ) - #endif // PC_PROG - AddDialogFooter( dialogData, "#B_BUTTON_DISMISS_RUI" ) - - OpenDialog( dialogData ) - - return - } - } + // If we get here, means that mod version exists locally => we good } if ( server.requiresPassword ) @@ -1136,25 +1108,31 @@ void function ThreadedAuthAndConnectToServer( string password = "", bool modsCha if ( NSWasAuthSuccessful() ) { // disable all RequiredOnClient mods that are not required by the server and are currently enabled - foreach ( string modName in NSGetModNames() ) + foreach ( ModInfo mod in NSGetModsInformation() ) { - if ( NSIsModRequiredOnClient( modName ) && NSIsModEnabled( modName ) ) + string modName = mod.name + string modVersion = mod.version + + if ( mod.requiredOnClient && mod.enabled ) { // find the mod name in the list of server required mods bool found = false foreach ( RequiredModInfo mod in file.lastSelectedServer.requiredMods ) { - if (mod.name == modName) + // this tolerates a version difference for requiredOnClient core mods (only Northstar.Custom for now) + if (mod.name == modName && ( IsCoreMod( modName ) || mod.version == modVersion )) { found = true + print(format("\"%s\" (v%s) is required and already enabled.", modName, modVersion)) break } } - // if we didnt find the mod name, disable the mod + // if we didn't find the mod name, disable the mod if (!found) { modsChanged = true NSSetModEnabled( modName, false ) + print(format("Disabled \"%s\" (v%s) since it's not required on server.", modName, modVersion)) } } } @@ -1162,10 +1140,26 @@ void function ThreadedAuthAndConnectToServer( string password = "", bool modsCha // enable all RequiredOnClient mods that are required by the server and are currently disabled foreach ( RequiredModInfo mod in file.lastSelectedServer.requiredMods ) { - if ( NSIsModRequiredOnClient( mod.name ) && !NSIsModEnabled( mod.name )) + string modName = mod.name + string modVersion = mod.version + + // Tolerate core mods (only Northstar.Custom for now) having a different version than server + if ( IsCoreMod(modName) ) + { + string coreModVersion = NSGetModVersions( modName )[0] + if ( !NSIsModEnabled( modName ) ) + { + modsChanged = true + NSSetModEnabled( modName, true ) + print(format("Enabled \"%s\" (v%s) to join server.", modName, coreModVersion)) + } + } + + else if ( NSIsModRequiredOnClient( mod.name ) && !NSIsModEnabled( mod.name )) { modsChanged = true NSSetModEnabled( mod.name, true ) + print(format("Enabled \"%s\" (v%s) to join server.", modName, modVersion)) } } @@ -1361,3 +1355,9 @@ void function TriggerConnectToServerCallbacks( ServerInfo ornull targetServer = callback( expect ServerInfo( targetServer ) ) } } + +const array CORE_MODS = ["Northstar.Client", "Northstar.Coop", "Northstar.CustomServers", "Northstar.Custom"] +bool function IsCoreMod( string modName ) +{ + return CORE_MODS.find( modName ) != -1 +} \ No newline at end of file diff --git a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_setversionlabel.nut b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_setversionlabel.nut index 6dbafde96..0b868a910 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_setversionlabel.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_setversionlabel.nut @@ -5,6 +5,6 @@ void function NS_SetVersionLabel() { var mainMenu = GetMenu( "MainMenu" ) //Gets main menu element var versionLabel = GetElementsByClassname( mainMenu, "nsVersionClass" )[0] //Gets the label from the mainMenu element. - Hud_SetText( versionLabel, "v" + NSGetModVersionByModName("Northstar.Client")) //Sets the label text (Getting Northstar version from Northstar.Client) + Hud_SetText( versionLabel, "v" + NSGetModVersions("Northstar.Client")[0]) //Sets the label text (Getting Northstar version from Northstar.Client) } diff --git a/Northstar.Client/mod/scripts/vscripts/ui/panel_mainmenu.nut b/Northstar.Client/mod/scripts/vscripts/ui/panel_mainmenu.nut index 2f1bcf025..330cd0d6a 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/panel_mainmenu.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/panel_mainmenu.nut @@ -431,9 +431,9 @@ void function UpdatePlayButton( var button ) { // restrict non-vanilla players from accessing official servers bool hasNonVanillaMods = false - foreach ( string modName in NSGetModNames() ) + foreach ( ModInfo mod in NSGetModsInformation() ) { - if ( NSIsModEnabled( modName ) && NSIsModRequiredOnClient( modName ) ) + if ( mod.enabled && mod.requiredOnClient ) { hasNonVanillaMods = true break From d57c6e9ec3a39a059899978f6b58eb5cdad704cc Mon Sep 17 00:00:00 2001 From: Remy Raes Date: Fri, 1 Nov 2024 02:24:57 +0100 Subject: [PATCH 05/12] build: add NSGetModsInformation method to UI signatures --- .github/nativefuncs.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/nativefuncs.json b/.github/nativefuncs.json index 3658fc8e0..892f5c3d0 100644 --- a/.github/nativefuncs.json +++ b/.github/nativefuncs.json @@ -394,6 +394,12 @@ "returnTypeString":"array", "argTypes":"" }, + { + "name":"NSGetModsInformation", + "helpText":"", + "returnTypeString":"array", + "argTypes":"" + }, { "name":"NSIsModEnabled", "helpText":"", From b57b158978618dce5648e15555289ca62fe34752 Mon Sep 17 00:00:00 2001 From: Remy Raes Date: Fri, 1 Nov 2024 02:27:14 +0100 Subject: [PATCH 06/12] build: add NSGetModVersions method to UI signatures --- .github/nativefuncs.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/nativefuncs.json b/.github/nativefuncs.json index 892f5c3d0..cb344f3e6 100644 --- a/.github/nativefuncs.json +++ b/.github/nativefuncs.json @@ -400,6 +400,12 @@ "returnTypeString":"array", "argTypes":"" }, + { + "name":"NSGetModVersions", + "helpText":"", + "returnTypeString":"array", + "argTypes":"string modName" + }, { "name":"NSIsModEnabled", "helpText":"", From 2a7d592f8008570e927ceea0362e0fb3858e0ae5 Mon Sep 17 00:00:00 2001 From: Remy Raes Date: Fri, 1 Nov 2024 02:29:30 +0100 Subject: [PATCH 07/12] build: add back NSIsModRequiredOnClient method to UI signatures --- .github/nativefuncs.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/nativefuncs.json b/.github/nativefuncs.json index cb344f3e6..65d40cb5b 100644 --- a/.github/nativefuncs.json +++ b/.github/nativefuncs.json @@ -406,6 +406,12 @@ "returnTypeString":"array", "argTypes":"string modName" }, + { + "name":"NSIsModRequiredOnClient", + "helpText":"", + "returnTypeString":"bool", + "argTypes":"string modName" + }, { "name":"NSIsModEnabled", "helpText":"", From d0286a904923bf98307901b110bc768c37faf277 Mon Sep 17 00:00:00 2001 From: Remy Raes Date: Wed, 20 Nov 2024 19:13:40 +0100 Subject: [PATCH 08/12] build: add NSGetModInformation signature to CI configuration --- .github/nativefuncs.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/nativefuncs.json b/.github/nativefuncs.json index 65d40cb5b..c3119f0d7 100644 --- a/.github/nativefuncs.json +++ b/.github/nativefuncs.json @@ -400,6 +400,12 @@ "returnTypeString":"array", "argTypes":"" }, + { + "name":"NSGetModInformation", + "helpText":"", + "returnTypeString":"array", + "argTypes":"string modName" + }, { "name":"NSGetModVersions", "helpText":"", From fa568018bb3423a41451ebb9683b1fa42c0ce436 Mon Sep 17 00:00:00 2001 From: Remy Raes Date: Wed, 20 Nov 2024 19:14:14 +0100 Subject: [PATCH 09/12] refactor: remove NSGetModVersions method --- .github/nativefuncs.json | 12 -------- .../vscripts/ui/menu_ns_serverbrowser.nut | 28 ++++++++++++++----- .../vscripts/ui/menu_ns_setversionlabel.nut | 2 +- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/.github/nativefuncs.json b/.github/nativefuncs.json index c3119f0d7..e5e82101d 100644 --- a/.github/nativefuncs.json +++ b/.github/nativefuncs.json @@ -12,12 +12,6 @@ "returnTypeString":"array", "argTypes":"" }, - { - "name":"NSGetModVersions", - "helpText":"", - "returnTypeString":"array", - "argTypes":"string modName" - }, { "name":"NSIsModEnabled", "helpText":"", @@ -406,12 +400,6 @@ "returnTypeString":"array", "argTypes":"string modName" }, - { - "name":"NSGetModVersions", - "helpText":"", - "returnTypeString":"array", - "argTypes":"string modName" - }, { "name":"NSIsModRequiredOnClient", "helpText":"", diff --git a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut index ffbc1a306..247d619a9 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut @@ -982,7 +982,8 @@ void function OnServerSelected_Threaded( var button ) uninstalledModFound = true break } else { - array modVersions = NSGetModVersions( requiredModInfo.name ) + array modVersions = GetModVersions( requiredModInfo.name ) + if ( !modVersions.contains( requiredModInfo.version ) ) { print( format ( "\"%s\" was found locally but has versions:", requiredModInfo.name ) ) foreach ( string version in modVersions ) @@ -1009,7 +1010,9 @@ void function OnServerSelected_Threaded( var button ) if ( IsCoreMod( mod.name ) ) continue - if ( !NSGetModNames().contains( mod.name ) || !NSGetModVersions( mod.name ).contains( mod.version ) ) + array modVersions = GetModVersions( mod.name ) + + if ( !NSGetModNames().contains( mod.name ) || !modVersions.contains( mod.version ) ) { // Auto-download mod if ( autoDownloadAllowed ) @@ -1142,20 +1145,21 @@ void function ThreadedAuthAndConnectToServer( string password = "", bool modsCha { string modName = mod.name string modVersion = mod.version + array localModInfo = NSGetModInformation( modName ) + ModInfo firstModInfo = localModInfo[0] // Tolerate core mods (only Northstar.Custom for now) having a different version than server if ( IsCoreMod(modName) ) { - string coreModVersion = NSGetModVersions( modName )[0] - if ( !NSIsModEnabled( modName ) ) + if ( !firstModInfo.enabled ) { modsChanged = true NSSetModEnabled( modName, true ) - print(format("Enabled \"%s\" (v%s) to join server.", modName, coreModVersion)) + print(format("Enabled \"%s\" (v%s) to join server.", modName, firstModInfo.version)) } } - else if ( NSIsModRequiredOnClient( mod.name ) && !NSIsModEnabled( mod.name )) + else if ( !firstModInfo.enabled ) //todo(in multiple versions PR): loop over `NSGetModInformation` members and check versions { modsChanged = true NSSetModEnabled( mod.name, true ) @@ -1360,4 +1364,14 @@ const array CORE_MODS = ["Northstar.Client", "Northstar.Coop", "Northsta bool function IsCoreMod( string modName ) { return CORE_MODS.find( modName ) != -1 -} \ No newline at end of file +} + +array function GetModVersions( string modName ) +{ + array versions = [] + foreach ( ModInfo mod in NSGetModInformation( modName ) ) + { + versions.append( mod.version ) + } + return versions +} diff --git a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_setversionlabel.nut b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_setversionlabel.nut index 0b868a910..afba8a70d 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_setversionlabel.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_setversionlabel.nut @@ -5,6 +5,6 @@ void function NS_SetVersionLabel() { var mainMenu = GetMenu( "MainMenu" ) //Gets main menu element var versionLabel = GetElementsByClassname( mainMenu, "nsVersionClass" )[0] //Gets the label from the mainMenu element. - Hud_SetText( versionLabel, "v" + NSGetModVersions("Northstar.Client")[0]) //Sets the label text (Getting Northstar version from Northstar.Client) + Hud_SetText( versionLabel, "v" + NSGetModInformation( "Northstar.Client" )[0].version ) //Sets the label text (Getting Northstar version from Northstar.Client) } From e17454fe846b3f243d3dcc209018850d9fed8544 Mon Sep 17 00:00:00 2001 From: Remy Raes Date: Wed, 20 Nov 2024 19:17:13 +0100 Subject: [PATCH 10/12] build: remove NSIsModRequiredOnClient method from CI configuration --- .github/nativefuncs.json | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/nativefuncs.json b/.github/nativefuncs.json index e5e82101d..e23766dec 100644 --- a/.github/nativefuncs.json +++ b/.github/nativefuncs.json @@ -400,12 +400,6 @@ "returnTypeString":"array", "argTypes":"string modName" }, - { - "name":"NSIsModRequiredOnClient", - "helpText":"", - "returnTypeString":"bool", - "argTypes":"string modName" - }, { "name":"NSIsModEnabled", "helpText":"", From 9c85d6cbafef72ac2df70ad63cae914014c83d04 Mon Sep 17 00:00:00 2001 From: Remy Raes Date: Wed, 20 Nov 2024 20:57:40 +0100 Subject: [PATCH 11/12] refactor: remove NSIsModEnabled method --- .github/nativefuncs.json | 18 ---- .../scripts/vscripts/ui/menu_ns_modmenu.nut | 86 +++++++++++-------- 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/.github/nativefuncs.json b/.github/nativefuncs.json index e23766dec..abc213caf 100644 --- a/.github/nativefuncs.json +++ b/.github/nativefuncs.json @@ -12,12 +12,6 @@ "returnTypeString":"array", "argTypes":"" }, - { - "name":"NSIsModEnabled", - "helpText":"", - "returnTypeString":"bool", - "argTypes":"string modName" - }, { "name":"NSSetModEnabled", "helpText":"", @@ -224,12 +218,6 @@ "returnTypeString":"array", "argTypes":"" }, - { - "name":"NSIsModEnabled", - "helpText":"", - "returnTypeString":"bool", - "argTypes":"string modName" - }, { "name":"NSSetModEnabled", "helpText":"", @@ -400,12 +388,6 @@ "returnTypeString":"array", "argTypes":"string modName" }, - { - "name":"NSIsModEnabled", - "helpText":"", - "returnTypeString":"bool", - "argTypes":"string modName" - }, { "name":"NSSetModEnabled", "helpText":"", diff --git a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_modmenu.nut b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_modmenu.nut index 5f938bced..67a184312 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_modmenu.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_modmenu.nut @@ -195,7 +195,7 @@ void function OnModButtonFocused( var button ) Hud_SetVisible( linkButton, false ) } - SetControlBarColor( modName ) + SetControlBarColor( file.lastMod ) bool required = file.lastMod.requiredOnClient Hud_SetVisible( Hud_GetChild( file.menu, "WarningLegendLabel" ), required ) @@ -206,18 +206,33 @@ void function OnModButtonPressed( var button ) { ModInfo mod = file.mods[ int ( Hud_GetScriptID( Hud_GetParent( button ) ) ) + file.scrollOffset - 1 ].mod string modName = mod.name - if ( StaticFind( modName ) && NSIsModEnabled( modName ) ) + if ( StaticFind( modName ) && mod.enabled ) CoreModToggleDialog( modName ) else { - NSSetModEnabled( modName, !NSIsModEnabled( modName ) ) - var panel = file.panels[ int ( Hud_GetScriptID( Hud_GetParent( button ) ) ) - 1 ] - SetControlBoxColor( Hud_GetChild( panel, "ControlBox" ), modName ) - SetControlBarColor( modName ) - SetModEnabledHelperImageAsset( Hud_GetChild( panel, "EnabledImage" ), modName ) - // RefreshMods() - UpdateListSliderPosition() - UpdateListSliderHeight() + NSSetModEnabled( modName, !mod.enabled ) + + // retrieve state of the mod that just got toggled + array infos = NSGetModInformation( mod.name ) + foreach ( modInfo in infos ) + { + if ( modInfo.name != modName || modInfo.version != mod.version ) + { + continue + } + + // Update UI mod state + file.mods[ int ( Hud_GetScriptID( Hud_GetParent( button ) ) ) + file.scrollOffset - 1 ].mod = modInfo + + var panel = file.panels[ int ( Hud_GetScriptID( Hud_GetParent( button ) ) ) - 1 ] + SetControlBoxColor( Hud_GetChild( panel, "ControlBox" ), modInfo ) + SetControlBarColor( modInfo ) + SetModEnabledHelperImageAsset( Hud_GetChild( panel, "EnabledImage" ), modInfo ) + // RefreshMods() + UpdateListSliderPosition() + UpdateListSliderHeight() + break + } } } @@ -291,12 +306,23 @@ void function DisableMod() string modName = mod.name NSSetModEnabled( modName, false ) - var panel = file.panels[ int ( Hud_GetScriptID( Hud_GetParent( file.currentButton ) ) ) - 1] - SetControlBoxColor( Hud_GetChild( panel, "ControlBox" ), modName ) - SetControlBarColor( modName ) - SetModEnabledHelperImageAsset( Hud_GetChild( panel, "EnabledImage" ), modName ) + // retrieve state of the mod that just got toggled + array infos = NSGetModInformation( mod.name ) + foreach ( modInfo in infos ) + { + if ( modInfo.name != modName || modInfo.version != mod.version ) + { + continue + } - RefreshMods() + var panel = file.panels[ int ( Hud_GetScriptID( Hud_GetParent( file.currentButton ) ) ) - 1] + SetControlBoxColor( Hud_GetChild( panel, "ControlBox" ), modInfo ) + SetControlBarColor( modInfo ) + SetModEnabledHelperImageAsset( Hud_GetChild( panel, "EnabledImage" ), modInfo ) + + RefreshMods() + break + } } array function GetEnabledModsArray() @@ -431,53 +457,45 @@ void function DisplayModPanels() Hud_SetVisible( headerLabel, false ) - SetControlBoxColor( box, mod.name ) + SetControlBoxColor( box, mod ) Hud_SetVisible( box, true ) Hud_SetVisible( line, false ) Hud_SetVisible( warning, mod.requiredOnClient ) - SetModEnabledHelperImageAsset( enabledImage, c.mod.name ) + SetModEnabledHelperImageAsset( enabledImage, c.mod ) } Hud_SetVisible( panel, true ) } } -void function SetModEnabledHelperImageAsset( var panel, string modName ) +void function SetModEnabledHelperImageAsset( var panel, ModInfo mod ) { - if( NSIsModEnabled( modName ) ) + if( mod.enabled ) RuiSetImage( Hud_GetRui( panel ), "basicImage", $"rui/menu/common/merit_state_success" ) else RuiSetImage( Hud_GetRui( panel ), "basicImage", $"rui/menu/common/merit_state_failure" ) - RuiSetFloat3(Hud_GetRui( panel ), "basicImageColor", GetControlColorForMod( modName ) ) + RuiSetFloat3(Hud_GetRui( panel ), "basicImageColor", GetControlColorForMod( mod ) ) Hud_SetVisible( panel, true ) } -void function SetControlBoxColor( var box, string modName ) +void function SetControlBoxColor( var box, ModInfo mod ) { var rui = Hud_GetRui( box ) - // if ( NSIsModEnabled( modName ) ) - // RuiSetFloat3(rui, "basicImageColor", <0,1,0>) - // else - // RuiSetFloat3(rui, "basicImageColor", <1,0,0>) - RuiSetFloat3(rui, "basicImageColor", GetControlColorForMod( modName ) ) + RuiSetFloat3(rui, "basicImageColor", GetControlColorForMod( mod ) ) } -void function SetControlBarColor( string modName ) +void function SetControlBarColor( ModInfo mod ) { var bar_element = Hud_GetChild( file.menu, "ModEnabledBar" ) var bar = Hud_GetRui( bar_element ) - // if ( NSIsModEnabled( modName ) ) - // RuiSetFloat3(bar, "basicImageColor", <0,1,0>) - // else - // RuiSetFloat3(bar, "basicImageColor", <1,0,0>) - RuiSetFloat3(bar, "basicImageColor", GetControlColorForMod( modName ) ) + RuiSetFloat3(bar, "basicImageColor", GetControlColorForMod( mod ) ) Hud_SetVisible( bar_element, true ) } -vector function GetControlColorForMod( string modName ) +vector function GetControlColorForMod( ModInfo mod ) { - if ( NSIsModEnabled( modName ) ) + if ( mod.enabled ) switch ( GetConVarInt( "colorblind_mode" ) ) { case 1: From 93c15fbf25b63d1722bc407f2b0f5b55e3e1d3cb Mon Sep 17 00:00:00 2001 From: Remy Raes Date: Wed, 20 Nov 2024 21:32:15 +0100 Subject: [PATCH 12/12] fix: enable required local mods on server join --- .../vscripts/ui/menu_ns_serverbrowser.nut | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut index 247d619a9..f2effd128 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut @@ -1010,9 +1010,7 @@ void function OnServerSelected_Threaded( var button ) if ( IsCoreMod( mod.name ) ) continue - array modVersions = GetModVersions( mod.name ) - - if ( !NSGetModNames().contains( mod.name ) || !modVersions.contains( mod.version ) ) + if ( !NSGetModNames().contains( mod.name ) || !GetModVersions( mod.name ).contains( mod.version ) ) { // Auto-download mod if ( autoDownloadAllowed ) @@ -1145,25 +1143,31 @@ void function ThreadedAuthAndConnectToServer( string password = "", bool modsCha { string modName = mod.name string modVersion = mod.version - array localModInfo = NSGetModInformation( modName ) - ModInfo firstModInfo = localModInfo[0] + array localModInfos = NSGetModInformation( modName ) // Tolerate core mods (only Northstar.Custom for now) having a different version than server if ( IsCoreMod(modName) ) { - if ( !firstModInfo.enabled ) + if ( !localModInfos[0].enabled ) { modsChanged = true NSSetModEnabled( modName, true ) - print(format("Enabled \"%s\" (v%s) to join server.", modName, firstModInfo.version)) + print(format("Enabled \"%s\" (v%s) to join server.", modName, localModInfos[0].version)) } } - else if ( !firstModInfo.enabled ) //todo(in multiple versions PR): loop over `NSGetModInformation` members and check versions + else { - modsChanged = true - NSSetModEnabled( mod.name, true ) - print(format("Enabled \"%s\" (v%s) to join server.", modName, modVersion)) + foreach( localMod in localModInfos ) + { + if ( localMod.version == mod.version ) + { + modsChanged = true + NSSetModEnabled( mod.name, true ) + print(format("Enabled \"%s\" (v%s) to join server.", modName, modVersion)) + break + } + } } }