SUBSIM Radio Room Forums



SUBSIM: The Web's #1 resource for all submarine & naval simulations since 1997

Go Back   SUBSIM Radio Room Forums > Silent Hunter 3 - 4 - 5 > SH4 Mods Workshop
Forget password? Reset here

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 07-16-22, 01:40 AM   #1
Ataraxzy
Watch
 
Join Date: Apr 2021
Posts: 16
Downloads: 37
Uploads: 0
gear Tired of Missing Broadcasts? Me too!

The Events folders in the various sound mods are fabulous, and really let you relive history. The only problem with them is that unless you've painstakingly gone through every. single. entry. of. every. events.ini file, they come and go with nary a peep to let you know. Sure, there are big days like D-day, Sevastopol, Guadalcanal and so on that everyone knows, but what about speeches? What about listening to old-time radio shows in the order they were broadcast?

You can have the game send you a radio message when an EVENT happens. If there's an entry in a radio folder's event.ini, the game will do TWO things: 1. it'll start playing the appropriate sound file and 2. if there's an accompanying full.sound.file.name.ini for that sound file, and it's properly formatted as follows:

Code:
[NEWS]
Title=Whatever You Want Your Title To Be
Body=Put the body text of your new radio message here!
The game will send a radio message to you that appears on your clipboard, letting you know that there's a broadcast you might want to listen to.


But Raaaaaax, you say, some of us have thousands of files in various Event folders. That's weeks worth of thankless work!

Well, yes.

Unless you automate it. With scripts!


First off, I'm a Linux sysadmin, not a Windows one, so while these could be rewritten in PowerShell (or, as I like to call it, PowersHell), I wrote them in bash. There are an abundance of ways to get a proper bash command line on a windows PC, but details on how to accomplish that are beyond the scope of this post. Google for WSL2, Git for Windows or MinGW if you're looking to start. Or, go to the Microsoft Store, type in "Ubuntu" at the search bar and grab the latest and greatest.

Problem: You've got to create thousands of files, with names that match thousands of source files. Then you've got to fill those thousands of new files with "stuff".

First, let's normalize the file names. Music filenames are the absolute worst. Everyone's got their own 'method', sometimes two, and nobody's method is the same as anyone else's. Oh, and song names are linguistic phrases and sentences, explicitly the opposite of nice, standardized variable names. They have all sorts of awful things in them, for example, single quotes for all the "You'll"s and "I'll"s and so on. Scripting languages use quotes for more than separating letters, so we need to remove them.

First, remove them from the events.ini file. Open in your favorite text editor and find/replace all "'" with "". (that's "find/replace all single quotes with nothing.")

Next, we run a little two-liner in our Events directory:
Code:
$ shopt -s globstar 

$ find -name **" -type f -exec rename "s///g '{}' \;
Boom. No more single quotes.

Now, we want to create new .ini files to match all the .mp3/.ogg/.wav files in the Events directory. Another one liner, again run from the Events directory:
Code:
$ ls *.mp3 |  xargs -IX touch X.ini
change *.mp3 for *.ogg or *.wav as needed to get all the files.


k, now we have a folder populated with the following:
sound files.
sound.mp3.ini files and a single
event.ini file.

Time to fill those .mp3.ini files with actual information. We're going to write a script to do it.

create a file, use your favorite text editor to populate the file with the following, and finally, don't forget to chmod +x the file so that you can actually run it:

Code:
#!/bin/bash

mv events.ini ..  #move the events.ini file up one directory level
for file in *.ini; do
        echo "[NEWS]" >> "$file"
        echo "Title=StationName Broadcast" >> "$file"
        echo "Body=Channel: NN.NN" >> "$file"
done
mv ../events.ini . #move the events.ini file back
For each radio station Events folder, change the echo lines to information that is appropriate, like the Station Name and the Channel number. Then, run that script in the Events folder.

And that's it. Now you'll get a radio message every time an event fires from that radio station.

Here's a pic of the end-state:
Attached Images
File Type: jpg inifile format.jpg (97.3 KB, 13 views)

Last edited by Ataraxzy; 07-21-22 at 08:21 AM. Reason: Formatting.
Ataraxzy is offline   Reply With Quote
 

Tags
events, radio, scripts, sound mods


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 05:52 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright © 1995- 2024 Subsim®
"Subsim" is a registered trademark, all rights reserved.