Skip to content

Commit

Permalink
Update to fix instant production errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dvize committed Aug 2, 2024
1 parent 39e2f7a commit acfb60d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 61 deletions.
78 changes: 21 additions & 57 deletions Patches/InstantProductionPatch.cs
Original file line number Diff line number Diff line change
@@ -1,53 +1,13 @@
using System.Collections.Generic;
using System;
using System;
using System.Collections.Generic;
using System.Reflection;
using SPT.Reflection.Patching;
using dvize.GodModeTest;
using EFT.InventoryLogic;
using HarmonyLib;
using EFT.Hideout;
using System.Threading.Tasks;
using System.Threading;
using Comfort.Common;

using static dvize.GodModeTest.dadGamerPlugin;
using SPT.Reflection.Patching;

namespace dvize.DadGamerMode.Patches
{
//These patches relate to production and not hideout upgrades
// Patch for the StartProducing method
internal class InstantStartProducingPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(GClass1933), nameof(GClass1933.StartProducing));
}

[PatchPrefix]
private static bool Prefix(GClass1933 __instance, ProductionBuildAbstractClass scheme)
{
if (dadGamerPlugin.InstantProductionEnabled.Value)
{
if (__instance == null || scheme == null)
{
//dadGamerPlugin.Logger.LogError("InstantStartProducingPatch: __instance or scheme is null.");
return false;
}

GClass1937 producingItem = scheme.GetProducingItem(__instance.ProductionSpeedCoefficient, __instance.ReductionCoefficient);
if (producingItem == null)
{
//dadGamerPlugin.Logger.LogError("InstantStartProducingPatch: producingItem is null.");
return false;
}

__instance.AddProducingItem(producingItem);
__instance.CompleteProduction(producingItem, scheme);
return false;
}
return true;
}
}

// Patch for the Update method
internal class InstantUpdatePatch : ModulePatch
Expand All @@ -64,24 +24,23 @@ private static bool Prefix(GClass1931 __instance, float deltaTime)
{
if (__instance == null || __instance.ProducingItems == null)
{
//dadGamerPlugin.Logger.LogError("InstantUpdatePatch: __instance or ProducingItems is null.");
return false;
}

// Filter itemsToComplete by removing bitcoin farm
List<KeyValuePair<string, GClass1937>> itemsToComplete = new List<KeyValuePair<string, GClass1937>>(__instance.ProducingItems);
itemsToComplete.RemoveAll(x => x.Key == "5d5589c1f934db045e6c5492" || x.Key == "5d5c205bd582a50d042a3c0e"); //bitcoin and fuel?

foreach (var kvp in itemsToComplete)
{
if (__instance.Schemes != null && __instance.Schemes.TryGetValue(kvp.Key, out ProductionBuildAbstractClass scheme))
{
__instance.CompleteProduction(kvp.Value, scheme);
}
else
{
//dadGamerPlugin.Logger.LogError($"InstantUpdatePatch: Scheme for key {kvp.Key} not found or __instance.Schemes is null.");
}
}
return false;

// Allow normal update processing for Bitcoin items
return true;
}

return true;
Expand All @@ -104,7 +63,7 @@ public static void CompleteProduction(this GClass1931 __instance, GClass1937 pro
{
if (__instance == null || producingItem == null || scheme == null)
{
//dadGamerPlugin.Logger.LogError("CompleteProduction: __instance, producingItem, or scheme is null.");
dadGamerPlugin.Logger.LogError("CompleteProduction: __instance, producingItem, or scheme is null.");
return;
}

Expand All @@ -113,7 +72,7 @@ public static void CompleteProduction(this GClass1931 __instance, GClass1937 pro
var class1666Instance = Class1666Field.GetValue(producingItem);
if (class1666Instance == null)
{
//dadGamerPlugin.Logger.LogError("CompleteProduction: class1666Instance is null.");
dadGamerPlugin.Logger.LogError("CompleteProduction: class1666Instance is null.");
return;
}

Expand All @@ -123,27 +82,32 @@ public static void CompleteProduction(this GClass1931 __instance, GClass1937 pro
Item item = __instance.CreateCompleteItem(scheme);
if (item == null)
{
//dadGamerPlugin.Logger.LogError("CompleteProduction: item is null.");
dadGamerPlugin.Logger.LogError("CompleteProduction: item is null.");
return;
}

// Log the current state of the ProducingItems dictionary
dadGamerPlugin.Logger.LogInfo("CompleteProduction: Current ProducingItems:");
foreach (var kvp in __instance.ProducingItems)
{
dadGamerPlugin.Logger.LogInfo($"Key: {kvp.Key}, Value SchemeId: {kvp.Value.SchemeId}");
}

// Check if the SchemeId exists in the dictionary before calling BeforeProductionComplete
if (__instance.ProducingItems != null && __instance.ProducingItems.ContainsKey(producingItem.SchemeId))
{
dadGamerPlugin.Logger.LogInfo($"CompleteProduction: Found SchemeId {producingItem.SchemeId} in ProducingItems.");

__instance.BeforeProductionComplete(producingItem.SchemeId);
__instance.CompleteItemsStorage.AddItem(scheme._id, item);
__instance.ProducingItems.Remove(producingItem.SchemeId);
__instance.SetDetailsData();
}
else
{
//dadGamerPlugin.Logger.LogError($"SchemeId {producingItem.SchemeId} not found in ProducingItems for {item.LocalizedName()}");
dadGamerPlugin.Logger.LogError($"SchemeId {producingItem.SchemeId} not found in ProducingItems.");
}
}
catch (KeyNotFoundException ex)
{
dadGamerPlugin.Logger.LogError($"KeyNotFoundException: The given key {producingItem.SchemeId} was not present in the dictionary. Exception: {ex.Message}");
}
catch (Exception ex)
{
dadGamerPlugin.Logger.LogError($"Unexpected error during CompleteProduction: {ex.Message}");
Expand Down
3 changes: 1 addition & 2 deletions Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace dvize.GodModeTest
{
[BepInPlugin("com.dvize.DadGamerMode", "dvize.DadGamerMode", "1.9.2")]
[BepInPlugin("com.dvize.DadGamerMode", "dvize.DadGamerMode", "1.9.3")]
//[BepInDependency("com.SPT.core", "3.8.0")]
public class dadGamerPlugin : BaseUnityPlugin
{
Expand Down Expand Up @@ -197,7 +197,6 @@ internal void Awake()

//instant production patches
new DadGamerMode.Patches.InstantUpdatePatch().Enable();
new DadGamerMode.Patches.InstantStartProducingPatch().Enable();

//instant hideout upgrade patches
new DadGamerMode.Patches.InstantConstructionPatch().Enable();
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.9.2.0")]
[assembly: AssemblyFileVersion("1.9.2.0")]
[assembly: AssemblyVersion("1.9.3.0")]
[assembly: AssemblyFileVersion("1.9.3.0")]
[assembly: TarkovVersion(30626)]

0 comments on commit acfb60d

Please sign in to comment.