Skip to content

Commit 1703710

Browse files
committed
try to automatically get offline raid map
1 parent cfc9ffd commit 1703710

File tree

2 files changed

+60
-25
lines changed

2 files changed

+60
-25
lines changed

TarkovMonitor/GameWatcher.cs

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ public int AccountId
105105
public event EventHandler<LogContentEventArgs<GroupMatchRaidReadyLogContent>>? GroupMemberReady;
106106
public event EventHandler? GroupDisbanded;
107107
public event EventHandler<LogContentEventArgs<GroupMatchUserLeaveLogContent>>? GroupUserLeave;
108-
public event EventHandler? MapLoading;
109-
public event EventHandler<RaidInfoEventArgs>? MatchingStarted;
108+
public event EventHandler<RaidInfoEventArgs>? MapLoading;
109+
//public event EventHandler<RaidInfoEventArgs>? MatchingStarted;
110110
public event EventHandler<RaidInfoEventArgs>? MatchFound; // only fires on initial load into a raid
111111
public event EventHandler<RaidInfoEventArgs>? MapLoaded; // fires on initial and subsequent loads into a raid
112112
public event EventHandler<RaidInfoEventArgs>? MatchingAborted;
@@ -131,6 +131,22 @@ public static string GetDefaultLogsFolder()
131131
return Path.Combine(key.GetValue("InstallLocation")?.ToString() ?? throw new Exception("InstallLocation registry value not found"), "Logs");
132132
}
133133

134+
public static Dictionary<string, string> MapBundles = new() {
135+
{ "city_preset", "TarkovStreets" },
136+
{ "customs_preset", "bigmap" },
137+
{ "factory_day_preset", "factory4_day" },
138+
{ "factory_night_preset", "factory4_night" },
139+
{ "laboratory_preset", "laboratory" },
140+
{ "labyrinth_preset", "Labyrinth" },
141+
{ "lighthouse_preset", "Lighthouse" },
142+
{ "rezerv_base_preset", "ReservBase" },
143+
{ "sandbox_preset", "Sandbox" },
144+
{ "sandbox_high_preset", "Sandbox_high" },
145+
{ "shopping_mall", "Interchange" },
146+
{ "shoreline_preset", "Shoreline" },
147+
{ "woods_preset", "Woods" },
148+
};
149+
134150
public GameWatcher()
135151
{
136152
Monitors = new();
@@ -391,19 +407,33 @@ internal void GameWatcher_NewLogData(object? sender, NewLogDataEventArgs e)
391407
// Occurs for each other member of the group when ready
392408
GroupMemberReady?.Invoke(this, new LogContentEventArgs<GroupMatchRaidReadyLogContent>() { LogContent = jsonNode?.AsObject().Deserialize<GroupMatchRaidReadyLogContent>() ?? throw new Exception("Error parsing GroupMatchRaidReadyEventArgs"), Profile = CurrentProfile });
393409
}
394-
if (eventLine.Contains("application|Matching with group id"))
410+
/*if (eventLine.Contains("application|Matching with group id"))
395411
{
396412
MapLoading?.Invoke(this, new());
413+
}*/
414+
if (eventLine.Contains("application|scene preset path:"))
415+
{
416+
raidInfo = new()
417+
{
418+
ProfileType = CurrentProfile.Type,
419+
};
420+
var bundleMatch = Regex.Match(eventLine, @"scene preset path:maps\/(?<mapBundleName>[a-zA-Z0-9_]+)\.bundle");
421+
if (bundleMatch.Success)
422+
{
423+
var mapBundle = bundleMatch.Groups["mapBundleName"].Value;
424+
if (MapBundles.ContainsKey(mapBundle))
425+
{
426+
string mapId = MapBundles[mapBundle];
427+
raidInfo.Map = mapId;
428+
MapLoading?.Invoke(this, new(raidInfo, CurrentProfile));
429+
}
430+
}
397431
}
398432
if (eventLine.Contains("application|LocationLoaded"))
399433
{
400-
// The map has been loaded and the game is searching for a match
401-
raidInfo = new()
402-
{
403-
MapLoadTime = float.Parse(Regex.Match(eventLine, @"LocationLoaded:[0-9.,]+ real:(?<loadTime>[0-9.,]+)").Groups["loadTime"].Value.Replace(",", "."), CultureInfo.InvariantCulture),
404-
ProfileType = CurrentProfile.Type,
405-
};
406-
MatchingStarted?.Invoke(this, new(raidInfo, CurrentProfile));
434+
// The map has been loaded and the game is searching for a match
435+
raidInfo.MapLoadTime = float.Parse(Regex.Match(eventLine, @"LocationLoaded:[0-9.,]+ real:(?<loadTime>[0-9.,]+)").Groups["loadTime"].Value.Replace(",", "."), CultureInfo.InvariantCulture);
436+
//MatchingStarted?.Invoke(this, new(raidInfo, CurrentProfile));
407437
}
408438
if (eventLine.Contains("application|MatchingCompleted"))
409439
{
@@ -418,6 +448,7 @@ internal void GameWatcher_NewLogData(object? sender, NewLogDataEventArgs e)
418448
{
419449
// Immediately after matching is complete
420450
// Sufficient information is available to raise the MatchFound event
451+
var mapUnknown = raidInfo.Map == "" || raidInfo.Map == null;
421452
raidInfo.Map = Regex.Match(eventLine, "Location: (?<map>[^,]+)").Groups["map"].Value;
422453
raidInfo.Online = eventLine.Contains("RaidMode: Online");
423454
raidInfo.RaidId = Regex.Match(eventLine, @"shortId: (?<raidId>[A-Z0-9]{6})").Groups["raidId"].Value;
@@ -434,6 +465,10 @@ internal void GameWatcher_NewLogData(object? sender, NewLogDataEventArgs e)
434465
// Raise the MatchFound event only if we queued; not if we are re-loading back into a raid
435466
MatchFound?.Invoke(this, new(raidInfo, CurrentProfile));
436467
}
468+
if (mapUnknown)
469+
{
470+
MapLoading?.Invoke(this, new(raidInfo, CurrentProfile));
471+
}
437472
MapLoaded?.Invoke(this, new(raidInfo, CurrentProfile));
438473
}
439474
if (eventLine.Contains("application|GameStarting"))

TarkovMonitor/MainBlazorUI.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ public MainBlazorUI()
6767
eft.MatchingAborted += Eft_GroupStaleEvent;
6868
eft.GameStarted += Eft_GroupStaleEvent;
6969
eft.MapLoading += Eft_MapLoading;
70+
eft.MapLoading += Eft_MapLoading_NavigateToMap;
7071
eft.MatchFound += Eft_MatchFound;
71-
eft.MapLoaded += Eft_MapLoaded;
7272
eft.PlayerPosition += Eft_PlayerPosition;
7373
eft.ProfileChanged += Eft_ProfileChanged;
7474

@@ -280,20 +280,6 @@ protected override void OnShown(EventArgs e)
280280
}
281281
}
282282

283-
private void Eft_MapLoaded(object? sender, RaidInfoEventArgs e)
284-
{
285-
if (!Properties.Settings.Default.autoNavigateMap)
286-
{
287-
return;
288-
}
289-
var map = TarkovDev.Maps.Find(m => m.nameId == e.RaidInfo.Map);
290-
if (map == null)
291-
{
292-
return;
293-
}
294-
SocketClient.NavigateToMap(map);
295-
}
296-
297283
private async void Eft_PlayerPosition(object? sender, PlayerPositionEventArgs e)
298284
{
299285
var map = TarkovDev.Maps.Find(m => m.nameId == e.RaidInfo.Map);
@@ -373,6 +359,20 @@ private async void Eft_MapLoading(object? sender, EventArgs e)
373359
}
374360
}
375361

362+
private void Eft_MapLoading_NavigateToMap(object? sender, RaidInfoEventArgs e)
363+
{
364+
if (!Properties.Settings.Default.autoNavigateMap)
365+
{
366+
return;
367+
}
368+
var map = TarkovDev.Maps.Find(m => m.nameId == e.RaidInfo.Map);
369+
if (map == null)
370+
{
371+
return;
372+
}
373+
SocketClient.NavigateToMap(map);
374+
}
375+
376376
private void Eft_GroupUserLeave(object? sender, LogContentEventArgs<GroupMatchUserLeaveLogContent> e)
377377
{
378378
if (e.LogContent.Nickname != "You")

0 commit comments

Comments
 (0)