// main actual spawn method internal Character InternalSpawn(Vector3 position, Vector3 rotation, string characterUID, string extraRpcData, bool loadingFromSave) { characterUID = characterUID ?? this.UID; if (CharacterManager.Instance.GetCharacter(characterUID) is Character existing) { SL.Log("Trying to spawn a character UID " + characterUID + " but one already exists with that UID!"); return(existing); } return(CustomCharacters.SpawnCharacter(this, position, rotation, characterUID, extraRpcData, loadingFromSave).GetComponent <Character>()); }
// Normal template apply method internal void Internal_ApplyTemplate() { if (!StatusEffectFamilyLibrary.Instance) { return; } var library = StatusEffectFamilyLibrary.Instance; StatusEffectFamily family; if (library.StatusEffectFamilies.Where(it => (string)it.UID == this.UID).Any()) { family = library.StatusEffectFamilies.First(it => (string)it.UID == this.UID); } else { family = new StatusEffectFamily(); library.StatusEffectFamilies.Add(family); } if (family == null) { SL.LogWarning("Applying SL_StatusEffectFamily template, null error"); return; } if (this.UID != null) { At.SetField(family, "m_uid", new UID(this.UID)); } if (this.Name != null) { family.Name = this.Name; } if (this.StackBehaviour != null) { family.StackBehavior = (StatusEffectFamily.StackBehaviors) this.StackBehaviour; } if (this.MaxStackCount != null) { family.MaxStackCount = (int)this.MaxStackCount; } if (this.LengthType != null) { family.LengthType = (StatusEffectFamily.LengthTypes) this.LengthType; } }
public static void InitializePatch(InputManager_Base __instance) { //s_userData = __instance.userData; foreach (var keybindInfo in s_customKeyDict.Values) { // This actually creates the new actions: AddRewiredAction(__instance.userData, keybindInfo.name, keybindInfo.category, keybindInfo.type, out int actionID); keybindInfo.actionID = actionID; SL.Log($"Set up custom keybinding '{keybindInfo.name}', actionID: " + keybindInfo.actionID); } }
private IEnumerator DelayedStopCoroutine() { yield return(new WaitForSeconds(AutoStopTime)); if (At.GetField(this as PlayVFX, "m_startVFX") is VFXSystem vfx) { vfx.Stop(); } else { SL.LogWarning("SL_PlayTimedVFX.DelayedStopCoroutine - vfx was null after delay"); } }
/// <summary> Clone's an items current visual prefab (and materials), then sets this item's visuals to the new cloned prefab. </summary> public static GameObject CloneVisualPrefab(Item item, VisualPrefabType type, bool logging = false) { var prefab = GetOrigItemVisuals(item, type); if (!prefab) { if (logging) { SL.Log("Error, no VisualPrefabType defined or could not find visual prefab of that type!"); } return(null); } return(CloneAndSetVisuals(item, prefab.gameObject, type)); }
// invoked when character is being saved internal string INTERNAL_OnPrepareSave(Character character) { string ret = null; try { ret = OnCharacterBeingSaved?.Invoke(character); } catch (Exception e) { SL.LogWarning("Exception invoking OnCharacterBeingSaved for template '" + this.UID + "'"); SL.LogInnerException(e); } return(ret); }
public static void DebugVfxNames() { SL.Log("----------- VFXSystems ------------ "); var vfxsystems = Resources.FindObjectsOfTypeAll <VFXSystem>(); var names = new List <string>(); foreach (var vfx in vfxsystems) { var safename = GetSafeVFXName(vfx); if (!names.Contains(safename)) { names.Add(safename); } } File.WriteAllLines("vfxsystems.txt", names.ToArray()); }
public static Texture2D LoadTexture(byte[] data, bool mipmap, bool linear) { Texture2D tex = new Texture2D(4, 4, TextureFormat.DXT5, mipmap, linear); try { tex.LoadImage(data); } catch (Exception e) { SL.Log("Error loading texture! Message: " + e.Message + "\r\nStack: " + e.StackTrace); } tex.filterMode = FilterMode.Bilinear; return(tex); }
internal void Internal_ApplyTemplate() { if (string.IsNullOrEmpty(this.UID)) { SL.LogWarning("Cannot prepare an SL_DropTable with a null or empty UID!"); return; } if (s_registeredTables.ContainsKey(this.UID)) { SL.LogWarning("Trying to register an SL_DropTable but one already exists with this UID: " + this.UID); return; } s_registeredTables.Add(this.UID, this); SL.Log("Registered SL_DropTable '" + this.UID + "'"); }
internal bool GetShouldSpawn() { if (this.ShouldSpawn != null) { try { return(ShouldSpawn.Invoke()); } catch (Exception ex) { SL.LogWarning("Exception invoking ShouldSpawn callback for " + this.Name + " (" + this.UID + "), not spawning."); SL.LogInnerException(ex); return(false); } } return(true); }
public override void ApplyActualTemplate() { base.ApplyActualTemplate(); if (string.IsNullOrEmpty(this.IdentifierName)) { SL.LogWarning("Cannot register an SL_ItemSpawn without an InternalName set!"); return; } if (s_registeredSpawnSources.ContainsKey(this.IdentifierName)) { SL.LogWarning($"An SL_ItemSpawn with the UID '{IdentifierName}' has already been registered!"); return; } s_registeredSpawnSources.Add(this.IdentifierName, this); }
/// <summary>Use this to check if a key is held this frame, and get the local ID of the player who pressed it.</summary> /// <param name="keyName">The name of the key which you registered with.</param> /// <param name="playerID">If the key is pressed, this is the local split-player ID that pressed it.</param> /// <returns>True if pressed, false if not.</returns> public static bool GetKey(string keyName, out int playerID) { if (s_customKeyDict.TryGetValue(keyName, out KeybindInfo key)) { return(key.GetKey(out playerID)); } if (!s_loggedMissingKeyNames.Contains(keyName)) { SL.LogWarning($"Attempting to get custom keybinding state, but no custom keybinding " + $"with the name '{keyName}' was registered, this will not be logged again."); s_loggedMissingKeyNames.Add(keyName); } playerID = -1; return(false); }
/// <summary> /// Returns the game's actual Tag for the string you provide, if it exists. /// </summary> /// <param name="TagName">Eg "Food", "Blade", etc...</param> /// <param name="logging">Whether to log error messages to debug console or not (if tag doesnt exist)</param> /// <returns></returns> public static Tag GetTag(string TagName, bool logging = true) { var tags = (Tag[])At.GetField(TagSourceManager.Instance, "m_tags"); var tag = tags.FirstOrDefault(x => x.TagName == TagName); if (tag.TagName == TagName) { return(tag); } else { if (logging) { SL.Log("GetTag :: Could not find a tag by the name: " + TagName); } return(Tag.None); } }
internal static void OnSceneLoaded() { if (PhotonNetwork.isNonMasterClientInRoom) { return; } SL.Log("Checking SL_ItemSpawns..."); s_activeSavableSpawns.Clear(); Dictionary <string, ItemSpawnInfo> savedData = null; if (!SL.WasLastSceneReset) { savedData = LoadItemSpawnData(); } foreach (var spawn in s_registeredSpawnSources.Values) { // Check if already spawned if (savedData != null && savedData.ContainsKey(spawn.IdentifierName)) { var data = savedData[spawn.IdentifierName]; s_activeSavableSpawns.Add(data); var item = ItemManager.Instance.GetItem(data.ItemUID); if (item && string.IsNullOrEmpty(item.MostRecentOwnerUID)) { // item hasn't been picked up yet, update it to current template settings. s_registeredSpawnSources[spawn.IdentifierName].ApplyToItem(item); } continue; } // else, new spawn if (spawn.SceneToSpawnIn == SceneManagerHelper.ActiveSceneName) { spawn.GenerateItem(); } } }
public EffectCondition ApplyToTransform(Transform transform) { Type componentType = Serializer.GetGameType(this.GetType()); if (componentType != null) { var comp = transform.gameObject.AddComponent(componentType) as EffectCondition; comp.Invert = this.Invert; ApplyToComponent(comp); return(comp); } else { SL.Log("Could not get Game type for SL_type: " + this.ToString()); return(null); } }
public static SL_EffectCondition ParseCondition(EffectCondition component) { Type slType = Serializer.GetBestSLType(component.GetType()); if (slType != null && !slType.IsAbstract) { var holder = Activator.CreateInstance(slType) as SL_EffectCondition; holder.Invert = component.Invert; holder.SerializeEffect(component); return(holder); } else { SL.Log(component.ToString() + " is not supported yet, sorry!"); return(null); } }
/// <summary>Serialize an effect and get the equivalent SL_Effect.</summary> public static SL_Effect ParseEffect(Effect effect) { Type slType = Serializer.GetBestSLType(effect.GetType()); if (slType != null && !slType.IsAbstract) { var holder = Activator.CreateInstance(slType) as SL_Effect; holder.Delay = effect.Delay; holder.OverrideCategory = effect.OverrideEffectCategory; holder.SyncType = effect.SyncType; holder.SerializeEffect(effect); return(holder); } else { SL.Log(effect.ToString() + " is not supported yet, sorry!"); return(null); } }
/// <summary>Use this to add a new Keybinding to the game.</summary> /// <param name="name">The name for the keybinding displayed in the menu.</param> /// <param name="category">The category to add to</param> /// <param name="controlType">What type of control this is</param> /// <param name="type">What type(s) of input it will accept</param> public static void AddAction(string name, KeybindingsCategory category, ControlType controlType = ControlType.Keyboard, InputType type = InputType.Button) { bool initialized = (bool)At.GetPropertyStatic(typeof(ReInput), "initialized"); if (initialized) { SL.LogWarning("Tried to add Custom Keybinding too late. Add your keybinding earlier, such as in your BaseUnityPlugin.Awake() method."); return; } if (s_customKeyDict.ContainsKey(name)) { SL.LogWarning($"Attempting to add a keybind '{name}', but one with this name has already been registered."); return; } var customKey = new KeybindInfo(name, category, controlType, type); s_customKeyDict.Add(name, customKey); }
internal virtual void ApplyItemVisualSettings(ItemVisual itemVisual, Transform visuals) { SL.Log($"Applying ItemVisuals settings to " + visuals.name); if (Position != null) { visuals.localPosition = (Vector3)Position; } if (Rotation != null) { visuals.eulerAngles = (Vector3)Rotation; } if (PositionOffset != null) { visuals.localPosition += (Vector3)PositionOffset; } if (RotationOffset != null) { visuals.eulerAngles += (Vector3)RotationOffset; } }
public override void ApplyToComponent <T>(T component) { var comp = component as Summon; if (this.SummonPrefabType == PrefabTypes.Resource) { if (Resources.Load <GameObject>(Prefab) is GameObject prefab) { comp.SummonedPrefab = prefab.transform; } else { SL.Log("Could not find Resources asset: " + this.Prefab + "!"); return; } } else { if (int.TryParse(this.Prefab, out int id) && ResourcesPrefabManager.Instance.GetItemPrefab(id) is Item item) { comp.SummonedPrefab = item.transform; } else { SL.Log("Could not find an Item with the ID " + this.Prefab + ", or that is not a valid ID!"); return; } } comp.BufferSize = this.BufferSize; comp.LimitOfOne = this.LimitOfOne; comp.InstantiationMode = this.SummonMode; comp.PositionType = this.PositionType; comp.MinDistance = this.MinDistance; comp.MaxDistance = this.MaxDistance; comp.SameDirAsSummoner = this.SameDirectionAsSummoner; comp.SummonLocalForward = this.SummonLocalForward; comp.IgnoreOnDestroy = this.IgnoreOnDestroy; }
public static object LoadFromXml(Stream stream, Type baseType) { try { var xml = GetXmlSerializer(baseType); object obj = null; using (var reader = new StreamReader(stream)) { obj = xml.Deserialize(reader); } return(obj); } catch (Exception ex) { SL.LogWarning("Exception loading XML stream!"); SL.LogInnerException(ex); return(null); } }
/// <summary> /// Internal use for setting a required slot. /// </summary> /// <param name="comp">The component that this SkillSlot is setting. Not the required slot.</param> public void SetRequiredSlot(BaseSkillSlot comp) { bool success = false; var reqrow = RequiredSkillSlot.x; var reqcol = RequiredSkillSlot.y; if (comp.transform.root.Find("Row" + reqrow) is Transform reqrowTrans && reqrowTrans.Find("Col" + reqcol) is Transform reqcolTrans) { var reqslot = reqcolTrans.GetComponent <BaseSkillSlot>(); if (reqslot) { At.SetField(comp, "m_requiredSkillSlot", reqslot); success = true; } } if (!success) { SL.Log("Could not set required slot. Maybe it's not set yet?"); } }
/// <summary> /// Load an Audio Clip from a given byte array, and optionally put it in the provided SL Pack.<br/><br/> /// WARNING: AudioClips loaded from byte arrays are currently unreliable and may be glitched, use at own risk! /// </summary> /// <param name="data">The byte[] array from <see cref="File.ReadAllBytes(string)"/> on the wav file path.</param> /// <param name="name">The name to give to the audio clip.</param> /// <param name="pack">Optional SL Pack to put the audio clip inside.</param> /// <returns>The loaded audio clip, if successful.</returns> public static AudioClip LoadAudioClip(byte[] data, string name, SLPack pack = null) { SL.LogWarning("WARNING: AudioClips loaded from embedded .zip archives are currently unreliable and may be glitched, use at own risk!"); try { var clip = ConvertByteArrayToAudioClip(data, name); if (!clip) { return(null); } return(FinalizeAudioClip(clip, name, pack)); } catch (Exception ex) { SL.LogWarning("Exception loading AudioClip!"); SL.LogInnerException(ex); return(null); } }
/// <summary>Replace a global sound with the provided AudioClip.</summary> public static void ReplaceAudio(GlobalAudioManager.Sounds sound, AudioClip clip) { if (!GAMInstance) { SL.LogWarning("Cannot find GlobalAudioManager Instance!"); return; } if (ReplacedClips.Contains(sound)) { SL.Log($"The Sound clip '{sound}' has already been replaced, replacing again..."); } try { DoReplaceClip(sound, clip); } catch (Exception e) { SL.LogError($"Exception replacing clip '{sound}'.\r\nMessage: {e.Message}\r\nStack: {e.StackTrace}"); } }
public SL_ItemDropChance GetDropForDiceRoll(int diceRoll) { if (diceRoll < 0 || diceRoll > MaxDiceValue) { SL.Log("ERROR: Roll " + diceRoll + " is <0 or >" + MaxDiceValue); return(null); } if (m_dropRanges == null) { GetDropRanges(); } for (int i = 0; i < m_dropRanges.Count; i++) { var entry = m_dropRanges.ElementAt(i); // if dice roll was within range if (entry.Key <= diceRoll && entry.Value >= diceRoll) { // if there is a NoDrop chance if (NoDrop_DiceValue > 0) { if (i == 0) { return(null); // Index was 0 so it was a no-drop. } else { i--; // NoDrop was set, so remove 1 from index to get the real drop index. } } return(Drops[i]); } } return(null); }
public void GenerateItems(Transform container) { if (this.DropTableUIDsToAdd == null) { SL.LogWarning($"Trying to generate drops from an SL_DropTableAddition '{IdentifierName}', but the DropTableUIDsToAdd is null!"); return; } foreach (string tableUID in this.DropTableUIDsToAdd) { SL_DropTable.s_registeredTables.TryGetValue(tableUID, out SL_DropTable table); if (table == null) { SL.LogWarning($"SL_DropTableAddition: Could not find any SL_DropTable with UID '{tableUID}'!"); continue; } //SL.Log("Generating from '" + table.UID + "'"); table.GenerateDrops(container); } }
/// <summary> /// Pass a SideLoader class type (eg, SL_Item) and get the corresponding Game class (eg, Item). /// </summary> /// <param name="_slType">Eg, typeof(SL_Item)</param> /// <param name="logging">If you want to log debug messages.</param> public static Type GetGameType(Type _slType, bool logging = true) { if (s_typeConversions.ContainsKey(_slType)) { return(s_typeConversions[_slType]); } if (typeof(ICustomModel).IsAssignableFrom(_slType)) { var custom = (ICustomModel)Activator.CreateInstance(_slType); s_typeConversions.Add(_slType, custom.GameModel); return(custom.GameModel); } var name = _slType.Name.Substring(3, _slType.Name.Length - 3); Type ret = null; try { ret = Game_Assembly.GetType(name); if (ret == null) { throw new Exception(); } } catch { if (logging) { SL.Log($"Could not get Game_Assembly Type '{name}'"); } } s_typeConversions.Add(_slType, ret); return(ret); }
public static Type GetBaseTypeOfXmlDocument(Stream stream) { string typeName = ""; using (var reader = XmlReader.Create(stream)) { while (reader.Read()) // just get the first element (root) then break. { if (reader.NodeType == XmlNodeType.Element) { // the real type might be saved as an attribute if (!string.IsNullOrEmpty(reader.GetAttribute("type"))) { typeName = reader.GetAttribute("type"); } else { typeName = reader.Name; } break; } } } s_typesByName.TryGetValue(typeName, out Type type); if (type == null) { type = SLTypes.FirstOrDefault(it => it.Name == typeName); if (type == null) { SL.LogWarning("Could not get Type from document with base node '" + typeName + "'!"); return(null); } } return(type); }
/// <summary>Adds and applies this effect to the provided Transform.</summary> public Effect ApplyToTransform(Transform t) { Type componentType = Serializer.GetGameType(this.GetType()); if (componentType != null) { var comp = t.gameObject.AddComponent(componentType) as Effect; // set base fields comp.Delay = this.Delay; comp.SyncType = this.SyncType; comp.OverrideEffectCategory = this.OverrideCategory; ApplyToComponent(comp); return(comp); } else { SL.Log("Could not get Game type for SL_Type: " + this.ToString()); return(null); } }
public override void ApplyToComponent <T>(T component) { var tag = CustomItems.GetTag(Stat_Tag); if (tag == Tag.None) { SL.Log("AffectStat: could not find tag of ID " + (this.Stat_Tag ?? "")); return; } var comp = component as AffectStat; comp.AffectedStat = new TagSourceSelector(tag); comp.Value = this.AffectQuantity; comp.IsModifier = this.IsModifier; if (this.Tags != null) { comp.Tags = this.Tags .Select(it => new TagSourceSelector(CustomTags.GetTag(it))) .ToArray(); } }