using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.Json;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using CrimsonHunt.Hooks;
using CrimsonHunt.Structs;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.Network;
using Stunlock.Core;
using Unity.Collections;
using Unity.Entities;
using VAMP;
using VAMP.Utilities;
using VampireCommandFramework;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("CrimsonHunt")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Created with VRising.ModTemplate, you should edit this.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+Branch.master.Sha.14ec462eccd8cb229ad9cf4a47d0b3eaeac7b715.14ec462eccd8cb229ad9cf4a47d0b3eaeac7b715")]
[assembly: AssemblyProduct("CrimsonHunt")]
[assembly: AssemblyTitle("CrimsonHunt")]
[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.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;
}
}
[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 CrimsonHunt
{
[BepInPlugin("CrimsonHunt", "CrimsonHunt", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BasePlugin
{
private Harmony _harmony;
public static Plugin Instance { get; private set; }
public static Harmony Harmony => Instance._harmony;
public static ManualLogSource LogInstance => ((BasePlugin)Instance).Log;
public static Settings Settings { get; private set; }
public override void Load()
{
Instance = this;
Settings = new Settings(((BasePlugin)this).Config);
Settings.InitConfig();
Database.InitDatabase("player_hunts");
_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
CommandRegistry.RegisterAll();
Plugin.OnCoreLoaded = (Action)Delegate.Combine(Plugin.OnCoreLoaded, new Action(Loaded));
}
public void Loaded()
{
ActionScheduler.StartTimer();
}
public override bool Unload()
{
CommandRegistry.UnregisterAssembly();
((BasePlugin)this).Config.Clear();
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
return true;
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "CrimsonHunt";
public const string PLUGIN_NAME = "CrimsonHunt";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace CrimsonHunt.Structs
{
public class Database
{
private static Database INSTANCE;
public static int ExpBonus;
public string DbPath { get; set; }
public Dictionary<ulong, PlayerStats> PlayerExp { get; set; }
public DateTime Dumped { get; set; }
public Database(string _path, string _fileName)
{
DbPath = Path.Combine(_path, _fileName + ".json");
PlayerExp = new Dictionary<ulong, PlayerStats>();
Dumped = DateTime.Now;
}
public static void InitDatabase(string fileName)
{
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Expected O, but got Unknown
INSTANCE = new Database(Path.Combine(Paths.ConfigPath, "CrimsonHunt"), fileName);
if (File.Exists(INSTANCE.DbPath))
{
string json = File.ReadAllText(INSTANCE.DbPath);
try
{
INSTANCE.PlayerExp = JsonSerializer.Deserialize<Dictionary<ulong, PlayerStats>>(json);
}
catch (Exception ex)
{
Plugin.LogInstance.LogWarning((object)ex.Message);
}
}
ManualLogSource logInstance = Plugin.LogInstance;
bool flag = default(bool);
BepInExMessageLogInterpolatedStringHandler val = new BepInExMessageLogInterpolatedStringHandler(26, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Database loaded: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(INSTANCE.PlayerExp.Count);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" entries.");
}
logInstance.LogMessage(val);
}
public static Database Data()
{
return INSTANCE;
}
public float GetExp(User player)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
if (!PlayerExp.TryGetValue(player.PlatformId, out var value))
{
return 0f;
}
return value.Exp;
}
public void UpdateExp(User player, Entity boss)
{
//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_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Expected O, but got Unknown
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
int num = ModifiableInt.op_Implicit(EntityUtil.Read<UnitLevel>(boss).Level);
ManualLogSource logInstance = Plugin.LogInstance;
bool flag = default(bool);
BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(34, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Player defeated a boss with level ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num);
}
logInstance.LogDebug(val);
Equipment val2 = EntityUtil.Read<Equipment>(player.LocalCharacter._Entity);
((Equipment)(ref val2)).GetFullLevel();
float num2 = (float)num / 10f;
ManualLogSource logInstance2 = Plugin.LogInstance;
val = new BepInExDebugLogInterpolatedStringHandler(14, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Add ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(num2);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" to player");
}
logInstance2.LogDebug(val);
if (ExpBonus != 0)
{
num2 *= 1f + (float)ExpBonus / 100f;
}
UpdateExp(player, (int)num2);
}
public void UpdateExp(User player, int value)
{
//IL_0006: 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_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_011d: Unknown result type (might be due to invalid IL or missing references)
//IL_0109: Unknown result type (might be due to invalid IL or missing references)
//IL_0129: 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_013a: Unknown result type (might be due to invalid IL or missing references)
PlayerStats value2;
bool num = PlayerExp.TryGetValue(player.PlatformId, out value2);
int expNeeded = (from x in Settings.GetLevels()
orderby x.ExpNeeded descending
select x).ToList().First().ExpNeeded;
PlayerStats playerStats;
if (num)
{
playerStats = PlayerExp[player.PlatformId];
playerStats.Name = ((FixedString64Bytes)(ref player.CharacterName)).Value;
playerStats.IsAdmin = player.IsAdmin;
playerStats.Exp = ((playerStats.Exp + (float)value > (float)expNeeded) ? ((float)expNeeded) : (playerStats.Exp + (float)value));
}
else
{
playerStats = new PlayerStats
{
Name = ((FixedString64Bytes)(ref player.CharacterName)).Value,
IsAdmin = player.IsAdmin,
Exp = value
};
}
HuntLevel prestige = GetPrestige(playerStats.Exp);
int level = playerStats.Level;
playerStats.Level = prestige.Level;
if (num)
{
PlayerExp[player.PlatformId] = playerStats;
}
else
{
PlayerExp.Add(player.PlatformId, playerStats);
}
CheckForItemRewards(player, level, prestige);
AddPrestigeBuff(player, playerStats, prestige, level);
ChatUtil.SystemSendUser(player, $"Hunt Score [Lvl: <color=#ffc905>{prestige.Level}</color> ~ (<color=#ffc905>{playerStats.Exp.ToString("0.##", CultureInfo.InvariantCulture)}</color>/<color=#ffc905>{prestige.ExpNeeded}</color>)]");
}
private static void CheckForItemRewards(User player, int curLevel, HuntLevel newLevel)
{
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_0111: Unknown result type (might be due to invalid IL or missing references)
if (newLevel.Level <= curLevel)
{
return;
}
PrefabGUID val = default(PrefabGUID);
Entity val2 = default(Entity);
foreach (HuntLevel item in (from x in Settings.GetLevels()
orderby x.Level
select x).ToList())
{
if (item.Level > curLevel && item.Level <= newLevel.Level && item.HuntReward.ItemHash != 0)
{
((PrefabGUID)(ref val))..ctor(item.HuntReward.ItemHash);
ItemUtil.AddItemToInventory(player.LocalCharacter._Entity, val, item.HuntReward.ItemQuantity, ref val2, true, 0, true);
ChatUtil.SystemSendUser(player, $"Hunt Level [Lvl: <color=#ffc905>{item.Level}</color> ~ Reward: (<color=#ffc905>{item.HuntReward.ItemQuantity} {Extensions.LookupName(val)}</color>");
}
}
}
private static void AddPrestigeBuff(User player, PlayerStats stats, HuntLevel prestige, int curLevel)
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//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_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_00fa: 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_00fc: Unknown result type (might be due to invalid IL or missing references)
//IL_0101: 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_015c: Unknown result type (might be due to invalid IL or missing references)
//IL_015d: Unknown result type (might be due to invalid IL or missing references)
//IL_015e: Unknown result type (might be due to invalid IL or missing references)
//IL_0163: Unknown result type (might be due to invalid IL or missing references)
//IL_0178: Unknown result type (might be due to invalid IL or missing references)
//IL_017d: 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_0128: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: 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)
//IL_0189: Unknown result type (might be due to invalid IL or missing references)
//IL_018a: Unknown result type (might be due to invalid IL or missing references)
//IL_018f: Unknown result type (might be due to invalid IL or missing references)
//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
if (prestige.Level <= curLevel)
{
return;
}
EntityManager entityManager = Core.EntityManager;
Entity val = default(Entity);
if (!BuffUtility.HasBuff<EntityManager>(entityManager, player.LocalCharacter._Entity, PrefabIdentifier.op_Implicit(new PrefabGUID(-1133938228))))
{
BuffUtil.BuffEntity(player.LocalCharacter._Entity, new PrefabGUID(-1133938228), ref val, 2f, false);
}
ChatUtil.SystemSendAll(prestige.Message.Replace("{player}", ((FixedString64Bytes)(ref player.CharacterName)).Value).Replace("{level}", prestige.Level.ToString()));
foreach (HuntLevel item in (from x in Settings.GetLevels()
orderby x.Level
select x).ToList())
{
if (item.HuntReward.EffectHash == 0)
{
continue;
}
if (stats.Level > item.Level && BuffUtility.HasBuff<EntityManager>(entityManager, player.LocalCharacter._Entity, PrefabIdentifier.op_Implicit(new PrefabGUID(item.HuntReward.EffectHash))))
{
BuffUtil.RemoveBuff(player.LocalCharacter._Entity, new PrefabGUID(item.HuntReward.EffectHash));
}
if (stats.Level == item.Level)
{
if (!BuffUtility.HasBuff<EntityManager>(entityManager, player.LocalCharacter._Entity, PrefabIdentifier.op_Implicit(new PrefabGUID(item.HuntReward.EffectHash))))
{
BuffUtil.BuffEntity(player.LocalCharacter._Entity, new PrefabGUID(item.HuntReward.EffectHash), ref val, 0f, true);
}
break;
}
}
}
public static HuntLevel GetPrestige(float exp)
{
List<HuntLevel> list = (from x in Settings.GetLevels()
orderby x.Level
select x).ToList();
HuntLevel huntLevel = new HuntLevel();
huntLevel.Level = 0;
huntLevel.ExpNeeded = 0;
huntLevel.Message = "";
HuntLevel result = huntLevel;
for (int i = 0; i < list.Count; i++)
{
result.ExpNeeded = list.ElementAt(i).ExpNeeded;
if (!(exp >= (float)list.ElementAt(i).ExpNeeded))
{
break;
}
result.Level = list.ElementAt(i).Level;
result.Message = list.ElementAt(i).Message;
}
return result;
}
public void SaveDatabase(bool check = true)
{
if (!(DateTime.Now - Dumped < TimeSpan.FromMinutes(1.0) && check))
{
DateTime now = DateTime.Now;
string contents = JsonSerializer.Serialize(PlayerExp, new JsonSerializerOptions
{
WriteIndented = true
});
File.WriteAllText(DbPath, contents);
Dumped = now;
}
}
public List<PlayerStats> GetTopScores(int amount)
{
return PlayerExp.Values.OrderByDescending((PlayerStats x) => x.Exp).Take(amount).ToList();
}
}
public struct PlayerStats
{
public string Name { get; set; }
public bool IsAdmin { get; set; }
public float Exp { get; set; }
public int Level { get; set; }
}
public struct HuntLevel
{
public int Level { get; set; }
public int ExpNeeded { get; set; }
public HuntReward HuntReward { get; set; }
public string Message { get; set; }
public HuntLevel(int _level, int _expNeeded, HuntReward _reward, string _message)
{
Level = _level;
ExpNeeded = _expNeeded;
HuntReward = _reward;
Message = _message;
}
public HuntLevel()
{
Level = 0;
ExpNeeded = 0;
HuntReward = default(HuntReward);
Message = null;
}
}
public struct HuntReward
{
public int EffectHash { get; set; }
public int ItemHash { get; set; }
public int ItemQuantity { get; set; }
public HuntReward(int effectHash, int itemHash, int itemQuantity)
{
EffectHash = effectHash;
ItemHash = itemHash;
ItemQuantity = itemQuantity;
}
public HuntReward()
{
EffectHash = 0;
ItemHash = 0;
ItemQuantity = 0;
}
}
public struct KillEvent
{
public DateTime Killed { get; set; }
public Entity Boss { get; set; }
public string BossName { get; set; }
public List<User> Players { get; set; }
public KillEvent(Entity _boss, string _bossName)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
Killed = DateTime.Now;
Boss = _boss;
BossName = _bossName;
Players = new List<User>();
}
public readonly void AddPlayer(User player)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
if (Players.Where((User x) => ((FixedString64Bytes)(ref x.CharacterName)).Value == ((FixedString64Bytes)(ref player.CharacterName)).Value).ToList().Count == 0)
{
Players.Add(player);
}
}
}
public readonly struct Settings
{
private readonly ConfigFile CONFIG;
private readonly ConfigEntry<bool> ENABLE_MOD;
private readonly ConfigEntry<bool> ENABLE_BOUNTY;
public static readonly string CONFIG_PATH = Path.Combine(Paths.ConfigPath, "CrimsonHunt");
private static readonly string PRESTIGE = Path.Combine(CONFIG_PATH, "hunt_levels.json");
private static List<HuntLevel> HUNT_LEVELS = new List<HuntLevel>();
public Settings(ConfigFile config)
{
CONFIG = config;
ENABLE_MOD = CONFIG.Bind<bool>("Config", "EnableMod", true, "Enable or disable the mod");
ENABLE_BOUNTY = CONFIG.Bind<bool>("Config", "EnableHunt", true, "Enable or disable v blood hunting");
}
public void InitConfig()
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Expected O, but got Unknown
WriteConfig();
HUNT_LEVELS.Clear();
HUNT_LEVELS = JsonSerializer.Deserialize<List<HuntLevel>>(File.ReadAllText(PRESTIGE));
ManualLogSource logInstance = Plugin.LogInstance;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(13, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Mod enabled: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(ENABLE_MOD.Value);
}
logInstance.LogInfo(val);
}
public void WriteConfig()
{
if (!Directory.Exists(CONFIG_PATH))
{
Directory.CreateDirectory(CONFIG_PATH);
}
if (!File.Exists(PRESTIGE))
{
HUNT_LEVELS.Add(new HuntLevel(1, 1000, new HuntReward(), "{player} has reached {level}!"));
HUNT_LEVELS.Add(new HuntLevel(2, 2000, new HuntReward(), "{player} has reached {level}!"));
string contents = JsonSerializer.Serialize(HUNT_LEVELS, new JsonSerializerOptions
{
WriteIndented = true
});
File.WriteAllText(PRESTIGE, contents);
}
}
public bool GetActiveSystem(Systems type)
{
return type switch
{
Systems.ENABLE => ENABLE_MOD.Value,
Systems.BOUNTY => ENABLE_BOUNTY.Value,
_ => false,
};
}
public string ToggleSystem()
{
ENABLE_BOUNTY.Value = !ENABLE_BOUNTY.Value;
if (!ENABLE_BOUNTY.Value)
{
return "disabled";
}
return "enabled";
}
public static List<HuntLevel> GetLevels()
{
return HUNT_LEVELS;
}
}
public enum Systems
{
ENABLE,
BOUNTY
}
}
namespace CrimsonHunt.Hooks
{
internal class ActionScheduler
{
public static List<KillEvent> KillEvents = new List<KillEvent>();
public static Action action;
public static DateTime lastDateMinute = DateTime.Now;
private static DateTime lastDateSecond = DateTime.Now;
private static Dictionary<string, DateTime> lastCheck = new Dictionary<string, DateTime>();
public static void HandleHuntFrame()
{
//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_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
if (!Plugin.Settings.GetActiveSystem(Systems.ENABLE))
{
return;
}
Database.Data().SaveDatabase();
for (int num = KillEvents.Count - 1; num >= 0; num--)
{
if (!(DateTime.Now - KillEvents[num].Killed < TimeSpan.FromSeconds(1.0)))
{
foreach (User player in KillEvents[num].Players)
{
Database.Data().UpdateExp(player, KillEvents[num].Boss);
}
KillEvents.RemoveAt(num);
}
}
}
public static void StartTimer()
{
Plugin.LogInstance.LogInfo((object)"Start Timner for BloodyBoss");
action = delegate
{
DateTime now = DateTime.Now;
if (lastDateMinute.ToString("HH:mm") != now.ToString("HH:mm"))
{
HandleHuntFrame();
}
ActionSchedulerPatch.RunActionOnceAfterFrames(action, 30);
};
ActionSchedulerPatch.RunActionOnceAfterFrames(action, 30);
}
}
[HarmonyPatch]
public class ActionSchedulerPatch
{
public static int CurrentFrameCount = 0;
public static ConcurrentQueue<Action> actionsToExecuteOnMainThread = new ConcurrentQueue<Action>();
public static List<Timer> activeTimers;
[HarmonyPatch(typeof(RandomizedSpawnChainUpdateSystem), "OnUpdate")]
[HarmonyPostfix]
public static void Postfix()
{
CurrentFrameCount++;
Action result;
while (actionsToExecuteOnMainThread.TryDequeue(out result))
{
result?.Invoke();
}
}
public static Timer RunActionEveryInterval(Action action, double intervalInSeconds)
{
return new Timer(delegate
{
actionsToExecuteOnMainThread.Enqueue(action);
}, null, TimeSpan.FromSeconds(intervalInSeconds), TimeSpan.FromSeconds(intervalInSeconds));
}
public static Timer RunActionOnceAfterDelay(Action action, double delayInSeconds)
{
Timer timer = null;
timer = new Timer(delegate
{
actionsToExecuteOnMainThread.Enqueue(delegate
{
action();
timer?.Dispose();
});
}, null, TimeSpan.FromSeconds(delayInSeconds), Timeout.InfiniteTimeSpan);
return timer;
}
public static Timer RunActionOnceAfterFrames(Action action, int frameDelay)
{
int startFrame = CurrentFrameCount;
Timer timer = null;
timer = new Timer(delegate
{
if (CurrentFrameCount - startFrame >= frameDelay)
{
actionsToExecuteOnMainThread.Enqueue(delegate
{
action();
});
timer?.Dispose();
}
}, null, TimeSpan.Zero, TimeSpan.FromMilliseconds(8.0));
return timer;
}
public static Timer RunActionAtTime(Action action, DateTime scheduledTime)
{
DateTime now = DateTime.Now;
TimeSpan timeSpan = scheduledTime - now;
if (timeSpan.TotalMilliseconds < 0.0)
{
return null;
}
return RunActionOnceAfterDelay(action, timeSpan.TotalSeconds);
}
public static void RunActionOnMainThread(Action action)
{
actionsToExecuteOnMainThread.Enqueue(delegate
{
action();
});
}
}
[HarmonyPatch]
internal class Hunt
{
[HarmonyPatch(typeof(VBloodSystem), "OnUpdate")]
[HarmonyPrefix]
public static void OnUpdate_Prefix(VBloodSystem __instance)
{
//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)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: 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_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: 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_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_008c: 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)
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: 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_0160: Unknown result type (might be due to invalid IL or missing references)
if (!Plugin.Settings.GetActiveSystem(Systems.ENABLE) || __instance.EventList.IsEmpty)
{
return;
}
Enumerator<VBloodConsumed> enumerator = __instance.EventList.GetEnumerator();
PlayerCharacter val = default(PlayerCharacter);
while (enumerator.MoveNext())
{
VBloodConsumed current = enumerator.Current;
FixedString128Bytes _bossId = __instance._PrefabCollectionSystem._PrefabDataLookup[current.Source].AssetName;
Entity vBlood = GetVBlood(__instance, current);
Plugin.LogInstance.LogMessage((object)"VBloodSystem.OnUpdate");
EntityManager entityManager = Core.EntityManager;
if (!((EntityManager)(ref entityManager)).TryGetComponentData<PlayerCharacter>(current.Target, ref val) || ((object)(FixedString128Bytes)(ref _bossId)).ToString() == "CHAR_Vermin_DireRat_VBlood" || vBlood == Entity.Null)
{
continue;
}
User player = EntityUtil.Read<User>(val.UserEntity);
if (ActionScheduler.KillEvents.Where((KillEvent x) => x.BossName == ((object)(FixedString128Bytes)(ref _bossId)).ToString()).ToList().Count == 0)
{
KillEvent item = new KillEvent(vBlood, ((object)(FixedString128Bytes)(ref _bossId)).ToString());
ActionScheduler.KillEvents.Add(item);
}
foreach (KillEvent killEvent in ActionScheduler.KillEvents)
{
if (killEvent.BossName == ((object)(FixedString128Bytes)(ref _bossId)).ToString())
{
killEvent.AddPlayer(player);
}
}
}
}
private static Entity GetVBlood(VBloodSystem __instance, VBloodConsumed _event)
{
//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_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: 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_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_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: 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_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
EntityManager entityManager = ((ComponentSystemBase)__instance).EntityManager;
EntityQueryDesc[] array = new EntityQueryDesc[1];
EntityQueryDesc val = new EntityQueryDesc();
val.All = Il2CppStructArray<ComponentType>.op_Implicit((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<VBloodUnit>() });
val.Options = (EntityQueryOptions)195;
array[0] = val;
EntityQuery val2 = ((EntityManager)(ref entityManager)).CreateEntityQuery((EntityQueryDesc[])(object)array);
NativeArray<Entity> val3 = ((EntityQuery)(ref val2)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
Entity result = Entity.Null;
Enumerator<Entity> enumerator = val3.GetEnumerator();
PrefabGUID val4 = default(PrefabGUID);
while (enumerator.MoveNext())
{
Entity current = enumerator.Current;
entityManager = Core.EntityManager;
if (((EntityManager)(ref entityManager)).TryGetComponentData<PrefabGUID>(current, ref val4) && ((PrefabGUID)(ref val4)).GuidHash == ((PrefabGUID)(ref _event.Source)).GuidHash)
{
result = current;
break;
}
}
return result;
}
}
}
namespace CrimsonHunt.Commands
{
[CommandGroup("crimsonhunt", "bloodhunt")]
internal class ActivateDeactivate
{
[Command("toggle", "t", null, "Activates / Deactivates the plugin.", null, true)]
public static void ToggleSystem(ChatCommandContext ctx, string reason)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
string value = Plugin.Settings.ToggleSystem();
User val = EntityUtil.Read<User>(ctx.Event.SenderUserEntity);
string[] array = reason.Split("#");
StringBuilder stringBuilder = new StringBuilder();
StringBuilder stringBuilder2 = stringBuilder;
StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(79, 2, stringBuilder2);
handler.AppendLiteral("The Crimson Hunt system was <color=#ffc905>");
handler.AppendFormatted(value);
handler.AppendLiteral("</color> by <color=#ffc905>");
handler.AppendFormatted<FixedString64Bytes>(val.CharacterName);
handler.AppendLiteral("</color>!");
stringBuilder2.Append(ref handler);
if (!Plugin.Settings.GetActiveSystem(Systems.BOUNTY))
{
stringBuilder.Append(" Reason: <color=#cc2936>");
for (int i = 0; i < array.Length; i++)
{
stringBuilder.Append(array[i]);
if (i < array.Length - 1)
{
stringBuilder.Append(' ');
}
}
stringBuilder.Append("</color>.");
}
ChatUtil.SystemSendAll(stringBuilder.ToString());
}
}
[CommandGroup("crimsonhunt", "bloodhunt")]
internal class DumpDatabase
{
[Command("dumpdb", "ddb", null, "Dumps the database manually.", null, true)]
public static void Dump(ChatCommandContext ctx)
{
Database.Data().SaveDatabase(check: false);
ctx.Reply($"Database Dumped! {Database.Data().PlayerExp.Count} entries");
}
}
[CommandGroup("crimsonhunt", "bloodhunt")]
internal class Event
{
[Command("event", null, null, "Toggle exp event.", null, true)]
public static void ToggleExpEvent(ChatCommandContext ctx, int expBuff)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
User val = EntityUtil.Read<User>(ctx.Event.SenderUserEntity);
if (expBuff >= 0)
{
Database.ExpBonus = expBuff;
string obj = ((expBuff == 0) ? ("<color=#ffc905>" + ((FixedString64Bytes)(ref val.CharacterName)).Value + "</color> has deactivated the <color=#ffc905>Hunt Event</color>!") : $"<color=#ffc905>{((FixedString64Bytes)(ref val.CharacterName)).Value}</color> activated an <color=#ffc905>Hunt Event</color>. EXP: <color=#ffc905>+{expBuff}%</color>");
ctx.Reply("Hunt Event " + ((expBuff == 0) ? "deactivated" : "activated") + "!");
ChatUtil.SystemSendAll(obj);
}
}
}
[CommandGroup("crimsonhunt", "bloodhunt")]
internal class Leaderboard
{
[Command("leaderboard", "top", "Returns the top 5 Hunt Scores", null, null, false)]
public static void GetLeaderboard(ChatCommandContext context)
{
List<PlayerStats> topScores = Database.Data().GetTopScores(5);
string text = "BloodHunt Leaderboard:\n";
for (int i = 0; i < topScores.Count; i++)
{
text += $"{i + 1}: <color=#ffc905>{topScores[i].Name}</color> : <color=#ffc905>{topScores[i].Exp}</color>\n";
}
context.Reply(text);
}
}
[CommandGroup("crimsonhunt", "bloodhunt")]
internal class ReloadCmd
{
[Command("reload", "rl", null, "Reloads the config of Crimson Hunt.", null, true)]
public static void ReloadNotify(ChatCommandContext ctx)
{
Plugin.Settings.InitConfig();
Database.Data().SaveDatabase();
Database.InitDatabase("player_hunts");
ctx.Reply($"Crimson Hunt reloaded! {Database.Data().PlayerExp.Count} entries.");
}
}
[CommandGroup("crimsonhunt", "bloodhunt")]
internal class Reward
{
[Command("reward", "r", null, "Give yourself a reward of hunt points", null, true)]
public static void GiveScore(ChatCommandContext ctx, int amount)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: 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)
User player = EntityUtil.Read<User>(ctx.Event.SenderUserEntity);
Database.Data().UpdateExp(player, amount);
}
}
[CommandGroup("crimsonhunt", "bloodhunt")]
internal class Score
{
[Command("score", null, null, "Get your current hunt score", null, false)]
public static void GetScore(ChatCommandContext context)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: 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)
User player = EntityUtil.Read<User>(context.Event.SenderUserEntity);
float exp = Database.Data().GetExp(player);
HuntLevel prestige = Database.GetPrestige(exp);
context.Reply($"Hunt Score progress [Lvl: <color=#ffc905>{prestige.Level}</color> ~ (<color=#ffc905>{exp.ToString("0.##", CultureInfo.InvariantCulture)}</color>/<color=#ffc905>{prestige.ExpNeeded}</color>)]");
}
}
[CommandGroup("crimsonhunt", "bloodhunt")]
internal class ToggleEffectCmd
{
[Command("mode", null, null, "Toggle crimson hunt effects.", null, false)]
public static void ToggleHuntEffects(ChatCommandContext ctx)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: 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_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: 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_00b1: 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_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_00cd: 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_0141: 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)
//IL_0147: Unknown result type (might be due to invalid IL or missing references)
//IL_015c: Unknown result type (might be due to invalid IL or missing references)
//IL_016f: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
//IL_00df: Unknown result type (might be due to invalid IL or missing references)
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
//IL_0103: Unknown result type (might be due to invalid IL or missing references)
EntityManager entityManager = Core.EntityManager;
User val = EntityUtil.Read<User>(ctx.Event.SenderUserEntity);
HuntLevel prestige = Database.GetPrestige(Database.Data().GetExp(val));
if (prestige.Level == 0)
{
ChatUtil.SystemSendUser(val, $"You dont have any hunt score [Lvl: <color=#ffc905>{prestige.Level}</color>]");
return;
}
Entity val2 = default(Entity);
foreach (HuntLevel level in Settings.GetLevels())
{
if (level.HuntReward.EffectHash != 0 && level.Level <= prestige.Level)
{
if (BuffUtility.HasBuff<EntityManager>(entityManager, val.LocalCharacter._Entity, PrefabIdentifier.op_Implicit(new PrefabGUID(level.HuntReward.EffectHash))))
{
BuffUtil.RemoveBuff(val.LocalCharacter._Entity, new PrefabGUID(level.HuntReward.EffectHash));
ChatUtil.SystemSendUser(val, $"Your hunt effect [Rank: <color=#ffc905>{level.Level}</color>] was removed!");
}
else
{
BuffUtil.BuffEntity(val.LocalCharacter._Entity, new PrefabGUID(level.HuntReward.EffectHash), ref val2, 0f, true);
ChatUtil.SystemSendUser(val, $"Your hunt effect [Rank: <color=#ffc905>{level.Level}</color>] was added!");
}
}
}
}
}
}