static public bool Prefix(Spellbook __instance, ref bool __result, BlueprintAbility blueprint, AbilityData spell, bool doSpend, bool excludeSpecial, ref int[] ___m_SpontaneousSlots, ref int?___m_MaxSpellLevel)
        {
            if (__instance.Blueprint.CharacterClass != ArcanistClass.arcanist)
            {
                return(true);
            }
            UnitDescriptor unit = __instance.Owner;

            if (doSpend && spell == null)
            {
                UberDebug.LogError("Trying to spend ability without specfying instance", Array.Empty <object>());
                __result = false;
                return(false);
            }
            int num = (!(spell != null)) ? __instance.GetSpellLevel(blueprint) : __instance.GetSpellLevel(spell);

            //Main.logger.Log($"spell={spell.Name},num={num}");
            if (num < 0)
            {
                //Main.logger.Log("Return FALSE");
                __result = false;
                return(false);
            }
            int?maxSpellLevel = ___m_MaxSpellLevel;

            if (maxSpellLevel != null && num >= ___m_MaxSpellLevel)
            {
                __result = false;
                return(false);
            }
            int num2 = __instance.Owner.Stats.GetStat(__instance.Blueprint.CastingAttribute);

            if (num2 < 10 + num)
            {
                __result = false;
                return(false);
            }



            List <SpellSlot> list = SureMemorizedSpellsBelowAndK(__instance, num);

            for (int i = list.Count - 1; i >= 0; i--)
            {
                SpellSlot spellSlot = list[i];
                //Main.logger.Log($"In spellslot {i}, named {(spellSlot.Spell == null ? "null" : spellSlot.Spell.Name)}"); ;
                int num3 = ___m_SpontaneousSlots[num];

                if (spellSlot.Available && (num3 > 0 || (num3 == 0 && !doSpend)))
                {
                    //Main.logger.Log("DUA 1");
                    if (spellSlot.Type != SpellSlotType.Favorite || !excludeSpecial)
                    {
                        // Main.logger.Log("DUA 2");
                        if (spell != null && spellSlot.Spell != null)
                        {
                            //Main.logger.Log("Rua !");
                            int spellMeta = spell.MetamagicData == null ? 0 : (int)spell.MetamagicData.MetamagicMask;
                            //Main.logger.Log($"spellMeta is {spellMeta}");
                            int slotSpellMeta = spellSlot.Spell.MetamagicData == null ? 0 : (int)spellSlot.Spell.MetamagicData.MetamagicMask;
                            //Main.logger.Log($"slotspellMeta is {slotSpellMeta}");
                            bool flag = ((spellMeta | slotSpellMeta) == spellMeta);//metamagic of spellSlot.Spell is a subset of metamagic of spell.
                            if (spell.Blueprint.Equals(spellSlot.Spell.Blueprint) && flag)
                            {
                                if (doSpend)
                                {
                                    ___m_SpontaneousSlots[num] = num3 - 1;
                                }
                                //Main.logger.Log($"RUA");
                                __result = true;
                                return(false);
                            }
                        }
                        else if (spell == null)
                        {
                            AbilityData spell2 = spellSlot.Spell;
                            //Main.logger.Log($"RUA1");
                            if (blueprint == ((spell2 != null) ? spell2.Blueprint : null))
                            {
                                //Main.logger.Log($"RUA1.2");
                                __result = true;
                                return(false);
                            }
                        }
                    }
                }
            }
            //Main.logger.Log("Dua???");
            __result = false;
            return(false);
        }