Skip to content

Commit

Permalink
Fix INVALID_REF errors caused by mods (#657)
Browse files Browse the repository at this point in the history
`INVALID_REF` errors were being caused by trying to get the item image for weapon skins.

If a mod (e.g. moreskins) added new skins, the client equipped one, and then the mod is disabled, the client now has bad persistence.
This is mostly handled fine by the game, except for weapon skins. This PR prevents the crash, and resets the bad persistence to default.
  • Loading branch information
ASpoonPlaysGames authored Oct 12, 2023
1 parent c2716db commit 407c5ce
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ void function OnLoadoutButton_Focused( var button )
{
int index = expect int( button.s.rowIndex )

// update the editingLoadoutIndex on focus so that it always matches
// with the pilot loadout panel
uiGlobal.editingLoadoutIndex = index
uiGlobal.editingLoadoutType = "pilot"

UpdatePilotLoadout( index )

string pilotLoadoutRef = "pilot_loadout_" + ( index + 1 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,23 @@ void function UpdatePilotLoadoutPanel( var loadoutPanel, PilotLoadoutDef loadout
else if ( loadout.primarySkinIndex == 1 ) // camo
primaryAppearanceImage = CamoSkin_GetImage( CamoSkins_GetByIndex( loadout.primaryCamoIndex ) )
else // warpaint skin
primaryAppearanceImage = GetItemImage( GetSkinRefFromWeaponRefAndPersistenceValue( loadout.primary, loadout.primarySkinIndex ) )
primaryAppearanceImage = GetItemImageFromWeaponRefAndPersistenceValue( loadout.primary, loadout.primarySkinIndex, "primarySkinIndex" )

asset secondaryAppearanceImage
if ( loadout.secondarySkinIndex == 0 ) // default skin
secondaryAppearanceImage = $"rui/menu/common/appearance_button_swatch"
else if ( loadout.secondarySkinIndex == 1 ) // camo
secondaryAppearanceImage = CamoSkin_GetImage( CamoSkins_GetByIndex( loadout.secondaryCamoIndex ) )
else // warpaint skin
secondaryAppearanceImage = GetItemImage( GetSkinRefFromWeaponRefAndPersistenceValue( loadout.secondary, loadout.secondarySkinIndex ) )
secondaryAppearanceImage = GetItemImageFromWeaponRefAndPersistenceValue( loadout.secondary, loadout.secondarySkinIndex, "secondarySkinIndex" )

asset weapon3AppearanceImage
if ( loadout.weapon3SkinIndex == 0 ) // default skin
weapon3AppearanceImage = $"rui/menu/common/appearance_button_swatch"
else if ( loadout.weapon3SkinIndex == 1 ) // camo
weapon3AppearanceImage = CamoSkin_GetImage( CamoSkins_GetByIndex( loadout.weapon3CamoIndex ) )
else // warpaint skin
weapon3AppearanceImage = GetItemImage( GetSkinRefFromWeaponRefAndPersistenceValue( loadout.weapon3, loadout.weapon3SkinIndex ) )
weapon3AppearanceImage = GetItemImageFromWeaponRefAndPersistenceValue( loadout.weapon3, loadout.weapon3SkinIndex, "weapon3SkinIndex" )

RuiSetImage( Hud_GetRui( Hud_GetChild( loadoutPanel, "ButtonPilotCamo" ) ), "camoImage", pilotAppearanceImage )
RuiSetImage( Hud_GetRui( Hud_GetChild( loadoutPanel, "ButtonPrimarySkin" ) ), "camoImage", primaryAppearanceImage )
Expand Down Expand Up @@ -282,3 +282,19 @@ void function UpdatePilotLoadoutPanelBinds( var loadoutPanel )
//SetLabelRuiText( Hud_GetChild( loadoutPanel, "TacticalBind" ), Localize( "%offhand1%" ) )
//SetLabelRuiText( Hud_GetChild( loadoutPanel, "OrdnanceBind" ), Localize( "%offhand0%" ) )
}

asset function GetItemImageFromWeaponRefAndPersistenceValue(string weaponRef, int persistenceValue, string loadoutProperty)
{
string skinRef = GetSkinRefFromWeaponRefAndPersistenceValue( weaponRef, persistenceValue )
if (!IsRefValid(skinRef))
{
if (uiGlobal.editingLoadoutIndex != -1)
{
printt( "Resetting invalid " + loadoutProperty + " for weapon " + weaponRef )
SetCachedLoadoutValue(GetUIPlayer(), "pilot", uiGlobal.editingLoadoutIndex, loadoutProperty, "0")
}
return $"rui/menu/common/appearance_button_swatch"
}

return GetItemImage( skinRef )
}

0 comments on commit 407c5ce

Please sign in to comment.