Jump to content

21 posts in this topic Last Reply

Highlighted Posts

Posted:
Last Online:  
 

Is it possible to add custom audiofiles to assets?

 

 

Share this post


Link to post
Share on other sites
Posted:
Last Online:  
 

It would require an additional mod that registers the sound effects and applies them to the assets.

  • Like 2

Share this post


Link to post
Share on other sites
  • Original Poster
  • Posted:
    Last Online:  
     

    how much scripting effort it needs? You know my next question! ;-)

     

    :read::ohyes:

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     

    It's basically a mix of Sub Buildings Enabler and Ambient Sounds Tuner. You have to import the mp3 sound, then copy the whole effect structure of a vanilla asset and change the sounds.

    I'm not sure if it is worth it for a single asset.

    It would be easier to create a sound pack that replaces the sound of all assets.

    Share this post


    Link to post
    Share on other sites
  • Original Poster
  • Posted:
    Last Online:  
     

    Wouldt like to have some unique sounds for some uniqe buildings that are to rare for common building sounds.

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     

    I am sorry to resurrect such an old discussion, but I've been always interested whether you can upload custom audio files together with the asset. If I understand correctly what boformer said about that, you can't - you need a special mod for that. But - if I look at the Ploppable RICO mod, you can actually upload xml files in the folder. So, with that, would it be possible to mask xml files as audio files? Or is there any other possibility how to smuggle the sound file (for example as a byte array) with the asset?

    Then it would be possible to create one universal mod which would play the audio for every custom asset, without the need of having a mod for almost every single one.

    I would test it myself but I bet that somebody must have already tried something like this. Is there any catch than coding the mod itself?

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     
    2 hours ago, Strdate said:

    I am sorry to resurrect such an old discussion, but I've been always interested whether you can upload custom audio files together with the asset. If I understand correctly what boformer said about that, you can't - you need a special mod for that. But - if I look at the Ploppable RICO mod, you can actually upload xml files in the folder. So, with that, would it be possible to mask xml files as audio files? Or is there any other possibility how to smuggle the sound file (for example as a byte array) with the asset?

    Then it would be possible to create one universal mod which would play the audio for every custom asset, without the need of having a mod for almost every single one.

    I would test it myself but I bet that somebody must have already tried something like this. Is there any catch than coding the mod itself?

    Something like that has already been done for vehicle assets by @accessviolation (https://steamcommunity.com/sharedfiles/filedetails/?id=780720853) - for buildings something like this would also be possible. So you could pull the code needed from Git I guess.

    I like the concept CO did on buildings by using sounds per building type as irl those don't also differ that much. Well, to be honest, Buildings don't create that much noise on the outside irl. The sounds we hear is mostly wind, birds, people and traffic ;)

    When it comes to those types we got the ambient sounds tuner.

    More interesting, imo, would be a sound enabler for props which only plays sounds while close to the prop (so if the lod is not yet triggered) - this could add ambient like aircondition/transformer buzz or something like this to the scenario without getting annoying :)

    • Like 1

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     
    3 hours ago, Strdate said:

    I am sorry to resurrect such an old discussion, but I've been always interested whether you can upload custom audio files together with the asset. If I understand correctly what boformer said about that, you can't - you need a special mod for that. But - if I look at the Ploppable RICO mod, you can actually upload xml files in the folder. So, with that, would it be possible to mask xml files as audio files? Or is there any other possibility how to smuggle the sound file (for example as a byte array) with the asset?

    Then it would be possible to create one universal mod which would play the audio for every custom asset, without the need of having a mod for almost every single one.

    I would test it myself but I bet that somebody must have already tried something like this. Is there any catch than coding the mod itself?

    CO added a new function that allows you to add any kind of data to a .crp file: https://skylines.paradoxwikis.com/Modding_API#IAssetDataExtension

    With that, you could include an audio file in the .crp file. Performance would be better than with a separate .mp3 file in the asset folder.

    You would still need a mod to detect the custom data and to play the custom sounds.

    • Like 2

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     

    @Delta2k5 Something like that I had on my mind, sounds that are played when you are close to an object. If I am not mistaken, this is already achieved by Ambient Sound Tuner from BloodyPenguin. But it lets you replace the building sounds globally, not per asset. Thanks for link to the Vehicle Effects mod - there probably is all the needed code.

    @boformer Thanks for info! I had no idea about that. Out of curiosity, do you know about any mod that would utilize this? As I again look at the Vehicle Effect Mod, it seems the files are loaded directly from the folder.

    Anyway, thanks for the answers! Altho I was not planning to do a mod like this, I will definitely study the source codes. Maybe it would be a good update for the Ambient Sound Tuner, but when I look at the code from BloodyPenguin (or you, boformer ;) ) it is still well over my capabilities.

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     
    30 minutes ago, Strdate said:

    Thanks for info! I had no idea about that. Out of curiosity, do you know about any mod that would utilize this? As I again look at the Vehicle Effect Mod, it seems the files are loaded directly from the folder.

    Not sure if any mod utilizes it. They all use xml files, because that's how we started in 2015.

    • Like 1

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     
    6 hours ago, boformer said:

    CO added a new function that allows you to add any kind of data to a .crp file: https://skylines.paradoxwikis.com/Modding_API#IAssetDataExtension

    With that, you could include an audio file in the .crp file. Performance would be better than with a separate .mp3 file in the asset folder.

    You would still need a mod to detect the custom data and to play the custom sounds.

    Whoa! I didn't know that! I always wanted to make custom sounds for my trains. Gonna check this out. Thanks for the info.

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     
    12 minutes ago, Mr_Maison said:

    Whoa! I didn't know that! I always wanted to make custom sounds for my trains. Gonna check this out. Thanks for the info.

    Keep in mind that you need a mod to play the effects. It doesn't have much to do with where the sound files are stored, that is an internal issue of the mod itself. As Delta2k5 pointed out, you can use the Vehicle Effects mod.

    • Like 1

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     

    It would be worth looking at the amusement park assets in Park Life DLC to see how those work; each of the building seem to have their own custom sounds.

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     
    On 2/11/2019 at 2:43 PM, boformer said:

    CO added a new function that allows you to add any kind of data to a .crp file: https://skylines.paradoxwikis.com/Modding_API#IAssetDataExtension

    With that, you could include an audio file in the .crp file. Performance would be better than with a separate .mp3 file in the asset folder.

    You would still need a mod to detect the custom data and to play the custom sounds.

    Sooo, today I was playing with the IAssetDataExtension interface (not for custom audio, but something else) and found out that it is not working with the Loading Screen Mod - the OnAssetLoaded method is never called. That sucks.

    By the way, it is all a bit clumsy because apparently you have to store the data yourself in some kind of dictionary - as I searched through the source files, there is no way to access the data if you don't save them somewhere when the OnAssetLoaded method is called. (Or, as always, I miss something)

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     
    12 minutes ago, Strdate said:

    Sooo, today I was playing with the IAssetDataExtension interface (not for custom audio, but something else) and found out that it is not working with the Loading Screen Mod - the OnAssetLoaded method is never called. That sucks.

    That sounds like a bug in LSM that should be fixed. Can you create an issue in its Github repo?

    12 minutes ago, Strdate said:

    By the way, it is all a bit clumsy because apparently you have to store the data yourself in some kind of dictionary - as I searched through the source files, there is no way to access the data if you don't save them somewhere when the OnAssetLoaded method is called. (Or, as always, I miss something)

    That's correct, you need your own dictionary (or something faster, depending on where and how often you want to access the data). You could just make your IAssetDataExtension a singleton (static instance field) and delete the data in OnReleased.

    The real benefit is that you don't have to bundle extra files with the asset. When there are many assets, looking for extra files will slow down the loading process: https://stackoverflow.com/a/35870684/2461957

     

    • Like 1

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     

    Yes, I've already created an issue on github.

    You are right that it is still faster than saving it in a separate file, even from the perspective of how many lines of code it takes.

    I save the data in a dictionary with the key being the asset's name (for example BuildingInfo.name) without the dot prefix (i would save it with the prefix as well, but sometimes it is there and sometimes it is not...). I am not sure if it's safe against duplicates though.

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     
    4 hours ago, Strdate said:

    I am not sure if it's safe against duplicates though.

    Duplicates? I don't think that the dict you are receiving in OnAssetLoaded contains duplicates. Take a look at what's happening behind the scenes in ILSpy if you want to be certain...

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     
    On 4/14/2019 at 11:27 PM, boformer said:

    Duplicates? I don't think that the dict you are receiving in OnAssetLoaded contains duplicates. Take a look at what's happening behind the scenes in ILSpy if you want to be certain...

    I thought that if two assets have the same name it could cause problems.

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     
    4 hours ago, Strdate said:

    I thought that if two assets have the same name it could cause problems.

    The name is always prefixed be the workshop ID, so it should be unique. If you are transferring the data to your own Dictionary, you can use dict[prefabName] = value syntax instead of dict.Add(prefabName, value). to safely handle duplicates. But it should never happen.

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     

    After some testing I think I finally found out how it all works. Maybe after everything is clear I could make a tutorial out of this :D

    Let's start with this

    OnAssetLoaded(string name, object asset, Dictionary<string, byte[]> userData)

    The "name" variable is a beautified name of the asset without the prefix or whatever. So, in my opinion, you actually can receive two asset called "New Asset". Because of this it's not a good idea to use this name as a key when you want to store something from the userData.

    Thankfully, you can take the "asset", cast it into BuildingInfo or whatever and use the name of the prefab itself. This includes the prefix (which is the name of the file or workshop id) plus a dot, plus the actual prefab name, plus "_Data" postfix (For example "6558756.New Asset_Data"). That's good, you can use this as an unique key to access the data at any given point.

    The "userData" dictionary is a dictionary containing data of all mods taking advantage of the IAssetDataExtension, thus you shouldn't keep it all but only check for the data saved by your mod, otherwise the asset data will be unnecessarily saved by multiple mods at once. (Well, in fact if you only store the reference to the dictionary it shouldn't be such a problem, but you should keep in mind that it is shared by others and some other mod could, for example, delete your data. Thus I think it is a better idea to copy what you need and disregard the rest of the dictionary)

    Now let's look at this

    public void OnAssetSaved(string name, object asset, out Dictionary<string, byte[]> userData)

    "name" - again, simple name of the asset

    "asset" - There is where the problems start. Imagine that you have your userData ready and besides saving them with the asset you would like to update the prefab-data dictionary, so that you can load them when the asset is reloaded (Inbetween saving the asset and reloading the asset the OnAssetLoaded method WON'T be called unless you are reloading the whole editor!!)

    You would again cast the "asset" to BuildingInfo and read the name, in the good faith that you would receive the same key as when you are doing this thing in the OnAssetLoaded method. But you would be wrong. This time, the name of the asset doesn't contain the prefix (or at least that is my experience) and the rest of the name could be out-of-date! If the user renames the asset when it's being saved, you don't see this change when this method is called. My question is: is there any way to get the prefix, so I can obtain the correct key? I receive the correct asset name in the "name" variable and can add the "_Data" postfix myself, but I don't see how to get the prefix.

    "userData" - Warning! This is not the same dictionary as you will receive in the OnLevelLoaded method. It will be merged with the dictionaries of all other mods.

    There is a code concept which might illustrate it all better:

    /* Untested snippet */
    public class AssetDataExtension : IAssetDataExtension
        {
    
      		public AssetDataExtension instance;
      		
      		/* Dictionary of assets and their data */
      		private Dictionary<string,byte[]> myModData = new Dictionary<string,byte[]>();
      
      		public AssetDataExtension()
            {
              instance = this;
            }
      
            public void OnAssetLoaded(string name, object asset, Dictionary<string, byte[]> userData)
            {
                BuildingInfo info = asset as BuildingInfo;
                if (info != null)
                {
                        if( userData.ContainsKey( "MyModKey" ) )
                        {
                          if( ModLoading.IsInAssetEditor )
                          {
                            myModData[ info.name ] = userData[ "myModKey" ];
                          } else
                          {
                            // Let's hope for no duplicates?
                            myModData[ name ] = userData[ myModKey ];
                          }
                        }
                }
            }
    
            public void OnAssetSaved(string name, object asset, out Dictionary<string, byte[]> userData)
            {
              byte[] data = SomeClass.SerializeMyData();
              if(data != null)
              {
                userData = new Dictionary<string,byte[]>();
                userData[ "myModKey" ] = data;
                myModData[ name ] = data;
              }
            }
      
      		public byte[] GetAssetData(BuildingInfo info)
            {
              if(ModLoading.IsInAssetEditor)
              {
                return myModData[ GetNameWithoutPrefixAndPostfix( info.name ) ];
              }
              else
              {
                return myModData[ info.name ];
              }
            }
      
      		private string GetNameWithoutPrefixAndPostfix(string str)
            {
              ...
            }
    
            public void OnCreated(IAssetData assetData)
            {
    
            }
    
            public void OnReleased()
            {
              // reset saved data
    			myModData = new Dictionary<string,byte[]>();
            }

    And about the compatibility with the LSM mod. The author replied to my topic, you can see how it is going there https://steamcommunity.com/workshop/filedetails/discussion/667342976/2605804632891559366/

     

    EDIT: Tested it, with the code above you really can end up with Assets with the same name that clash. So this must be somehow solved.

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     

    HELP! Anyone know how I can get the evac shelter sound to apply to other buildings/ objects? 
    Wana make functional ems sirens for disasters!

    Share this post


    Link to post
    Share on other sites

    Sign In or register to comment...

    To comment in reply, you must be a community member

    Sign In  

    Already have an account? Sign in here.

    Sign In Now

    Create an Account  

    Sign up to join our friendly community. It's easy!  

    Register a New Account


    ×

    Thank You for the Continued Support!

    Simtropolis depends on donations to fund site maintenance costs.
    Without your support, we just would not be in our 24th year online!  You really help make this a great community. *:thumb:

    But we still need your support to stay online. If you're able to, please consider a donation to help us stay up and running. This helps sustain a platform where we can share our community creations for years to come.

    Make a Donation, Get a Gift!

    Expand your city with the best from the Simtropolis Exchange.
    Make a Donation and get one or all three discs today!

    STEX Collections

    By way of a "Thank You" gift, we'd like to send you our STEX Collector's DVD. It's some of the best buildings, lots, maps and mods collected for you over the years. Check out the STEX Collections for more info.

    Each donation helps keep Simtropolis online, open and free!

    Thank you for reading and enjoy the site!

    More About STEX Collections