Sanitize invalid icons on menu installation (#146)

This commit is contained in:
bd_ 2022-12-09 11:40:22 -08:00 committed by GitHub
parent e7ec5b08b4
commit 2ac191555e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -61,7 +61,8 @@ namespace nadena.dev.modular_avatar.core.editor
if (!_installTargets.TryGetValue(installer.installTargetMenu, out var targetMenu)) return;
if (_installTargets.ContainsKey(installer.menuToAppend)) return;
targetMenu.controls.AddRange(installer.menuToAppend.controls);
// Clone before appending to sanitize menu icons
targetMenu.controls.AddRange(CloneMenu(installer.menuToAppend).controls);
while (targetMenu.controls.Count > VRCExpressionsMenu.MAX_CONTROLS)
{
@ -103,6 +104,20 @@ namespace nadena.dev.modular_avatar.core.editor
foreach (var control in newMenu.controls)
{
if (Util.ValidateExpressionMenuIcon(control.icon) != Util.ValidateExpressionMenuIconResult.Success)
control.icon = null;
for (int i = 0; i < control.labels.Length; i++)
{
var label = control.labels[i];
var labelResult = Util.ValidateExpressionMenuIcon(label.icon);
if (labelResult != Util.ValidateExpressionMenuIconResult.Success)
{
label.icon = null;
control.labels[i] = label;
}
}
if (control.type == VRCExpressionsMenu.Control.ControlType.SubMenu)
{
control.subMenu = CloneMenu(control.subMenu);