Skip to content
This repository was archived by the owner on Aug 17, 2025. It is now read-only.

Commit a2ad7e5

Browse files
committed
v1.0.0 Release
0 parents  commit a2ad7e5

7 files changed

Lines changed: 183 additions & 0 deletions

File tree

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
bin/
2+
obj/
3+
/packages/
4+
riderModule.iml
5+
/_ReSharper.Caches/
6+
7+
.idea/

LethalDataAPI.sln

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LethalDataAPI", "LethalDataAPI\LethalDataAPI.csproj", "{7CDA77CA-E79C-4866-900A-9083EC1F298B}"
4+
EndProject
5+
Global
6+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7+
Debug|Any CPU = Debug|Any CPU
8+
Release|Any CPU = Release|Any CPU
9+
EndGlobalSection
10+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
11+
{7CDA77CA-E79C-4866-900A-9083EC1F298B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
12+
{7CDA77CA-E79C-4866-900A-9083EC1F298B}.Debug|Any CPU.Build.0 = Debug|Any CPU
13+
{7CDA77CA-E79C-4866-900A-9083EC1F298B}.Release|Any CPU.ActiveCfg = Release|Any CPU
14+
{7CDA77CA-E79C-4866-900A-9083EC1F298B}.Release|Any CPU.Build.0 = Release|Any CPU
15+
EndGlobalSection
16+
EndGlobal

LethalDataAPI/LethalData.cs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System.Collections.Generic;
2+
using System.IO;
3+
using Newtonsoft.Json;
4+
5+
namespace LethalDataAPI
6+
{
7+
public class LethalData
8+
{
9+
private static string dir = "";
10+
11+
public LethalData(string modName)
12+
{
13+
string _dir = dir;
14+
15+
dir = Path.Combine(_dir, modName);
16+
17+
if (!Directory.Exists(dir))
18+
{
19+
Directory.CreateDirectory(dir);
20+
}
21+
}
22+
23+
public static void Save<T>(string key, T value)
24+
{
25+
string currentSave = Plugin.currentSave;
26+
string _dir = Path.Combine(dir, currentSave + ".json");
27+
28+
Dictionary<string, object> currentData;
29+
30+
if (File.Exists(_dir))
31+
{
32+
string jsonContent = File.ReadAllText(_dir);
33+
currentData = JsonConvert.DeserializeObject<Dictionary<string, object>>(jsonContent);
34+
}
35+
else
36+
{
37+
currentData = new Dictionary<string, object>();
38+
using (FileStream fs = File.Create(_dir)) { }
39+
}
40+
41+
currentData[key] = value;
42+
43+
string jsonData = JsonConvert.SerializeObject(currentData, Formatting.Indented);
44+
File.WriteAllText(_dir, jsonData);
45+
}
46+
47+
public static T? Load<T>(string key)
48+
{
49+
string currentSave = Plugin.currentSave;
50+
string _dir = Path.Combine(dir, currentSave + ".json");
51+
52+
Dictionary<string, object> currentData = new Dictionary<string, object>();
53+
54+
if (File.Exists(_dir))
55+
{
56+
string jsonContent = File.ReadAllText(_dir);
57+
currentData = JsonConvert.DeserializeObject<Dictionary<string, object>>(jsonContent);
58+
}
59+
else
60+
{
61+
using (FileStream fs = File.Create(_dir)) { };
62+
}
63+
64+
if (currentData.TryGetValue(key, out var value))
65+
{
66+
return (T?)value;
67+
}
68+
69+
return (T?)(object)null;
70+
}
71+
}
72+
}

LethalDataAPI/LethalDataAPI.csproj

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.1</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<LangVersion>latest</LangVersion>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<Reference Include="0Harmony">
12+
<HintPath>..\..\..\AppData\Roaming\Thunderstore Mod Manager\DataFolder\LethalCompany\profiles\Default\BepInEx\core\0Harmony.dll</HintPath>
13+
</Reference>
14+
<Reference Include="Assembly-CSharp">
15+
<HintPath>Z:\SteamLibrary\steamapps\common\Lethal Company\Lethal Company_Data\Managed\Assembly-CSharp.dll</HintPath>
16+
</Reference>
17+
<Reference Include="BepInEx">
18+
<HintPath>..\..\..\AppData\Roaming\Thunderstore Mod Manager\DataFolder\LethalCompany\profiles\Default\BepInEx\core\BepInEx.dll</HintPath>
19+
</Reference>
20+
<Reference Include="Newtonsoft.Json">
21+
<HintPath>Z:\SteamLibrary\steamapps\common\Lethal Company\Lethal Company_Data\Managed\Newtonsoft.Json.dll</HintPath>
22+
</Reference>
23+
<Reference Include="Unity.Netcode.Runtime">
24+
<HintPath>Z:\SteamLibrary\steamapps\common\Lethal Company\Lethal Company_Data\Managed\Unity.Netcode.Runtime.dll</HintPath>
25+
</Reference>
26+
<Reference Include="UnityEngine">
27+
<HintPath>Z:\SteamLibrary\steamapps\common\Lethal Company\Lethal Company_Data\Managed\UnityEngine.dll</HintPath>
28+
</Reference>
29+
<Reference Include="UnityEngine.CoreModule">
30+
<HintPath>Z:\SteamLibrary\steamapps\common\Lethal Company\Lethal Company_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
31+
</Reference>
32+
</ItemGroup>
33+
34+
</Project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using HarmonyLib;
2+
3+
namespace LethalDataAPI.Patches;
4+
5+
[HarmonyPatch(typeof(StartOfRound))]
6+
public class StartOfRoundPatch
7+
{
8+
[HarmonyPostfix, HarmonyPatch("Start")]
9+
static void Start(StartOfRound __instance)
10+
{
11+
if (__instance.IsServer)
12+
{
13+
Plugin.currentSave = GameNetworkManager.Instance.currentSaveFileName;
14+
}
15+
}
16+
}

LethalDataAPI/Plugin.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Reflection;
2+
using BepInEx;
3+
using BepInEx.Logging;
4+
using HarmonyLib;
5+
using LethalDataAPI.Patches;
6+
using UnityEngine;
7+
using PluginInfo = LethalDataAPI.PluginInfo;
8+
9+
namespace LethalDataAPI
10+
{
11+
[BepInPlugin(PluginInfo.modGUID, PluginInfo.modName, PluginInfo.modVersion)]
12+
public class Plugin : BaseUnityPlugin
13+
{
14+
15+
private static Harmony harmony = new Harmony(PluginInfo.modGUID);
16+
public static ManualLogSource logger = new ManualLogSource(PluginInfo.modGUID);
17+
18+
private Plugin Instance;
19+
public static string currentSave;
20+
21+
void Awake()
22+
{
23+
Instance = this;
24+
logger.LogWarning("LethalDataAPI Loaded!");
25+
26+
harmony.PatchAll(typeof(StartOfRoundPatch));
27+
}
28+
}
29+
}

LethalDataAPI/PluginInfo.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace LethalDataAPI
2+
{
3+
public class PluginInfo
4+
{
5+
public const string modName = "LethalDataAPI";
6+
public const string modVersion = "1.0.0";
7+
public const string modGUID = "Avocado.LethalDataAPI";
8+
}
9+
}

0 commit comments

Comments
 (0)