145 lines
5.7 KiB
C#
145 lines
5.7 KiB
C#
namespace Harmony.EModelBasePatches
|
|
{
|
|
[HarmonyPatch(typeof(EModelBase))]
|
|
[HarmonyPatch("Init")]
|
|
public class InitPatch
|
|
{
|
|
private static void Postfix(EModelBase __instance, Entity ___entity)
|
|
{
|
|
if (__instance.GetModelTransform() == null)
|
|
return;
|
|
|
|
// Add the animation Bridge to all entities that do not have it.
|
|
__instance.GetModelTransform().gameObject.GetOrAddComponent<AnimationEventBridge>();
|
|
|
|
// Add any missing Root TransformRef Entity scripts where a CollisionCallForward exists.
|
|
foreach (var collisionCallForward in __instance.GetComponentsInChildren<CollisionCallForward>())
|
|
{
|
|
collisionCallForward.transform.gameObject.GetOrAddComponent<RootTransformRefEntity>();
|
|
}
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(EModelBase))]
|
|
[HarmonyPatch("DoRagdoll")]
|
|
[HarmonyPatch(new Type[] { typeof(DamageResponse), typeof(float) })]
|
|
public class DoRagdollPatch
|
|
{
|
|
public static bool Prefix(ref EModelBase __instance, DamageResponse dr, float stunTime, Entity ___entity
|
|
)
|
|
{
|
|
//Log.Out("DoRagdollPatch1-DoRagdoll START");
|
|
|
|
//Log.Out("DoRagdollPatch1-DoRagdoll dr.HitBodyPart: " + dr.HitBodyPart);
|
|
|
|
float num = (float)dr.Strength;
|
|
DamageSource source = dr.Source;
|
|
if (num > 0f && source != null)
|
|
{
|
|
//Log.Out("DoRagdollPatch1-DoRagdoll stunTime: " + stunTime);
|
|
Vector3 vector = source.getDirection();
|
|
EnumDamageTypes damageType = source.GetDamageType();
|
|
if (damageType != EnumDamageTypes.Falling && damageType != EnumDamageTypes.Crushing)
|
|
{
|
|
float num2;
|
|
if (dr.HitBodyPart == EnumBodyPartHit.None)
|
|
{
|
|
//Log.Out("DoRagdollPatch1-DoRagdoll 2");
|
|
num2 = ___entity.rand.RandomRange(5f, 25f);
|
|
}
|
|
else
|
|
{
|
|
//Log.Out("DoRagdollPatch1-DoRagdoll 3");
|
|
float min = -20f;
|
|
if (stunTime == 0f)
|
|
{
|
|
//Log.Out("DoRagdollPatch1-DoRagdoll 4");
|
|
min = 5f;
|
|
}
|
|
num2 = ___entity.rand.RandomRange(min, 40f);
|
|
num *= 0.5f;
|
|
if (source.damageType == EnumDamageTypes.Bashing)
|
|
{
|
|
//Log.Out("DoRagdollPatch1-DoRagdoll 5");
|
|
num *= 2.5f;
|
|
}
|
|
if (dr.Critical)
|
|
{
|
|
//Log.Out("DoRagdollPatch1-DoRagdoll 6");
|
|
num2 += 25f;
|
|
num *= 2f;
|
|
}
|
|
if ((dr.HitBodyPart & EnumBodyPartHit.Head) > EnumBodyPartHit.None)
|
|
{
|
|
//Log.Out("DoRagdollPatch1-DoRagdoll 7");
|
|
num *= 0.45f;
|
|
}
|
|
num = Utils.FastMin(20f + num, 500f);
|
|
vector *= num;
|
|
}
|
|
Vector3 vector2 = Vector3.Cross(vector.normalized, Vector3.up);
|
|
vector = Quaternion.AngleAxis(num2, vector2) * vector;
|
|
|
|
if (___entity.EntityClass.HasRagdoll)
|
|
{
|
|
__instance.DoRagdoll(stunTime, dr.HitBodyPart, vector, source.getHitTransformPosition(), false);
|
|
}
|
|
else
|
|
{
|
|
//Log.Out("DoRagdollPatch1-DoRagdoll 10, dr.HitBodyPart: " + dr.HitBodyPart);
|
|
bool isRemote = false;
|
|
EnumBodyPartHit bodyPart = dr.HitBodyPart;
|
|
Vector3 forceVec = vector;
|
|
Vector3 forceWorldPos = source.getHitTransformPosition();
|
|
|
|
if (!isRemote && !SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer && ___entity.isEntityRemote)
|
|
{
|
|
//Log.Out("DoRagdollPatch1-DoRagdoll 11");
|
|
SingletonMonoBehaviour<ConnectionManager>.Instance.SendToServer(NetPackageManager.GetPackage<NetPackageEntityRagdoll>().Setup(___entity, stunTime, bodyPart, forceVec, forceWorldPos), false);
|
|
return false;
|
|
}
|
|
bool flag = SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer && ___entity.isEntityRemote;
|
|
if (stunTime == 0f)
|
|
{
|
|
//Log.Out("DoRagdollPatch1-DoRagdoll 12");
|
|
if (!flag)
|
|
{
|
|
//Log.Out("DoRagdollPatch1-DoRagdoll 13");
|
|
___entity.PhysicsPush(forceVec, forceWorldPos);
|
|
}
|
|
if (SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer)
|
|
{
|
|
//Log.Out("DoRagdollPatch1-DoRagdoll 14");
|
|
___entity.world.entityDistributer.SendPacketToTrackedPlayersAndTrackedEntity(___entity.entityId, -1, NetPackageManager.GetPackage<NetPackageEntityRagdoll>().Setup(___entity, 0f, EnumBodyPartHit.Torso, forceVec, forceWorldPos));
|
|
}
|
|
return false;
|
|
}
|
|
if (!flag)
|
|
{
|
|
//Log.Out("DoRagdollPatch1-DoRagdoll 15");
|
|
if (forceVec.sqrMagnitude > 0f)
|
|
{
|
|
//Log.Out("DoRagdollPatch1-DoRagdoll 16");
|
|
|
|
___entity.PhysicsPush(forceVec, dr.Source.getHitTransformPosition());
|
|
}
|
|
}
|
|
if (SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer)
|
|
{
|
|
//Log.Out("DoRagdollPatch1-DoRagdoll 17");
|
|
___entity.world.entityDistributer.SendPacketToTrackedPlayersAndTrackedEntity(___entity.entityId, -1, NetPackageManager.GetPackage<NetPackageEntityRagdoll>().Setup(___entity, stunTime, bodyPart, forceVec, forceWorldPos));
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
//Log.Out("DoRagdollPatch1-DoRagdoll 18");
|
|
|
|
__instance.DoRagdoll(stunTime, dr.HitBodyPart, Vector3.zero, Vector3.zero, false);
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|