RacesOfValheim/JotunnModStub/ConfigSync.cs
kanym d1f328a496 feat(fenrir): eyes glow at night, bright when a form is ready
A community suggestion: an indicator on the character instead of the
"<form> is Ready!" text. FenrirVisuals borrows the Skeleton's eye_l and
eye_r the way AswidVisuals does, with the Aswid's playtested placement,
and tints them with the Fenring's own emission colour (2.0, 0.372, 0),
read from bundle c4210710.

Dark by day and in a beast form. At night they glow faintly, and
brightly while one of the three keys would transform. That uses the
same gates as TryTransformWithRules: tier, night, sun sickness,
cooldown. The owner writes it to the ZDO only on a change, so remote
players see the same.

New local section "Fenrir - Appearance": Ready Message (on by
default), Eye Glow, and the night and ready strengths.
2026-10-23 19:33:00 +02:00

101 lines
4.6 KiB
C#

using System;
using System.Linq;
using System.Reflection;
using BepInEx.Configuration;
using UnityEngine;
namespace RacesOfValheim
{
/// <summary>
/// Marks every gameplay config entry as admin-only so Jotunn syncs it from the server to the
/// clients (and locks it for non-admins in Configuration Manager).
///
/// Jotunn only recognises ITS OWN ConfigurationManagerAttributes (global namespace, in
/// Jotunn.dll) as a tag - it does an `is` check, not the field-name duck typing Configuration
/// Manager does - so our internal look-alike tag is not enough. This runs once after every
/// Bind() and adds Jotunn's tag beside whatever tags the entry already has, rather than
/// touching each of the ~350 Bind() calls.
///
/// Left local, because they are per-player preferences and syncing them would only take the
/// choice away from the player: keybinds, and the purely cosmetic entries (eye/claw colours,
/// glow, tint, rotation and offset of models, the VFX toggle, the stamina-bar toggle, debug
/// logging). Anything that changes a number the game computes with stays synced.
/// </summary>
internal static class ConfigSync
{
// Whole sections that are cosmetic or per-player.
private static readonly string[] LocalSections =
{
"Aswid - Claws",
"Aswid - Eyes",
"Fenrir - Appearance",
"Skeleton - Visuals",
"Sverm - Dorsal Spines",
"Sverm - Emberform",
"Trol - Appearance",
"War Vulture - Model",
"War Vulture - Interface",
};
// Cosmetic entries scattered through otherwise gameplay sections.
private static readonly string[] LocalKeyParts =
{
"marker light", "tint", "colour", "color", "glow", "swarm scale", "log rounds", "debug",
// Each player picks their own True Form: a player model mod (VRM and the like) breaks
// under the troll costume, so a server cannot be allowed to force the costume on.
"legacy true form",
};
public static void Apply(ConfigFile config)
{
FieldInfo descField = typeof(ConfigEntryBase)
.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
.FirstOrDefault(f => f.FieldType == typeof(ConfigDescription));
if (descField == null)
{
Debug.LogWarning("[RacesOfValheim] Config sync skipped: ConfigEntryBase has no ConfigDescription field.");
return;
}
int synced = 0, local = 0;
foreach (ConfigDefinition def in config.Keys.ToList())
{
ConfigEntryBase entry = config[def];
if (!ShouldSync(entry)) { local++; continue; }
ConfigDescription old = entry.Description;
object[] tags = (old.Tags ?? new object[0]).Concat(new object[]
{
new global::ConfigurationManagerAttributes { IsAdminOnly = true }
}).ToArray();
descField.SetValue(entry, new ConfigDescription(old.Description, old.AcceptableValues, tags));
synced++;
}
Debug.Log($"[RacesOfValheim] Config sync: {synced} entries admin-synced, {local} left local.");
}
private static bool ShouldSync(ConfigEntryBase entry)
{
Type type = entry.SettingType;
if (type == typeof(KeyboardShortcut) || type == typeof(KeyCode)) return false;
string section = entry.Definition.Section ?? "";
string key = (entry.Definition.Key ?? "").ToLowerInvariant();
if (section.EndsWith("Keybinds", StringComparison.OrdinalIgnoreCase)) return false;
if (LocalSections.Contains(section, StringComparer.OrdinalIgnoreCase)) return false;
if (LocalKeyParts.Any(key.Contains)) return false;
// Model pose nudges (rotation/offset/yaw) are cosmetic, but "Attack Reach Offset" is a
// real hit-detection distance and must stay in step with the server.
if ((key.Contains("rotation") || key.Contains("offset") || key.Contains("yaw"))
&& !key.Contains("reach")) return false;
// Decorative note lines (CustomDrawer/ReadOnly) carry no value worth sending.
ConfigurationManagerAttributes ours = (entry.Description?.Tags ?? new object[0]).OfType<ConfigurationManagerAttributes>().FirstOrDefault();
if (ours != null && (ours.CustomDrawer != null || ours.ReadOnly == true)) return false;
return true;
}
}
}