mirror of
https://github.com/sp-tarkov/modules.git
synced 2025-02-13 06:30:43 -05:00
104 lines
2.8 KiB
C#
104 lines
2.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using SPT.Reflection.Patching;
|
|
using EFT;
|
|
using Comfort.Common;
|
|
using EFT.Interactive;
|
|
using Newtonsoft.Json;
|
|
using UnityEngine;
|
|
|
|
namespace SPT.Debugging.Patches
|
|
{
|
|
public class StaticLootDumper : ModulePatch
|
|
{
|
|
public static string DumpFolder = Path.Combine(Environment.CurrentDirectory, "Dumps");
|
|
|
|
protected override MethodBase GetTargetMethod()
|
|
{
|
|
return typeof(GameWorld).GetMethod(nameof(GameWorld.OnGameStarted));
|
|
}
|
|
|
|
[PatchPrefix]
|
|
public static void PatchPreFix()
|
|
{
|
|
InitDirectory();
|
|
|
|
var gameWorld = Singleton<GameWorld>.Instance;
|
|
string mapName = gameWorld.MainPlayer.Location.ToLower();
|
|
|
|
var containersData = new SPTContainersData();
|
|
|
|
Resources.FindObjectsOfTypeAll(typeof(LootableContainersGroup)).ExecuteForEach(obj =>
|
|
{
|
|
var containersGroup = (LootableContainersGroup)obj;
|
|
var sptContainersGroup = new SPTContainersGroup { minContainers = containersGroup.Min, maxContainers = containersGroup.Max };
|
|
if (containersData.containersGroups.ContainsKey(containersGroup.Id))
|
|
{
|
|
Logger.LogError($"Container group ID {containersGroup.Id} already exists in dictionary!");
|
|
}
|
|
else
|
|
{
|
|
containersData.containersGroups.Add(containersGroup.Id, sptContainersGroup);
|
|
}
|
|
});
|
|
|
|
Resources.FindObjectsOfTypeAll(typeof(LootableContainer)).ExecuteForEach(obj =>
|
|
{
|
|
var container = (LootableContainer)obj;
|
|
|
|
// Skip empty ID containers
|
|
if (container.Id.Length == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (containersData.containers.ContainsKey(container.Id))
|
|
{
|
|
Logger.LogError($"Container {container.Id} already exists in dictionary!");
|
|
}
|
|
else
|
|
{
|
|
containersData.containers.Add(container.Id, new SPTContainer { groupId = container.LootableContainersGroupId });
|
|
}
|
|
});
|
|
|
|
string jsonString = JsonConvert.SerializeObject(containersData, Formatting.Indented);
|
|
string outputFile = Path.Combine(DumpFolder, $"{mapName}", $"statics.json");
|
|
Directory.CreateDirectory(Path.GetDirectoryName(outputFile));
|
|
if (File.Exists(outputFile))
|
|
{
|
|
File.Delete(outputFile);
|
|
}
|
|
File.Create(outputFile).Dispose();
|
|
StreamWriter streamWriter = new StreamWriter(outputFile);
|
|
streamWriter.Write(jsonString);
|
|
streamWriter.Flush();
|
|
streamWriter.Close();
|
|
}
|
|
|
|
public static void InitDirectory()
|
|
{
|
|
Directory.CreateDirectory(DumpFolder);
|
|
}
|
|
}
|
|
|
|
public class SPTContainer
|
|
{
|
|
public string groupId;
|
|
}
|
|
|
|
public class SPTContainersGroup
|
|
{
|
|
public int minContainers;
|
|
public int maxContainers;
|
|
}
|
|
|
|
public class SPTContainersData
|
|
{
|
|
public Dictionary<string, SPTContainersGroup> containersGroups = new Dictionary<string, SPTContainersGroup>();
|
|
public Dictionary<string, SPTContainer> containers = new Dictionary<string, SPTContainer>();
|
|
}
|
|
|
|
} |