using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Logging; using GameNetcodeStuff; using HarmonyLib; using Unity.Netcode; using UnityEngine; using UnityEngine.AI; using YamlDotNet.Serialization; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("InverseGift")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("InverseGift")] [assembly: AssemblyCopyright("Copyright © 2025")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("2acb810c-a0ab-455f-a9bd-1658317c49aa")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] namespace InverseGift; public class InverseGiftConfig { public List Items { get; set; } public List Gift { get; set; } } public class GiftConfig { public int Rarity { get; set; } public string Message { get; set; } public List Items { get; set; } } public class ItemConfig { public string Name { get; set; } public string Count { get; set; } public string Value { get; set; } public float? radius { get; set; } } internal static class ConfigValueParser { public static int ParseCount(ItemConfig item, string errorPrefix) { string text = (string.IsNullOrWhiteSpace(item?.Count) ? "1" : item.Count.Trim()); if (int.TryParse(text, out var result)) { return result; } if (text.Contains("-")) { string[] array = text.Split(new char[1] { '-' }); if (array.Length == 2 && int.TryParse(array[0], out var result2) && int.TryParse(array[1], out var result3) && result2 <= result3) { return Random.Range(result2, result3 + 1); } } InverseGiftPlugin.ManualLog.LogInfo((object)(errorPrefix + " -> Item: " + item?.Name + " | Count: " + text)); return 1; } } internal delegate void SpawnObjectDelegate(GameObject spawn, Vector3 pos, Vector3 itempos, Vector3 playerPos, ref string value); internal sealed class GiftEventContext { public string Value { get; set; } public int Count { get; set; } public PlayerControllerB Player { get; set; } public GiftBoxItem GiftBox { get; set; } public GameObjectRegistry Registry { get; set; } public SpawnObjectDelegate SpawnObject { get; set; } } internal static class CustomGiftEvents { private delegate bool GiftEventAction(GiftEventContext context); [CompilerGenerated] private sealed class d__5 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public GameObjectRegistry registry; public string value; public SpawnObjectDelegate spawnObject; private GameObject 5__1; private List 5__2; private GameObject[] 5__3; private PlayerControllerB[] <>s__4; private int <>s__5; private PlayerControllerB 5__6; private int 5__7; private Vector3 5__8; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__5(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { 5__1 = null; 5__2 = null; 5__3 = null; <>s__4 = null; 5__6 = null; <>1__state = -2; } private bool MoveNext() { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Expected O, but got Unknown //IL_017e: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Unknown result type (might be due to invalid IL or missing references) //IL_019b: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = (object)new WaitForSeconds(0.5f); <>1__state = 1; return true; case 1: <>1__state = -1; if (!registry.TryGet("maskedplayerenemy", out 5__1)) { InverseGiftPlugin.ManualLog.LogWarning((object)"MaskEvent skipped -> maskedplayerenemy not found."); return false; } 5__2 = new List(); <>s__4 = StartOfRound.Instance.allPlayerScripts; for (<>s__5 = 0; <>s__5 < <>s__4.Length; <>s__5++) { 5__6 = <>s__4[<>s__5]; if (5__6.isPlayerControlled && !5__6.isPlayerDead) { 5__2.Add(5__6); } 5__6 = null; } <>s__4 = null; 5__3 = GameObject.FindGameObjectsWithTag("OutsideAINode"); if (5__3 == null || 5__3.Length == 0) { InverseGiftPlugin.ManualLog.LogWarning((object)"MaskEvent skipped -> OutsideAINode not found."); return false; } 5__7 = 0; break; case 2: <>1__state = -1; 5__7++; break; } if (5__7 < 5__2.Count * 10) { 5__8 = 5__3[Random.Range(0, 5__3.Length)].transform.position; spawnObject(5__1, 5__8, 5__8, 5__8, ref value); <>2__current = (object)new WaitForSeconds(0.1f); <>1__state = 2; return true; } return false; } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } private static readonly Dictionary Handlers = new Dictionary(StringComparer.OrdinalIgnoreCase) { { "meteor", Meteor }, { "maskevent", MaskEvent }, { "gohome", GoHome }, { "gohomeall", GoHomeAll } }; public static bool TryHandle(string eventName, GiftEventContext context) { string text = GameObjectRegistry.NormalizeName(eventName); if (string.IsNullOrEmpty(text)) { return false; } if (!Handlers.TryGetValue(text, out var value)) { return false; } return value(context); } private static bool Meteor(GiftEventContext context) { if ((Object)(object)TimeOfDay.Instance == (Object)null) { InverseGiftPlugin.ManualLog.LogWarning((object)"Meteor event skipped -> TimeOfDay not found."); return true; } TimeOfDay.Instance.meteorShowerAtTime = 0.1f; return true; } private static bool MaskEvent(GiftEventContext context) { if (context?.Registry == null || context.SpawnObject == null) { InverseGiftPlugin.ManualLog.LogWarning((object)"MaskEvent skipped -> event context is invalid."); return true; } PlayerControllerB val = StartOfRound.Instance?.localPlayerController; if ((Object)(object)val == (Object)null) { InverseGiftPlugin.ManualLog.LogWarning((object)"MaskEvent skipped -> local player not found."); return true; } ((MonoBehaviour)val).StartCoroutine(MaskEventCoroutine(context.Registry, context.Value, context.SpawnObject)); return true; } [IteratorStateMachine(typeof(d__5))] private static IEnumerator MaskEventCoroutine(GameObjectRegistry registry, string value, SpawnObjectDelegate spawnObject) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__5(0) { registry = registry, value = value, spawnObject = spawnObject }; } private static bool GoHome(GiftEventContext context) { if ((Object)(object)context?.Player == (Object)null) { InverseGiftPlugin.ManualLog.LogWarning((object)"GoHome event skipped -> player not found."); return true; } TeleportPlayerHome(context.Player); return true; } private static bool GoHomeAll(GiftEventContext context) { TeleportAllPlayersHome(); return true; } private static bool TeleportAllPlayersHome() { ManualCameraRenderer val = StartOfRound.Instance?.mapScreen; if ((Object)(object)val == (Object)null) { return false; } int targetTransformIndex = val.targetTransformIndex; bool flag = false; ShipTeleporter val2 = FindShipTeleporter(); if ((Object)(object)val2 == (Object)null) { return false; } for (int i = 0; i < val.radarTargets.Count; i++) { TransformAndName val3 = val.radarTargets[i]; if (!val3.isNonPlayer) { PlayerControllerB component = ((Component)val3.transform).gameObject.GetComponent(); if (!((Object)(object)component == (Object)null) && component.isPlayerControlled) { InverseGiftPlugin.LogInfo("GoHomeAll -> " + component.playerUsername); val.SwitchRadarTargetAndSync(i); val.SwitchRadarTargetClientRpc(i); val2.PressTeleportButtonClientRpc(); flag = true; } } } if (!flag) { return false; } val.SwitchRadarTargetClientRpc(targetTransformIndex); return true; } private static bool TeleportPlayerHome(PlayerControllerB player) { ManualCameraRenderer val = StartOfRound.Instance?.mapScreen; if ((Object)(object)val == (Object)null) { return false; } int targetTransformIndex = val.targetTransformIndex; bool flag = false; for (int i = 0; i < val.radarTargets.Count; i++) { TransformAndName val2 = val.radarTargets[i]; if (!val2.isNonPlayer) { PlayerControllerB component = ((Component)val2.transform).gameObject.GetComponent(); if (!((Object)(object)component == (Object)null) && component.isPlayerControlled && component.actualClientId == player.actualClientId) { InverseGiftPlugin.LogInfo("GoHome -> " + component.playerUsername); val.SwitchRadarTargetAndSync(i); val.SwitchRadarTargetClientRpc(i); flag = true; } } } if (!flag) { return false; } ShipTeleporter val3 = FindShipTeleporter(); if ((Object)(object)val3 == (Object)null) { return false; } val3.PressTeleportButtonClientRpc(); val.SwitchRadarTargetAndSync(targetTransformIndex); val.SwitchRadarTargetClientRpc(targetTransformIndex); return true; } private static ShipTeleporter FindShipTeleporter() { return ((IEnumerable)Object.FindObjectsOfType()).FirstOrDefault((Func)((ShipTeleporter x) => !x.isInverseTeleporter)); } } internal sealed class GameObjectRegistry { private readonly Dictionary _objects = new Dictionary(StringComparer.OrdinalIgnoreCase); private readonly Dictionary> _randomMap = new Dictionary>(StringComparer.OrdinalIgnoreCase); private readonly Dictionary _nameCounts = new Dictionary(StringComparer.OrdinalIgnoreCase); public static GameObjectRegistry Build() { GameObjectRegistry gameObjectRegistry = new GameObjectRegistry(); gameObjectRegistry.LoadItems(); gameObjectRegistry.LoadLevelObjects(); return gameObjectRegistry; } public static string NormalizeName(string name) { return string.IsNullOrWhiteSpace(name) ? null : name.Trim().ToLowerInvariant(); } public bool TryGet(string name, out GameObject gameObject) { gameObject = null; string text = NormalizeName(name); return !string.IsNullOrEmpty(text) && _objects.TryGetValue(text, out gameObject); } public bool IsRandomKey(string name) { string text = NormalizeName(name); return !string.IsNullOrEmpty(text) && _randomMap.ContainsKey(text); } public bool TryGetRandomName(string randomKey, out string objectName) { objectName = null; string text = NormalizeName(randomKey); if (string.IsNullOrEmpty(text) || !_randomMap.TryGetValue(text, out var value) || value == null || value.Count == 0) { InverseGiftPlugin.ManualLog.LogWarning((object)("RandomMap Empty -> " + randomKey)); return false; } int num = Random.Range(0, value.Count); objectName = value[num]; InverseGiftPlugin.LogInfo($"{text} -> {objectName}({num})"); return true; } public string ToExportText() { return string.Join(Environment.NewLine, _objects.OrderBy((KeyValuePair x) => x.Key).Select(delegate(KeyValuePair x) { string key = x.Key; GameObject value = x.Value; return key + ":" + ((value != null) ? ((Object)value).name : null); })); } private void LoadItems() { if (StartOfRound.Instance?.allItemsList?.itemsList == null) { return; } foreach (Item items in StartOfRound.Instance.allItemsList.itemsList) { if (!((Object)(object)items == (Object)null) && !((Object)(object)items.spawnPrefab == (Object)null)) { string text = Register(((Object)items).name, items.spawnPrefab, "Item"); if (!string.IsNullOrEmpty(text)) { AddRandomName(items.isScrap ? "randomscrap" : "randomtool", text); } } } } private void LoadLevelObjects() { if (StartOfRound.Instance?.levels == null) { return; } SelectableLevel[] levels = StartOfRound.Instance.levels; foreach (SelectableLevel val in levels) { if (!((Object)(object)val == (Object)null)) { LoadEnemies(val.Enemies); LoadMapObjects(val.spawnableMapObjects); } } } private void LoadEnemies(IEnumerable enemies) { if (enemies == null) { return; } foreach (SpawnableEnemyWithRarity enemy in enemies) { if ((Object)(object)enemy?.enemyType == (Object)null || (Object)(object)enemy.enemyType.enemyPrefab == (Object)null) { continue; } string text = NormalizeName(((Object)enemy.enemyType).name); if (!(text == "lassoman")) { string text2 = Register(text, enemy.enemyType.enemyPrefab, "Enemy"); if (!string.IsNullOrEmpty(text2)) { AddRandomName("randomenemy", text2); } } } } private void LoadMapObjects(IEnumerable mapObjects) { if (mapObjects == null) { return; } foreach (SpawnableMapObject item in from x in mapObjects where (Object)(object)x?.prefabToSpawn != (Object)null orderby ((Object)x.prefabToSpawn).GetInstanceID() select x) { string text = Register(((Object)item.prefabToSpawn).name, item.prefabToSpawn, "MapObject"); if (!string.IsNullOrEmpty(text)) { AddRandomName("randomobject", text); } } } private string Register(string name, GameObject gameObject, string source) { string text = NormalizeName(name); if (string.IsNullOrEmpty(text) || (Object)(object)gameObject == (Object)null) { return null; } if (IsSamePrefabRegistered(text, gameObject)) { return null; } int value = 0; _nameCounts.TryGetValue(text, out value); string text2; do { value++; text2 = ((value == 1) ? text : $"{text}_{value}"); } while (_objects.ContainsKey(text2)); _nameCounts[text] = value; _objects.Add(text2, gameObject); if (!text2.Equals(text, StringComparison.OrdinalIgnoreCase)) { InverseGiftPlugin.ManualLog.LogWarning((object)("Duplicate GameObject name registered -> Name: " + text + " | Alias: " + text2 + " | Prefab: " + ((Object)gameObject).name + " | Source: " + source)); } return text2; } private bool IsSamePrefabRegistered(string baseName, GameObject gameObject) { int value = 0; if (!_nameCounts.TryGetValue(baseName, out value)) { return false; } for (int i = 1; i <= value; i++) { string key = ((i == 1) ? baseName : $"{baseName}_{i}"); if (_objects.TryGetValue(key, out var value2) && (Object)(object)value2 == (Object)(object)gameObject) { return true; } } return false; } private void AddRandomName(string randomKey, string objectName) { if (!string.IsNullOrEmpty(objectName)) { if (!_randomMap.TryGetValue(randomKey, out var value)) { value = new List(); _randomMap.Add(randomKey, value); } value.Add(objectName); } } } [BepInPlugin("InverseGift", "chuxia.InverseGift", "1.1.5")] public class InverseGiftPlugin : BaseUnityPlugin { public const string PLUGIN_GUID = "chuxia.InverseGift"; public static readonly string config = Utility.CombinePaths(new string[2] { Paths.ConfigPath, "chuxia.InverseGift.yml" }); public const string PLUGIN_NAME = "InverseGift"; public const string PLUGIN_VERSION = "1.1.5"; public static ManualLogSource ManualLog = null; public static readonly Harmony _harmony = new Harmony("chuxia.InverseGift"); public static InverseGiftConfig InverseConfig { get; set; } = new InverseGiftConfig(); public void Awake() { ManualLog = ((BaseUnityPlugin)this).Logger; LoadConfig(); _harmony.PatchAll(typeof(Patches)); } public static void LoadConfig() { if (!File.Exists(config)) { InverseConfig = new InverseGiftConfig { Gift = new List { new GiftConfig { Message = "{player}:女士们先生们!一起来看流星雨!", Rarity = 2, Items = new List { new ItemConfig { Name = "Meteor" } } }, new GiftConfig { Rarity = 5, Items = new List { new ItemConfig { Name = "GoldBar", Value = "1000-9999" } }, Message = "{player}:找到了价值连城的传世宝藏!({values} 元)" }, new GiftConfig { Rarity = 1, Items = new List { new ItemConfig { Name = "Candy", Value = "999" } } }, new GiftConfig { Rarity = 10, Items = new List { new ItemConfig { Name = "Key" } } }, new GiftConfig { Rarity = 5, Items = new List { new ItemConfig { Name = "Turret" } } }, new GiftConfig { Rarity = 5, Items = new List { new ItemConfig { Name = "Landmine" } } }, new GiftConfig { Rarity = 10, Items = new List { new ItemConfig { Name = "Nutcracker" } } }, new GiftConfig { Rarity = 10, Items = new List { new ItemConfig { Name = "HoarderBug" } } }, new GiftConfig { Rarity = 30 } }, Items = new List { new ItemConfig { Name = "GiftBox", Count = "1" }, new ItemConfig { Name = "Shovel", Count = "1" }, new ItemConfig { Name = "ProFlashlight", Count = "1" } } }; NormalizeConfig(); File.WriteAllText(config, SerializeHelper.YamlSerialize(InverseConfig)); ManualLog.LogInfo((object)"Init InverseConfig"); return; } try { InverseConfig = SerializeHelper.YamlDeserialize(File.ReadAllText(config)); NormalizeConfig(); ManualLog.LogInfo((object)$"Load InverseConfig Success(Items:{InverseConfig.Items.Count})"); } catch (Exception ex) { ManualLog.LogError((object)("Load Config Fail -> " + ex.ToString())); InverseConfig = new InverseGiftConfig(); NormalizeConfig(); } } private static void NormalizeConfig() { if (InverseConfig == null) { InverseConfig = new InverseGiftConfig(); } if (InverseConfig.Items == null) { InverseConfig.Items = new List(); } if (InverseConfig.Gift == null) { InverseConfig.Gift = new List(); } } public static void LogInfo(object data) { ManualLog.LogInfo((object)$"{data}"); } } public static class Patches { [CompilerGenerated] private sealed class d__13 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; private Exception 5__1; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__13(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { 5__1 = null; <>1__state = -2; } private bool MoveNext() { //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; break; case 1: <>1__state = -1; break; } try { doCheckForChanges(); } catch (Exception ex) { 5__1 = ex; InverseGiftPlugin.LogInfo($"Exception in coroutine: {5__1}"); } <>2__current = (object)new WaitForSeconds(5f); <>1__state = 1; return true; } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } private static DateTime _lastModifiedTime; private static FileInfo _fileInfo; private static Coroutine checkForChangesCoroutine; private static GameObjectRegistry ObjectRegistry { get; set; } private static List GiftInstanceIds { get; set; } = new List(); [HarmonyPostfix] [HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")] [HarmonyWrapSafe] public static void ConnectClientToPlayerObjectPostfix(PlayerControllerB __instance) { if (((NetworkBehaviour)StartOfRound.Instance).IsHost && checkForChangesCoroutine == null) { _fileInfo = new FileInfo(InverseGiftPlugin.config); _lastModifiedTime = _fileInfo.LastWriteTime; checkForChangesCoroutine = ((MonoBehaviour)__instance).StartCoroutine(CheckForChanges()); } } [HarmonyPrefix] [HarmonyPatch(typeof(GameNetworkManager), "Disconnect")] [HarmonyWrapSafe] public static void OnDestroy(PlayerControllerB __instance) { if (checkForChangesCoroutine != null) { ((MonoBehaviour)__instance).StopCoroutine(checkForChangesCoroutine); checkForChangesCoroutine = null; } ObjectRegistry = null; } [IteratorStateMachine(typeof(d__13))] private static IEnumerator CheckForChanges() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__13(0); } private static void doCheckForChanges() { _fileInfo.Refresh(); if (_fileInfo.LastWriteTime > _lastModifiedTime) { _lastModifiedTime = _fileInfo.LastWriteTime; InverseGiftPlugin.LogInfo("Config file changed, reloading..."); InverseGiftPlugin.LoadConfig(); } } private static GameObjectRegistry EnsureObjectRegistry() { if (ObjectRegistry != null) { return ObjectRegistry; } ObjectRegistry = GameObjectRegistry.Build(); string path = Utility.CombinePaths(new string[2] { Paths.ConfigPath, "chuxia.InverseGiftItems.txt" }); File.WriteAllText(path, ObjectRegistry.ToExportText()); return ObjectRegistry; } private static bool TryResolveObjectName(string objectName, out string resolvedName) { resolvedName = GameObjectRegistry.NormalizeName(objectName); if (string.IsNullOrEmpty(resolvedName)) { return false; } GameObjectRegistry gameObjectRegistry = EnsureObjectRegistry(); return !gameObjectRegistry.IsRandomKey(resolvedName) || gameObjectRegistry.TryGetRandomName(resolvedName, out resolvedName); } [HarmonyPatch(typeof(ShipTeleporter), "TeleportPlayerOutWithInverseTeleporter")] [HarmonyPostfix] [HarmonyWrapSafe] public static void Postfix(Vector3 teleportPos) { //IL_009b: 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_009d: Unknown result type (might be due to invalid IL or missing references) if (!((NetworkBehaviour)StartOfRound.Instance).IsHost) { return; } GameObjectRegistry gameObjectRegistry = EnsureObjectRegistry(); foreach (ItemConfig item in InverseGiftPlugin.InverseConfig.Items) { if (item == null || string.IsNullOrWhiteSpace(item.Name) || !TryResolveObjectName(item.Name, out var resolvedName)) { continue; } if (gameObjectRegistry.TryGet(resolvedName, out var gameObject)) { int num = ConfigValueParser.ParseCount(item, "Count Parse Error"); for (int i = 0; i < num; i++) { string Value = "0"; SpawnObject(gameObject, teleportPos, teleportPos, teleportPos, ref Value); } } else { InverseGiftPlugin.ManualLog.LogInfo((object)("InverseConfig Error -> Items: " + item.Name + " ConvertGameObjectFail.")); } } } [HarmonyPatch(typeof(GiftBoxItem), "OpenGiftBoxServerRpc")] [HarmonyPrefix] [HarmonyWrapSafe] public static bool OpenGiftBoxServerRpc(GiftBoxItem __instance) { //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Expected O, but got Unknown //IL_02ca: Unknown result type (might be due to invalid IL or missing references) //IL_02d1: Unknown result type (might be due to invalid IL or missing references) //IL_02d6: Unknown result type (might be due to invalid IL or missing references) //IL_02de: Unknown result type (might be due to invalid IL or missing references) //IL_02e3: Unknown result type (might be due to invalid IL or missing references) //IL_02e5: Unknown result type (might be due to invalid IL or missing references) //IL_02ea: Unknown result type (might be due to invalid IL or missing references) //IL_02ec: Unknown result type (might be due to invalid IL or missing references) //IL_0312: Unknown result type (might be due to invalid IL or missing references) //IL_0303: Unknown result type (might be due to invalid IL or missing references) //IL_0308: Unknown result type (might be due to invalid IL or missing references) //IL_033b: Unknown result type (might be due to invalid IL or missing references) //IL_0340: Unknown result type (might be due to invalid IL or missing references) //IL_032c: Unknown result type (might be due to invalid IL or missing references) //IL_0331: Unknown result type (might be due to invalid IL or missing references) //IL_0344: Unknown result type (might be due to invalid IL or missing references) //IL_034c: Unknown result type (might be due to invalid IL or missing references) //IL_0357: Unknown result type (might be due to invalid IL or missing references) if (((NetworkBehaviour)StartOfRound.Instance).IsHost && !GiftInstanceIds.Contains(((Object)__instance).GetInstanceID())) { if (GiftInstanceIds.Count > 20) { GiftInstanceIds.Clear(); } GiftInstanceIds.Add(((Object)__instance).GetInstanceID()); AccessTools.DeclaredField(typeof(GiftBoxItem), "objectInPresent").SetValue(__instance, null); PlayerControllerB val = (PlayerControllerB)AccessTools.DeclaredField(typeof(GiftBoxItem), "previousPlayerHeldBy").GetValue(__instance); if (!val.isInsideFactory) { return true; } GameObjectRegistry gameObjectRegistry = EnsureObjectRegistry(); GiftConfig randomGiftNormalized = GetRandomGiftNormalized(InverseGiftPlugin.InverseConfig); InverseGiftPlugin.LogInfo($"{val?.playerUsername}|OpenGift|{randomGiftNormalized.Rarity}"); List list = new List(); Dictionary valueMap = new Dictionary(StringComparer.OrdinalIgnoreCase); Dictionary countMap = new Dictionary(StringComparer.OrdinalIgnoreCase); List list2 = new List(); List list3 = new List(); if (randomGiftNormalized.Items == null || randomGiftNormalized.Items.Count == 0) { randomGiftNormalized.Items = new List(); } NavMeshHit val4 = default(NavMeshHit); foreach (ItemConfig item in randomGiftNormalized.Items) { if (item == null || string.IsNullOrWhiteSpace(item.Name)) { continue; } string text = GameObjectRegistry.NormalizeName(item.Name); string Value = item.Value; int num = ConfigValueParser.ParseCount(item, "InverseGift SetCount Error"); string text2 = item.Name?.Trim(); for (int i = 0; i < num; i++) { string resolvedName = text; if (!CustomGiftEvents.TryHandle(text, new GiftEventContext { Value = Value, Count = num, Player = val, GiftBox = __instance, Registry = gameObjectRegistry, SpawnObject = SpawnObject }) && TryResolveObjectName(resolvedName, out resolvedName) && !string.IsNullOrWhiteSpace(resolvedName)) { if (gameObjectRegistry.TryGet(resolvedName, out var gameObject)) { list.Add(resolvedName); float num2 = (float)i * (360f / (float)num); float num3 = num2 * ((float)Math.PI / 180f); float valueOrDefault = item.radius.GetValueOrDefault(0.5f); Vector3 val2 = new Vector3(Mathf.Cos(num3), 0f, Mathf.Sin(num3)) * valueOrDefault; Vector3 val3 = ((Component)__instance).transform.position + val2; SpawnObject(pos: NavMesh.SamplePosition(val3, ref val4, 5f, -1) ? ((NavMeshHit)(ref val4)).position : ((!NavMesh.SamplePosition(((Component)__instance).transform.position, ref val4, 10f, -1)) ? ((Component)__instance).transform.position : ((NavMeshHit)(ref val4)).position), spawn: gameObject, itempos: ((Component)__instance).transform.position, playerPos: ((Component)val).transform.position, Value: ref Value); } else { InverseGiftPlugin.ManualLog.LogInfo((object)("InverseConfig Error -> Item: " + text + " ConvertGameObjectFail.")); } if (!string.IsNullOrEmpty(text2)) { valueMap[text2] = Value ?? "0"; } list2.Add(Value ?? "0"); } } if (!string.IsNullOrEmpty(text2)) { countMap[text2] = num; } list3.Add(num); } if (!string.IsNullOrWhiteSpace(randomGiftNormalized.Message)) { InverseGiftPlugin.LogInfo("Gift Message -> " + randomGiftNormalized.Message); string message = randomGiftNormalized.Message; message = message.Replace("{player}", val.playerUsername); message = message.Replace("{result}", string.Join("、", list)); message = message.Replace("{values}", list2.Sum((string x) => decimal.Parse(x)).ToString("0")); message = message.Replace("{counts}", list3.Sum((int x) => x).ToString("0")); message = Regex.Replace(message, "\\{value:(.+?)\\}", delegate(Match match) { string key2 = match.Groups[1].Value.Trim(); string value2; return valueMap.TryGetValue(key2, out value2) ? value2 : ""; }); message = Regex.Replace(message, "\\{count:(.+?)\\}", delegate(Match match) { string key = match.Groups[1].Value.Trim(); int value; return countMap.TryGetValue(key, out value) ? value.ToString() : "0"; }); InverseGiftPlugin.LogInfo("Final Message -> " + message); HUDManager.Instance.AddTextToChatOnServer(message, -1); } return true; } return true; } public static GiftConfig GetRandomGiftNormalized(InverseGiftConfig config) { if (config?.Gift == null || config.Gift.Count == 0) { throw new ArgumentException("Gift configuration is null or empty"); } int num = config.Gift.Sum((GiftConfig g) => g.Rarity); if (num <= 0) { throw new ArgumentException("Total Rarity must be positive"); } int num2 = Random.Range(1, num + 1); int num3 = 0; foreach (GiftConfig item in config.Gift) { num3 += item.Rarity; if (num2 <= num3) { return item; } } return config.Gift.Last(); } public static void SpawnObject(GameObject spawn, Vector3 pos, Vector3 itempos, Vector3 playerPos, ref string Value) { //IL_0017: 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_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_0056: 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_007a: Unknown result type (might be due to invalid IL or missing references) //IL_021d: Unknown result type (might be due to invalid IL or missing references) //IL_021e: Unknown result type (might be due to invalid IL or missing references) //IL_026d: Unknown result type (might be due to invalid IL or missing references) //IL_0273: Unknown result type (might be due to invalid IL or missing references) //IL_0279: Unknown result type (might be due to invalid IL or missing references) //IL_0284: Unknown result type (might be due to invalid IL or missing references) //IL_0285: Unknown result type (might be due to invalid IL or missing references) //IL_028f: Unknown result type (might be due to invalid IL or missing references) //IL_0294: Unknown result type (might be due to invalid IL or missing references) //IL_0299: Unknown result type (might be due to invalid IL or missing references) //IL_029c: Unknown result type (might be due to invalid IL or missing references) //IL_029d: Unknown result type (might be due to invalid IL or missing references) //IL_02c8: Unknown result type (might be due to invalid IL or missing references) //IL_031e: Unknown result type (might be due to invalid IL or missing references) //IL_02ee: Unknown result type (might be due to invalid IL or missing references) //IL_02ef: Unknown result type (might be due to invalid IL or missing references) //IL_02f0: Unknown result type (might be due to invalid IL or missing references) //IL_02f5: Unknown result type (might be due to invalid IL or missing references) //IL_02f9: Unknown result type (might be due to invalid IL or missing references) GrabbableObject val = default(GrabbableObject); EnemyAI val3 = default(EnemyAI); NetworkObject val5 = default(NetworkObject); if (spawn.TryGetComponent(ref val)) { GameObject val2 = Object.Instantiate(spawn, RoundManager.Instance.GetRandomNavMeshPositionInBoxPredictable(pos, 1f, RoundManager.Instance.navHit, RoundManager.Instance.AnomalyRandom, -1, 1f) + Vector3.up * val.itemProperties.verticalOffset, Quaternion.identity, (Transform)null); GrabbableObject component = val2.GetComponent(); ((Component)component).transform.rotation = Quaternion.Euler(component.itemProperties.restingRotation); component.fallTime = 0f; component.isInFactory = true; if (Value != null) { if (int.TryParse(Value, out var result)) { component.SetScrapValue(result); } else if (Value.Contains("-")) { string[] array = Value.Split(new char[1] { '-' }); string text = array[0]; string text2 = array[1]; if (int.TryParse(text, out var result2) && int.TryParse(text2, out var result3) && result2 < result3) { Random.InitState(Guid.NewGuid().GetHashCode()); int scrapValue = Random.Range(result2, result3 + 1); component.SetScrapValue(scrapValue); Value = scrapValue.ToString(); } else { InverseGiftPlugin.ManualLog.LogInfo((object)("InverseGift SetValue Error -> Gift: " + ((Object)spawn).name + " | Value1: " + text + " | Value2: " + text2 + ".")); } } else { InverseGiftPlugin.ManualLog.LogInfo((object)("InverseGift SetValue Error -> Gift: " + ((Object)spawn).name + " | Value: " + Value + ".")); component.SetScrapValue(0); } } ((NetworkBehaviour)component).NetworkObject.Spawn(false); } else if (spawn.TryGetComponent(ref val3)) { GameObject val4 = Object.Instantiate(spawn, pos, Quaternion.identity); EnemyAI component2 = val4.GetComponent(); ((Component)component2).GetComponentInChildren().Spawn(true); RoundManager.Instance.SpawnedEnemies.Add(component2); } else if (spawn.TryGetComponent(ref val5)) { ((Vector3)(ref pos))..ctor(pos.x, itempos.y, pos.z); pos -= Vector3.up * 1.8f; GameObject val6 = Object.Instantiate(spawn, pos, Quaternion.identity, RoundManager.Instance.mapPropsContainer.transform); NetworkObject component3 = val6.GetComponent(); ((Component)component3).transform.position = pos; if (((Object)component3).name == "TurretContainer") { Transform transform = ((Component)component3).transform; Vector3 val7 = playerPos - pos; transform.forward = ((Vector3)(ref val7)).normalized; } else { ((Component)component3).transform.forward = new Vector3(1f, 0f, 0f); } ((Component)component3).GetComponent().Spawn(true); } } } public static class SerializeHelper { public static string YamlSerialize(object obj) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) ISerializer val = new SerializerBuilder().ConfigureDefaultValuesHandling((DefaultValuesHandling)1).Build(); return val.Serialize(obj); } public static T YamlDeserialize(string input) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) try { IDeserializer val = new DeserializerBuilder().Build(); return val.Deserialize(input); } catch (Exception ex) { InverseGiftPlugin.ManualLog.LogError((object)ex.ToString()); return default(T); } } }