Skip to content

Commit

Permalink
Hearth and Home update
Browse files Browse the repository at this point in the history
Tentative fix for ores spawning at 0,0
  • Loading branch information
diogo.garrett93 committed Sep 20, 2021
1 parent c560ab4 commit aea2656
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 43 deletions.
1 change: 1 addition & 0 deletions VeinMine/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libs/
55 changes: 26 additions & 29 deletions VeinMine/Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class Patches
[HarmonyPatch(typeof(MineRock), "Damage")]
public static void MineRock_Damage_Prefix(MineRock __instance, HitData hit)
{
if (!VeinMine.progressiveMode.Value) hit.m_damage.m_pickaxe = __instance.m_health + 10;
hit.m_point = __instance.GetHitArea(__instance.GetAreaIndex(hit.m_hitCollider)).bounds.center;
}

Expand All @@ -27,6 +26,26 @@ public static void MineRock5_Damage_Prefix(MineRock5 __instance, HitData hit, ou
{
var radiusColliders = Physics.OverlapSphere(hit.m_point, VeinMine.progressiveMult.Value * (float)GetSkillLevel(Player.m_localPlayer.GetSkills(), Skills.SkillType.Pickaxes));

if (radiusColliders != null)
{
foreach (var area in radiusColliders)
{
if (__instance.GetAreaIndex(area) >= 0)
{
__state.Add(__instance.GetAreaIndex(area), __instance.GetHitArea(__instance.GetAreaIndex(area)).m_bound.m_pos +
__instance.GetHitArea(__instance.GetAreaIndex(area)).m_collider.transform.position);
}
}
}
}
if (Input.GetKey(VeinMine.veinMineKey.Value) && !VeinMine.progressiveMode.Value)
{
List<Collider> radiusColliders = new List<Collider>();
foreach(var area in __instance.m_hitAreas)
{
radiusColliders.Add(area.m_collider);
}

if (radiusColliders != null)
{
foreach (var area in radiusColliders)
Expand All @@ -47,30 +66,7 @@ public static void MineRock5_Damage_Patch(MineRock5 __instance, ZNetView ___m_nv
{
if (Player.m_localPlayer != null && hit.m_attacker == Player.m_localPlayer.GetZDOID())
{
if (Input.GetKey(VeinMine.veinMineKey.Value) && !VeinMine.progressiveMode.Value)
{
for (int i = 0; i < (___m_hitAreas.Count <= 128 ? ___m_hitAreas.Count : 128); i++)
{
if (Player.m_localPlayer.GetCurrentWeapon().m_durability > 0 || !Player.m_localPlayer.GetCurrentWeapon().m_shared.m_useDurability)
{
hit.m_point = __instance.GetHitArea(i).m_bound.m_pos;
hit.m_damage.m_pickaxe = __instance.m_health + 10;
try
{
___m_nview.InvokeRPC("Damage", new object[]
{
hit,
i
});
}
catch
{
VeinMine.logger.LogInfo("Skipping section: " + i + ".");
}
}
}
}
else if (Input.GetKey(VeinMine.veinMineKey.Value) && VeinMine.progressiveMode.Value)
if (Input.GetKey(VeinMine.veinMineKey.Value))
{
foreach (var index in __state)
{
Expand Down Expand Up @@ -99,6 +95,7 @@ public static void MineRock5_Damage_Patch(MineRock5 __instance, ZNetView ___m_nv
[HarmonyPatch(typeof(MineRock5), "DamageArea")]
public static bool MineRock5_DamageArea_Prefix(MineRock5 __instance, HitData hit, int hitAreaIndex, ref EffectList ___m_destroyedEffect, ref EffectList ___m_hitEffect, out float __state, ref bool __result)
{
if (!VeinMine.progressiveMode.Value) hit.m_damage.m_pickaxe = __instance.m_health;
bool isVeinmined = false;
MineRock5.HitArea hitArea = __instance.GetHitArea(hitAreaIndex);
__state = hitArea.m_health;
Expand Down Expand Up @@ -137,7 +134,7 @@ public static bool MineRock5_DamageArea_Prefix(MineRock5 __instance, HitData hit
}
hitArea.m_health -= totalDamage;
__instance.SaveHealth();
if (!VeinMine.removeEffects.Value) __instance.m_hitEffect.Create(hit.m_point, Quaternion.identity, null, 1f);
if (!VeinMine.removeEffects.Value) __instance.m_hitEffect.Create(hit.m_point, Quaternion.identity, null, 1f, -1);
Player closestPlayer = Player.GetClosestPlayer(hit.m_point, 10f);
if (closestPlayer)
{
Expand All @@ -150,14 +147,14 @@ public static bool MineRock5_DamageArea_Prefix(MineRock5 __instance, HitData hit
hitAreaIndex,
hitArea.m_health
});
if (!VeinMine.removeEffects.Value) __instance.m_destroyedEffect.Create(hit.m_point, Quaternion.identity, null, 1f);
if (!VeinMine.removeEffects.Value) __instance.m_destroyedEffect.Create(hit.m_point, Quaternion.identity, null, 1f, -1);
foreach (GameObject gameObject in __instance.m_dropItems.GetDropList())
{
if (isVeinmined)
{
Vector3 position = Player.m_localPlayer.GetTransform().position + new Vector3 { x = 0, y = 2, z = 0 } + UnityEngine.Random.insideUnitSphere * 0.3f;
Vector3 position = closestPlayer.GetTransform().localPosition + new Vector3 { x = 0, y = 2, z = 0 } + UnityEngine.Random.insideUnitSphere * 0.3f;
UnityEngine.Object.Instantiate<GameObject>(gameObject, position, Quaternion.identity);
hit.m_point = Player.m_localPlayer.GetTransform().position + new Vector3 { x = 0, y = 2, z = 0 };
hit.m_point = closestPlayer.GetTransform().localPosition + new Vector3 { x = 0, y = 2, z = 0 };
}
else if (!isVeinmined)
{
Expand Down
4 changes: 2 additions & 2 deletions VeinMine/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// 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.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyVersion("1.2.1.0")]
[assembly: AssemblyFileVersion("1.2.1.0")]
2 changes: 1 addition & 1 deletion VeinMine/VeinMine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class VeinMine : BaseUnityPlugin
{
private const string MOD_ID = "com.wisehorror.Veinmine";
private const string MOD_NAME = "Veinmine";
private const string VERSION = "1.2.0";
private const string VERSION = "1.2.1";

public static ManualLogSource logger = BepInEx.Logging.Logger.CreateLogSource("Veinmine");

Expand Down
22 changes: 11 additions & 11 deletions VeinMine/VeinMine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony, Version=2.0.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Lib.Harmony.2.0.4\lib\net45\0Harmony.dll</HintPath>
<Reference Include="0Harmony">
<HintPath>libs\0Harmony.dll</HintPath>
</Reference>
<Reference Include="assembly_guiutils_publicized">
<HintPath>..\..\ValheimMods-main\Libs\assembly_guiutils_publicized.dll</HintPath>
<Reference Include="assembly_guiutils_public">
<HintPath>libs\assembly_guiutils_public.dll</HintPath>
</Reference>
<Reference Include="assembly_utils_publicized">
<HintPath>..\..\ValheimMods-main\Libs\assembly_utils_publicized.dll</HintPath>
<Reference Include="assembly_utils_public">
<HintPath>libs\assembly_utils_public.dll</HintPath>
</Reference>
<Reference Include="assembly_valheim_publicized">
<HintPath>..\..\ValheimMods-main\Libs\assembly_valheim_publicized.dll</HintPath>
<Reference Include="assembly_valheim_public">
<HintPath>libs\assembly_valheim_public.dll</HintPath>
</Reference>
<Reference Include="BepInEx">
<HintPath>..\..\MultiSmelt\MultiSmelt\Libs\BepInEx.dll</HintPath>
<HintPath>libs\BepInEx.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -57,10 +57,10 @@
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine">
<HintPath>..\..\SmeltingSkill\SmeltingSkill\Libs\UnityEngine.dll</HintPath>
<HintPath>libs\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\..\MultiSmelt\MultiSmelt\Libs\UnityEngine.CoreModule.dll</HintPath>
<HintPath>libs\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.ImageConversionModule">
<HintPath>D:\Games\Steam\steamapps\common\Valheim\unstripped_corlib\UnityEngine.ImageConversionModule.dll</HintPath>
Expand Down

0 comments on commit aea2656

Please sign in to comment.