using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using API;
using Agents;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Hook;
using ClientSidePrediction.BepInEx;
using Enemies;
using GameData;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppInterop.Runtime.Runtime;
using Il2CppInterop.Runtime.Runtime.VersionSpecific.Class;
using Il2CppInterop.Runtime.Runtime.VersionSpecific.MethodInfo;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using Player;
using SNetwork;
using ShaderValueAnimation;
using TMPro;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Analytics;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ClientSidePrediction")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+41abda4e8bc3dda8e1320d812ac4c62640cb0aea")]
[assembly: AssemblyProduct("ClientSidePrediction")]
[assembly: AssemblyTitle("ClientSidePrediction")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
}
namespace API
{
[HarmonyPatch(typeof(GameDataInit))]
internal class GameDataInit_Patches
{
[HarmonyPatch("Initialize")]
[HarmonyWrapSafe]
[HarmonyPostfix]
public static void Initialize_Postfix()
{
Analytics.enabled = false;
}
}
internal static class APILogger
{
private static readonly ManualLogSource logger;
static APILogger()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Expected O, but got Unknown
logger = new ManualLogSource("Rand-API");
Logger.Sources.Add((ILogSource)(object)logger);
}
private static string Format(string module, object msg)
{
return $"[{module}]: {msg}";
}
public static void Info(string module, object data)
{
logger.LogMessage((object)Format(module, data));
}
public static void Verbose(string module, object data)
{
}
public static void Log(object data)
{
logger.LogDebug((object)Format("ClientSidePrediction", data));
}
public static void Debug(object data)
{
if (ConfigManager.Debug)
{
Log(data);
}
}
public static void Warn(object data)
{
logger.LogWarning((object)Format("ClientSidePrediction", data));
}
public static void Error(object data)
{
logger.LogError((object)Format("ClientSidePrediction", data));
}
}
}
namespace ClientSidePrediction
{
[HarmonyPatch]
internal class Forecast
{
private static float lerpFactor = 7.5f;
private static Vector3 sentPos = Vector3.zero;
private static Vector3 prevPos = Vector3.zero;
private static Vector3 oldVel = Vector3.zero;
private static CharacterController? characterController = null;
private static long prevTimestamp = 0L;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static Vector3 ExpDecay(Vector3 a, Vector3 b, float decay, float dt)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
return b + (a - b) * Mathf.Exp((0f - decay) * dt);
}
[HarmonyPatch(typeof(PlayerSync), "SendLocomotion")]
[HarmonyPrefix]
private static void Prefix_SendLocomotion(PlayerSync __instance, PLOC_State state, ref Vector3 pos, Vector3 lookDir, float velFwd, float velRight)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Invalid comparison between Unknown and I4
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Invalid comparison between Unknown and I4
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Invalid comparison between Unknown and I4
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_0146: Unknown result type (might be due to invalid IL or missing references)
//IL_014b: Unknown result type (might be due to invalid IL or missing references)
//IL_016e: Unknown result type (might be due to invalid IL or missing references)
//IL_0174: Unknown result type (might be due to invalid IL or missing references)
//IL_0179: Unknown result type (might be due to invalid IL or missing references)
//IL_017e: Unknown result type (might be due to invalid IL or missing references)
//IL_018e: Unknown result type (might be due to invalid IL or missing references)
//IL_0193: Unknown result type (might be due to invalid IL or missing references)
//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
//IL_01af: Unknown result type (might be due to invalid IL or missing references)
if (SNet.IsMaster || (int)state == 7 || (int)state == 9 || (int)state == 15)
{
return;
}
long now = LatencyTracker.Now;
float num = Mathf.Min((float)(now - prevTimestamp), 1000f) / 1000f;
Vector3 val = (pos - prevPos) / num;
prevPos = pos;
prevTimestamp = now;
float num2 = Mathf.Min(LatencyTracker.Ping, 1f) / 2f;
if (num2 <= 0f)
{
return;
}
Vector3 val2 = pos - prevPos;
if (((Vector3)(ref val2)).sqrMagnitude > 9f)
{
return;
}
if (Vector3.Dot(oldVel, val) < 0f)
{
sentPos = pos;
}
oldVel = val;
Vector3 val3 = pos + val * num2;
Vector3 a = sentPos;
float num3 = lerpFactor;
val2 = sentPos - val3;
sentPos = ExpDecay(a, val3, num3 * Mathf.Max(((Vector3)(ref val2)).magnitude, 1f), num);
if ((Object)(object)characterController == (Object)null)
{
characterController = ((Il2CppObjectBase)__instance.m_agent).Cast<LocalPlayerAgent>().m_playerCharacterController.m_characterController;
}
if (!((Object)(object)characterController == (Object)null))
{
Vector3 position = ((Component)characterController).transform.position;
if (!characterController.isGrounded)
{
sentPos.y = pos.y;
}
characterController.Move(sentPos - pos);
sentPos = ((Component)characterController).transform.position;
((Component)characterController).transform.position = position;
pos = sentPos;
}
}
}
[HarmonyPatch]
internal class LatencyTracker : MonoBehaviour
{
internal static float ping;
private static long sendTime;
private static int index;
private static bool expected;
private static bool running;
private static pNavMarkerState visibleState;
private static float markerHideTimer;
private static bool show;
private static float timer;
public static float Ping
{
get
{
if (!((Object)(object)SNet.Master == (Object)null) && !SNet.IsMaster)
{
return ping / 1000f;
}
return 0f;
}
}
public static long Now => ((DateTimeOffset)DateTime.Now).ToUnixTimeMilliseconds();
public static void OnGameplayStarted()
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
timer = 0f;
running = true;
visibleState.status = (eNavMarkerStatus)1;
}
[HarmonyPatch(typeof(RundownManager), "EndGameSession")]
[HarmonyPrefix]
private static void EndGameSession()
{
running = false;
}
[HarmonyPatch(typeof(SNet_SessionHub), "LeaveHub")]
[HarmonyPrefix]
private static void LeaveHub()
{
running = false;
}
[HarmonyPatch(typeof(GuiManager), "AttemptSetPlayerPingStatus")]
[HarmonyPrefix]
private static void GuiManagerHide(PlayerAgent sourceAgent, bool visible, Vector3 worldPos, eNavMarkerStyle style)
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
if (!visible)
{
markerHideTimer = Clock.Time - 1f;
visibleState.status = (eNavMarkerStatus)1;
}
else
{
show = false;
}
}
[HarmonyPatch(typeof(LocalPlayerAgent), "Update")]
[HarmonyPrefix]
private static void Update(LocalPlayerAgent __instance)
{
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Invalid comparison between Unknown and I4
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
if (SNet.IsMaster || !running)
{
return;
}
index = ((PlayerAgent)__instance).Owner.PlayerSlotIndex();
SyncedNavMarkerWrapper val = ((Il2CppArrayBase<SyncedNavMarkerWrapper>)(object)GuiManager.Current.m_playerPings)[index];
timer += Time.deltaTime;
if (!(timer > 1f))
{
return;
}
timer = 0f;
if (Clock.Time > markerHideTimer)
{
visibleState.status = (eNavMarkerStatus)1;
if (!expected && (int)visibleState.status == 1)
{
pNavMarkerInteraction val2 = default(pNavMarkerInteraction);
val2.type = (eNavMarkerInteractionType)1;
sendTime = Now;
expected = true;
val.m_stateReplicator.AttemptInteract(val2);
}
}
}
[HarmonyPatch(typeof(SyncedNavMarkerWrapper), "OnStateChange")]
[HarmonyPrefix]
private static void OnRecievePingStatus(SyncedNavMarkerWrapper __instance, pNavMarkerState oldState, pNavMarkerState newState, bool isDropinState)
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Invalid comparison between Unknown and I4
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
if (!SNet.IsMaster && running && __instance.m_playerIndex == index)
{
if (!show && Clock.Time > markerHideTimer && (int)newState.status == 0)
{
visibleState = newState;
markerHideTimer = Clock.Time + __instance.AutoHideDelay;
show = true;
expected = false;
}
else if (show && Clock.Time <= markerHideTimer && (int)newState.status == 1 && (int)visibleState.status == 0)
{
expected = false;
pNavMarkerInteraction val = default(pNavMarkerInteraction);
val.type = (eNavMarkerInteractionType)0;
val.style = visibleState.style;
val.worldPos = visibleState.worldPos;
val.terminalItemId = visibleState.terminalItemId;
__instance.m_stateReplicator.AttemptInteract(val);
}
else if (expected)
{
expected = false;
float num = Now - sendTime;
ping = Mathf.Clamp(0.5f * ping + 0.5f * num, 0f, 1000f);
}
}
}
[HarmonyPatch(typeof(PUI_LocalPlayerStatus), "UpdateBPM")]
[HarmonyWrapSafe]
[HarmonyPostfix]
private static void Initialize_Postfix(PUI_LocalPlayerStatus __instance)
{
TextMeshPro pulseText = __instance.m_pulseText;
((TMP_Text)pulseText).text = ((TMP_Text)pulseText).text + " | " + (SNet.IsMaster ? "IsHost" : $"{(int)ping} ms");
}
}
[HarmonyPatch]
internal class Prediction
{
public class EnemyData
{
public EnemyAgent agent;
public NavMeshAgent navMeshAgent;
public EnemyAI ai;
public Vector3 prevPos = Vector3.zero;
public Vector3 vel = Vector3.zero;
public long prevTimestamp;
public int lastAnimIndex;
public float triggeredTongue;
public float lastSound;
public bool hasTongue;
public AgentAbility type = (AgentAbility)1;
public Vector3 targetPos;
public float lerpFactor = 5f;
public long desyncTimestamp;
public EnemyData(EnemyAgent agent)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
this.agent = agent;
ai = agent.AI;
navMeshAgent = ((Il2CppObjectBase)((AgentAI)agent.AI).m_navMeshAgent).Cast<NavMeshAgentProxy>().m_agent;
hasTongue = CheckAbilityTypeHasTongue((AgentAbility)1);
if (!hasTongue)
{
hasTongue = CheckAbilityTypeHasTongue((AgentAbility)2);
type = (AgentAbility)2;
}
targetPos = ((Component)agent).transform.position;
}
private bool CheckAbilityTypeHasTongue(AgentAbility type)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Invalid comparison between Unknown and I4
EnemyAbility ability = agent.Abilities.GetAbility(type, 0);
if ((Object)(object)ability == (Object)null)
{
return false;
}
EAB_MovingEnemeyTentacle val = ((Il2CppObjectBase)ability).TryCast<EAB_MovingEnemeyTentacle>();
if ((Object)(object)val == (Object)null)
{
return false;
}
return (int)val.m_type == 0;
}
}
private unsafe delegate Vector3* Interpolate(Vector3* _Vector3Ptr, IntPtr _thisPtr, float t, Il2CppMethodInfo* _);
public static Dictionary<IntPtr, EnemyData> map = new Dictionary<IntPtr, EnemyData>();
private unsafe static Interpolate Patch_Interpolate = Patch;
private static Interpolate Original_Interpolate;
private const float lerpFactor = 5f;
[HarmonyPatch(typeof(RundownManager), "EndGameSession")]
[HarmonyPrefix]
private static void EndGameSession()
{
map.Clear();
}
[HarmonyPatch(typeof(SNet_SessionHub), "LeaveHub")]
[HarmonyPrefix]
private static void LeaveHub()
{
map.Clear();
}
[HarmonyPatch(typeof(Vector4Transition), "FeedMaterial")]
[HarmonyPrefix]
private static void FeedMaterial(Vector4Transition __instance, List<ISVA_MaterialHolder> mats, Vector4 value, ref float t)
{
if (float.IsNaN(t))
{
t = 0f;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static Vector3 ExpDecay(Vector3 a, Vector3 b, float decay, float dt)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
return b + (a - b) * Mathf.Exp((0f - decay) * dt);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static float ExpDecay(float a, float b, float decay, float dt)
{
return b + (a - b) * Mathf.Exp((0f - decay) * dt);
}
[HarmonyPatch(typeof(ES_StrikerAttack), "OnAttackWindUp")]
[HarmonyPrefix]
private static bool ES_StrikerAttack_OnAttackWindUp(ES_StrikerAttack __instance, int attackIndex, AgentAbility abilityType, int abilityIndex)
{
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
if (SNet.IsMaster)
{
return true;
}
ES_PathMove val = ((Il2CppObjectBase)((ES_Base)__instance).m_enemyAgent.Locomotion.PathMove).TryCast<ES_PathMove>();
if (val == null)
{
return true;
}
IntPtr pointer = ((Il2CppObjectBase)val.m_positionBuffer).Pointer;
if (!map.ContainsKey(pointer))
{
return true;
}
EnemyData enemyData = map[pointer];
if (Clock.Time < enemyData.lastSound + 0.5f)
{
__instance.m_tentacleAbility = ((Il2CppObjectBase)((ES_Base)__instance).m_ai.m_enemyAgent.Abilities.GetAbility(abilityType, 0)).Cast<EAB_MovingEnemeyTentacle>();
((ES_Base)__instance).m_locomotion.m_animator.CrossFadeInFixedTime(((Il2CppArrayBase<int>)(object)EnemyLocomotion.s_hashAbilityFires)[attackIndex], ((ES_Base)__instance).m_enemyAgent.EnemyMovementData.BlendIntoAttackAnim);
((ES_Base)__instance).m_enemyAgent.Appearance.InterpolateGlow(Color.op_Implicit(__instance.m_attackGlowColor), __instance.m_attackGlowLocationEnd, ((ES_EnemyAttackBase)__instance).m_attackWindupDuration * 1.2f);
return false;
}
enemyData.lastSound = Clock.Time;
return true;
}
[HarmonyPatch(typeof(EnemySync), "OnSpawn")]
[HarmonyPostfix]
private static void OnSpawn(EnemySync __instance)
{
if (!SNet.IsMaster && ((Il2CppObjectBase)__instance.m_agent.Locomotion.PathMove).TryCast<ES_PathMove>() != null)
{
map.Add(((Il2CppObjectBase)((Il2CppObjectBase)__instance.m_agent.Locomotion.PathMove).Cast<ES_PathMove>().m_positionBuffer).Pointer, new EnemyData(__instance.m_agent));
}
}
[HarmonyPatch(typeof(EnemySync), "OnDespawn")]
[HarmonyPostfix]
private static void OnDespawn(EnemySync __instance)
{
if (!SNet.IsMaster)
{
ES_PathMove val = ((Il2CppObjectBase)__instance.m_agent.Locomotion.PathMove).TryCast<ES_PathMove>();
if (val != null)
{
map.Remove(((Il2CppObjectBase)val.m_positionBuffer).Pointer);
}
}
}
[HarmonyPatch(typeof(EnemyBehaviour), "ChangeState", new Type[] { typeof(EB_States) })]
[HarmonyPrefix]
private static void Behaviour_ChangeState(EnemyBehaviour __instance, EB_States state)
{
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Invalid comparison between Unknown and I4
if (!SNet.IsMaster && __instance.m_currentStateName != state && (int)state == 19)
{
ES_PathMove val = ((Il2CppObjectBase)__instance.m_ai.m_enemyAgent.Locomotion.PathMove).TryCast<ES_PathMove>();
if (val != null)
{
map.Remove(((Il2CppObjectBase)val.m_positionBuffer).Pointer);
}
}
}
public unsafe Prediction()
{
INativeClassStruct val = UnityVersionHandler.Wrap((Il2CppClass*)(void*)Il2CppClassPointerStore<PositionSnapshotBuffer<pES_PathMoveData>>.NativeClassPtr);
for (int i = 0; i < val.MethodCount; i++)
{
INativeMethodInfoStruct val2 = UnityVersionHandler.Wrap(val.Methods[i]);
if (Marshal.PtrToStringAnsi(val2.Name) == "Interpolate")
{
INativeDetour.CreateAndApply<Interpolate>(val2.MethodPointer, Patch_Interpolate, ref Original_Interpolate);
break;
}
}
}
[HarmonyPatch(typeof(ES_PathMove), "RecieveStateData")]
[HarmonyPrefix]
private static bool ES_PathMove_RecieveStateData(ES_PathMove __instance, pES_PathMoveData incomingData)
{
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
if (SNet.IsMaster)
{
return true;
}
if (Mathf.Min(LatencyTracker.Ping, 1f) / 2f <= 0f)
{
return true;
}
IntPtr pointer = ((Il2CppObjectBase)__instance.m_positionBuffer).Pointer;
if (!map.ContainsKey(pointer))
{
return true;
}
EnemyData enemyData = map[pointer];
enemyData.targetPos = incomingData.Position;
float num = enemyData.agent.Locomotion.AnimHandle.TentacleAttackWindUpLen / enemyData.agent.Locomotion.AnimSpeedOrg;
if (Clock.Time < enemyData.triggeredTongue + num)
{
__instance.m_positionBuffer.Push(incomingData);
enemyData.prevTimestamp = LatencyTracker.Now;
enemyData.prevPos = incomingData.Position;
return false;
}
return true;
}
[HarmonyPatch(typeof(ES_EnemyAttackBase), "SyncFixedUpdate")]
[HarmonyPrefix]
private static void OnStrikerAttackUpdate(ES_EnemyAttackBase __instance)
{
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
if (SNet.IsMaster || ((Il2CppObjectBase)__instance).TryCast<ES_StrikerAttack>() == null || Mathf.Min(LatencyTracker.Ping, 1f) / 2f <= 0f)
{
return;
}
ES_PathMove val = ((Il2CppObjectBase)((ES_Base)__instance).m_ai.m_enemyAgent.Locomotion.PathMove).TryCast<ES_PathMove>();
if (val != null)
{
IntPtr pointer = ((Il2CppObjectBase)val.m_positionBuffer).Pointer;
if (map.ContainsKey(pointer))
{
EnemyData enemyData = map[pointer];
long now = LatencyTracker.Now;
float dt = Mathf.Clamp01((float)(now - enemyData.desyncTimestamp) / 1000f);
enemyData.desyncTimestamp = now;
((Component)enemyData.agent).transform.position = ExpDecay(((Component)enemyData.agent).transform.position, enemyData.targetPos, 0.5f, dt);
}
}
}
[HarmonyPatch(typeof(ES_PathMove), "SyncEnter")]
[HarmonyPostfix]
private static void ES_PathMove_SyncEnter(ES_PathMove __instance)
{
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
if (!SNet.IsMaster)
{
IntPtr pointer = ((Il2CppObjectBase)__instance.m_positionBuffer).Pointer;
if (map.ContainsKey(pointer))
{
EnemyData enemyData = map[pointer];
enemyData.prevPos = ((ES_Base)__instance).m_enemyAgent.Position;
enemyData.prevTimestamp = LatencyTracker.Now;
enemyData.vel = Vector3.zero;
((AgentAI)enemyData.ai).m_navMeshAgent.enabled = true;
}
}
}
[HarmonyPatch(typeof(ES_PathMove), "SyncUpdate")]
[HarmonyPostfix]
private static void ES_PathMove_SyncUpdate(ES_PathMove __instance)
{
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Invalid comparison between Unknown and I4
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_012f: Unknown result type (might be due to invalid IL or missing references)
//IL_0149: Unknown result type (might be due to invalid IL or missing references)
//IL_0159: Unknown result type (might be due to invalid IL or missing references)
//IL_0166: Unknown result type (might be due to invalid IL or missing references)
//IL_019a: Unknown result type (might be due to invalid IL or missing references)
//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
//IL_020c: Unknown result type (might be due to invalid IL or missing references)
if (SNet.IsMaster || (int)LatencyTracker.ping < ConfigManager.TonguePredictThreshold)
{
return;
}
IntPtr pointer = ((Il2CppObjectBase)__instance.m_positionBuffer).Pointer;
if (!map.ContainsKey(pointer))
{
return;
}
EnemyData enemyData = map[pointer];
if (!enemyData.hasTongue)
{
return;
}
PlayerAgent localPlayerAgent = PlayerManager.GetLocalPlayerAgent();
float num = (((int)enemyData.type == 1) ? enemyData.agent.EnemyBehaviorData.MeleeAttackDistance.Max : enemyData.agent.EnemyBehaviorData.RangedAttackDistance.Max) * 1.05f;
float num2 = num * num;
Vector3 val = ((Agent)localPlayerAgent).AimTarget.position - ((Agent)enemyData.agent).EyePosition;
if (((Vector3)(ref val)).sqrMagnitude > num2 && enemyData.triggeredTongue != 0f)
{
enemyData.triggeredTongue = 0f;
}
if (enemyData.triggeredTongue == 0f && !((AgentAI)enemyData.ai).m_navMeshAgent.isOnOffMeshLink && ((AgentAI)enemyData.ai).m_target != null && (Object)(object)((AgentAI)enemyData.ai).m_target.m_agent == (Object)(object)localPlayerAgent && ((Vector3)(ref val)).sqrMagnitude < num * num)
{
Vector3 eyePosition = ((Agent)enemyData.agent).EyePosition;
val.y = 0.0001f;
((Vector3)(ref val)).Normalize();
float num3 = Vector3.Dot(((Vector3)(ref val)).normalized, ((Component)enemyData.agent).transform.forward);
bool flag = Physics.Linecast(eyePosition, ((Agent)localPlayerAgent).EyePosition, LayerManager.MASK_WORLD);
if ((((Vector3)(ref val)).sqrMagnitude < 4f || num3 > 0.45f) && !flag)
{
pES_EnemyAttackData val2 = default(pES_EnemyAttackData);
val2.Position = enemyData.agent.Position;
val2.TargetPosition = ((Agent)localPlayerAgent).AimTarget.position;
((pAgent)(ref val2.TargetAgent)).Set((Agent)(object)localPlayerAgent);
val2.AnimIndex = (byte)enemyData.agent.Locomotion.GetUniqueAnimIndex(EnemyLocomotion.s_hashAbilityFires, ref enemyData.lastAnimIndex);
val2.AbilityType = (AgentAbility)1;
((ES_EnemyAttackBase)enemyData.agent.Locomotion.StrikerAttack).RecieveAttackStart(val2);
enemyData.lerpFactor = 1f;
enemyData.triggeredTongue = Clock.Time;
}
}
}
[HarmonyPatch(typeof(ES_PathMove), "Exit")]
[HarmonyPostfix]
private static void ES_PathMove_Exit(ES_PathMove __instance)
{
if (!SNet.IsMaster)
{
IntPtr pointer = ((Il2CppObjectBase)__instance.m_positionBuffer).Pointer;
if (map.ContainsKey(pointer))
{
((AgentAI)map[pointer].ai).m_navMeshAgent.enabled = false;
}
}
}
private unsafe static Vector3* Patch(Vector3* _Vector3Ptr, IntPtr _thisPtr, float t, Il2CppMethodInfo* _)
{
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
//IL_0116: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_0127: Unknown result type (might be due to invalid IL or missing references)
//IL_012c: Unknown result type (might be due to invalid IL or missing references)
//IL_0131: Unknown result type (might be due to invalid IL or missing references)
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
//IL_0148: Unknown result type (might be due to invalid IL or missing references)
Vector3* ptr = Original_Interpolate(_Vector3Ptr, _thisPtr, t, _);
if (SNet.IsMaster)
{
return ptr;
}
if (!map.ContainsKey(_thisPtr))
{
return ptr;
}
float num = Mathf.Min(LatencyTracker.Ping, 1f) / 2f;
if (num <= 0f)
{
return ptr;
}
EnemyData enemyData = map[_thisPtr];
long now = LatencyTracker.Now;
float num2 = Mathf.Clamp01((float)(now - enemyData.prevTimestamp) / 1000f);
enemyData.prevTimestamp = now;
Vector3 val = *ptr - enemyData.prevPos;
enemyData.prevPos = *ptr;
if (num2 <= 0f)
{
return ptr;
}
enemyData.lerpFactor = ExpDecay(enemyData.lerpFactor, 5f, 0.5f, num2);
enemyData.vel = ExpDecay(enemyData.vel, val / num2, enemyData.lerpFactor, num2);
Vector3 destination = *ptr + Vector3.ClampMagnitude(enemyData.vel * num, 5f);
enemyData.navMeshAgent.destination = destination;
Unsafe.Write(ptr, enemyData.navMeshAgent.pathEndPosition);
Vector3 val2 = *ptr - enemyData.prevPos;
if (((Vector3)(ref val2)).sqrMagnitude > 25.1f)
{
Unsafe.Write(ptr, enemyData.prevPos);
}
return ptr;
}
}
}
namespace ClientSidePrediction.BepInEx
{
public static class Module
{
public const string GUID = "randomuserhi.ClientSidePrediction";
public const string Name = "ClientSidePrediction";
public const string Version = "0.0.1";
}
public static class ConfigManager
{
public static ConfigFile configFile;
private static ConfigEntry<bool> debug;
private static ConfigEntry<int> tonguePredictThreshold;
public static bool Debug
{
get
{
return debug.Value;
}
set
{
debug.Value = value;
}
}
public static int TonguePredictThreshold
{
get
{
return tonguePredictThreshold.Value;
}
set
{
tonguePredictThreshold.Value = value;
}
}
static ConfigManager()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Expected O, but got Unknown
configFile = new ConfigFile(Path.Combine(Paths.ConfigPath, "ClientSidePrediction.cfg"), true);
debug = configFile.Bind<bool>("Debug", "enable", false, "Enables debug messages when true.");
tonguePredictThreshold = configFile.Bind<int>("Settings", "TonguePredictThreshold", 150, "When ping (in ms) exceeds this value enemy tongue windup animations are predicted.");
}
}
[BepInPlugin("randomuserhi.ClientSidePrediction", "ClientSidePrediction", "0.0.1")]
public class Plugin : BasePlugin
{
private static Harmony? harmony;
public override void Load()
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Expected O, but got Unknown
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
APILogger.Log("Plugin is loaded!");
harmony = new Harmony("randomuserhi.ClientSidePrediction");
harmony.PatchAll();
APILogger.Log("Debug is " + (ConfigManager.Debug ? "Enabled" : "Disabled"));
ClassInjector.RegisterTypeInIl2Cpp<LatencyTracker>();
RundownManager.OnExpeditionGameplayStarted += Action.op_Implicit((Action)LatencyTracker.OnGameplayStarted);
new GameObject().AddComponent<LatencyTracker>();
new Prediction();
}
}
}