fix(client): derive loaded plugin reporting from the managed registry

Pass managed plugin IDs and DLL names through launcher runtime settings. Report real versions only from loaded managed assemblies, excluding third-party and failed plugins.
This commit is contained in:
Flechazo committed 2026-10-25 19:20:52 +08:00
1 parent e8f0ed8e7d
commit 339b2dcaee
7 files changed
+85 -27

No files matched your search

+5 -1
View File
@@ -341,7 +341,11 @@ func (s *Studio) Launch(input Request) (Response, error) {
launch := func() (Response, error) {
configured := input.settings()
if s.updates != nil {
configured.Runtime = s.updates.Runtime(input.GameDirectory)
runtime, err := s.updates.Runtime(input.GameDirectory)
if err != nil {
return Response{}, err
}
configured.Runtime = runtime
}
settings, err := clientsetup.SaveSettings(input.GameDirectory, configured)
if err != nil {
+7 -6
View File
@@ -37,12 +37,13 @@ type Settings struct {
}
type Runtime struct {
ClientVersion string `json:"client_version"`
UpdateFingerprint string `json:"update_fingerprint"`
ResourceFingerprint string `json:"resource_fingerprint"`
GameVersion string `json:"game_version"`
BundleVersion string `json:"bundle_version"`
GameDataVersion string `json:"game_data_version"`
PluginFiles map[string]string `json:"plugin_files,omitempty"`
ClientVersion string `json:"client_version"`
UpdateFingerprint string `json:"update_fingerprint"`
ResourceFingerprint string `json:"resource_fingerprint"`
GameVersion string `json:"game_version"`
BundleVersion string `json:"bundle_version"`
GameDataVersion string `json:"game_data_version"`
}
func Path(gameDir string) string {
+6 -2
View File
@@ -15,8 +15,12 @@ func (m *Manager) PrepareLocalDatabase(ctx context.Context, client *http.Client,
if client == nil {
client = m.options.Client
}
_, err := dbpatch.Run(ctx, dbpatch.Options{
GameDirectory: game, Origin: origin, GameVersion: m.Runtime(game).GameVersion,
runtime, err := m.Runtime(game)
if err != nil {
return err
}
_, err = dbpatch.Run(ctx, dbpatch.Options{
GameDirectory: game, Origin: origin, GameVersion: runtime.GameVersion,
Client: client, Logger: m.options.Logger, Running: func() (bool, error) { return m.localDatabaseRunning(game) },
})
return err
+31 -5
View File
@@ -14,6 +14,7 @@ import (
clientconfig "bd2server/internal/client/config"
"bd2server/internal/client/download"
"bd2server/internal/client/plugin"
"bd2server/internal/client/setup"
commonconfig "bd2server/internal/common/config"
"bd2server/internal/common/release"
@@ -68,12 +69,34 @@ func (m *Manager) Versions(game string) versionconfig.Config {
return v
}
func (m *Manager) Runtime(game string) *clientconfig.Runtime {
func (m *Manager) Runtime(game string) (*clientconfig.Runtime, error) {
var runtime *clientconfig.Runtime
if m.options.Development {
return m.developmentRuntime()
runtime = m.developmentRuntime()
for _, artifact := range m.options.DevelopmentPlugins {
if artifact.ID != "" {
if runtime.PluginFiles == nil {
runtime.PluginFiles = map[string]string{}
}
runtime.PluginFiles[artifact.ID] = artifact.Name
}
}
return runtime, nil
}
v := m.Versions(game)
runtime := &clientconfig.Runtime{ClientVersion: v.ClientVersion, GameVersion: v.GameVersion, BundleVersion: v.BundleVersion, GameDataVersion: v.GameDataVersion}
runtime = &clientconfig.Runtime{ClientVersion: v.ClientVersion, GameVersion: v.GameVersion, BundleVersion: v.BundleVersion, GameDataVersion: v.GameDataVersion}
store, err := plugin.ReadStore(m.options.Directory)
if err != nil {
return nil, fmt.Errorf("read runtime plugin identities: %w", err)
}
for _, file := range store.Files {
if file.ID != "" {
if runtime.PluginFiles == nil {
runtime.PluginFiles = map[string]string{}
}
runtime.PluginFiles[file.ID] = file.Name
}
}
m.mu.Lock()
fp := m.fingerprint
m.mu.Unlock()
@@ -83,7 +106,7 @@ func (m *Manager) Runtime(game string) *clientconfig.Runtime {
runtime.ResourceFingerprint = receipt.ResourceFingerprint
}
}
return runtime
return runtime, nil
}
func (m *Manager) configureGame(game string) error {
@@ -91,7 +114,10 @@ func (m *Manager) configureGame(game string) error {
if err != nil {
return err
}
settings.Runtime = m.Runtime(game)
settings.Runtime, err = m.Runtime(game)
if err != nil {
return err
}
_, err = clientconfig.Save(game, settings)
return err
}
+9 -4
View File
@@ -6,11 +6,13 @@ import (
"fmt"
"os"
"path/filepath"
"reflect"
"strings"
"testing"
"time"
clientconfig "bd2server/internal/client/config"
"bd2server/internal/client/plugin"
commonconfig "bd2server/internal/common/config"
"bd2server/internal/common/release"
"bd2server/internal/common/versionconfig"
@@ -89,7 +91,7 @@ func TestServerOnlyFingerprintChangeReusesVerifiedGameResources(t *testing.T) {
func TestDevelopmentGameUsesProjectFingerprintAndNeverInstallsServerRequirement(t *testing.T) {
game := t.TempDir()
versions := versionconfig.Config{ServerVersion: "2.37.13+server.0.2.0", ClientVersion: "2.37.13+client.0.2.7", GameVersion: "2.37.13", BundleVersion: "20261022174708", GameDataVersion: "20261021182514"}
m := New(Options{Directory: t.TempDir(), Versions: versions, Development: true})
m := New(Options{Directory: t.TempDir(), Versions: versions, Development: true, DevelopmentPlugins: plugin.Set{{ID: "future_plugin", Name: "UnrelatedFileName.dll"}}})
m.project = &release.Fingerprint{ID: "project", ServerVersion: versions.ServerVersion, ClientVersion: versions.ClientVersion, GameFingerprint: "project-resources"}
m.fingerprint = &release.Fingerprint{ID: "server", RequireGameUpdate: true}
err := m.ensureGame(context.Background(), game)
@@ -99,9 +101,12 @@ func TestDevelopmentGameUsesProjectFingerprintAndNeverInstallsServerRequirement(
if entries, err := os.ReadDir(game); err != nil || len(entries) != 0 {
t.Fatalf("development preparation wrote into the game directory: %v %v", entries, err)
}
got := m.Runtime(game)
want := clientconfig.Runtime{ClientVersion: versions.ClientVersion, GameVersion: versions.GameVersion, BundleVersion: versions.BundleVersion, GameDataVersion: versions.GameDataVersion, UpdateFingerprint: "project", ResourceFingerprint: "project-resources"}
if *got != want {
got, err := m.Runtime(game)
if err != nil {
t.Fatal(err)
}
want := clientconfig.Runtime{ClientVersion: versions.ClientVersion, GameVersion: versions.GameVersion, BundleVersion: versions.BundleVersion, GameDataVersion: versions.GameDataVersion, UpdateFingerprint: "project", ResourceFingerprint: "project-resources", PluginFiles: map[string]string{"future_plugin": "UnrelatedFileName.dll"}}
if !reflect.DeepEqual(*got, want) {
t.Fatalf("development runtime = %+v, want project configuration %+v", *got, want)
}
}
+12 -8
View File
@@ -20,11 +20,6 @@ namespace Bd2LoginUI;
internal static class UpdateCompatibility
{
private static readonly KeyValuePair<string, string>[] PluginIds =
[
new("local_identity", "bd2.localidentity"), new("login_ui", Plugin.PluginId),
new("cash_shop", "bd2.cashshop"), new("fchat", "bd2.fchat")
];
private static readonly string Fingerprint = ClientSettings.Current.runtime.update_fingerprint;
private static readonly string ResourceFingerprint = ClientSettings.Current.runtime.resource_fingerprint;
private static readonly string ClientVersion = ClientSettings.Current.ClientVersion;
@@ -45,9 +40,18 @@ internal static class UpdateCompatibility
{
if (headers != null) return headers;
plugins = new Dictionary<string, string>(StringComparer.Ordinal);
foreach (KeyValuePair<string, string> id in PluginIds)
if (Chainloader.PluginInfos.TryGetValue(id.Value, out BepInEx.PluginInfo info))
plugins.Add(id.Key, info.Metadata.Version.ToString());
foreach (KeyValuePair<string, string> entry in ClientSettings.Current.runtime.plugin_files)
{
string expected = Path.GetFullPath(Path.Combine(BepInEx.Paths.PluginPath, entry.Value));
foreach (BepInEx.PluginInfo info in Chainloader.PluginInfos.Values)
{
if (info.Instance == null || !string.Equals(info.Instance.GetType().Assembly.Location, expected,
Path.DirectorySeparatorChar == '\\' ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal)) continue;
if (plugins.ContainsKey(entry.Key))
throw new InvalidDataException("Multiple loaded plugins use the managed DLL " + entry.Value);
plugins.Add(entry.Key, info.Metadata.Version.ToString());
}
}
using var stream = new MemoryStream();
Serializer(typeof(Dictionary<string, string>)).WriteObject(stream, plugins);
headers = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
+15 -1
View File
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using BepInEx;
@@ -28,7 +29,7 @@ internal sealed class ClientSettings
{
if (token == null || token.Type == JTokenType.Null) return new ClientRuntime();
if (token is not JObject value) throw new InvalidDataException("runtime must be an object");
RequireOnly(value, "client_version", "update_fingerprint", "resource_fingerprint", "game_version", "bundle_version", "game_data_version");
RequireOnly(value, "client_version", "update_fingerprint", "resource_fingerprint", "game_version", "bundle_version", "game_data_version", "plugin_files");
var runtime = new ClientRuntime
{
client_version = OptionalString(value, "client_version"),
@@ -38,6 +39,18 @@ internal sealed class ClientSettings
bundle_version = OptionalString(value, "bundle_version"),
game_data_version = OptionalString(value, "game_data_version")
};
if (value["plugin_files"] is JToken files && files.Type != JTokenType.Null)
{
if (files is not JObject entries) throw new InvalidDataException("runtime.plugin_files must be an object");
foreach (JProperty entry in entries.Properties())
{
string file = RequiredString(entries, entry.Name);
if (string.IsNullOrWhiteSpace(entry.Name) || Path.GetFileName(file) != file ||
file.IndexOfAny(['/', '\\', ':']) >= 0 || !file.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))
throw new InvalidDataException("runtime.plugin_files must map plugin IDs to DLL file names");
runtime.plugin_files.Add(entry.Name, file);
}
}
ValidateFingerprint(runtime.update_fingerprint, "update_fingerprint");
ValidateFingerprint(runtime.resource_fingerprint, "resource_fingerprint");
ValidateResourceVersion(runtime.bundle_version, "bundle_version");
@@ -232,6 +245,7 @@ internal sealed class ClientSettings
internal sealed class ClientRuntime
{
internal Dictionary<string, string> plugin_files = new(StringComparer.Ordinal);
internal string client_version = string.Empty;
internal string update_fingerprint = string.Empty;
internal string resource_fingerprint = string.Empty;