Skip to content

Commit 2757b1a

Browse files
authored
Add files via upload
1 parent 0649d49 commit 2757b1a

35 files changed

+7217
-0
lines changed

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 ds5678
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Remove Ammo
2+
3+
A mod for The Long Dark that removes (almost) all ammo from the game, forcing the player to craft their own. Intended for a more difficult Rifleloper, but works in any difficulty.
4+
5+
## Instructions
6+
7+
Install MelonLoader and put RemoveAmmo.dll into the Mods folder. There's no settings or anything, just start a new game. I stongly recommend agaisnt loading previous saves.
8+
9+
## Additional Notes
10+
11+
* The mod deactivats ammo objects and empties any guns whenever a scene is loaded or when a container is searched for the first time.
12+
* Ammo you place in the world, in a gun, or in a container is safe from being removed, barring some edge case I haven't found.
13+
14+
## Disclaimer
15+
16+
* The effects are permenant, please be careful with your saves.
17+
* Any area you've visited before installing the mod will still have all the ammo. And any area you revisit after uninstalling the mod will not have any ammo.
18+
* There's at least one location that still spawns a box of ammo, despite my best efforts to get it removed, and there might be others. Consider it a feature.

RemoveAmmo.sln

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.4.33122.133
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RemoveAmmo", "RemoveAmmo\RemoveAmmo.csproj", "{B72C0DA2-49E6-4A00-8415-8E06CCF000B8}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A5CEB40A-277F-4230-B194-923D1869E442}"
9+
ProjectSection(SolutionItems) = preProject
10+
.gitignore = .gitignore
11+
LICENSE.txt = LICENSE.txt
12+
README.md = README.md
13+
EndProjectSection
14+
EndProject
15+
Global
16+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
17+
Debug|Any CPU = Debug|Any CPU
18+
Release|Any CPU = Release|Any CPU
19+
EndGlobalSection
20+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
21+
{B72C0DA2-49E6-4A00-8415-8E06CCF000B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22+
{B72C0DA2-49E6-4A00-8415-8E06CCF000B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
23+
{B72C0DA2-49E6-4A00-8415-8E06CCF000B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
24+
{B72C0DA2-49E6-4A00-8415-8E06CCF000B8}.Release|Any CPU.Build.0 = Release|Any CPU
25+
EndGlobalSection
26+
GlobalSection(SolutionProperties) = preSolution
27+
HideSolutionNode = FALSE
28+
EndGlobalSection
29+
GlobalSection(ExtensibilityGlobals) = postSolution
30+
SolutionGuid = {23667D17-A719-496A-86C6-C96A5A171DE3}
31+
EndGlobalSection
32+
EndGlobal
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using MelonLoader;
2+
using System.Reflection;
3+
4+
[assembly: AssemblyTitle(BuildInfo.ModName)]
5+
[assembly: AssemblyCopyright($"Created by ModAuthor")]
6+
7+
[assembly: AssemblyVersion(BuildInfo.ModVersion)]
8+
[assembly: AssemblyFileVersion(BuildInfo.ModVersion)]
9+
[assembly: MelonInfo(typeof(ModNamespace.RemoveAmmo), BuildInfo.ModName, BuildInfo.ModVersion, BuildInfo.ModAuthor)]
10+
11+
[assembly: MelonGame("Hinterland", "TheLongDark")]
12+
13+
internal static class BuildInfo
14+
{
15+
internal const string ModName = "Delete Ammo";
16+
internal const string ModAuthor = "Corwin";
17+
internal const string ModVersion = "1.0.0";
18+
}

RemoveAmmo/RemoveAmmo.cs

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
using MelonLoader;
2+
using UnityEngine;
3+
using HarmonyLib;
4+
using Il2Cpp;
5+
6+
namespace ModNamespace
7+
{
8+
public class RemoveAmmo : MelonMod
9+
{
10+
public static readonly List<string> gunNames = new()
11+
{
12+
"GEAR_Rifle",
13+
"GEAR_Rifle_Barbs",
14+
"GEAR_Rifle_Curators",
15+
"GEAR_Rifle_Vaughns",
16+
"GEAR_Revolver"
17+
};
18+
19+
public static readonly List<string> ammoNames = new()
20+
{
21+
"GEAR_RifleAmmoSingle",
22+
"GEAR_RevolverAmmoSingle",
23+
"GEAR_RifleAmmoBox",
24+
"GEAR_RevolverAmmoBox"
25+
};
26+
27+
public static readonly List<string> protectedParents = new()
28+
{
29+
"Gear",
30+
"DesignGear"
31+
};
32+
33+
public override void OnInitializeMelon()
34+
{
35+
var harmony = new HarmonyLib.Harmony("com.delete.ammo");
36+
harmony.PatchAll();
37+
}
38+
39+
public override void OnSceneWasLoaded(int buildIndex, string sceneName)
40+
{
41+
if (sceneName.EndsWith("_SANDBOX"))
42+
{
43+
GameObject[] activeObjects = UnityEngine.Object.FindObjectsOfType<GameObject>();
44+
foreach (GameObject obj in activeObjects)
45+
{
46+
if (ammoNames.Contains(obj.name))
47+
{
48+
GameObject parent = obj.transform.parent.gameObject;
49+
if (parent == null || (!protectedParents.Contains(parent.name) && !sceneName.StartsWith(parent.name)))
50+
{
51+
obj.SetActive(false);
52+
}
53+
}
54+
}
55+
}
56+
}
57+
}
58+
59+
[HarmonyPatch(typeof(Il2Cpp.Container), "ShowItemsAfterSearch")]
60+
public class Container_ShowItemsAfterSearch_Patch
61+
{
62+
private static void Postfix(Il2Cpp.Container __instance)
63+
{
64+
Il2CppSystem.Collections.Generic.List<Il2Cpp.GearItem> allItems = new();
65+
66+
__instance.GetItems(allItems);
67+
foreach (Il2Cpp.GearItem gearItem in allItems)
68+
{
69+
if (RemoveAmmo.ammoNames.Contains(gearItem.name))
70+
{
71+
__instance.DestroyGear(gearItem);
72+
}
73+
else if (RemoveAmmo.gunNames.Contains(gearItem.name))
74+
{
75+
var gunItem = gearItem.transform.parent?.GetComponent<GunItem>();
76+
gunItem?.EmptyClip();
77+
}
78+
}
79+
}
80+
}
81+
82+
[HarmonyPatch(typeof(Il2Cpp.GunItem), "AddRoundsToClip")]
83+
public class GunItem_AddRoundsToClip_Patch
84+
{
85+
private static void Postfix(Il2Cpp.GunItem __instance)
86+
{
87+
GameObject obj = __instance.transform.parent.gameObject;
88+
string sceneName = obj.scene.name;
89+
GameObject parent = obj.transform.parent.gameObject;
90+
91+
if (sceneName != null && (sceneName.EndsWith("_SANDBOX") || (!RemoveAmmo.protectedParents.Contains(parent.name) && !sceneName.StartsWith(parent.name))))
92+
{
93+
__instance.EmptyClip();
94+
}
95+
}
96+
}
97+
}

RemoveAmmo/RemoveAmmo.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+
<!--This is an xml comment. Comments have no impact on compiling.-->
3+
4+
<PropertyGroup>
5+
<!--This is the .NET version the mod will be compiled with. Don't change it.-->
6+
<TargetFramework>net6.0</TargetFramework>
7+
8+
<!--This tells the compiler to use the latest C# version.-->
9+
<LangVersion>Latest</LangVersion>
10+
11+
<!--This adds global usings for a few common System namespaces.-->
12+
<ImplicitUsings>enable</ImplicitUsings>
13+
14+
<!--This enables nullable annotation and analysis. It's good coding form.-->
15+
<Nullable>enable</Nullable>
16+
17+
<!--This tells the compiler to use assembly attributes instead of generating its own.-->
18+
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
19+
20+
<!--PDB files give line numbers in stack traces (errors). This is useful for debugging. There are 3 options:-->
21+
<!--full has a pdb file created beside the dll.-->
22+
<!--embedded has the pdb data embedded within the dll. This is useful because bug reports will then have line numbers.-->
23+
<!--none skips creation of pdb data.-->
24+
<DebugType>embedded</DebugType>
25+
</PropertyGroup>
26+
27+
<!--This is the of packages that the mod references.-->
28+
<ItemGroup>
29+
<!--This package contains almost everything a person could possibly need to reference while modding.-->
30+
<PackageReference Include="STBlade.Modding.TLD.Il2CppAssemblies.Windows" Version="2.10.0" />
31+
<!--The package version here in this template may be outdated and need to be updated. Visual Studio can update package versions automatically.-->
32+
<!--If the mod references any other mods (such as ModSettings), that NuGet package will also need to be listed here.-->
33+
</ItemGroup>
34+
</Project>

0 commit comments

Comments
 (0)