Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bazaarplusplus-mod/BppComposition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ internal sealed class BppComposition : IDisposable
private readonly InMemoryBppEventBus _eventBus = new();
private readonly BppConfig _config = new();
private readonly BppPathService _paths = new();
private readonly MonsterDatabase _monsterCatalog = new();
private readonly RunContextStore _runContext = new();
private readonly GameStateProbe _gameStateProbe = new();
private readonly BppRuntimeServices _services;
Expand All @@ -40,6 +41,7 @@ public BppComposition(ManualLogSource logger, ConfigFile configFile)

_config.Initialize(configFile);
_paths.Initialize();
_monsterCatalog.Initialize();
_runContext.Reset();

_services = new BppRuntimeServices(
Expand All @@ -48,6 +50,7 @@ public BppComposition(ManualLogSource logger, ConfigFile configFile)
_paths,
_runContext,
_gameStateProbe,
_monsterCatalog,
logger
);

Expand Down
10 changes: 9 additions & 1 deletion bazaarplusplus-mod/Core/Config/BppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ internal sealed class BppConfig : IBppConfig

public ConfigEntry<string>? UpgradePreviewHotkeyPathConfig { get; private set; }

public ConfigEntry<bool>? EnableCommunityContributionConfig { get; private set; }

public ConfigEntry<BppChineseLocaleMode>? ChineseLocaleModeConfig { get; private set; }

public ConfigEntry<LegendaryPositionDisplayMode>? LegendaryPositionDisplayModeConfig
Expand Down Expand Up @@ -77,6 +79,12 @@ public void Initialize(ConfigFile config)
"<Keyboard>/shift",
"Binding path for upgrade preview tooltip mode."
);
EnableCommunityContributionConfig = config.Bind(
"CommunityContribution",
"Enabled",
false,
"Whether to participate in BazaarPlusPlus community data contribution features, including background uploads and History Review access while out of a live run."
);
ChineseLocaleModeConfig = config.Bind(
"Localization",
"ChineseLocaleMode",
Expand All @@ -98,7 +106,7 @@ public void Initialize(ConfigFile config)
FinalBuildsRemoteUrlConfig = config.Bind(
"Network",
"FinalBuildsRemoteUrl",
"https://api.example.com/final_builds_for_mod.json",
"https://bpp-metrics.bazaarplusplus.com/final_builds/1d/all.json",
"Remote URL for downloading final build recommendations used by monster preview."
);
SponsorListUrlConfig = config.Bind(
Expand Down
2 changes: 2 additions & 0 deletions bazaarplusplus-mod/Core/Config/IBppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ internal interface IBppConfig

ConfigEntry<string>? UpgradePreviewHotkeyPathConfig { get; }

ConfigEntry<bool>? EnableCommunityContributionConfig { get; }

ConfigEntry<BppChineseLocaleMode>? ChineseLocaleModeConfig { get; }

ConfigEntry<LegendaryPositionDisplayMode>? LegendaryPositionDisplayModeConfig { get; }
Expand Down
24 changes: 24 additions & 0 deletions bazaarplusplus-mod/Core/Paths/BppPathService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ namespace BazaarPlusPlus.Core.Paths;

internal sealed class BppPathService : IPathService
{
public string? CardsJsonPath { get; private set; }

public string? RunLogDatabasePath { get; private set; }

public string? CombatReplayDirectoryPath { get; private set; }
Expand All @@ -12,8 +14,15 @@ internal sealed class BppPathService : IPathService

public string? IdentityDirectoryPath { get; private set; }

public string? RunUploadInstallIdentityPath { get; private set; }

public string? RunUploadClientStatePath { get; private set; }

public string? RunUploadPrivateKeyPath { get; private set; }

public void Initialize()
{
CardsJsonPath = CardJsonPathResolver.GetCardsJsonPath();
RunLogDatabasePath = System.IO.Path.Combine(
BepInEx.Paths.GameRootPath,
"BazaarPlusPlus",
Expand All @@ -34,5 +43,20 @@ public void Initialize()
"BazaarPlusPlus",
"Identity"
);
RunUploadInstallIdentityPath = System.IO.Path.Combine(
BepInEx.Paths.GameRootPath,
"BazaarPlusPlus",
"install-id.txt"
);
RunUploadClientStatePath = System.IO.Path.Combine(
BepInEx.Paths.GameRootPath,
"BazaarPlusPlus",
"run-upload-client.json"
);
RunUploadPrivateKeyPath = System.IO.Path.Combine(
BepInEx.Paths.GameRootPath,
"BazaarPlusPlus",
"run-upload-rsa.json"
);
}
}
8 changes: 8 additions & 0 deletions bazaarplusplus-mod/Core/Paths/IPathService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@ namespace BazaarPlusPlus.Core.Paths;

internal interface IPathService
{
string? CardsJsonPath { get; }

string? RunLogDatabasePath { get; }

string? CombatReplayDirectoryPath { get; }

string? ScreenshotsDirectoryPath { get; }

string? IdentityDirectoryPath { get; }

string? RunUploadInstallIdentityPath { get; }

string? RunUploadClientStatePath { get; }

string? RunUploadPrivateKeyPath { get; }
}
117 changes: 19 additions & 98 deletions bazaarplusplus-mod/Core/Runtime/BppRuntimeHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,136 +2,57 @@
using System;
using System.Collections.Generic;
using BazaarGameShared.Domain.Core.Types;
using BazaarPlusPlus;
using BazaarPlusPlus.Core.Config;
using BazaarPlusPlus.Core.Events;
using BazaarPlusPlus.Core.GameState;
using BazaarPlusPlus.Core.Paths;
using BazaarPlusPlus.Core.RunContext;
using BazaarPlusPlus.Game.CombatReplay;
using BazaarPlusPlus.Game.CombatStatusBar;
using BazaarPlusPlus.Game.RunLifecycle;
using BepInEx.Configuration;
using BepInEx.Logging;
using UnityEngine;

namespace BazaarPlusPlus.Core.Runtime;

internal sealed class BppRuntimeHost
internal static class BppRuntimeHost
{
private static readonly BppRuntimeServices DetachedServices = new(
new InMemoryBppEventBus(),
new BppConfig(),
new BppPathService(),
new EmptyMonsterCatalog(),
new RunContextStore(),
new GameStateProbe()
);
private readonly ManualLogSource _logger;
private readonly InMemoryBppEventBus _eventBus = new();
private readonly BppConfig _config = new();
private readonly BppPathService _paths = new();
private readonly MonsterDatabase _monsterCatalog = new();
private readonly RunContextStore _runContext = new();
private readonly GameStateProbe _gameStateProbe = new();
private readonly RunLifecycleModule _runLifecycle;
private readonly CombatReplayModule _combatReplayModule;
private readonly CombatStatusBarModule _combatStatusBarModule;
private readonly BppFeatureRegistry _featureRegistry;

public BppRuntimeHost(
GameObject hostObject,
ManualLogSource logger,
ConfigFile configFile,
Func<CombatReplayRuntime?> combatReplayRuntimeAccessor
)
{
if (hostObject == null)
throw new ArgumentNullException(nameof(hostObject));
if (logger == null)
throw new ArgumentNullException(nameof(logger));
if (configFile == null)
throw new ArgumentNullException(nameof(configFile));
if (combatReplayRuntimeAccessor == null)
throw new ArgumentNullException(nameof(combatReplayRuntimeAccessor));

_logger = logger;
_config.Initialize(configFile);
_paths.Initialize();
_monsterCatalog.Initialize();
_runContext.Reset();
Services = new BppRuntimeServices(
_eventBus,
_config,
_paths,
_monsterCatalog,
_runContext,
_gameStateProbe
);
_runLifecycle = new RunLifecycleModule(
Services.EventBus,
Services.GameStateProbe,
Services.RunContext
);
_combatReplayModule = new CombatReplayModule(
Services.EventBus,
combatReplayRuntimeAccessor
);
_combatStatusBarModule = new CombatStatusBarModule(Services.EventBus, Services.RunContext);
_featureRegistry = new BppFeatureRegistry();
_featureRegistry.Register(_runLifecycle);
_featureRegistry.Register(_combatReplayModule);
_featureRegistry.Register(_combatStatusBarModule);
}

public static BppRuntimeHost? Current { get; private set; }

public BppRuntimeServices Services { get; }
private static IBppServices? _services;

public RunLifecycleModule LifecycleModule => _runLifecycle;
public static IBppEventBus EventBus =>
_services?.EventBus ?? throw CreateNotInstalledException();

public static IBppEventBus EventBus => Current?.Services.EventBus ?? DetachedServices.EventBus;
public static ManualLogSource? Logger => _services?.Logger;

public static ManualLogSource? Logger => Current?._logger;
public static IBppConfig Config => _services?.Config ?? throw CreateNotInstalledException();

public static IBppConfig Config => Current?.Services.Config ?? DetachedServices.Config;

public static IPathService Paths => Current?.Services.Paths ?? DetachedServices.Paths;
public static IPathService Paths => _services?.Paths ?? throw CreateNotInstalledException();

public static IMonsterCatalog MonsterCatalog =>
Current?.Services.MonsterCatalog ?? DetachedServices.MonsterCatalog;
_services?.MonsterCatalog ?? EmptyMonsterCatalog.Instance;

public static IRunContext RunContext =>
Current?.Services.RunContext ?? DetachedServices.RunContext;
_services?.RunContext ?? throw CreateNotInstalledException();

public static IGameStateProbe GameStateProbe =>
Current?.Services.GameStateProbe ?? DetachedServices.GameStateProbe;

public static RunLifecycleModule RunLifecycle =>
Current?._runLifecycle
?? throw new InvalidOperationException("Runtime host is not installed.");
_services?.GameStateProbe ?? throw CreateNotInstalledException();

public void Install()
public static void Install(IBppServices services)
{
Current = this;
BppLog.Info("RuntimeHost", "Installed runtime host");
_services = services ?? throw new ArgumentNullException(nameof(services));
BppLog.Info("RuntimeHost", "Installed runtime service bridge");
}

public void Start()
public static void Reset()
{
_featureRegistry.Start();
BppLog.Info("RuntimeHost", "Started runtime host");
_services = null;
}

public void Stop()
private static InvalidOperationException CreateNotInstalledException()
{
_featureRegistry.Stop();
if (ReferenceEquals(Current, this))
Current = null;
return new InvalidOperationException("Runtime services are not installed.");
}

private sealed class EmptyMonsterCatalog : IMonsterCatalog
{
public static readonly EmptyMonsterCatalog Instance = new();

public bool TryGetByEncounterId(Guid encounterId, out MonsterInfo? monster)
{
monster = null;
Expand Down
3 changes: 3 additions & 0 deletions bazaarplusplus-mod/Core/Runtime/BppRuntimeServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public BppRuntimeServices(
IPathService paths,
IRunContext runContext,
IGameStateProbe gameStateProbe,
IMonsterCatalog monsterCatalog,
ManualLogSource logger
)
{
Expand All @@ -25,6 +26,7 @@ ManualLogSource logger
Paths = paths ?? throw new ArgumentNullException(nameof(paths));
RunContext = runContext ?? throw new ArgumentNullException(nameof(runContext));
GameStateProbe = gameStateProbe ?? throw new ArgumentNullException(nameof(gameStateProbe));
MonsterCatalog = monsterCatalog ?? throw new ArgumentNullException(nameof(monsterCatalog));
Logger = logger ?? throw new ArgumentNullException(nameof(logger));
}

Expand All @@ -33,5 +35,6 @@ ManualLogSource logger
public IPathService Paths { get; }
public IRunContext RunContext { get; }
public IGameStateProbe GameStateProbe { get; }
public IMonsterCatalog MonsterCatalog { get; }
public ManualLogSource Logger { get; }
}
1 change: 1 addition & 0 deletions bazaarplusplus-mod/Core/Runtime/IBppServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ internal interface IBppServices
IPathService Paths { get; }
IRunContext RunContext { get; }
IGameStateProbe GameStateProbe { get; }
IMonsterCatalog MonsterCatalog { get; }
ManualLogSource Logger { get; }
}
3 changes: 2 additions & 1 deletion bazaarplusplus-mod/Game/CombatReplay/CombatReplayRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ private static Func<NetMessageGameSim, Task> CreateHandleSpawnMessageAsync(
GameSimHandler gameSimHandler
)
{
return async spawnMessage =>
return spawnMessage =>
{
if (!processor.Handle(spawnMessage))
throw new InvalidOperationException(
Expand All @@ -579,6 +579,7 @@ GameSimHandler gameSimHandler

Data.UpdateFromGameSimAsync(spawnMessage);
MarkGameSimMessageHandled(gameSimHandler, spawnMessage.MessageId);
return Task.CompletedTask;
};
}

Expand Down
Loading