-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVigorModSystem.cs
More file actions
688 lines (590 loc) · 26.6 KB
/
VigorModSystem.cs
File metadata and controls
688 lines (590 loc) · 26.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using Vintagestory.API.Client;
using Vintagestory.API.Common;
using Vintagestory.API.Datastructures;
using Vintagestory.API.Server;
using Vigor.API;
using Vigor.Behaviors;
using Vigor.Config;
using Vigor.Hud;
using Vigor.Utils;
using Vigor.Core;
using Vintagestory.Client.NoObf;
namespace Vigor
{
public class VigorModSystem : ModSystem
{
private const string NETWORK_CHANNEL = "vigor:statesync";
private const string ConfigLibConfigSavedEvent = "configlib:vigor:config-saved";
private const string ConfigLibConfigReloadEvent = "configlib:config-reload";
private ICoreAPI _api;
private ICoreClientAPI _capi;
private ICoreServerAPI _sapi;
private HudVigorBar _vigorHud;
private HudVigorDebug _debugHud;
private long _syncTimerId;
private long _drainTickId;
private long _diagnosticsAutoDumpListenerId;
private bool _initialDiagnosticsSnapshotCaptured;
private float _timeSinceLastAutoDiagnosticsSnapshot;
private IClientNetworkChannel _clientNetworkChannel;
private IServerNetworkChannel _serverNetworkChannel;
private VigorAPI _activeStaminaDrainHandler;
// Dictionary to store synchronized client-side stamina state by player UID
private readonly ConcurrentDictionary<string, StaminaStatePacket> _clientStaminaState = new ConcurrentDictionary<string, StaminaStatePacket>();
public event Action<StaminaStatePacket> LocalPlayerStaminaStateUpdated;
public static VigorModSystem Instance { get; private set; }
public VigorConfig CurrentConfig { get; private set; }
public string ModId => Mod.Info.ModID;
public ILogger Logger => Mod.Logger;
// Public API instances that other mods can access
public IVigorAPI API { get; private set; } // General API - maintains backward compatibility
public IVigorAPI ClientAPI { get; private set; } // Client-specific API
public IVigorAPI ServerAPI { get; private set; } // Server-specific API
public override void Start(ICoreAPI api)
{
base.Start(api);
_api = api;
Instance = this;
LoadConfig(api);
RegisterConfigReloadListeners(api);
// Create general API instance for backward compatibility
// Note: This instance should be avoided in client/server contexts
API = new VigorAPI(api);
// Register behavior
api.RegisterEntityBehaviorClass("vigor:vigorstamina", typeof(Behaviors.EntityBehaviorVigorStamina));
// Register network channel for stamina state synchronization
api.Network.RegisterChannel(NETWORK_CHANNEL)
.RegisterMessageType<StaminaStatePacket>();
if (CurrentConfig.DebugMode)
{
Logger.Debug($"[{ModId}] Registered network channel '{NETWORK_CHANNEL}'");
Logger.Debug($"[{ModId}] {api.Side} API available via ModLoader.GetModSystem<VigorModSystem>().API");
}
}
// Added property to check for HydrateOrDiedrate mod
public bool IsHydrateOrDiedrateLoaded { get; private set; }
public override void StartClientSide(ICoreClientAPI api)
{
base.StartClientSide(api);
_capi = api;
// Create client-specific API instance
ClientAPI = new VigorAPI(api);
// Set up client network channel and register packet handler
_clientNetworkChannel = api.Network.GetChannel(NETWORK_CHANNEL);
_clientNetworkChannel.SetMessageHandler<StaminaStatePacket>(OnStaminaStatePacket);
if (CurrentConfig.DebugMode)
{
Logger.Debug($"[{ModId}] Client API initialized");
Logger.Debug($"[{ModId}] Client stamina sync handler registered");
}
// Check if HydrateOrDiedrate mod is installed
IsHydrateOrDiedrateLoaded = api.ModLoader.IsModEnabled("hydrateordiedrate");
if (IsHydrateOrDiedrateLoaded && CurrentConfig.DebugMode)
{
Logger.Notification($"[{ModId}] HydrateOrDiedrate mod detected, will adjust HUD position.");
}
_vigorHud = new HudVigorBar(api);
_debugHud = new HudVigorDebug(api);
api.Gui.RegisterDialog(_vigorHud);
api.Gui.RegisterDialog(_debugHud);
api.Input.RegisterHotKey("vigordebug", "Vigor: Toggle Debug Info", GlKeys.F8, HotkeyType.GUIOrOtherControls);
api.Input.SetHotKeyHandler("vigordebug", OnToggleDebugHud);
api.Input.RegisterHotKey("vigordiagdump", "Vigor: Dump Diagnostics Snapshot", GlKeys.F6, HotkeyType.GUIOrOtherControls);
api.Input.SetHotKeyHandler("vigordiagdump", OnDumpDiagnostics);
if (CurrentConfig.EnableDiagnosticsSnapshots)
{
_diagnosticsAutoDumpListenerId = api.Event.RegisterGameTickListener(OnDiagnosticsTick, 1000);
}
if (CurrentConfig.EnableDiagnosticsSnapshots)
{
if (CurrentConfig.EnableAutomaticDiagnosticsSnapshots)
{
Logger.Notification($"Stamina systems ready. Diagnostics enabled. Press F6 for a manual snapshot. Automatic snapshots every {Math.Max(1, CurrentConfig.DiagnosticsSnapshotIntervalMinutes)} minutes.");
}
else
{
Logger.Notification("Stamina systems ready. Diagnostics enabled. Press F6 for a manual snapshot.");
}
}
else
{
Logger.Notification("Stamina systems ready. Diagnostics disabled in vigor.json.");
}
}
private void RegisterConfigReloadListeners(ICoreAPI api)
{
api.Event.RegisterEventBusListener(OnConfigLibConfigSaved, filterByEventName: ConfigLibConfigSavedEvent);
api.Event.RegisterEventBusListener(OnConfigLibConfigReload, filterByEventName: ConfigLibConfigReloadEvent);
}
private void OnConfigLibConfigSaved(string eventName, ref EnumHandling handling, IAttribute data)
{
if (!IsVigorConfigEvent(data))
{
return;
}
ReloadConfigAndApplyRuntimeChanges();
}
private void OnConfigLibConfigReload(string eventName, ref EnumHandling handling, IAttribute data)
{
if (!IsVigorConfigEvent(data))
{
return;
}
ReloadConfigAndApplyRuntimeChanges();
}
private bool IsVigorConfigEvent(IAttribute data)
{
return (data as ITreeAttribute)?.GetAsString("domain") == ModId;
}
private void ReloadConfigAndApplyRuntimeChanges()
{
if (_api == null)
{
return;
}
LoadConfig(_api);
if (_sapi != null)
{
RefreshServerSyncTimer();
}
if (_capi != null)
{
RefreshClientRuntimeConfigState();
}
}
private void RefreshServerSyncTimer()
{
if (_sapi == null)
{
return;
}
if (_syncTimerId != 0)
{
_sapi.Event.UnregisterGameTickListener(_syncTimerId);
_syncTimerId = 0;
}
float syncIntervalSeconds = Math.Max(0.03f, CurrentConfig.StaminaSyncIntervalSeconds);
_syncTimerId = _sapi.Event.RegisterGameTickListener(SyncStaminaState, (int)(syncIntervalSeconds * 1000));
}
private void RefreshClientRuntimeConfigState()
{
if (_capi == null)
{
return;
}
RefreshClientDiagnosticsListener();
RecreateClientHudElements();
}
private void RefreshClientDiagnosticsListener()
{
if (_capi == null)
{
return;
}
if (_diagnosticsAutoDumpListenerId != 0)
{
_capi.Event.UnregisterGameTickListener(_diagnosticsAutoDumpListenerId);
_diagnosticsAutoDumpListenerId = 0;
}
_initialDiagnosticsSnapshotCaptured = false;
_timeSinceLastAutoDiagnosticsSnapshot = 0f;
if (CurrentConfig.EnableDiagnosticsSnapshots)
{
_diagnosticsAutoDumpListenerId = _capi.Event.RegisterGameTickListener(OnDiagnosticsTick, 1000);
}
}
private void RecreateClientHudElements()
{
if (_capi == null)
{
return;
}
DisposeClientDialog(_vigorHud);
DisposeClientDialog(_debugHud);
_vigorHud = new HudVigorBar(_capi);
_debugHud = new HudVigorDebug(_capi);
_capi.Gui.RegisterDialog(_vigorHud, _debugHud);
}
private void DisposeClientDialog(GuiDialog dialog)
{
if (dialog == null || _capi == null)
{
return;
}
dialog.TryClose();
if (_capi.World is ClientMain clientMain)
{
clientMain.UnregisterDialog(dialog);
}
dialog.Dispose();
}
private bool OnToggleDebugHud(KeyCombination comb)
{
_debugHud?.Toggle();
return true;
}
private bool OnDumpDiagnostics(KeyCombination comb)
{
try
{
if (!CurrentConfig.EnableDiagnosticsSnapshots)
{
_capi?.Logger.Notification("Diagnostics snapshots are disabled in the Vigor config.");
return true;
}
var filePath = DumpDiagnosticsSnapshot("manual");
_capi?.Logger.Notification($"Diagnostics snapshot written to {filePath}");
}
catch (Exception ex)
{
_capi?.Logger.Error($"Failed to dump diagnostics snapshot: {ex}");
}
return true;
}
private void OnDiagnosticsTick(float dt)
{
try
{
if (_capi?.World?.Player?.Entity == null) return;
if (!CurrentConfig.EnableDiagnosticsSnapshots) return;
if (!_initialDiagnosticsSnapshotCaptured && CurrentConfig.CaptureInitialDiagnosticsSnapshot)
{
var initialPath = DumpDiagnosticsSnapshot("initial");
_initialDiagnosticsSnapshotCaptured = true;
_timeSinceLastAutoDiagnosticsSnapshot = 0f;
_capi.Logger.Notification($"Initial diagnostics snapshot written to {initialPath}");
return;
}
if (!CurrentConfig.EnableAutomaticDiagnosticsSnapshots) return;
_timeSinceLastAutoDiagnosticsSnapshot += dt;
float intervalSeconds = Math.Max(1, CurrentConfig.DiagnosticsSnapshotIntervalMinutes) * 60f;
if (_timeSinceLastAutoDiagnosticsSnapshot < intervalSeconds) return;
_timeSinceLastAutoDiagnosticsSnapshot = 0f;
var filePath = DumpDiagnosticsSnapshot("auto");
_capi.Logger.Notification($"Automatic diagnostics snapshot written to {filePath}");
}
catch (Exception ex)
{
_capi?.Logger.Error($"Failed to write automatic diagnostics snapshot: {ex}");
}
}
private string DumpDiagnosticsSnapshot(string reason)
{
VigorDiagnostics.SetGauge("clientStaminaState.count", _clientStaminaState.Count);
return VigorDiagnostics.DumpSnapshotToFile(ModId, reason);
}
/// <summary>
/// Client-side handler for stamina state packet
/// </summary>
private void OnStaminaStatePacket(StaminaStatePacket packet)
{
if (_capi == null)
{
Logger.Error($"[{ModId}] OnStaminaStatePacket: _capi is null, cannot process packet!");
return;
}
try
{
// Always log first packet received for own player (critical for debugging sync issues)
bool isFirstPacket = !_clientStaminaState.ContainsKey(packet.PlayerUID);
bool isOwnPlayer = _capi.World.Player != null && _capi.World.Player.PlayerUID == packet.PlayerUID;
// Store the updated state in our client-side dictionary
_clientStaminaState[packet.PlayerUID] = packet;
VigorDiagnostics.Increment("network.packetReceived");
VigorDiagnostics.SetGauge("clientStaminaState.count", _clientStaminaState.Count);
if (isFirstPacket && isOwnPlayer)
{
// Use Error level for the first packet to ensure it's visible in logs
_capi.Logger.Error($"[{ModId}] FIRST stamina state packet received for own player: {packet.CurrentStamina}/{packet.MaxStamina}, Exhausted: {packet.IsExhausted}");
}
else if (CurrentConfig.DebugMode && isOwnPlayer)
{
// Use regular debug for subsequent packets
_capi.Logger.Debug($"[{ModId}] Received stamina state: {packet.CurrentStamina}/{packet.MaxStamina}, Exhausted: {packet.IsExhausted}");
}
if (isOwnPlayer)
{
VigorDiagnostics.Increment("network.packetLocalPlayerCached");
LocalPlayerStaminaStateUpdated?.Invoke(packet);
if (CurrentConfig.DebugMode)
{
_capi.Logger.Debug($"[{ModId}] Cached local stamina packet without mirroring to WatchedAttributes");
}
}
}
catch (Exception ex)
{
_capi.Logger.Error($"[{ModId}] Error processing stamina state packet: {ex.Message}\nStack trace: {ex.StackTrace}");
}
}
/// <summary>
/// Gets the synchronized client-side stamina state for a player
/// </summary>
/// <param name="playerUID">The player UID</param>
/// <returns>The stamina state packet, or null if not found</returns>
public StaminaStatePacket GetClientStaminaState(string playerUID)
{
if (string.IsNullOrEmpty(playerUID)) return null;
if (_clientStaminaState.TryGetValue(playerUID, out var state))
{
return state;
}
return null;
}
/// <summary>
/// Server-side method to sync stamina state to clients
/// </summary>
private void SyncStaminaState(float dt)
{
if (_sapi == null)
{
Logger.Error($"[{ModId}] SyncStaminaState: _sapi is null! Stamina sync to clients will not work.");
return;
}
try
{
// Log channel status
if (_serverNetworkChannel == null)
{
Logger.Error($"[{ModId}] SyncStaminaState: _serverNetworkChannel is null! Network not initialized properly.");
return;
}
if (CurrentConfig.DebugMode)
{
Logger.Debug($"[{ModId}] SyncStaminaState: Syncing stamina data for {_sapi.World.AllOnlinePlayers.Length} online players");
}
// Sync stamina state for all online players
foreach (var player in _sapi.World.AllOnlinePlayers)
{
// Get player entity
var playerEntity = player.Entity;
if (playerEntity == null)
{
Logger.Warning($"[{ModId}] SyncStaminaState: Entity null for player {player.PlayerName}");
continue;
}
// Skip very-early entities not fully initialized
if (playerEntity.Api == null || playerEntity.World == null)
{
if (CurrentConfig.DebugMode)
{
Logger.Debug($"[{ModId}] SyncStaminaState: Entity API/World not ready for player {player.PlayerName}, skipping this tick");
}
continue;
}
// Get stamina behavior (guard against rare NRE during engine init)
EntityBehaviorVigorStamina staminaBehavior = null;
try
{
staminaBehavior = playerEntity.GetBehavior<EntityBehaviorVigorStamina>();
}
catch (Exception ex)
{
if (CurrentConfig.DebugMode)
{
Logger.Debug($"[{ModId}] SyncStaminaState: GetBehavior threw early for {player.PlayerName}: {ex.Message}");
}
continue;
}
if (staminaBehavior == null)
{
if (CurrentConfig.DebugMode)
{
Logger.Debug($"[{ModId}] SyncStaminaState: Stamina behavior not yet attached for {player.PlayerName}");
}
continue;
}
// Create packet with current state
var packet = new StaminaStatePacket
{
PlayerUID = player.PlayerUID,
CurrentStamina = staminaBehavior.CurrentStamina,
MaxStamina = staminaBehavior.MaxStamina,
IsExhausted = staminaBehavior.IsExhausted
};
// Send to player (cast to IServerPlayer is safe since we're in server-side code)
var serverPlayer = player as IServerPlayer;
if (serverPlayer == null)
{
Logger.Warning($"[{ModId}] SyncStaminaState: Failed to cast player {player.PlayerName} to IServerPlayer");
continue;
}
_serverNetworkChannel.SendPacket(packet, serverPlayer);
VigorDiagnostics.Increment("network.packetSent");
// Log more frequently when in debug mode to identify synchronization issues
if (CurrentConfig.DebugMode && (_sapi.World.Rand.NextDouble() < 0.2)) // Increased log frequency to 20%
{
_sapi.Logger.Debug($"[{ModId}] SyncStaminaState: Sent packet to {player.PlayerName}: {packet.CurrentStamina}/{packet.MaxStamina}, Exhausted: {packet.IsExhausted}");
}
}
}
catch (Exception ex)
{
_sapi.Logger.Error($"[{ModId}] Error syncing stamina state: {ex.Message}\nStack trace: {ex.StackTrace}");
}
}
/// <summary>
/// Cleanup when player disconnects
/// </summary>
private void OnPlayerDisconnect(IServerPlayer player)
{
if (player != null)
{
// No need to sync data for disconnected players
_sapi?.Logger.Debug($"[{ModId}] Player {player.PlayerName} disconnected, cleaning up sync state");
}
}
public override void StartServerSide(ICoreServerAPI api)
{
base.StartServerSide(api);
_sapi = api;
// Create server-specific API instance
ServerAPI = new VigorAPI(api);
// Set up server network channel
_serverNetworkChannel = api.Network.GetChannel(NETWORK_CHANNEL);
if (_serverNetworkChannel == null)
{
Logger.Error($"[{ModId}] Failed to get network channel for stamina state sync");
}
else if (CurrentConfig.DebugMode)
{
Logger.Debug($"[{ModId}] Server API initialized");
Logger.Debug($"[{ModId}] Server network channel ready");
}
// Register periodic sync timer
float syncIntervalSeconds = Math.Max(0.03f, CurrentConfig.StaminaSyncIntervalSeconds);
_syncTimerId = api.Event.RegisterGameTickListener(SyncStaminaState, (int)(syncIntervalSeconds * 1000));
if (CurrentConfig.DebugMode)
{
Logger.Debug($"[{ModId}] Registered stamina state sync timer ({syncIntervalSeconds}s)");
}
// Listen for player disconnect to clean up sync state
api.Event.PlayerDisconnect += OnPlayerDisconnect;
// Listen for player join to attach behavior
api.Event.PlayerJoin += OnPlayerJoin;
Logger.Notification($"[{ModId}] Server stamina synchronization ready.");
}
/// <summary>
/// Called when a player joins the server, attaches the stamina behavior to them
/// </summary>
private void OnPlayerJoin(IServerPlayer player)
{
try
{
// Delay attachment slightly to ensure entity is fully initialized
_sapi?.Event.RegisterCallback(dt =>
{
try
{
if (player?.Entity == null) return;
var entity = player.Entity;
if (entity.Api == null || entity.World == null) return;
if (entity.GetBehavior<EntityBehaviorVigorStamina>() == null)
{
entity.AddBehavior(new EntityBehaviorVigorStamina(entity));
Logger.Event($"[{ModId}] Attached vigor stamina behavior to player {player.PlayerName}");
}
}
catch (Exception ex)
{
Logger.Error($"[{ModId}] Delayed attach error: {ex.Message}\n{ex.StackTrace}");
}
}, 100);
}
catch (Exception ex)
{
Logger.Error($"[{ModId}] Error attaching stamina behavior to player: {ex.Message}\n{ex.StackTrace}");
}
}
/// <summary>
/// Process continuous stamina drain for all active drains
/// </summary>
private void ProcessStaminaDrainTick(float dt)
{
if (_sapi == null || _activeStaminaDrainHandler == null) return;
try
{
// Process all active stamina drains
_activeStaminaDrainHandler.ProcessActiveStaminaDrains(dt);
}
catch (Exception ex)
{
Logger.Error($"[{ModId}] Error processing stamina drains: {ex}");
}
}
/// <summary>
/// Checks if the continuous stamina drain is active
/// </summary>
/// <returns>True if the drain is currently active</returns>
public bool IsStaminaDrainActive()
{
Logger.Debug($"[{ModId}] IsStaminaDrainActive called, current _drainTickId: {_drainTickId}");
return _drainTickId != 0;
}
/// <summary>
/// Starts the continuous stamina drain tick processing
/// </summary>
/// <param name="handler">The VigorAPI instance that will handle the drain processing</param>
public void StartStaminaDrainTick(VigorAPI handler)
{
Logger.Debug($"[{ModId}] StartStaminaDrainTick called with handler: {handler}");
if (_sapi == null)
{
Logger.Error($"[{ModId}] Cannot start stamina drain tick - _sapi is null!");
return;
}
// Don't register multiple times
if (IsStaminaDrainActive())
{
Logger.Debug($"[{ModId}] Drain tick already active, updating handler only");
_activeStaminaDrainHandler = handler; // Update handler if needed
return;
}
_activeStaminaDrainHandler = handler;
// Register tick processor at 4 times per second (250ms)
Logger.Debug($"[{ModId}] About to register game tick listener for stamina drain");
_drainTickId = _sapi.Event.RegisterGameTickListener(dt => ProcessStaminaDrainTick(dt), 250);
Logger.Event($"[{ModId}] Started continuous stamina drain processing with tickId: {_drainTickId}");
}
/// <summary>
/// Stops the continuous stamina drain tick processing
/// </summary>
public void StopStaminaDrainTick()
{
if (_sapi == null || !IsStaminaDrainActive()) return;
_sapi.Event.UnregisterGameTickListener(_drainTickId);
_drainTickId = 0;
_activeStaminaDrainHandler = null;
Logger.Event($"[{ModId}] Stopped continuous stamina drain processing");
}
public void LoadConfig(ICoreAPI api)
{
try
{
CurrentConfig = api.LoadModConfig<VigorConfig>($"{ModId}.json");
if (CurrentConfig == null)
{
Logger.Notification($"[{ModId}] No config found, creating default.");
CurrentConfig = new VigorConfig();
api.StoreModConfig(CurrentConfig, $"{ModId}.json");
}
else
{
// Use a loud, unconditional log level to ensure this message always appears.
if (CurrentConfig.DebugMode)
{
Logger.Notification("Debug mode enabled.");
}
}
}
catch (Exception e)
{
Logger.Error($"[{ModId}] Failed to load or create config: {e}");
CurrentConfig = new VigorConfig();
}
}
}
}