Skip to content

Commit

Permalink
Reordered caching steps so that items causing errors don't get cached…
Browse files Browse the repository at this point in the history
… at all, and will gracefully warn the user of the item every run
  • Loading branch information
devyndamonster committed Nov 21, 2021
1 parent 3eab527 commit 043b02f
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions Scripts/MagazinePatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,11 @@ private static IEnumerator LoadMagazineCacheAsync()
//If this magazine isn't cached, then we should store it's data
if (!CompatibleMagazineCache.Instance.Magazines.Contains(magazine.ItemID))
{
CompatibleMagazineCache.Instance.Magazines.Add(magazine.ItemID);

gameObjectCallback = magazine.GetGameObjectAsync();
yield return AnvilManager.Instance.RunDriven(gameObjectCallback);
if (gameObjectCallback.Result == null)
{
PatchLogger.LogWarning("No object was found to use FVRObject! ItemID: " + magazine.ItemID);
PatchLogger.LogError("No object was found to use FVRObject! ItemID: " + magazine.ItemID);
continue;
}

Expand All @@ -268,12 +266,14 @@ private static IEnumerator LoadMagazineCacheAsync()
{
if (magComp.ObjectWrapper == null)
{
PatchLogger.LogWarning("Object was found to have no ObjectWrapper assigned! ItemID: " + magazine.ItemID);
PatchLogger.LogError("Object was found to have no ObjectWrapper assigned! ItemID: " + magazine.ItemID);
continue;
}

CompatibleMagazineCache.Instance.AddMagazineData(magComp);
}

CompatibleMagazineCache.Instance.Magazines.Add(magazine.ItemID);
}
}

Expand All @@ -297,13 +297,11 @@ private static IEnumerator LoadMagazineCacheAsync()
//If this clip isn't cached, then we should store it's data
if (!CompatibleMagazineCache.Instance.Clips.Contains(clip.ItemID))
{
CompatibleMagazineCache.Instance.Clips.Add(clip.ItemID);

gameObjectCallback = clip.GetGameObjectAsync();
yield return AnvilManager.Instance.RunDriven(gameObjectCallback);
if (gameObjectCallback.Result == null)
{
PatchLogger.LogWarning("No object was found to use FVRObject! ItemID: " + clip.ItemID);
PatchLogger.LogError("No object was found to use FVRObject! ItemID: " + clip.ItemID);
continue;
}

Expand All @@ -314,12 +312,14 @@ private static IEnumerator LoadMagazineCacheAsync()
{
if (clipComp.ObjectWrapper == null)
{
PatchLogger.LogWarning("Object was found to have no ObjectWrapper assigned! ItemID: " + clip.ItemID);
PatchLogger.LogError("Object was found to have no ObjectWrapper assigned! ItemID: " + clip.ItemID);
continue;
}

CompatibleMagazineCache.Instance.AddClipData(clipComp);
}

CompatibleMagazineCache.Instance.Clips.Add(clip.ItemID);
}
}

Expand All @@ -342,13 +342,11 @@ private static IEnumerator LoadMagazineCacheAsync()
//If this clip isn't cached, then we should store it's data
if (!CompatibleMagazineCache.Instance.SpeedLoaders.Contains(speedloader.ItemID))
{
CompatibleMagazineCache.Instance.SpeedLoaders.Add(speedloader.ItemID);

gameObjectCallback = speedloader.GetGameObjectAsync();
yield return AnvilManager.Instance.RunDriven(gameObjectCallback);
if (gameObjectCallback.Result == null)
{
PatchLogger.LogWarning("No object was found to use FVRObject! ItemID: " + speedloader.ItemID);
PatchLogger.LogError("No object was found to use FVRObject! ItemID: " + speedloader.ItemID);
continue;
}

Expand All @@ -357,12 +355,14 @@ private static IEnumerator LoadMagazineCacheAsync()
{
if (speedloaderComp.ObjectWrapper == null)
{
PatchLogger.LogWarning("Object was found to have no ObjectWrapper assigned! ItemID: " + speedloader.ItemID);
PatchLogger.LogError("Object was found to have no ObjectWrapper assigned! ItemID: " + speedloader.ItemID);
continue;
}

CompatibleMagazineCache.Instance.AddSpeedLoaderData(speedloaderComp);
}

CompatibleMagazineCache.Instance.SpeedLoaders.Add(speedloader.ItemID);
}
}

Expand All @@ -386,13 +386,11 @@ private static IEnumerator LoadMagazineCacheAsync()
//If this bullet isn't cached, then we should store it's data
if (!CompatibleMagazineCache.Instance.Bullets.Contains(bullet.ItemID))
{
CompatibleMagazineCache.Instance.Bullets.Add(bullet.ItemID);

gameObjectCallback = bullet.GetGameObjectAsync();
yield return AnvilManager.Instance.RunDriven(gameObjectCallback);
if (gameObjectCallback.Result == null)
{
PatchLogger.LogWarning("No object was found to use FVRObject! ItemID: " + bullet.ItemID);
PatchLogger.LogError("No object was found to use FVRObject! ItemID: " + bullet.ItemID);
continue;
}

Expand All @@ -403,12 +401,14 @@ private static IEnumerator LoadMagazineCacheAsync()
{
if (bulletComp.ObjectWrapper == null)
{
PatchLogger.LogWarning("Object was found to have no ObjectWrapper assigned! ItemID: " + bullet.ItemID);
PatchLogger.LogError("Object was found to have no ObjectWrapper assigned! ItemID: " + bullet.ItemID);
continue;
}

CompatibleMagazineCache.Instance.AddBulletData(bulletComp);
}

CompatibleMagazineCache.Instance.Bullets.Add(bullet.ItemID);
}
}

Expand All @@ -432,19 +432,17 @@ private static IEnumerator LoadMagazineCacheAsync()
//If this firearm isn't cached, then we should store it's data
if (!CompatibleMagazineCache.Instance.Firearms.Contains(firearm.ItemID))
{
CompatibleMagazineCache.Instance.Firearms.Add(firearm.ItemID);

gameObjectCallback = firearm.GetGameObjectAsync();
yield return AnvilManager.Instance.RunDriven(gameObjectCallback);
if (gameObjectCallback.Result == null)
{
PatchLogger.LogWarning("No object was found to use FVRObject! ItemID: " + firearm.ItemID);
PatchLogger.LogError("No object was found to use FVRObject! ItemID: " + firearm.ItemID);
continue;
}

if (!IM.OD.ContainsKey(firearm.ItemID))
{
PatchLogger.LogWarning("Item not found in Object Dictionary! It will not be patched! ItemID: " + firearm.ItemID);
PatchLogger.LogError("Item not found in Object Dictionary! ItemID: " + firearm.ItemID);
continue;
}

Expand All @@ -455,7 +453,7 @@ private static IEnumerator LoadMagazineCacheAsync()
{
if (firearmComp.ObjectWrapper == null)
{
PatchLogger.LogWarning("Object was found to have no ObjectWrapper assigned! ItemID: " + firearm.ItemID);
PatchLogger.LogError("Object was found to have no ObjectWrapper assigned! ItemID: " + firearm.ItemID);
continue;
}

Expand All @@ -476,6 +474,8 @@ private static IEnumerator LoadMagazineCacheAsync()

CompatibleMagazineCache.Instance.Entries.Add(firearm.ItemID, entry);
}

CompatibleMagazineCache.Instance.Firearms.Add(firearm.ItemID);
}
}

Expand Down

0 comments on commit 043b02f

Please sign in to comment.