static public bool Prefix(ApplySpellbook __instance, LevelUpState state, UnitDescriptor unit)
        {
            if (state.SelectedClass != ArcanistClass.arcanist)
            {
                return(true);
            }

            if (state.SelectedClass == null)
            {
                return(false);
            }
            SkipLevelsForSpellProgression component = state.SelectedClass.GetComponent <SkipLevelsForSpellProgression>();

            if (component != null && component.Levels.Contains(state.NextClassLevel))
            {
                return(false);
            }
            ClassData classData = unit.Progression.GetClassData(state.SelectedClass);

            if (classData == null)
            {
                return(false);
            }
            if (classData.Spellbook != null)
            {
                Spellbook spellbook = unit.DemandSpellbook(classData.Spellbook);
                if (state.SelectedClass.Spellbook && state.SelectedClass.Spellbook != classData.Spellbook)
                {
                    Spellbook spellbook2 = unit.Spellbooks.FirstOrDefault((Spellbook s) => s.Blueprint == state.SelectedClass.Spellbook);
                    if (spellbook2 != null)
                    {
                        foreach (AbilityData abilityData in spellbook2.GetAllKnownSpells())
                        {
                            spellbook.AddKnown(abilityData.SpellLevel, abilityData.Blueprint, false);
                        }
                        unit.DeleteSpellbook(state.SelectedClass.Spellbook);
                    }
                }
                int casterLevel = spellbook.CasterLevel;
                spellbook.AddCasterLevel();
                int casterLevel2 = spellbook.CasterLevel;
                SpellSelectionData spellSelectionData = state.DemandSpellSelection(spellbook.Blueprint, spellbook.Blueprint.SpellList);
                if (spellbook.Blueprint.SpellsKnown != null && 1 == 0)
                {
                    // SelectedClass must be arcanist, arcanist requires wizard-like spell selection,
                    // while its SpellsKnown is not null
                    for (int i = 0; i <= 9; i++)
                    {
                        int?count  = spellbook.Blueprint.SpellsKnown.GetCount(casterLevel, i);
                        int num    = (count == null) ? 0 : count.Value;
                        int?count2 = spellbook.Blueprint.SpellsKnown.GetCount(casterLevel2, i);
                        int num2   = (count2 == null) ? 0 : count2.Value;
                        spellSelectionData.SetLevelSpells(i, num2 - num);
                    }
                }
                int maxSpellLevel = spellbook.MaxSpellLevel;
                if (spellbook.Blueprint.SpellsPerLevel > 0)
                {
                    if (casterLevel == 0)
                    {
                        spellSelectionData.SetExtraSpells(0, maxSpellLevel);
                        spellSelectionData.ExtraByStat = true;
                        spellSelectionData.UpdateMaxLevelSpells(unit);
                    }
                    else
                    {
                        spellSelectionData.SetExtraSpells(spellbook.Blueprint.SpellsPerLevel, maxSpellLevel);
                    }
                }
                foreach (AddCustomSpells customSpells in spellbook.Blueprint.GetComponents <AddCustomSpells>())
                {
                    ApplySpellbook_TryApplyCustomSpells(__instance, spellbook, customSpells, state, unit);
                }
            }
            return(false);
        }