コード例 #1
0
        /// <summary>
        /// Allows custom playback of broadcasts.
        /// </summary>
        /// <param name="info">The content to be played</param>
        public void CustomQueueBroadcast(RadioContentInfo info)
        {
            if (!ModOptions.Instance.AllowContentBroadcast)
                return;

            var mgr = Singleton<AudioManager>.instance;

            var broadcastQueue = ReflectionHelper.GetPrivateField<FastList<RadioContentInfo>>(this, "m_broadcastQueue"); //Why does CO make everything private, so you can't access it ??

            while (!Monitor.TryEnter(broadcastQueue, SimulationManager.SYNCHRONIZE_TIMEOUT))
            {
            }
            try
            {
                if (broadcastQueue.m_size < 5)
                {
                    for (int i = 0; i < broadcastQueue.m_size; i++)
                    {
                        if (broadcastQueue.m_buffer[i] == info)
                        {
                            return;
                        }
                    }
                    broadcastQueue.Add(info);
                }
            }
            finally
            {
                Monitor.Exit(broadcastQueue);
            }
        }
コード例 #2
0
        void musicEntryEnableDisable(UIComponent component, int value)
        {
            RadioContentInfo info = m_CurrentContent[value];

            AudioManagerHelper.SetContentEnabled(info, !AudioManagerHelper.ContentIsEnabled(info));

            RebuildList();
        }
コード例 #3
0
        private void DebugOutput()
        {
            for (uint i = 0; i < PrefabCollection <RadioChannelInfo> .PrefabCount(); ++i)
            {
                String message = "";

                RadioChannelInfo info = PrefabCollection <RadioChannelInfo> .GetPrefab(i);

                if (info == null)
                {
                    continue;
                }

                message += "[ChannelInfo] " + info + "\n";
                message += "Schedule:\n";

                if (info.m_stateChain != null)
                {
                    foreach (RadioChannelInfo.State s in info.m_stateChain)
                    {
                        message += "\t" + s.m_contentType + " " + s.m_minCount + " - " + s.m_maxCount + "\n";
                    }
                }

                message += "Content:\n";

                for (uint j = 0; j < PrefabCollection <RadioContentInfo> .PrefabCount(); ++j)
                {
                    RadioContentInfo content = PrefabCollection <RadioContentInfo> .GetPrefab(j);

                    if (content == null)
                    {
                        continue;
                    }
                    if (content.m_radioChannels != null)
                    {
                        if (content.m_radioChannels.Contains(info))
                        {
                            message += "\t[ContentInfo] " + content + " " + content.m_fileName + "\n";
                        }
                    }
                }

                CSLMusicMod.Log(message);
            }

            for (uint i = 0; i < PrefabCollection <DisasterInfo> .PrefabCount(); ++i)
            {
                DisasterInfo info = PrefabCollection <DisasterInfo> .GetPrefab(i);

                if (info == null)
                {
                    continue;
                }

                CSLMusicMod.Log("[DisasterContext] Disaster name: " + info.name);
            }
        }
コード例 #4
0
        public static string GetContentName(RadioContentInfo info)
        {
            if (info == null)
            {
                return("<Null>");
            }

            return(String.IsNullOrEmpty(info.m_displayName) ? info.name : info.m_displayName);
        }
コード例 #5
0
        /// <summary>
        /// Returns true if a radio content info is disabled.
        /// </summary>
        /// <returns><c>true</c>, if is marked as disabled, <c>false</c> otherwise.</returns>
        /// <param name="info">Info.</param>
        public static bool ContentIsEnabled(RadioContentInfo info)
        {
            if (info == null)
            {
                return(true);
            }

            string id = info.m_folderName + "/" + info.m_fileName;

            return(!ModOptions.Instance.DisabledContent.Contains(id));
        }
コード例 #6
0
        /// <summary>
        /// Returns the custom content info from a vanilla content info if available.
        /// Otherwise returns null.
        /// </summary>
        /// <returns>The user content info.</returns>
        /// <param name="info">Info.</param>
        public static UserRadioContent GetUserContentInfo(RadioContentInfo info)
        {
            UserRadioContent usercontent;

            if (LoadingExtension.UserRadioContainer.m_UserContentDict.TryGetValue(info, out usercontent))
            {
                return(usercontent);
            }
            else
            {
                return(null);
            }
        }
コード例 #7
0
        protected static RadioContentInfo ClonePrefab(RadioContentInfo originalPrefab, string newName, Transform parentTransform)
        {
            var instance = UnityEngine.Object.Instantiate(originalPrefab.gameObject);

            instance.name = newName;

            var newPrefab = instance.GetComponent <RadioContentInfo>();


            instance.SetActive(false);
            newPrefab.m_prefabInitialized = false;
            return(newPrefab);
        }
コード例 #8
0
        private String GetEntryTextFor(RadioContentInfo content)
        {
            String name = AudioManagerHelper.GetContentName(content);

            switch (content.m_contentType)
            {
            case RadioContentInfo.ContentType.Blurb:
                name = "<sprite Blurb> " + name;
                break;

            case RadioContentInfo.ContentType.Broadcast:
                name = "<sprite Broadcast> " + name;
                break;

            case RadioContentInfo.ContentType.Commercial:
                name = "<sprite Commercial> " + name;
                break;

            case RadioContentInfo.ContentType.Music:
                name = "<sprite Music> " + name;
                break;

            case RadioContentInfo.ContentType.Talk:
                name = "<sprite Talk> " + name;
                break;
            }

            if (ModOptions.Instance.ImprovedDisableContentUI)
            {
                if (!AudioManagerHelper.ContentIsEnabled(content))
                {
                    name = "<sprite ContentUnchecked>" + name;
                }
                else
                {
                    name = "<sprite ContentChecked>" + name;
                }
            }
            else
            {
                if (!AudioManagerHelper.ContentIsEnabled(content))
                {
                    name = "<sprite ContentDisabled>" + name;
                }
            }



            return(name);
        }
コード例 #9
0
        void musicEntrySelected(UIComponent component, int value)
        {
            if (ModOptions.Instance.ImprovedDisableContentUI)
            {
                Vector3 mouse = Input.mousePosition / component.GetUIView().inputScale;
                Vector3 diff  = mouse - component.absolutePosition;

                if (diff.x <= 20)
                {
                    musicEntryEnableDisable(component, value);
                    return;
                }
            }

            RadioContentInfo info = m_CurrentContent[value];

            AudioManagerHelper.SwitchToContent(info);
        }
コード例 #10
0
        /// <summary>
        /// Collects information that is available after loading of the game
        /// </summary>
        public void CollectPostLoadingData()
        {
            for (uint i = 0; i < PrefabCollection <RadioChannelInfo> .PrefabCount(); ++i)
            {
                RadioChannelInfo info = PrefabCollection <RadioChannelInfo> .GetPrefab(i);

                if (info == null)
                {
                    continue;
                }

                UserRadioChannel user;

                if (m_Stations.TryGetValue(info.name, out user))
                {
                    m_UserRadioDict[info]     = user;
                    user.m_VanillaChannelInfo = info;
                }
            }
            for (uint i = 0; i < PrefabCollection <RadioContentInfo> .PrefabCount(); ++i)
            {
                RadioContentInfo info = PrefabCollection <RadioContentInfo> .GetPrefab(i);

                if (info == null)
                {
                    continue;
                }

                UserRadioContent user;

                if (m_Songs.TryGetValue(info.name, out user))
                {
                    m_UserContentDict[info]   = user;
                    user.m_VanillaContentInfo = info;
                }
            }
        }
コード例 #11
0
        /// <summary>
        /// Enables or disables a radio content info
        /// </summary>
        /// <param name="info">Info.</param>
        /// <param name="enabled">If set to <c>true</c> enabled.</param>
        public static void SetContentEnabled(RadioContentInfo info, bool enabled)
        {
            if (info == null)
            {
                return;
            }
            if (ContentIsEnabled(info) == enabled)
            {
                return;
            }

            string id = info.m_folderName + "/" + info.m_fileName;

            if (enabled)
            {
                ModOptions.Instance.DisabledContent.Remove(id);
            }
            else
            {
                ModOptions.Instance.DisabledContent.Add(id);
            }

            ModOptions.Instance.SaveSettings();
        }
コード例 #12
0
        /// <summary>
        /// Switches to a specific radio content (music)
        /// </summary>
        /// <returns><c>true</c>, if the switch was successful, <c>false</c> otherwise.</returns>
        /// <param name="info">Info.</param>
        public static bool SwitchToContent(RadioContentInfo info)
        {
            AudioManager mgr = Singleton <AudioManager> .instance;

            // musicFileIsRadio is false if no radio channel is active. We cannot
            // do anything in this case.
            if (ReflectionHelper.GetPrivateField <bool>(mgr, "m_musicFileIsRadio"))
            {
                ushort contentindex = 0;
                bool   found        = false;

                for (int i = 0; i < mgr.m_radioContentCount; ++i)
                {
                    RadioContentData data = mgr.m_radioContents[i];

                    //Debug.Log("CC: " + data + " + " + data.Info + " == " + info);

                    if (data.Info == info)
                    {
                        contentindex = (ushort)i;
                        //Debug.Log("Found content index for " + info);
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    CSLMusicMod.Log("Switching to unloaded music " + info);

                    if (!mgr.CreateRadioContent(out contentindex, info))
                    {
                        CSLMusicMod.Log("... failed to create content " + info);
                        return(false);
                    }
                }

                CSLMusicMod.Log("Radio switches to track " + info);

                //Debug.Log("Content index: " + contentindex);

                // Next content
                ushort activechannel = ReflectionHelper.GetPrivateField <ushort>(mgr, "m_activeRadioChannel");

                if (activechannel >= 0)
                {
                    RadioChannelData data = mgr.m_radioChannels[activechannel];
                    data.m_currentContent = contentindex;
                    //data.m_nextContent = contentindex;
                    mgr.m_radioChannels[activechannel] = data;
                    //mgr.m_radioChannels[activechannel].ChangeContent(activechannel);

                    return(true);
                }

                //var player = ReflectionHelper.GetPrivateField<AudioManager.AudioPlayer>(mgr, "m_currentRadioPlayer");
                //player.m_source.Stop();

                return(false);
            }
            else
            {
                return(false);
            }
        }
コード例 #13
0
        /// <summary>
        /// Allows restriction of content to specific songs
        /// </summary>
        /// <returns>The collect radio content info.</returns>
        /// <param name="type">Type.</param>
        /// <param name="channel">Channel.</param>
        public FastList<ushort> CustomCollectRadioContentInfo(RadioContentInfo.ContentType type, RadioChannelInfo channel)
        {
            var mgr = Singleton<AudioManager>.instance;
            //Debug.Log("[CSLMusic][Internal] Rebuilding the radio content of channel " + channel.GetLocalizedTitle());

            // CO makes some things public and other things private. This is completely insane.
            var m_tempRadioContentBuffer = ReflectionHelper.GetPrivateField<FastList<ushort>>(mgr, "m_tempRadioContentBuffer"); // This variable is being worked on
            var m_radioContentTable = ReflectionHelper.GetPrivateField<FastList<ushort>[]>(mgr, "m_radioContentTable");

            m_tempRadioContentBuffer.Clear(); 

            if (m_radioContentTable == null)
            {
                // Let's all sing the "Expensive Song!" ♬Expensive, Expensive♬ ♩OMG it's so expensive♩ (Rest of lyrics didn't load, yet)
				ReflectionHelper.InvokePrivateVoidMethod(mgr, "RefreshRadioContentTable");
                m_radioContentTable = ReflectionHelper.GetPrivateField<FastList<ushort>[]>(mgr, "m_radioContentTable");
            }

            // Get the allowed radio content
            HashSet<RadioContentInfo> disallowed_content = null;
            if(channel != null)
            {
                RadioContentWatcher.DisallowedContent.TryGetValue(channel, out disallowed_content);
            }

            //Debug.Log("[update]" + channel.GetLocalizedTitle() + " | " + allowed_content);
            /*if(allowed_content == null || allowed_content.Count == 0)
            {
                Debug.Log(channel.GetLocalizedTitle() + ": All content enabled!");
            }*/

            int prefabDataIndex = channel.m_prefabDataIndex;
            if (prefabDataIndex != -1)
            {
                int num = (int)(prefabDataIndex * 5 + type);
                if (num < m_radioContentTable.Length)
                {
                    FastList<ushort> fastList = m_radioContentTable[num];
                    if (fastList != null)
                    {
                        for (int i = 0; i < fastList.m_size; i++)
                        {
                            ushort num2 = fastList.m_buffer[i];
                            RadioContentInfo prefab = PrefabCollection<RadioContentInfo>.GetPrefab((uint)num2);

                            if (prefab != null && Singleton<UnlockManager>.instance.Unlocked(prefab.m_UnlockMilestone))
                            {
                                // Filter only content info that should be kept
                                if( disallowed_content == null || disallowed_content.Count ==  0 || !disallowed_content.Contains(prefab))
                                {
									prefab.m_cooldown = 1000000;
									m_tempRadioContentBuffer.Add(num2);
                                }
                            }
                        }
                    }
                }
            }

            for (int j = 0; j < mgr.m_radioContents.m_size; j++)
            {
                RadioContentData.Flags flags = mgr.m_radioContents.m_buffer[j].m_flags;
                if ((flags & RadioContentData.Flags.Created) != RadioContentData.Flags.None)
                {
                    RadioContentInfo info = mgr.m_radioContents.m_buffer[j].Info;
                    if (info != null)
                    {
                        info.m_cooldown = Mathf.Min(info.m_cooldown, (int)mgr.m_radioContents.m_buffer[j].m_cooldown);
                    }
                }
            }

            return m_tempRadioContentBuffer;

        }
コード例 #14
0
        /// <summary>
        /// Adds music files that are placed in the vanilla directories to the vanilla channels
        /// </summary>
        private void ExtendVanillaContent()
        {
            if (!ModOptions.Instance.EnableAddingContentToVanillaStations)
            {
                return;
            }
            if (!ModOptions.Instance.AddVanillaSongsToMusicMix)
            {
                return;
            }

            for (uint i = 0; i < PrefabCollection <RadioChannelInfo> .PrefabCount(); ++i)
            {
                RadioChannelInfo info = PrefabCollection <RadioChannelInfo> .GetPrefab(i);

                if (info == null)
                {
                    continue;
                }

                if (!UserRadioContainer.m_UserRadioDict.ContainsKey(info))
                {
                    // Collect existing radio content
                    HashSet <string> existing = new HashSet <string>();

                    for (uint j = 0; j < PrefabCollection <RadioContentInfo> .PrefabCount(); ++j)
                    {
                        RadioContentInfo content = PrefabCollection <RadioContentInfo> .GetPrefab(j);

                        if (content == null)
                        {
                            continue;
                        }
                        if (content.m_radioChannels == null)
                        {
                            continue;
                        }

                        if (content.m_radioChannels.Contains(info))
                        {
                            string text = Path.Combine(DataLocation.gameContentPath, "Radio");
                            text = Path.Combine(text, content.m_contentType.ToString());
                            text = Path.Combine(text, content.m_folderName);
                            text = Path.Combine(text, content.m_fileName);

                            existing.Add(text);
                        }
                    }

                    HashSet <string> validcollectionnames = new HashSet <string>();
                    foreach (RadioContentInfo.ContentType type in Enum.GetValues(typeof(RadioContentInfo.ContentType)))
                    {
                        validcollectionnames.Add(type + ": " + info.name);
                    }

                    // Check our collection for non-existing files
                    foreach (UserRadioContent usercontent in UserRadioContainer.m_Songs.Values)
                    {
                        if (!existing.Contains(usercontent.m_FileName) && validcollectionnames.Contains(usercontent.m_Collection))
                        {
                            CSLMusicMod.Log("[ExtendedVanillaContent] Adding " + usercontent.m_FileName + " to vanilla station " + info.name);

                            List <RadioChannelInfo> v = GenericHelper.CopyOrCreateList <RadioChannelInfo>(usercontent.m_VanillaContentInfo.m_radioChannels);
                            v.Add(info);
                            usercontent.m_VanillaContentInfo.m_radioChannels = v.ToArray();
                        }
                    }
                }
            }
        }