public override Dictionary <string, object> LoadContent(SLPack pack, bool isHotReload)
        {
            var dir = pack.GetPathForCategory <PackBundleCategory>();

            if (!Directory.Exists(dir))
            {
                return(null);
            }

            foreach (var bundlePath in Directory.GetFiles(dir))
            {
                try
                {
                    SL.Log("Loading Pack AssetBundle: " + bundlePath);

                    var assetbundle = AssetBundle.LoadFromFile(bundlePath);

                    var bundlePack = new SLPackBundle(Path.GetFileName(bundlePath), pack, assetbundle);

                    pack.PackBundles.Add(bundlePack.Name, bundlePack);

                    s_loadedBundles.Add(bundlePath, bundlePack);

                    //SL.Log($"Added bundle '{bundlePack.Name}' to pack '{pack.Name}' (Bundle count: {pack.PackBundles.Count})");
                }
                catch (Exception ex)
                {
                    SL.LogWarning("Exception loading Pack Bundle: " + bundlePath);
                    SL.LogInnerException(ex);
                }
            }

            return(null);
        }
        // ~~~~~~~~~ Core internal ~~~~~~~~~

        internal static void OnSaveInstanceSave(SaveInstance __instance)
        {
            try
            {
                if (__instance.CharSave == null || string.IsNullOrEmpty(__instance.CharSave.CharacterUID))
                {
                    return;
                }

                var charUID = __instance.CharSave.CharacterUID;

                bool isHost = !PhotonNetwork.isNonMasterClientInRoom && !(bool)At.GetField(NetworkLevelLoader.Instance, "m_saveOnHostLost") &&
                              CharacterManager.Instance?.GetWorldHostCharacter()?.UID == charUID;

                // Save internal stuff for the host
                if (isHost)
                {
                    SLCharacterSaveManager.SaveCharacters();
                    SLItemSpawnSaveManager.SaveItemSpawns();
                }

                // Save custom extensions from other mods
                PlayerSaveExtension.SaveAllExtensions(CharacterManager.Instance.GetCharacter(charUID), isHost);
            }
            catch (Exception ex)
            {
                SL.LogWarning("Exception on SaveInstance.Save!");
                SL.LogInnerException(ex);
            }
        }
Example #3
0
        private IEnumerator WaitForSceneReady()
        {
            while (!NetworkLevelLoader.Instance.IsOverallLoadingDone || !NetworkLevelLoader.Instance.AllPlayerDoneLoading)
            {
                yield return(null);
            }

            try
            {
                foreach (var deployable in ItemManager.Instance.WorldItems.Values.Where(x => x.GetExtension("Deployable") != null))
                {
                    var comp = deployable.GetComponent <Deployable>();

                    if (comp.IsDeployed && comp.PackedStateItemPrefab == null)
                    {
                        AddDestroyInteraction(comp);
                    }
                }
            }
            catch (Exception ex)
            {
                SL.LogWarning("Exception applying Dismantler interactions");
                SL.LogInnerException(ex);
            }
        }
        public static void Postfix(Item __instance, ref string ___m_toLogString)
        {
            ___m_toLogString = Serializer.ReplaceInvalidChars(___m_toLogString);

            if (!SL.PacksLoaded)
            {
                return;
            }

            if (SL_Item.s_initCallbacks.TryGetValue(__instance.ItemID, out List <Action <Item> > invocationList))
            {
                foreach (var listener in invocationList)
                {
                    try
                    {
                        listener.Invoke(__instance);
                    }
                    catch (Exception e)
                    {
                        SL.LogWarning($"Exception invoking callback for Item.Start() on {__instance.Name}");
                        SL.LogInnerException(e);
                    }
                }
            }
        }
        public static void CheckTypeCache()
        {
            //SL.Log("Getting implementations of SLPackCategory in all assemblies...");
            var allTypes = At.GetImplementationsOf(typeof(SLPackCategory));

            if (allTypes.Count == s_lastTypeCount)
            {
                return;
            }

            s_lastTypeCount = allTypes.Count;

            var list = new List <SLPackCategory>();

            //var lateList = new List<SLPackCategory>();

            foreach (var type in allTypes)
            {
                try
                {
                    SLPackCategory ctg;
                    if (s_slPackCategories != null && s_slPackCategories.ContainsKey(type))
                    {
                        ctg = s_slPackCategories[type];
                    }
                    else
                    {
                        ctg = (SLPackCategory)At.TryCreateDefault(type);
                    }

                    if (ctg != null)
                    {
                        list.Add(ctg);
                        //if (ctg.HasLateContent)
                        //    lateList.Add(ctg);
                    }
                    else
                    {
                        SL.Log("SLPack categories internal: could not create instance of type '" + type.FullName + "'");
                    }
                }
                catch (Exception ex)
                {
                    SL.LogWarning("Exception checking SLPackCategory '" + type.FullName + "'");
                    SL.LogInnerException(ex);
                }
            }

            s_slPackCategories = new Dictionary <Type, SLPackCategory>();
            foreach (var instance in list.OrderBy(it => it.LoadOrder))
            {
                s_slPackCategories.Add(instance.GetType(), instance);
            }

            //s_slPackLateCategories = new Dictionary<Type, SLPackCategory>();
            //if (lateList.Any())
            //    foreach (var instance in lateList.OrderBy(it => it.LoadOrder))
            //        s_slPackLateCategories.Add(instance.GetType(), instance);
        }
        private void DeserializePack(SLPack pack, List <ContentTemplate> list)
        {
            try
            {
                var dict = new Dictionary <string, object>();

                var dirPath = pack.GetPathForCategory(this.GetType());

                if (!pack.DirectoryExists(dirPath))
                {
                    return;
                }

                // load root directory templates
                foreach (var filepath in pack.GetFiles(dirPath, ".xml"))
                {
                    DeserializeTemplate(dirPath, filepath);
                }

                // load one-subfolder templates
                foreach (var subDir in pack.GetDirectories(dirPath))
                {
                    foreach (var filepath in pack.GetFiles(subDir, ".xml"))
                    {
                        DeserializeTemplate(subDir, filepath, subDir);
                    }
                }

                AddToSLPackDictionary(pack, dict);

                void DeserializeTemplate(string directory, string filepath, string subfolder = null)
                {
                    //SL.Log($@"Deserializing template from '{directory}\{filepath}'");

                    var template = pack.ReadXmlDocument <T>(directory, Path.GetFileName(filepath));

                    dict.Add(filepath, template);
                    list.Add(template);

                    template.SerializedSLPackName = pack.Name;
                    template.SerializedFilename   = Path.GetFileNameWithoutExtension(filepath);

                    if (!string.IsNullOrEmpty(subfolder))
                    {
                        template.SerializedSubfolderName = Path.GetFileName(subfolder);
                    }
                }
            }
            catch (Exception ex)
            {
                SL.LogWarning("Exception loading " + this.FolderName + " from '" + pack.Name + "'");
                SL.LogInnerException(ex);
            }
        }
 private static void InvokeLateApplyListener(Action <object[]> listener, params object[] args)
 {
     try
     {
         listener.Invoke(args);
     }
     catch (Exception ex)
     {
         SL.LogWarning("Exception invoking OnLateApply listener!");
         SL.LogInnerException(ex);
     }
 }
Example #8
0
 public static void Postfix(Character _character)
 {
     try
     {
         PlayerSaveExtension.LoadExtensions(_character);
     }
     catch (Exception ex)
     {
         SL.LogWarning("Exception on loading SL PlayerSaveExtensions!");
         SL.LogInnerException(ex);
     }
 }
Example #9
0
            public static Exception Finalizer(Exception __exception)
            {
                if (__exception != null)
                {
                    SL.Log($"Exception on ResourcesPrefabManager.Load: {__exception.GetType().Name}, {__exception.Message}");
                    SL.LogInnerException(__exception);
                }

                SL.Setup();

                return(null);
            }
 private static void LoadPackCategory(List <SLPack> packs, SLPackCategory ctg, bool firstSetup)
 {
     try
     {
         ctg.InternalLoad(packs, !firstSetup);
     }
     catch (Exception ex)
     {
         SL.LogWarning($"Exception loading {ctg.FolderName}!");
         SL.LogInnerException(ex);
     }
 }
Example #11
0
 internal void SaveDataFromCharacter(Character character, bool isWorldHost)
 {
     try
     {
         Save(character, isWorldHost);
     }
     catch (Exception ex)
     {
         SL.LogWarning("Exception saving data from character: " + this.ToString());
         SL.LogInnerException(ex);
     }
 }
        protected internal override void InternalLoad(List <SLPack> packs, bool isHotReload)
        {
            if (AllCurrentTemplates.Count > 0)
            {
                AllCurrentTemplates.Clear();
            }

            var list = new List <ContentTemplate>();

            // Load SL packs first

            foreach (var pack in packs)
            {
                DeserializePack(pack, list);

                if (pack.PackBundles != null && pack.PackBundles.Count > 0)
                {
                    foreach (var bundle in pack.PackBundles.Values)
                    {
                        DeserializePack(bundle, list);
                    }
                }
            }

            // Load CSharp templates

            if (CSharpTemplates != null && CSharpTemplates.Any())
            {
                SL.Log(CSharpTemplates.Count + " registered C# templates found...");
                list.AddRange(CSharpTemplates);
            }

            list = TemplateDependancySolver.SolveDependencies(list);

            foreach (var template in list)
            {
                try
                {
                    ApplyTemplate(template);

                    Internal_AllCurrentTemplates.Add(template);
                }
                catch (Exception ex)
                {
                    SL.LogWarning("Exception applying template!");
                    SL.LogInnerException(ex);
                }
            }

            return;
        }
Example #13
0
        private IEnumerator DelayedLoadCoroutine(Character character, bool isWorldHost)
        {
            yield return(new WaitForSeconds(1.0f));

            try
            {
                ApplyLoadedSave(character, isWorldHost);
            }
            catch (Exception ex)
            {
                SL.LogWarning("Exception loading save data onto character: " + this.ToString());
                SL.LogInnerException(ex);
            }
        }
        private void SL_OnPacksLoaded()
        {
            Logger.LogWarning("----- Building Database -----");
            try
            {
                Database.BuildDB();
            }
            catch (Exception ex)
            {
                Logger.LogWarning("Exception building db!");
                SL.LogInnerException(ex);
                return;
            }

            m_packsLoaded = true;
            BuildCalcMenu.Init();
        }
Example #15
0
        private void OnSpawn(Character character, string rpcData)
        {
            SL.Log("Necromancy SummonManager.OnSpawn, character: " + character?.name + ", rpcData: " + rpcData);

            try
            {
                var ownerUID  = rpcData;
                var summonUID = character.UID;

                // add to dictionary
                if (SummonedCharacters.ContainsKey(ownerUID))
                {
                    SummonedCharacters[ownerUID].Add(summonUID);
                }
                else
                {
                    SummonedCharacters.Add(ownerUID, new List <string> {
                        summonUID
                    });
                }

                character.OnDeath += () => { StartCoroutine(OnSummonDeath(summonUID)); };

                if (!PhotonNetwork.isNonMasterClientInRoom)
                {
                    var owner = CharacterManager.Instance.GetCharacter(ownerUID);

                    //foreach (var wander in character.GetComponentsInChildren<AISWander>())
                    //{
                    //    wander.FollowTransform = owner.transform;
                    //    wander.FollowOffset = new Vector3(1.5f, 0f, 1.5f);
                    //}

                    // add auto-teleport component
                    var tele = character.gameObject.AddComponent <SummonTeleport>();
                    tele.m_character     = character;
                    tele.TargetCharacter = owner.transform;
                }
            }
            catch (Exception e)
            {
                SL.LogInnerException(e);
            }
        }
Example #16
0
        // Internal load all extensions
        internal static void LoadExtensions(Character character)
        {
            var dir = SLSaveManager.GetSaveFolderForCharacter(character)
                      + "\\" + SLSaveManager.CUSTOM_FOLDER + "\\";

            bool isWorldHost = character.UID == CharacterManager.Instance.GetWorldHostCharacter()?.UID;

            foreach (var file in Directory.GetFiles(dir))
            {
                try
                {
                    var typename = Path.GetFileNameWithoutExtension(file);

                    var type = s_registeredModels.FirstOrDefault(it => it.FullName == typename);
                    if (type != null)
                    {
                        using (var xml = File.OpenRead(file))
                        {
                            var serializer = Serializer.GetXmlSerializer(type);

                            if (serializer.Deserialize(xml) is PlayerSaveExtension loaded)
                            {
                                loaded.LoadSaveData(character, isWorldHost);
                            }
                            else
                            {
                                throw new Exception("Unknown - extension was null after attempting to load XML!");
                            }
                        }
                    }
                    else
                    {
                        SL.LogWarning("Loading PlayerSaveExtensions, could not find a matching registered type for " + typename);
                    }
                }
                catch (Exception ex)
                {
                    SL.LogWarning($"Exception loading Player Save Extension XML from '{file}'!");
                    SL.LogInnerException(ex);
                }
            }
        }
        public static bool Prefix(Item __instance, bool _special, ref Transform __result)
        {
            try
            {
                if (CustomItemVisuals.GetItemVisualLink(__instance) is CustomItemVisuals.ItemVisualsLink link)
                {
                    if (!_special)
                    {
                        if (link.ItemVisuals)
                        {
                            __result = link.ItemVisuals;
                            return(false);
                        }
                    }
                    else
                    {
                        if (__instance.UseSpecialVisualFemale)
                        {
                            if (link.ItemSpecialFemaleVisuals)
                            {
                                __result = link.ItemSpecialFemaleVisuals;
                                return(false);
                            }
                        }
                        else if (link.ItemSpecialVisuals)
                        {
                            __result = link.ItemSpecialVisuals;
                            return(false);
                        }
                    }
                }

                return(true);
            }
            catch (Exception e)
            {
                SL.LogInnerException(e);
                return(true);
            }
        }
Example #18
0
        private void OnSpawn(Character character, string rpcData)
        {
            //SL.Log("Necromancy SummonManager.OnSpawn, character: " + character?.name + ", rpcData: " + rpcData);

            try
            {
                var ownerUID  = rpcData;
                var summonUID = character.UID;

                // add to dictionary
                if (SummonedCharacters.ContainsKey(ownerUID))
                {
                    SummonedCharacters[ownerUID].Add(summonUID);
                }
                else
                {
                    SummonedCharacters.Add(ownerUID, new List <string> {
                        summonUID
                    });
                }

                if (!PhotonNetwork.isNonMasterClientInRoom)
                {
                    var owner = CharacterManager.Instance.GetCharacter(ownerUID);

                    // get the Wander state, and set the FollowTransfer to our caster character
                    var wander = character.GetComponentInChildren <AISWander>(true);
                    wander.FollowTransform = owner.transform;

                    // add auto-teleport component
                    var tele = character.gameObject.AddComponent <SummonTeleport>();
                    tele.m_character     = character;
                    tele.TargetCharacter = owner.transform;
                }
            }
            catch (Exception e)
            {
                SL.LogInnerException(e);
            }
        }
Example #19
0
        private static void OnSummonSpawn(Character character, string rpcData)
        {
            SL.Log("Necromancy SummonManager.OnSpawn, character: " + character?.name + ", rpcData: " + rpcData);

            try
            {
                var ownerUID  = rpcData;
                var summonUID = character.UID;

                // add to dictionary
                if (SummonedCharacters.ContainsKey(ownerUID))
                {
                    SummonedCharacters[ownerUID].Add(summonUID);
                }
                else
                {
                    SummonedCharacters.Add(ownerUID, new List <string> {
                        summonUID
                    });
                }

                character.OnDeath += () => { OnSummonDeath(character); };

                if (!PhotonNetwork.isNonMasterClientInRoom)
                {
                    var owner = CharacterManager.Instance.GetCharacter(ownerUID);

                    // add auto-teleport component
                    var tele = character.gameObject.AddComponent <SummonTeleport>();
                    tele.m_character     = character;
                    tele.TargetCharacter = owner.transform;
                }
            }
            catch (Exception e)
            {
                SL.LogInnerException(e);
            }
        }