Exemplo n.º 1
0
        public static void RerollTowers()
        {
            if (towerNames.Length == 0)
            {
                SetTowerNames();
            }
            if (towerButtons == null || towerButtons.Length == 0 || currentInventory != InGame.instance.GetTowerInventory())
            {
                towerButtons     = ShopMenu.instance.towerButtons.GetComponentsInChildren <TowerPurchaseButton>();
                currentInventory = InGame.instance.GetTowerInventory();
            }

            int numberOfRandomTowers        = MelonPreferences.GetEntryValue <int>(preferencesCategoryIdentifier, "NumberOfRandomTowers");
            Il2CppStringArray enabledTowers = new Il2CppStringArray(towerNames.OrderBy(x => random.Next()).Take(Math.Max(Math.Min(numberOfRandomTowers, towerNames.Length), 0)).ToArray());

            foreach (var purchaseButton in Main.towerButtons)
            {
                if (enabledTowers.Contains(purchaseButton.baseTowerModel.name))
                {
                    purchaseButton.transform.parent.gameObject.SetActive(true);
                }
                else
                {
                    purchaseButton.transform.parent.gameObject.SetActive(false);
                }
            }
        }
Exemplo n.º 2
0
 internal static void Postfix(Bloon __instance, float totalAmount, Il2CppStringArray types,
                              Projectile projectile, bool distributeToChildren, bool overrideDistributeBlocker, bool createEffect,
                              Tower tower, Il2CppStringArray ignoreImmunityForBloonTypes, bool ignoreNonTargetable = false,
                              bool blockSpawnChildren = false, bool canDestroyProjectile = true)
 {
     MelonMain.DoPatchMethods(mod =>
     {
         mod.PostBloonDamaged(__instance, totalAmount, types, projectile, distributeToChildren,
                              overrideDistributeBlocker, createEffect, tower, ignoreImmunityForBloonTypes,
                              ignoreNonTargetable, blockSpawnChildren, canDestroyProjectile);
     });
 }
Exemplo n.º 3
0
 public static void Prefix(Bloon __instance, float amount, Il2CppStringArray types, Projectile projectile, bool distributeToChildren, bool overrideDistributeBlocker, bool createEffect, Tower tower, bool blockSpawnChildren)
 {
     if (projectile != null)
     {
         var proj = projectile.projectileModel;
         if (proj.HasBehavior <ShowTextOnHitModel>() && proj.HasBehavior <DamageModel>())
         {
             proj.GetBehavior <ShowTextOnHitModel>().text = amount + "";
         }
         else
         {
             proj.AddBehavior(new ShowTextOnHitModel("", "3dcdbc19136c60846ab944ada06695c0", 3f, false, amount + ""));
         }
     }
 }
Exemplo n.º 4
0
        static TestClass()
        {
            for (int i = 0; i < BigList.Capacity; i++)
            {
                BigList.Add(i.ToString());
            }

#if CPP
            IL2CPP_Dict = new Il2CppSystem.Collections.Generic.Dictionary <string, string>();
            IL2CPP_Dict.Add("key1", "value1");
            IL2CPP_Dict.Add("key2", "value2");
            IL2CPP_Dict.Add("key3", "value3");

            IL2CPP_HashTable = new Il2CppSystem.Collections.Hashtable();
            IL2CPP_HashTable.Add("key1", "value1");
            IL2CPP_HashTable.Add("key2", "value2");
            IL2CPP_HashTable.Add("key3", "value3");

            var dict2 = new Il2CppSystem.Collections.Generic.Dictionary <string, string>();
            dict2.Add("key1", "value1");
            IL2CPP_IDict = dict2.TryCast <Il2CppSystem.Collections.IDictionary>();

            var list = new Il2CppSystem.Collections.Generic.List <Il2CppSystem.Object>(5);
            list.Add("one");
            list.Add("two");
            IL2CPP_IList = list.TryCast <Il2CppSystem.Collections.IList>();

            IL2CPP_ListString = new Il2CppSystem.Collections.Generic.List <string>();
            IL2CPP_ListString.Add("hello,");
            IL2CPP_ListString.Add("world!");

            IL2CPP_HashSet = new Il2CppSystem.Collections.Generic.HashSet <string>();
            IL2CPP_HashSet.Add("one");
            IL2CPP_HashSet.Add("two");

            CppBoxedDict = new Dictionary <Il2CppSystem.String, Il2CppSystem.Object>();
            CppBoxedDict.Add("1", new Il2CppSystem.Int32 {
                m_value = 1
            }.BoxIl2CppObject());
            CppBoxedDict.Add("2", new Il2CppSystem.Int32 {
                m_value = 2
            }.BoxIl2CppObject());
            CppBoxedDict.Add("3", new Il2CppSystem.Int32 {
                m_value = 3
            }.BoxIl2CppObject());
            CppBoxedDict.Add("4", new Il2CppSystem.Int32 {
                m_value = 4
            }.BoxIl2CppObject());

            cppDecimal      = new Il2CppSystem.Decimal(1f);
            cppDecimalBoxed = new Il2CppSystem.Decimal(1f).BoxIl2CppObject();
            cppVector3Boxed = Vector3.down.BoxIl2CppObject();


            IL2CPP_listOfBoxedObjects = new List <Il2CppSystem.Object>();
            IL2CPP_listOfBoxedObjects.Add((Il2CppSystem.String) "boxedString");
            IL2CPP_listOfBoxedObjects.Add(new Il2CppSystem.Int32 {
                m_value = 5
            }.BoxIl2CppObject());
            IL2CPP_listOfBoxedObjects.Add(Color.red.BoxIl2CppObject());

            try
            {
                var cppType = Il2CppType.Of <CameraClearFlags>();
                if (cppType != null)
                {
                    var boxedEnum = Il2CppSystem.Enum.Parse(cppType, "Color");
                    IL2CPP_listOfBoxedObjects.Add(boxedEnum);
                }

                var structBox = Vector3.one.BoxIl2CppObject();
                IL2CPP_listOfBoxedObjects.Add(structBox);
            }
            catch (Exception ex)
            {
                ExplorerCore.LogWarning($"Test fail: {ex}");
            }

            IL2CPP_structArray    = new UnhollowerBaseLib.Il2CppStructArray <int>(5);
            IL2CPP_structArray[0] = 0;
            IL2CPP_structArray[1] = 1;
            IL2CPP_structArray[2] = 2;
            IL2CPP_structArray[3] = 3;
            IL2CPP_structArray[4] = 4;

            IL2CPP_stringArray    = new UnhollowerBaseLib.Il2CppStringArray(2);
            IL2CPP_stringArray[0] = "hello, ";
            IL2CPP_stringArray[1] = "world!";

            IL2CPP_ReferenceArray    = new UnhollowerBaseLib.Il2CppReferenceArray <Il2CppSystem.Object>(3);
            IL2CPP_ReferenceArray[0] = new Il2CppSystem.Int32 {
                m_value = 5
            }.BoxIl2CppObject();
            IL2CPP_ReferenceArray[1] = null;
            IL2CPP_ReferenceArray[2] = (Il2CppSystem.String) "whats up";

            cppBoxedInt = new Il2CppSystem.Int32()
            {
                m_value = 5
            }.BoxIl2CppObject();
            cppInt = new Il2CppSystem.Int32 {
                m_value = 420
            };

            cppHashset = new Il2CppSystem.Collections.Hashtable();
            cppHashset.Add("key1", "itemOne");
            cppHashset.Add("key2", "itemTwo");
            cppHashset.Add("key3", "itemThree");
#endif
        }
Exemplo n.º 5
0
            public Value(Type type, JToken value)
            {
                IsNone = value == null;

                @bool         = default;
                @byte         = default;
                @sbyte        = default;
                @short        = default;
                @ushort       = default;
                @int          = default;
                @uint         = default;
                @long         = default;
                @ulong        = default;
                @char         = default;
                @double       = default;
                @float        = default;
                @string       = IL2CPP.ManagedStringToIl2Cpp("");
                intArray      = default;
                stringArray   = default;
                float2DArray  = default;
                int2DArray    = default;
                string2DArray = default;

                if (type == typeof(string))
                {
                    tag = ValueType.String;
                    if (value == null)
                    {
                        return;
                    }
                    // FIXME:
                    //  The purpose of intern is to prevent GC from freeing our string to avoid UAF.
                    //  But intern will run into some performance problems sometimes.
                    //  Maybe making a reference circle is another solution.
                    @string = Il2CppHelper.il2cpp_string_intern(
                        IL2CPP.ManagedStringToIl2Cpp(value.Value <string>()));
                }
                else if (type == typeof(bool))
                {
                    tag = ValueType.Boolean;
                    if (value == null)
                    {
                        return;
                    }
                    @bool = value.Value <bool>();
                }
                else if (type == typeof(byte))
                {
                    tag = ValueType.Byte;
                    if (value == null)
                    {
                        return;
                    }
                    @byte = value.Value <byte>();
                }
                else if (type == typeof(sbyte))
                {
                    tag = ValueType.SByte;
                    if (value == null)
                    {
                        return;
                    }
                    @sbyte = value.Value <sbyte>();
                }
                else if (type == typeof(short))
                {
                    tag = ValueType.Int16;
                    if (value == null)
                    {
                        return;
                    }
                    @short = value.Value <short>();
                }
                else if (type == typeof(ushort))
                {
                    tag = ValueType.UInt16;
                    if (value == null)
                    {
                        return;
                    }
                    @ushort = value.Value <ushort>();
                }
                else if (type == typeof(int))
                {
                    tag = ValueType.Int32;
                    if (value == null)
                    {
                        return;
                    }
                    @int = value.Value <int>();
                }
                else if (type == typeof(uint))
                {
                    tag = ValueType.UInt32;
                    if (value == null)
                    {
                        return;
                    }
                    @uint = value.Value <uint>();
                }
                else if (type == typeof(long))
                {
                    tag = ValueType.Int64;
                    if (value == null)
                    {
                        return;
                    }
                    @long = value.Value <long>();
                }
                else if (type == typeof(ulong))
                {
                    tag = ValueType.UInt64;
                    if (value == null)
                    {
                        return;
                    }
                    @ulong = value.Value <ulong>();
                }
                else if (type == typeof(char))
                {
                    tag = ValueType.Char;
                    if (value == null)
                    {
                        return;
                    }
                    @char = value.Value <char>();
                }
                else if (type == typeof(double))
                {
                    tag = ValueType.Double;
                    if (value == null)
                    {
                        return;
                    }
                    @double = value.Value <double>();
                }
                else if (type == typeof(float))
                {
                    tag = ValueType.Single;
                    if (value == null)
                    {
                        return;
                    }
                    @float = value.Value <float>();
                }
                else if (type == typeof(Il2CppStructArray <int>))
                {
                    tag = ValueType.IntArray;
                    if (value == null)
                    {
                        return;
                    }
                    var arr = value.Value <JArray>().Select(t => t.Value <int>()).ToArray();
                    intArray = arr;
                }
                else if (type == typeof(Il2CppStringArray))
                {
                    tag = ValueType.StringArray;
                    if (value == null)
                    {
                        return;
                    }
                    var arr = value.Value <JArray>().Select(t => t.Value <string>()).ToArray();
                    stringArray = arr;
                }
                else if (type == typeof(Il2CppReferenceArray <Il2CppStructArray <float> >))
                {
                    tag = ValueType.Float2DArray;
                    if (value == null)
                    {
                        return;
                    }
                    var arr = value.Value <JArray>()
                              .Select(t =>
                    {
                        Il2CppStructArray <float> arr2 = t.Value <JArray>()
                                                         .Select(t2 => t2.Value <float>())
                                                         .ToArray();
                        return(arr2);
                    })
                              .ToArray();
                    float2DArray = arr;
                }
                else if (type == typeof(Il2CppReferenceArray <Il2CppStructArray <int> >))
                {
                    tag = ValueType.Int2DArray;
                    if (value == null)
                    {
                        return;
                    }
                    var arr = value.Value <JArray>()
                              .Select(t =>
                    {
                        Il2CppStructArray <int> arr2 = t.Value <JArray>()
                                                       .Select(t2 => t2.Value <int>())
                                                       .ToArray();
                        return(arr2);
                    })
                              .ToArray();
                    int2DArray = arr;
                }
                else if (type == typeof(Il2CppReferenceArray <Il2CppStringArray>))
                {
                    tag = ValueType.String2DArray;
                    if (value == null)
                    {
                        return;
                    }
                    var arr = value.Value <JArray>()
                              .Select(t =>
                    {
                        Il2CppStringArray arr2 = t.Value <JArray>()
                                                 .Select(t2 => t2.Value <string>())
                                                 .ToArray();
                        return(arr2);
                    })
                              .ToArray();
                    string2DArray = arr;
                }
                else
                {
                    throw new NotSupportedException($"Type {type} is not supported");
                }
            }
Exemplo n.º 6
0
        private void LoadVanillaRegistries()
        {
            LobbyOptionsInitializer.RegisterAll();

            //Kill distances
            Il2CppStructArray <float> OldDistancesArray() => OEFJGMAEENB.JFMGLFCHLKK;
            Il2CppStringArray OldNamesArray() => OEFJGMAEENB.GCBCGFCMMMI;

            for (var i = 0; i < Math.Min(OldDistancesArray().Count, OldNamesArray().Count); i++)
            {
                var key      = new RegistryKey("AmongUs", OldNamesArray()[i]);
                var distance = new KillDistance(OldDistancesArray()[i])
                {
                    Key = key
                };
                KillDistances[i] = distance;
                ReverseKillDistances[distance] = i;
                KillDistance.Registry[key]     = distance;
            }

            Registrar <KillDistance> .OnRegister += (key, distance) =>
            {
                var newSize        = Math.Min(OldDistancesArray().Count, OldNamesArray().Count);
                var distancesArray = new Il2CppStructArray <float>(newSize + 1);
                var namesArray     = new Il2CppStringArray(newSize + 1);

                for (var i = 0; i < newSize; i++)
                {
                    distancesArray[i] = OldDistancesArray()[i];
                    namesArray[i]     = OldNamesArray()[i];
                }

                distancesArray[newSize] = distance.Value;
                namesArray[newSize]     = Language.Translate(key.ModId, key.Name);

                KillDistances[newSize]         = distance;
                ReverseKillDistances[distance] = newSize;

                OEFJGMAEENB.JFMGLFCHLKK = distancesArray;
                OEFJGMAEENB.GCBCGFCMMMI = namesArray;
            };

            //Tasks
            for (var i = 0; i <= _lastTaskId; i++)
            {
                var originalTask = (CANPENMJFOD)i;
                var key          = new RegistryKey("AmongUs", originalTask.ToString());
                var taskType     = new TaskType {
                    Key = key
                };
                TaskType.Registry[key]  = taskType;
                TaskTypes[originalTask] = taskType;
            }

            Registrar <TaskType> .OnRegister += (key, type) => TaskTypes[(CANPENMJFOD)(++_lastTaskId)] = type;

            //Maps
            for (var i = 0; i <= _lastMapId; i++)
            {
                var originalMap = (DAFPFFMKPJJ.DFCBBBIBKKC)i;
                var key         = new RegistryKey("AmongUs", originalMap.ToString());
                var gameMap     = new GameMap {
                    Key = key
                };
                GameMap.Registry[key]    = gameMap;
                MapTypes[originalMap]    = gameMap;
                ReverseMapTypes[gameMap] = i;
            }

            Registrar <GameMap> .OnRegister += (key, map) =>
            {
                var count    = OEFJGMAEENB.JAKFIOPEFBI.Count;
                var mapNames = new Il2CppStringArray(count);

                for (var i = 0; i < count; i++)
                {
                    mapNames[i] = OEFJGMAEENB.JAKFIOPEFBI[i];
                }

                mapNames[count] = Language.Translate(key.ModId, key.Name);

                OEFJGMAEENB.JAKFIOPEFBI = mapNames;
                MapTypes[(DAFPFFMKPJJ.DFCBBBIBKKC)(++_lastMapId)] = map;
                ReverseMapTypes[map] = _lastMapId;
            };
        }
Exemplo n.º 7
0
 /// <summary>
 /// Called right after a Bloon is damaged
 ///
 /// Equivalent to a HarmonyPostFix on Bloon.Damaged
 /// </summary>
 public virtual void PostBloonDamaged(Bloon bloon, float totalAmount, Il2CppStringArray types,
                                      Projectile projectile, bool distributeToChildren, bool overrideDistributeBlocker, bool createEffect,
                                      Tower tower, Il2CppStringArray ignoreImmunityForBloonTypes, bool ignoreNonTargetable = false,
                                      bool blockSpawnChildren = false, bool canDestroyProjectile = true)
 {
 }