aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Raes <raes.remy@gmail.com>2024-11-22 00:50:19 +0100
committerGitHub <noreply@github.com>2024-11-22 00:50:19 +0100
commite7aa1c2a3459c9a4ad63d89b5da577bf10e8366c (patch)
treee042fe8dcde883495e04697adc626f7eeb8d3af9
parentc1649d1e1d719b2859041afa1cbff32ee090a885 (diff)
downloadNorthstarMods-e7aa1c2a3459c9a4ad63d89b5da577bf10e8366c.tar.gz
NorthstarMods-e7aa1c2a3459c9a4ad63d89b5da577bf10e8366c.zip
Refactor getting mod information (#899)
Mod counterpart to the launcher PR. Adds a struct containing mod information instead of getting every field with its own dedicated function
-rw-r--r--.github/nativefuncs.json148
-rw-r--r--Northstar.Client/mod/scripts/vscripts/cl_northstar_client_init.nut13
-rw-r--r--Northstar.Client/mod/scripts/vscripts/ui/menu_ns_modmenu.nut194
-rw-r--r--Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut122
-rw-r--r--Northstar.Client/mod/scripts/vscripts/ui/menu_ns_setversionlabel.nut2
-rw-r--r--Northstar.Client/mod/scripts/vscripts/ui/panel_mainmenu.nut4
6 files changed, 203 insertions, 280 deletions
diff --git a/.github/nativefuncs.json b/.github/nativefuncs.json
index 11042903..abc213ca 100644
--- a/.github/nativefuncs.json
+++ b/.github/nativefuncs.json
@@ -7,10 +7,10 @@
"argTypes":""
},
{
- "name":"NSIsModEnabled",
+ "name":"NSGetModsInformation",
"helpText":"",
- "returnTypeString":"bool",
- "argTypes":"string modName"
+ "returnTypeString":"array<ModInfo>",
+ "argTypes":""
},
{
"name":"NSSetModEnabled",
@@ -19,48 +19,6 @@
"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<string>",
- "argTypes":"string modName"
- },
- {
"name":"DecodeJSON",
"helpText":"converts a json string to a squirrel table",
"returnTypeString":"table",
@@ -261,60 +219,12 @@
"argTypes":""
},
{
- "name":"NSIsModEnabled",
- "helpText":"",
- "returnTypeString":"bool",
- "argTypes":"string modName"
- },
- {
"name":"NSSetModEnabled",
"helpText":"",
"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<string>",
- "argTypes":"string modName"
- },
- {
"name":"DecodeJSON",
"helpText":"converts a json string to a squirrel table",
"returnTypeString":"table",
@@ -467,58 +377,22 @@
"argTypes":""
},
{
- "name":"NSIsModEnabled",
- "helpText":"",
- "returnTypeString":"bool",
- "argTypes":"string modName"
- },
- {
- "name":"NSSetModEnabled",
- "helpText":"",
- "returnTypeString":"void",
- "argTypes":"string modName, bool enabled"
- },
- {
- "name":"NSIsModRemote",
+ "name":"NSGetModsInformation",
"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"
+ "returnTypeString":"array<ModInfo>",
+ "argTypes":""
},
{
- "name":"NSIsModRequiredOnClient",
+ "name":"NSGetModInformation",
"helpText":"",
- "returnTypeString":"bool",
+ "returnTypeString":"array<ModInfo>",
"argTypes":"string modName"
},
{
- "name":"NSGetModConvarsByModName",
+ "name":"NSSetModEnabled",
"helpText":"",
- "returnTypeString":"array<string>",
- "argTypes":"string modName"
+ "returnTypeString":"void",
+ "argTypes":"string modName, bool enabled"
},
{
"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 9e683a86..e4e44d51 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<string> conVars = []
+}
+
global struct RequiredModInfo
{
string name
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 f08d69a7..67a18431 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<string> conVars = []
-}
-
struct panelContent {
- modData& mod
+ ModInfo& mod
bool isHeader = false
}
@@ -37,10 +28,10 @@ struct {
var menu
array<var> panels
int scrollOffset = 0
- array<string> enabledMods
+ array<ModInfo> 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<string> current = GetEnabledModsArray()
+ array<ModInfo> 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() )
{
@@ -193,28 +195,44 @@ void function OnModButtonFocused( var button )
Hud_SetVisible( linkButton, false )
}
- SetControlBarColor( modName )
+ SetControlBarColor( file.lastMod )
- 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
- if ( StaticFind( modName ) && NSIsModEnabled( modName ) )
+ ModInfo mod = file.mods[ int ( Hud_GetScriptID( Hud_GetParent( button ) ) ) + file.scrollOffset - 1 ].mod
+ string modName = mod.name
+ 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<ModInfo> 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
+ }
}
}
@@ -230,8 +248,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 +279,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,23 +302,35 @@ 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]
- SetControlBoxColor( Hud_GetChild( panel, "ControlBox" ), modName )
- SetControlBarColor( modName )
- SetModEnabledHelperImageAsset( Hud_GetChild( panel, "EnabledImage" ), modName )
+ // retrieve state of the mod that just got toggled
+ array<ModInfo> 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" ), modInfo )
+ SetControlBarColor( modInfo )
+ SetModEnabledHelperImageAsset( Hud_GetChild( panel, "EnabledImage" ), modInfo )
- RefreshMods()
+ RefreshMods()
+ break
+ }
}
-array<string> function GetEnabledModsArray()
+array<ModInfo> function GetEnabledModsArray()
{
- array<string> enabledMods
- foreach ( string mod in NSGetModNames() )
+ array<ModInfo> enabledMods
+ foreach ( ModInfo mod in NSGetModsInformation() )
{
- if ( NSIsModEnabled( mod ) )
+ if ( mod.enabled )
enabledMods.append( mod )
}
return enabledMods
@@ -324,29 +354,30 @@ void function UpdateList()
void function RefreshMods()
{
- array<string> modNames = NSGetModNames()
+ array<ModInfo> 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 +398,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 +412,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 +427,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" )
@@ -434,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, NSIsModRequiredOnClient( c.mod.name ) )
+ 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:
@@ -502,17 +517,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<string> modCvars = NSGetModConvarsByModName( modName )
+ array<string> modCvars = mod.conVars
if ( modCvars.len() != 0 && GetConVarBool( "modlist_show_convars" ) )
{
ret += "ConVars: "
@@ -529,7 +547,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 cdeb8b3e..f2effd12 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,27 @@ 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<string> 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 )
+ {
+ print(" - " + version)
+ }
+ print( format ( "while server requires \"%s\"" + ( autoDownloadAllowed ? ", triggering manifesto fetching." : "." ), requiredModInfo.version ) )
+ uninstalledModFound = true
+ break
+ }
}
}
@@ -992,17 +1001,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 ) || !GetModVersions( mod.name ).contains( mod.version ) )
{
// Auto-download mod
if ( autoDownloadAllowed )
@@ -1055,43 +1063,8 @@ void function OnServerSelected_Threaded( var button )
return
}
}
- else
- {
- // this uses semver https://semver.org
- array<string> serverModVersion = split( mod.name, "." )
- array<string> 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 +1109,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 +1141,33 @@ 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
+ array<ModInfo> localModInfos = NSGetModInformation( modName )
+
+ // Tolerate core mods (only Northstar.Custom for now) having a different version than server
+ if ( IsCoreMod(modName) )
+ {
+ if ( !localModInfos[0].enabled )
+ {
+ modsChanged = true
+ NSSetModEnabled( modName, true )
+ print(format("Enabled \"%s\" (v%s) to join server.", modName, localModInfos[0].version))
+ }
+ }
+
+ else
{
- modsChanged = true
- NSSetModEnabled( mod.name, true )
+ 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
+ }
+ }
}
}
@@ -1361,3 +1363,19 @@ void function TriggerConnectToServerCallbacks( ServerInfo ornull targetServer =
callback( expect ServerInfo( targetServer ) )
}
}
+
+const array<string> CORE_MODS = ["Northstar.Client", "Northstar.Coop", "Northstar.CustomServers", "Northstar.Custom"]
+bool function IsCoreMod( string modName )
+{
+ return CORE_MODS.find( modName ) != -1
+}
+
+array<string> function GetModVersions( string modName )
+{
+ array<string> 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 6dbafde9..afba8a70 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" + NSGetModInformation( "Northstar.Client" )[0].version ) //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 2f1bcf02..330cd0d6 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