private void Load()
        {
            if (RefPack == null)
            {
                SL.LogWarning("Error - RefPack is null on TemplateInspector.Load!");
                return;
            }

            var directory = RefPack.GetPathForCategory(Template.PackCategory.GetType());

            if (Template.TemplateAllowedInSubfolder && !string.IsNullOrEmpty(this.Template.SerializedSubfolderName))
            {
                directory += $@"\{this.Template.SerializedSubfolderName}";
            }

            var path = directory + "\\" + Template.SerializedFilename + ".xml";
            if (!File.Exists(path))
            {
                SL.LogWarning("No file exists at " + path);
                return;
            }

            if (Serializer.LoadFromXml(path) is ContentTemplate loadedData)
            {
                var loadedType = loadedData.GetType();
                SL.Log("Loaded xml, loaded type is " + loadedType);

                if (loadedType != m_targetType)
                    ChangeType(loadedType);

                CopyValuesFrom(loadedData);
            }

            UpdateFullPathText();
        }
        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);
        }
Example #3
0
        private void LoadTexture(SLPack pack, Dictionary <string, object> dict, string dirPath, string texFile, bool addGlobal)
        {
            var texture = pack.LoadTexture2D(dirPath, texFile, false, false);

            var name = Path.GetFileNameWithoutExtension(texFile);

            // add to the Texture2D dict for this pack
            if (pack.Texture2D.ContainsKey(name))
            {
                SL.LogWarning("Trying to load two textures with the same name into the same SLPack: " + name);
                return;
            }

            pack.Texture2D.Add(name, texture);

            dict.Add(Path.Combine(dirPath, texFile), texture);

            if (addGlobal)
            {
                // add to the global Tex replacements dict
                if (CustomTextures.Textures.ContainsKey(name))
                {
                    SL.Log("Custom Texture2Ds: A Texture already exists in the global list called " + name + "! Overwriting with this one...");
                    CustomTextures.Textures[name] = texture;
                }
                else
                {
                    CustomTextures.Textures.Add(name, texture);
                }
            }
        }
Example #4
0
        /// <summary>
        /// Helper to manually try to load the saved data for an extension of type T, with the given character UID.
        /// </summary>
        /// <typeparam name="T">The type of PlayerSaveExtension you're looking for</typeparam>
        /// <param name="characterUID">The saved character's UID</param>
        /// <returns>The loaded extension data, if found, otherwise null.</returns>
        public static T TryLoadExtension <T>(string characterUID) where T : PlayerSaveExtension
        {
            try
            {
                if (string.IsNullOrEmpty(characterUID))
                {
                    throw new ArgumentNullException("characterUID");
                }

                var filePath = GetSaveFilePath <T>(characterUID);

                T ret = null;
                if (File.Exists(filePath))
                {
                    var serializer = Serializer.GetXmlSerializer(typeof(T));
                    using (var file = File.OpenRead(filePath))
                    {
                        ret = (T)serializer.Deserialize(file);
                    }
                }
                else
                {
                    SL.LogWarning("No extension data found at '" + filePath + "'");
                }

                return(ret);
            }
            catch (Exception ex)
            {
                SL.LogWarning($"Exception loading save extension '{typeof(T).FullName}' for character '{characterUID}'");
                SL.Log(ex.ToString());
                return(null);
            }
        }
        internal static void LoadAllPacks(bool firstSetup)
        {
            var packs = LoadBaseSLPacks();

            if (SL.s_embeddedArchivePacks.Any())
            {
                packs.AddRange(SL.s_embeddedArchivePacks.Values);
                SL.Log("Added " + SL.s_embeddedArchivePacks.Count + " embedded packs to load order...");
            }

            // Normal load order
            foreach (var ctg in SLPackCategories)
            {
                LoadPackCategory(packs, ctg, firstSetup);
            }

            // Invoke late apply listeners
            if (s_onLateApplyListeners.Any())
            {
                SL.Log("Invoking " + s_onLateApplyListeners.Count + " OnLateApply listeners...");
                for (int i = 0; i < s_onLateApplyListeners.Count; i++)
                {
                    var entry = s_onLateApplyListeners.ElementAt(i);
                    InvokeLateApplyListener(entry.Key, entry.Value);
                }

                s_onLateApplyListeners.Clear();
            }
        }
Example #6
0
        /// <summary>
        /// Helper to manually save a PlayerSaveExtension of type T to the given character UID folder.
        /// </summary>
        /// <typeparam name="T">The type of extension you want to save.</typeparam>
        /// <param name="characterUID">The character UID you want to save to</param>
        /// <param name="extension">The extension data to save</param>
        public static void TrySaveExtension <T>(string characterUID, T extension) where T : PlayerSaveExtension
        {
            try
            {
                if (extension == null)
                {
                    throw new ArgumentNullException("extension");
                }

                if (string.IsNullOrEmpty(characterUID))
                {
                    throw new ArgumentNullException("characterUID");
                }

                var filePath = GetSaveFilePath <T>(characterUID);

                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }

                var serializer = Serializer.GetXmlSerializer(typeof(T));
                using (var file = File.Create(filePath))
                {
                    serializer.Serialize(file, extension);
                }
            }
            catch (Exception ex)
            {
                SL.LogWarning($"Exception saving save extension '{typeof(T).FullName}' for character '{characterUID}'");
                SL.Log(ex.ToString());
            }
        }
        internal static void SaveItemSpawns()
        {
            //SL.LogWarning("~~~~~~~~~~ Saving Item Spawns ~~~~~~~~~~");
            //SL.Log(SceneManager.GetActiveScene().name);

            var savePath = GetCurrentSavePath();

            if (File.Exists(savePath))
            {
                File.Delete(savePath);
            }

            if (SL_ItemSpawn.s_activeSavableSpawns == null || SL_ItemSpawn.s_activeSavableSpawns.Count < 1)
            {
                return;
            }

            SL.Log("Saving " + SL_ItemSpawn.s_activeSavableSpawns.Count + " item spawns");

            using (var file = File.Create(savePath))
            {
                var serializer = Serializer.GetXmlSerializer(typeof(ItemSpawnInfo[]));
                serializer.Serialize(file, SL_ItemSpawn.s_activeSavableSpawns.ToArray());
            }
        }
        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);
        }
Example #9
0
            public static bool Prefix(Character __instance, float _damage, Vector3 _hitVec, bool _syncIfClient = true)
            {
                var self = __instance;

                SL.Log(string.Format("{0} | {1} received {2} damage", Math.Round(Time.time, 1), self.Name, Math.Round(_damage, 2)));

                return(true);
            }
Example #10
0
        public object[] ParseArguments()
        {
            if (m_arguments.Length < 1)
            {
                return(new object[0]);
            }

            var parsedArgs = new List <object>();

            for (int i = 0; i < m_arguments.Length; i++)
            {
                var input = m_argumentInput[i];
                var type  = m_arguments[i].ParameterType;

                if (type.IsByRef)
                {
                    type = type.GetElementType();
                }

                if (!string.IsNullOrEmpty(input))
                {
                    if (type == typeof(string))
                    {
                        parsedArgs.Add(input);
                        continue;
                    }
                    else
                    {
                        try
                        {
                            var arg = type.GetMethod("Parse", new Type[] { typeof(string) })
                                      .Invoke(null, new object[] { input });

                            parsedArgs.Add(arg);
                            continue;
                        }
                        catch
                        {
                            SL.Log($"Could not parse input '{input}' for argument #{i} '{m_arguments[i].Name}' ({type.FullName})");
                        }
                    }
                }

                // No input, see if there is a default value.
                if (m_arguments[i].IsOptional)
                {
                    parsedArgs.Add(m_arguments[i].DefaultValue);
                    continue;
                }

                // Try add a null arg I guess
                parsedArgs.Add(null);
            }

            return(parsedArgs.ToArray());
        }
Example #11
0
        private void Load()
        {
            var path = $@"{this.RefMaterial.m_serializedFolderPath}\properties.xml";

            if (Serializer.LoadFromXml(path) is SL_Material loadedData)
            {
                SL.Log("Loaded SL_Material data, replacing");
                CopyValuesFrom(loadedData);
            }
        }
        public static bool Prefix(GlobalAudioManager.Sounds _sound)
        {
            if (CustomAudio.ReplacedClips.Contains(_sound))
            {
                SL.Log("Game tried to replace " + _sound + ", but it is already replaced with a custom sound! Skipping...");
                return(false);
            }

            return(true);
        }
 public override void ApplyToComponent <T>(T component)
 {
     if (ResourcesPrefabManager.Instance.GetItemPrefab(this.SkillID) is Skill skill)
     {
         (component as LearnSkillEffect).LearntSkill = skill;
     }
     else
     {
         SL.Log("SL_LearnSkillEffect - cannot find a skill with the ID " + this.SkillID);
     }
 }
        public override void ApplyToComponent <T>(T component)
        {
            var status = ResourcesPrefabManager.Instance.GetStatusEffectPrefab(StatusIdentifier);

            if (!status)
            {
                SL.Log("");
                return;
            }

            (component as ShooterPosStatusEffect).StatusEffect = status;
        }
        public override void ApplyToComponent <T>(T component)
        {
            var skill = component.transform.root.gameObject.GetComponent <CounterSkill>();

            if (!skill)
            {
                SL.Log("Trying to apply a CounterSuccessCondition on a skill which is not a Counter Skill! Error!");
                return;
            }

            (component as CounterSuccessCondition).Skill = skill;
        }
Example #16
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);
            }
        public override void RefreshUIForValue()
        {
            if (Value == null || !Owner.HasEvaluated)
            {
                m_stringGroupObj?.SetActive(false);
                base.RefreshUIForValue();
                return;
            }

            m_stringGroupObj.SetActive(true);

            GetDefaultLabel(false);
            UpdateCreateDestroyBtnState();

            try
            {
                m_baseLabel.text = m_richValueType;

                if (!m_hiddenObj.gameObject.activeSelf)
                {
                    m_hiddenObj.gameObject.SetActive(true);
                }

                if (!string.IsNullOrEmpty((string)Value))
                {
                    var toString = (string)Value;
                    if (toString.Length > 15000)
                    {
                        toString = toString.Substring(0, 15000);
                    }

                    m_valueInput.text      = toString;
                    m_placeholderText.text = toString;
                }
                else
                {
                    string s = Value == null
                                ? "null"
                                : "empty";

                    m_valueInput.text      = "";
                    m_placeholderText.text = s;
                }
            }
            catch (Exception e)
            {
                SL.Log("Exception setting InteractiveString: " + e);
            }

            m_labelLayout.minWidth      = 50;
            m_labelLayout.flexibleWidth = 0;
        }
        public override void ApplyToComponent <T>(T component)
        {
            var status = ResourcesPrefabManager.Instance.GetStatusEffectPrefab(this.StatusIdentifierToReduce);

            if (!status)
            {
                SL.Log("SL_ReduceStatusLevel: Could not find a status with the identifier '" + StatusIdentifierToReduce + "'!");
                return;
            }

            (component as ReduceStatusLevel).LevelAmount          = this.ReduceAmount;
            (component as ReduceStatusLevel).StatusEffectToReduce = status;
        }
Example #19
0
        public override void ApplyToComponent <T>(T component)
        {
            var item = ResourcesPrefabManager.Instance.GetItemPrefab(ReqItemID);

            if (!item)
            {
                SL.Log("SL_OwnsItemCondition: Could not find an Item with the ID " + this.ReqItemID + "!");
                return;
            }

            (component as OwnsItemCondition).ReqItem   = item;
            (component as OwnsItemCondition).MinAmount = this.ReqAmount;
        }
        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 #21
0
        public override void ApplyToComponent <T>(T component)
        {
            base.ApplyToComponent(component);

            var status = ResourcesPrefabManager.Instance.GetStatusEffectPrefab(this.AmplifiedEffect);

            if (!status)
            {
                SL.Log("Error getting AmplifiedEffect status effect on AddBoonHolder. Could not find " + this.AmplifiedEffect);
                return;
            }

            (component as AddBoonEffect).BoonAmplification = status;
        }
Example #22
0
        public override void ApplyToComponent <T>(T component)
        {
            var status1 = ResourcesPrefabManager.Instance.GetStatusEffectPrefab(StatusIdentifierToCheck);
            var status2 = ResourcesPrefabManager.Instance.GetStatusEffectPrefab(StatusIdentifierToCompareTo);

            if (!status1 || !status2)
            {
                SL.Log("SL_MostRecentCondition: Could not get required status effects!");
                return;
            }

            (component as MostRecentCondition).StatusEffectPrefab    = status1;
            (component as MostRecentCondition).StatusEffectToCompare = status2;
        }
        // ~~~~~ Loading ~~~~~

        internal static SL_CharacterSaveData[] TryLoadSaveData(CharSaveType type)
        {
            try
            {
                var savePath = GetCurrentSavePath(type);

                if (!File.Exists(savePath))
                {
                    return(null);
                }

                using (var file = File.OpenRead(savePath))
                {
                    var serializer = Serializer.GetXmlSerializer(typeof(SL_CharacterSaveData[]));

                    var list = new List <SL_CharacterSaveData>();
                    if (serializer.Deserialize(file) is SL_CharacterSaveData[] array)
                    {
                        foreach (var entry in array)
                        {
                            if (CustomCharacters.Templates.TryGetValue(entry.TemplateUID, out SL_Character template))
                            {
                                // if template was changed to temporary, ignore the save data.
                                if (template.SaveType == CharSaveType.Temporary)
                                {
                                    continue;
                                }

                                // update save data type to template current type
                                if (entry.SaveType != template.SaveType)
                                {
                                    entry.SaveType = template.SaveType;
                                }

                                list.Add(entry);
                            }
                        }
                    }

                    return(list.ToArray());
                }
            }
            catch (Exception ex)
            {
                SL.Log("Exception loading SL_Characters!");
                SL.Log(ex.ToString());
                return(new SL_CharacterSaveData[0]);
            }
        }
Example #24
0
        public override void ApplyToComponent <T>(T component)
        {
            var skill = ResourcesPrefabManager.Instance.GetItemPrefab(ReqSkillID) as PassiveSkill;

            if (!skill)
            {
                SL.Log("SL_PassiveSkillCondition: Could not find a Passive Skill with the ID " + this.ReqSkillID);
                return;
            }

            component.Invert = false;

            (component as PassiveSkillCondition).Inverse      = this.Invert;
            (component as PassiveSkillCondition).PassiveSkill = skill;
        }
        public override void ApplyToComponent <T>(T component)
        {
            var preset = ResourcesPrefabManager.Instance.GetEffectPreset(this.ImbueEffect_Preset_ID);

            if (!preset)
            {
                SL.Log($"{this.GetType().Name}: Could not find imbue effect preset of ID '{this.ImbueEffect_Preset_ID}'");
                return;
            }

            var comp = component as ImbueObject;

            comp.SetLifespanImbue(this.Lifespan);
            comp.ImbuedEffect = preset as ImbueEffectPreset;
        }
Example #26
0
        public override void ApplyToComponent <T>(T component)
        {
            var preset = ResourcesPrefabManager.Instance.GetEffectPreset(this.ImbuePresetID) as ImbueEffectPreset;

            if (!preset && !this.AnyImbue)
            {
                SL.Log("SL_ImbueEffectCondition: Could not get an Imbue Preset with the ID '" + this.ImbuePresetID + "'!");
                return;
            }

            var comp = component as ImbueEffectCondition;

            comp.ImbueEffectPreset = preset;
            comp.AnyImbue          = this.AnyImbue;
            comp.WeaponToCheck     = this.WeaponToCheck;
        }
        internal static void OnEnvironmentSaveLoaded(DictionaryExt <string, CharacterSaveInstanceHolder> charSaves)
        {
            var host = CharacterManager.Instance.GetWorldHostCharacter();

            if (!host || !host.IsPhotonPlayerLocal)
            {
                SL.WasLastSceneReset = false;
                return;
            }

            if (charSaves.TryGetValue(host.UID, out CharacterSaveInstanceHolder holder))
            {
                if (At.GetField(holder.CurrentSaveInstance, "m_loadedScene") is EnvironmentSave loadedScene)
                {
                    var areaHolder = AreaManager.Instance.GetAreaFromSceneName(loadedScene.AreaName);
                    if (areaHolder == null)
                    {
                        SLCharacterSaveManager.SceneResetWanted = true;
                    }
                    else
                    {
                        var area = (AreaManager.AreaEnum)AreaManager.Instance.GetAreaFromSceneName(loadedScene.AreaName).ID;
                        if (IsPermanent(area))
                        {
                            SLCharacterSaveManager.SceneResetWanted = false;
                        }
                        else
                        {
                            float age = (float)(loadedScene.GameTime - EnvironmentConditions.GameTime);
                            SLCharacterSaveManager.SceneResetWanted = AreaManager.Instance.IsAreaExpired(loadedScene.AreaName, age);
                        }
                    }
                }
                else
                {
                    SLCharacterSaveManager.SceneResetWanted = true;
                }
            }
            else
            {
                SLCharacterSaveManager.SceneResetWanted = true;
            }

            SL.WasLastSceneReset = SLCharacterSaveManager.SceneResetWanted;

            SL.Log("Set SceneResetWanted: " + SLCharacterSaveManager.SceneResetWanted);
        }
        public override Dictionary <string, object> LoadContent(SLPack pack, bool isHotReload)
        {
            var dict = new Dictionary <string, object>();

            // AssetBundle does not use hot reload at the moment.
            if (isHotReload)
            {
                return(dict);
            }

            var dirPath = pack.GetPathForCategory <AssetBundleCategory>();

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

            var fileQuery = pack.GetFiles(dirPath)
                            .Where(x => !x.EndsWith(".meta") &&
                                   !x.EndsWith(".manifest"));

            foreach (var bundlePath in fileQuery)
            {
                try
                {
                    string name = Path.GetFileName(bundlePath);

                    if (pack.LoadAssetBundle(dirPath, name) is AssetBundle bundle)
                    {
                        pack.AssetBundles.Add(name, bundle);

                        dict.Add(bundlePath, bundle);
                        SL.Log("Loaded assetbundle " + name);
                    }
                    else
                    {
                        throw new Exception($"Unknown error (Bundle '{Path.GetFileName(bundlePath)}' was null)");
                    }
                }
                catch (Exception e)
                {
                    SL.LogError("Error loading asset bundle! Message: " + e.Message + "\r\nStack: " + e.StackTrace);
                }
            }

            return(dict);
        }
Example #29
0
        private void LoadSettings()
        {
            // legacy settings check
            string legacySettingsPath = @"Mods\NecromancerSkills.xml";

            if (File.Exists(legacySettingsPath))
            {
                if (File.Exists(SAVE_PATH))
                {
                    File.Delete(legacySettingsPath);
                    SL.Log($"[Necromancer] Deleted legacy settings because new settings exist. Deleted: '{legacySettingsPath}'");
                }
                else
                {
                    File.Move(legacySettingsPath, SAVE_PATH);
                    SL.Log($"[Necromancer] Moved Necromancer settings from '{legacySettingsPath}' to '{SAVE_PATH}'");
                }
            }

            bool makeNew = true;

            try
            {
                if (File.Exists(SAVE_PATH))
                {
                    var serializer = new XmlSerializer(typeof(Settings));

                    using (var file = File.OpenRead(SAVE_PATH))
                    {
                        settings = serializer.Deserialize(file) as Settings;
                        makeNew  = false;
                    }
                }
            }
            catch (Exception ex)
            {
                makeNew = true;
                Debug.Log("Exception loading Necromancer settings!");
                Debug.Log(ex);
            }

            if (makeNew)
            {
                settings = new Settings();
                SaveSettings();
            }
        }
Example #30
0
        public override void ApplyToComponent <T>(T component)
        {
            var comp = component as HasStatusLevelCondition;

            var status = ResourcesPrefabManager.Instance.GetStatusEffectPrefab(this.StatusIdentifier);

            if (!status)
            {
                SL.Log("SL_HasStatusEffectLevelCondition: Could not find a Status Effect with the identifier '" + this.StatusIdentifier + "'!");
                return;
            }

            comp.StatusEffect    = status;
            comp.CheckOwner      = this.CheckOwner;
            comp.CompareLevel    = this.CompareLevel;
            comp.ComparaisonType = this.ComparisonType;
        }