Skip to content

Commit f59ed94

Browse files
author
Duodecimus
committed
Switched from using Harmony to inturrupt getting the data, to modifying the item stats directly.
SHould now work with Terror from the Void
1 parent 1b1623a commit f59ed94

6 files changed

+83
-116
lines changed

FreeAmmoAndGrenades/FreeAmmoAndGrenades.csproj

+4-2
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,10 @@
5353
</Reference>
5454
</ItemGroup>
5555
<ItemGroup>
56-
<Compile Include="FreeAmmoandGrenadesGeoscape.cs" />
5756
<Compile Include="FreeAmmoandGrenadesConfig.cs" />
5857
<Compile Include="FreeAmmoandGrenadesMain.cs" />
58+
<Compile Include="FreeAmmoAndGrenadesDefs.cs" />
5959
<Compile Include="Properties\AssemblyInfo.cs" />
60-
<Compile Include="Patches\ItemDef.cs" />
6160
</ItemGroup>
6261
<ItemGroup>
6362
<None Include="meta.json">
@@ -67,6 +66,9 @@
6766
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
6867
</Content>
6968
</ItemGroup>
69+
<ItemGroup>
70+
<Folder Include="Patches\" />
71+
</ItemGroup>
7072
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
7173
<PropertyGroup>
7274
<PostBuildEvent>RMDIR /S /Q "%25USERPROFILE%25\AppData\LocalLow\Snapshot Games Inc\Phoenix Point\Steam\WorkshopTool\TestMod"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using Base.Core;
2+
using Base.Defs;
3+
using PhoenixPoint.Common.Core;
4+
using PhoenixPoint.Common.Entities.GameTags;
5+
using PhoenixPoint.Common.Entities.Items;
6+
7+
using FreeAmmoAndGrenades;
8+
public class FreeAmmoAndGrenadesDefs
9+
{
10+
internal static readonly DefRepository Repo = GameUtl.GameComponent<DefRepository>();
11+
public static void Change_AmmoAndGrenades(ModMain Main)
12+
{
13+
// defining variables
14+
SharedData shared = GameUtl.GameComponent<SharedData>();
15+
GameTagDef GrenadeTag = (GameTagDef)Repo.GetDef("318dd3ff-28f0-1bb4-98bc-39164b7292b6"); // GrenadeItem_TagDef
16+
GameTagDef AmmoTag = shared.SharedGameTags.AmmoTag;
17+
// loop over all item defs in the repo
18+
int Count = 0;
19+
Main.Logger.LogInfo($"Free Ammo and Grenades: Beginning updating items");
20+
foreach (ItemDef ItemDef in Repo.GetAllDefs<ItemDef>())
21+
{
22+
// All hand thrown grenades (only these weapon defs ends with "Grenade_WeaponDef" <- checked by tag)
23+
if (ItemDef.Tags.Contains(GrenadeTag) && Main.Config.GrenadesAreFree)
24+
{
25+
//Main.Logger.LogInfo(System.String.Concat($"Applying Grenade Discount to: ", ItemDef.name));
26+
Count++;
27+
ItemDef.ManufactureMaterials = 0;
28+
ItemDef.ManufactureTech = 0;
29+
ItemDef.ManufactureMutagen = 0;
30+
ItemDef.ManufactureLivingCrystals = 0;
31+
ItemDef.ManufactureOricalcum = 0;
32+
ItemDef.ManufactureProteanMutane = 0;
33+
}
34+
else if (ItemDef.Tags.Contains(AmmoTag) && Main.Config.AmmoIsFree)
35+
{
36+
//Main.Logger.LogInfo(System.String.Concat($"Applying Ammo Discount to: ", ItemDef.name));
37+
Count++;
38+
ItemDef.ManufactureMaterials = 0;
39+
ItemDef.ManufactureTech = 0;
40+
ItemDef.ManufactureMutagen = 0;
41+
ItemDef.ManufactureLivingCrystals = 0;
42+
ItemDef.ManufactureOricalcum = 0;
43+
ItemDef.ManufactureProteanMutane = 0;
44+
}
45+
//else
46+
//{
47+
//Main.Logger.LogInfo(System.String.Concat($"Skipping item: ", ItemDef.name));
48+
//}
49+
}
50+
Main.Logger.LogInfo(System.String.Format("Free Ammo and Grenades: Finished updating {0} items", Count));
51+
}
52+
}

FreeAmmoAndGrenades/FreeAmmoandGrenadesConfig.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ namespace FreeAmmoAndGrenades
44
{
55
public class Configuration : ModConfig
66
{
7-
[ConfigField(description: "Ammo is free to manufacture, and provides no scrap.")]
8-
public bool AmmoIsFree = false;
7+
[ConfigField(text: "Ammo is free to manufacture, and provides no scrap", description: "Please be sure to restart the game after changing these settings, to reload the mod")]
8+
public bool AmmoIsFree = true;
99

10-
[ConfigField(description: "Grenades are free to manufacture and provide no scrap.")]
11-
public bool GrenadesAreFree = false;
10+
[ConfigField(text: "Grenades are free to manufacture and provide no scrap", description: "Please be sure to restart the game after changing these settings, to reload the mod")]
11+
public bool GrenadesAreFree = true;
1212
}
13-
}
13+
}

FreeAmmoAndGrenades/FreeAmmoandGrenadesGeoscape.cs

-48
This file was deleted.
+22-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using HarmonyLib;
2-
using PhoenixPoint.Modding;
32

3+
using System;
44
namespace FreeAmmoAndGrenades
55
{
66
/// <summary>
@@ -9,25 +9,34 @@ namespace FreeAmmoAndGrenades
99
/// </summary>
1010
public class ModMain : PhoenixPoint.Modding.ModMain
1111
{
12-
public override bool CanSafelyDisable => true;
13-
12+
public override bool CanSafelyDisable => false;
13+
1414
public static ModMain Main { get; private set; }
1515

1616
public new Configuration Config => (Configuration)base.Config;
1717

1818
public new Harmony HarmonyInstance => (Harmony)base.HarmonyInstance;
1919

20-
public new Geoscape GeoscapeMod => (Geoscape)base.GeoscapeMod;
21-
22-
public override void OnModEnabled() {
23-
24-
Main = this;
25-
HarmonyInstance.PatchAll(GetType().Assembly);
20+
//public new Geoscape GeoscapeMod => (Geoscape)base.GeoscapeMod;
21+
22+
public override void OnModEnabled()
23+
{
24+
try
25+
{
26+
Main = this;
27+
FreeAmmoAndGrenadesDefs.Change_AmmoAndGrenades(Main);
28+
HarmonyInstance.PatchAll();
29+
}
30+
catch (Exception e)
31+
{
32+
Main.Logger.LogInfo(e.Message);
33+
}
2634
}
2735

28-
public override void OnModDisabled() {
29-
HarmonyInstance.UnpatchAll(HarmonyInstance.Id);
36+
public override void OnModDisabled()
37+
{
38+
HarmonyInstance.UnpatchAll();
3039
Main = null;
3140
}
32-
}
33-
}
41+
}
42+
}

FreeAmmoAndGrenades/Patches/ItemDef.cs

-48
This file was deleted.

0 commit comments

Comments
 (0)