using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BoplFixedMath;
using Entwined;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("DesinkDetecter")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DesinkDetecter")]
[assembly: AssemblyTitle("DesinkDetecter")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace AntiKick
{
public static class PluginInfo
{
public const string PLUGIN_GUID = "DesinkDetecter";
public const string PLUGIN_NAME = "DesinkDetecter";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace DesinkDetecter
{
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.David_Loves_JellyCar_Worlds.DesinkDetecter", "DesinkDetecter", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(Host))]
public class myPatches
{
[HarmonyPatch("SendChecksumToPlayer1")]
[HarmonyPrefix]
private static bool FuncName_PlugenName_Plug(Host __instance, uint seqNum)
{
ulong num = CalculateChecksum();
if (seqNum == 1)
{
LocalChecksums = new Dictionary<uint, ulong>();
LocalDebugInfo = new Dictionary<uint, string>();
}
LocalChecksums.Add(seqNum, num);
string value = SerializeState();
LocalDebugInfo.Add(seqNum, value);
Checksum checksum = default(Checksum);
checksum.tick = seqNum;
checksum.checksum = num;
ChecksumsChannel.SendMessage(checksum);
return false;
}
}
[HarmonyPatch(typeof(FixTransform))]
public class myPatches2
{
[HarmonyPatch("Awake")]
[HarmonyPrefix]
private static void FuncName_PlugenName_Plug(FixTransform __instance)
{
FixTransforms.Add(__instance);
}
}
public struct Checksum
{
public ulong checksum;
public uint tick;
public byte level;
}
public static EntwinedPacketChannel<Checksum> ChecksumsChannel;
public static Dictionary<uint, ulong> LocalChecksums = new Dictionary<uint, ulong>();
public static Dictionary<uint, string> LocalDebugInfo = new Dictionary<uint, string>();
public static List<FixTransform> FixTransforms = new List<FixTransform>();
public static ConcurrentQueue<Checksum> checksumPacketQueue = new ConcurrentQueue<Checksum>();
public static List<Checksum> receivedCheckSumPackets = new List<Checksum>();
private void Awake()
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Expected O, but got Unknown
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin DesinkDetecter is loaded!");
Harmony val = new Harmony("com.David_Loves_JellyCar_Worlds.DesinkDetecter");
((BaseUnityPlugin)this).Logger.LogInfo((object)"harmany created");
val.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"DesinkDetecter Patch Compleate!");
GenericEntwiner<Checksum> val2 = new GenericEntwiner<Checksum>((Func<Checksum, byte[]>)ChecksumToBytes, (Func<byte[], Checksum>)BytesToChecksum);
ChecksumsChannel = new EntwinedPacketChannel<Checksum>((BaseUnityPlugin)(object)this, (IEntwiner<Checksum>)(object)val2);
ChecksumsChannel.OnMessage += OnChecksum;
}
private void Start()
{
SteamManager.instance.checkForDesyncs = true;
}
private void Update()
{
while (!checksumPacketQueue.IsEmpty)
{
if (checksumPacketQueue.TryDequeue(out var result) && result.level == Host.level)
{
receivedCheckSumPackets.Add(result);
}
}
List<Checksum> list = new List<Checksum>();
foreach (Checksum receivedCheckSumPacket in receivedCheckSumPackets)
{
list.Add(receivedCheckSumPacket);
}
int num = 0;
foreach (Checksum receivedCheckSumPacket2 in receivedCheckSumPackets)
{
if (Host.level == receivedCheckSumPacket2.level && LocalChecksums.ContainsKey(receivedCheckSumPacket2.tick))
{
if (LocalChecksums[receivedCheckSumPacket2.tick] == receivedCheckSumPacket2.checksum)
{
if (LocalDebugInfo.ContainsKey(receivedCheckSumPacket2.tick))
{
Debug.Log((object)"packet cheksum acsepted");
LocalDebugInfo.Remove(receivedCheckSumPacket2.tick);
}
LocalChecksums.Remove(receivedCheckSumPacket2.tick);
list.Remove(receivedCheckSumPacket2);
break;
}
Debug.Log((object)("desinking frame data = " + LocalDebugInfo[receivedCheckSumPacket2.tick]));
Debug.Log((object)$"desink happend on frame {receivedCheckSumPacket2.tick} and the outer players checksum was {receivedCheckSumPacket2.checksum} my checksum was {LocalChecksums[receivedCheckSumPacket2.tick]}");
GameSessionHandler.LeaveGame(true, false);
if (LocalDebugInfo.ContainsKey(receivedCheckSumPacket2.tick))
{
LocalDebugInfo.Remove(receivedCheckSumPacket2.tick);
}
LocalChecksums.Remove(receivedCheckSumPacket2.tick);
list.Remove(receivedCheckSumPacket2);
throw new Exception("DESINK DETECTED!!!!!!!!! AHHHHHH!!!!!!!!!!");
}
num++;
}
receivedCheckSumPackets = list;
}
public byte[] ChecksumToBytes(Checksum checksum)
{
uint tick = checksum.tick;
byte[] array = new byte[13];
int num = 0;
ulong checksum2 = checksum.checksum;
array[num++] = checksum.level;
tick = NetworkTools.SwapBytesIfLittleEndian(tick);
byte[] bytes = BitConverter.GetBytes(tick);
array[num++] = bytes[0];
array[num++] = bytes[1];
array[num++] = bytes[2];
array[num++] = bytes[3];
checksum2 = NetworkTools.SwapBytesIfLittleEndian(checksum2);
bytes = BitConverter.GetBytes(checksum2);
array[num++] = bytes[0];
array[num++] = bytes[1];
array[num++] = bytes[2];
array[num++] = bytes[3];
array[num++] = bytes[4];
array[num++] = bytes[5];
array[num++] = bytes[6];
array[num++] = bytes[7];
return array;
}
public Checksum BytesToChecksum(byte[] bytes)
{
Checksum result = default(Checksum);
byte[] array = new byte[4];
byte[] array2 = new byte[8];
int num = 0;
result.level = bytes[num++];
array[0] = bytes[num++];
array[1] = bytes[num++];
array[2] = bytes[num++];
array[3] = bytes[num++];
result.tick = BitConverter.ToUInt32(array, 0);
result.tick = NetworkTools.SwapBytesIfLittleEndian(result.tick);
array2[0] = bytes[num++];
array2[1] = bytes[num++];
array2[2] = bytes[num++];
array2[3] = bytes[num++];
array2[4] = bytes[num++];
array2[5] = bytes[num++];
array2[6] = bytes[num++];
array2[7] = bytes[num++];
result.checksum = BitConverter.ToUInt64(array2, 0);
result.checksum = NetworkTools.SwapBytesIfLittleEndian(result.checksum);
return result;
}
public static ulong CalculateChecksum()
{
//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_00b1: 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_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
Fix val = Fix.Zero;
List<FixTransform> list = new List<FixTransform>();
foreach (FixTransform fixTransform in FixTransforms)
{
if (!((Object)(object)fixTransform == (Object)null))
{
list.Add(fixTransform);
}
}
FixTransforms = list;
for (int i = 0; i < FixTransforms.Count; i++)
{
if (!FixTransforms[i].IsDestroyed)
{
val = Fix.SlowAdd(val, FixTransforms[i].ComputeCheckSum());
}
}
return (ulong)val.m_rawValue;
}
public static string SerializeState()
{
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0122: Unknown result type (might be due to invalid IL or missing references)
//IL_0142: Unknown result type (might be due to invalid IL or missing references)
FixTransform[] array = FixTransforms.ToArray();
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("----------------");
for (int i = 0; i < array.Length; i++)
{
if (array[i].IsDestroyed)
{
continue;
}
IUpdatable[] components = ((Component)array[i]).GetComponents<IUpdatable>();
if (components != null)
{
stringBuilder.Append(((Object)((Component)array[i]).gameObject).name + " hierarchyNumbers = ");
for (int j = 0; j < components.Length; j++)
{
if (components[j].IsDestroyed)
{
stringBuilder.Append("[DESTROYED]");
}
stringBuilder.Append(components[j].HierarchyNumber);
stringBuilder.Append(", ");
}
}
else
{
stringBuilder.Append(((Object)((Component)array[i]).gameObject).name);
}
stringBuilder.Append("\n");
stringBuilder.Append("posX = ");
stringBuilder.Append(array[i].position.x);
stringBuilder.Append(", posY = ");
stringBuilder.Append(array[i].position.y);
stringBuilder.Append(", rotation = ");
stringBuilder.Append(array[i].rotation);
stringBuilder.AppendLine("----------------");
}
return stringBuilder.ToString();
}
public void OnChecksum(Checksum checksumPacket, PacketSourceInfo sourceInfo)
{
checksumPacketQueue.Enqueue(checksumPacket);
if (LocalChecksums.ContainsKey(checksumPacket.tick) && checksumPacket.checksum != LocalChecksums[checksumPacket.tick] && checksumPacket.level == Host.level)
{
Debug.Log((object)("desinking frame data = " + LocalDebugInfo[checksumPacket.tick]));
Debug.Log((object)$"desink happend on frame {checksumPacket.tick} and the outer players checksum was {checksumPacket.checksum} my checksum was {LocalChecksums[checksumPacket.tick]}");
GameSessionHandler.LeaveGame(true, false);
throw new Exception("DESINK DETECTED!!!!!!!!! AHHHHHH!!!!!!!!!!");
}
}
}
}