diff --git a/.github/nativefuncs.json b/.github/nativefuncs.json index 10ceebd5d..1312d03c4 100644 --- a/.github/nativefuncs.json +++ b/.github/nativefuncs.json @@ -12,11 +12,29 @@ "returnTypeString":"array", "argTypes":"" }, + { + "name":"NSIsModEnabled", + "helpText":"", + "returnTypeString":"bool", + "argTypes":"string modName, string modVersion" + }, { "name":"NSSetModEnabled", "helpText":"", "returnTypeString":"void", - "argTypes":"string modName, bool enabled" + "argTypes":"string modName, string modVersion, bool enabled" + }, + { + "name":"NSGetModVersions", + "helpText":"", + "returnTypeString":"array", + "argTypes":"string modName" + }, + { + "name":"NSIsModRequiredOnClient", + "helpText":"", + "returnTypeString":"bool", + "argTypes":"string modName, string modVersion" }, { "name":"DecodeJSON", @@ -218,11 +236,35 @@ "returnTypeString":"array", "argTypes":"" }, + { + "name":"NSGetModsInformation", + "helpText":"", + "returnTypeString":"array", + "argTypes":"" + }, + { + "name":"NSIsModEnabled", + "helpText":"", + "returnTypeString":"bool", + "argTypes":"string modName, string modVersion" + }, { "name":"NSSetModEnabled", "helpText":"", "returnTypeString":"void", - "argTypes":"string modName, bool enabled" + "argTypes":"string modName, string modVersion, bool enabled" + }, + { + "name":"NSGetModVersions", + "helpText":"", + "returnTypeString":"array", + "argTypes":"string modName" + }, + { + "name":"NSIsModRequiredOnClient", + "helpText":"", + "returnTypeString":"bool", + "argTypes":"string modName, string modVersion" }, { "name":"DecodeJSON", @@ -383,16 +425,28 @@ "argTypes":"" }, { - "name":"NSGetModInformation", + "name":"NSIsModEnabled", "helpText":"", - "returnTypeString":"array", - "argTypes":"string modName" + "returnTypeString":"bool", + "argTypes":"string modName, string modVersion" }, { "name":"NSSetModEnabled", "helpText":"", "returnTypeString":"void", - "argTypes":"string modName, bool enabled" + "argTypes":"string modName, string modVersion, bool enabled" + }, + { + "name":"NSGetModVersions", + "helpText":"", + "returnTypeString":"array", + "argTypes":"string modName" + }, + { + "name":"NSIsModRequiredOnClient", + "helpText":"", + "returnTypeString":"bool", + "argTypes":"string modName, string modVersion" }, { "name": "NSFetchVerifiedModsManifesto", 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 e4e44d51e..f0881d102 100644 --- a/Northstar.Client/mod/scripts/vscripts/cl_northstar_client_init.nut +++ b/Northstar.Client/mod/scripts/vscripts/cl_northstar_client_init.nut @@ -31,15 +31,15 @@ global struct UIPresenceStruct { global struct ModInfo { - string name = "" + string name = "" string description = "" - string version = "" - string downloadLink = "" - int loadPriority = 0 - bool enabled = false - bool requiredOnClient = false - bool isRemote - array conVars = [] + string version = "" + string downloadLink = "" + int loadPriority = 0 + bool enabled = false + bool requiredOnClient = false + bool isRemote + array conVars = [] } global struct RequiredModInfo 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 67a184312..e3f470bdc 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_modmenu.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_modmenu.nut @@ -147,16 +147,16 @@ void function OnModMenuClosed() { bool notFound = true - foreach ( ModInfo enMod in file.enabledMods ) + foreach (ModInfo enMod in file.enabledMods ) { - if ( mod.name == enMod.name ) + if (mod.name == enMod.name && mod.version == enMod.version) { notFound = false break } } - if ( notFound ) + if (notFound) { reload = true break @@ -195,7 +195,7 @@ void function OnModButtonFocused( var button ) Hud_SetVisible( linkButton, false ) } - SetControlBarColor( file.lastMod ) + SetControlBarColor( modName, file.lastMod.version ) bool required = file.lastMod.requiredOnClient Hud_SetVisible( Hud_GetChild( file.menu, "WarningLegendLabel" ), required ) @@ -206,33 +206,18 @@ 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 ) && mod.enabled ) + if ( StaticFind( modName ) && NSIsModEnabled( modName, mod.version ) ) CoreModToggleDialog( modName ) else { - 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 - } + NSSetModEnabled( modName, mod.version, !NSIsModEnabled( modName, mod.version ) ) + var panel = file.panels[ int ( Hud_GetScriptID( Hud_GetParent( button ) ) ) - 1 ] + SetControlBoxColor( Hud_GetChild( panel, "ControlBox" ), modName, mod.version ) + SetControlBarColor( modName, mod.version ) + SetModEnabledHelperImageAsset( Hud_GetChild( panel, "EnabledImage" ), modName, mod.version ) + // RefreshMods() + UpdateListSliderPosition() + UpdateListSliderHeight() } } @@ -304,25 +289,14 @@ void function DisableMod() { ModInfo mod = file.mods[ int ( Hud_GetScriptID( Hud_GetParent( file.currentButton ) ) ) + file.scrollOffset - 1 ].mod string modName = mod.name - NSSetModEnabled( modName, false ) + NSSetModEnabled( modName, mod.version, false ) - // 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 - } + var panel = file.panels[ int ( Hud_GetScriptID( Hud_GetParent( file.currentButton ) ) ) - 1] + SetControlBoxColor( Hud_GetChild( panel, "ControlBox" ), modName, mod.version ) + SetControlBarColor( modName, mod.version ) + SetModEnabledHelperImageAsset( Hud_GetChild( panel, "EnabledImage" ), modName, mod.version ) - 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 - } + RefreshMods() } array function GetEnabledModsArray() @@ -457,45 +431,53 @@ void function DisplayModPanels() Hud_SetVisible( headerLabel, false ) - SetControlBoxColor( box, mod ) + SetControlBoxColor( box, mod.name, mod.version ) Hud_SetVisible( box, true ) Hud_SetVisible( line, false ) Hud_SetVisible( warning, mod.requiredOnClient ) - SetModEnabledHelperImageAsset( enabledImage, c.mod ) + SetModEnabledHelperImageAsset( enabledImage, c.mod.name, c.mod.version ) } Hud_SetVisible( panel, true ) } } -void function SetModEnabledHelperImageAsset( var panel, ModInfo mod ) +void function SetModEnabledHelperImageAsset( var panel, string modName, string modVersion ) { - if( mod.enabled ) + if( NSIsModEnabled( modName, modVersion ) ) 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( mod ) ) + RuiSetFloat3(Hud_GetRui( panel ), "basicImageColor", GetControlColorForMod( modName, modVersion ) ) Hud_SetVisible( panel, true ) } -void function SetControlBoxColor( var box, ModInfo mod ) +void function SetControlBoxColor( var box, string modName, string modVersion ) { var rui = Hud_GetRui( box ) - RuiSetFloat3(rui, "basicImageColor", GetControlColorForMod( mod ) ) + // if ( NSIsModEnabled( modName ) ) + // RuiSetFloat3(rui, "basicImageColor", <0,1,0>) + // else + // RuiSetFloat3(rui, "basicImageColor", <1,0,0>) + RuiSetFloat3(rui, "basicImageColor", GetControlColorForMod( modName, modVersion ) ) } -void function SetControlBarColor( ModInfo mod ) +void function SetControlBarColor( string modName, string modVersion ) { var bar_element = Hud_GetChild( file.menu, "ModEnabledBar" ) var bar = Hud_GetRui( bar_element ) - RuiSetFloat3(bar, "basicImageColor", GetControlColorForMod( mod ) ) + // if ( NSIsModEnabled( modName ) ) + // RuiSetFloat3(bar, "basicImageColor", <0,1,0>) + // else + // RuiSetFloat3(bar, "basicImageColor", <1,0,0>) + RuiSetFloat3(bar, "basicImageColor", GetControlColorForMod( modName, modVersion ) ) Hud_SetVisible( bar_element, true ) } -vector function GetControlColorForMod( ModInfo mod ) +vector function GetControlColorForMod( string modName, string modVersion ) { - if ( mod.enabled ) + if ( NSIsModEnabled( modName, modVersion ) ) switch ( GetConVarInt( "colorblind_mode" ) ) { case 1: 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 f2effd128..be5bd89e9 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut @@ -982,8 +982,7 @@ void function OnServerSelected_Threaded( var button ) uninstalledModFound = true break } else { - array modVersions = GetModVersions( requiredModInfo.name ) - + 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 ) @@ -1010,7 +1009,7 @@ void function OnServerSelected_Threaded( var button ) if ( IsCoreMod( mod.name ) ) continue - if ( !NSGetModNames().contains( mod.name ) || !GetModVersions( mod.name ).contains( mod.version ) ) + if ( !NSGetModNames().contains( mod.name ) || !NSGetModVersions( mod.name ).contains( mod.version ) ) { // Auto-download mod if ( autoDownloadAllowed ) @@ -1132,7 +1131,7 @@ void function ThreadedAuthAndConnectToServer( string password = "", bool modsCha if (!found) { modsChanged = true - NSSetModEnabled( modName, false ) + NSSetModEnabled( modName, modVersion, false ) print(format("Disabled \"%s\" (v%s) since it's not required on server.", modName, modVersion)) } } @@ -1143,31 +1142,24 @@ void function ThreadedAuthAndConnectToServer( string password = "", bool modsCha { string modName = mod.name string modVersion = mod.version - array localModInfos = NSGetModInformation( modName ) // Tolerate core mods (only Northstar.Custom for now) having a different version than server if ( IsCoreMod(modName) ) { - if ( !localModInfos[0].enabled ) + string coreModVersion = NSGetModVersions( modName )[0] + if ( !NSIsModEnabled( modName, coreModVersion ) ) { modsChanged = true - NSSetModEnabled( modName, true ) - print(format("Enabled \"%s\" (v%s) to join server.", modName, localModInfos[0].version)) + NSSetModEnabled( modName, coreModVersion, true ) + print(format("Enabled \"%s\" (v%s) to join server.", modName, coreModVersion)) } } - else + else if ( NSIsModRequiredOnClient( modName, modVersion ) && !NSIsModEnabled( 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 - } - } + modsChanged = true + NSSetModEnabled( modName, modVersion, true ) + print(format("Enabled \"%s\" (v%s) to join server.", modName, modVersion)) } } @@ -1368,14 +1360,4 @@ const array CORE_MODS = ["Northstar.Client", "Northstar.Coop", "Northsta bool function IsCoreMod( string modName ) { return CORE_MODS.find( modName ) != -1 -} - -array function GetModVersions( string modName ) -{ - array versions = [] - foreach ( ModInfo mod in NSGetModInformation( modName ) ) - { - versions.append( mod.version ) - } - return versions -} +} \ 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 afba8a70d..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" + NSGetModInformation( "Northstar.Client" )[0].version ) //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 330cd0d6a..354770e38 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/panel_mainmenu.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/panel_mainmenu.nut @@ -433,6 +433,7 @@ void function UpdatePlayButton( var button ) bool hasNonVanillaMods = false foreach ( ModInfo mod in NSGetModsInformation() ) { + string modName = mod.name if ( mod.enabled && mod.requiredOnClient ) { hasNonVanillaMods = true