Skip to content

Commit 0bc478d

Browse files
committed
Added audio level options, muted interior sound on external view
1 parent 735f995 commit 0bc478d

File tree

13 files changed

+25999
-23
lines changed

13 files changed

+25999
-23
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.39.6
2+
- Added rudimentary audio level customization
3+
- Fixed interior sounds being played when on an exterior view
4+
15
## 1.39.5
26
- Added support for more interior events:
37
- interior/stick_hazard_warning

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
A telemetry plugin for ATS/ETS2 that includes an FMOD instance so that you can use FMOD sound mods.
66

77
This is pretty useless in singleplayer because you could just load the mod directly in the game.<br>
8-
But I'm mostly playing TruckersMP, where fmod is still kinda broken and also doesn't support sound mods, which are much better than the base game sounds.
8+
But since I'm mostly playing TruckersMP, where sound mods are not supported (which are much better than the base game sounds).
99

1010
So this is something I kinda quickly put together after the broken sounds in 1.37 TruckersMP, and then didn't really update it once it worked except for making it compatible with the newer versions, so it is pretty basic.
1111

@@ -15,10 +15,10 @@ I'm not that great at c(++) and reverse engineering so it might just stay this w
1515

1616
# Some limitations/issues
1717
- Will keep playing sound even when alt-tabbed
18-
- Sound level/direction does not change with the camera, the sound is always as if you are in the truck looking forward.
18+
- Sound level/direction does not change with the camera, the sound is always as if you are in the truck looking forward, with the exception of interior sounds not being played when on an exterior camera.
1919
- You will need to mute or lower some of the in-game audio channels for your truck (or you will hear double audio), but this will also mute all truck sounds from other players
2020
- Can (and most probably will) break and (possibly) crash you game with every (major) game update because it needs to read some values directly from memory, and this structure can change with updates
21-
- No volume control (not sure how to add this except for adding imgui or something like it)
21+
- Only very basic volume control (might look into something better/easier in the future)
2222
- Probably some more that I forgot
2323

2424
# How to use
@@ -30,14 +30,15 @@ Here's the correct folder structure:
3030
```python
3131
<game_install_location>/bin/win_x64/
3232
│ eurotrucks2.exe # or amtrucks.exe for ATS
33-
... # removed to keep this list smaller
33+
... # hidden to keep this list smaller
3434
3535
└───plugins # create if not exists
3636
│ ts-fmod-plugin.dll # copy from release
3737
3838
└───ts-fmod-plugin # copy from release
3939
master.bank # copy from specific game folder in release
40-
selected.bank.txt # edit text in file with sound mod filename you want
40+
selected.bank.txt # copy from release | edit text in file with sound mod filename you want
41+
sound_levels.txt # copy from release | edit the sound levels to you liking
4142
the_sound_mod_you_want_to_use.bank # example of sound mod
4243
the_sound_mod_you_want_to_use.bank.guids # example of sound mod
4344
```
@@ -53,6 +54,8 @@ You will generally need to mute/lower the truck engine, exhaust and turbo sound
5354

5455
If you have the developer console enabled in-game you can switch sound mods without restarting by changing the filename in `selected.bank.txt` and then in the game console enter `sdk reload`. This will reload all telemetry plugins and cause this plugin to load the newly selected sound mod.
5556

57+
You can change the sound levels in the `sound_levels.txt` file, you will just kind of need to play with them until you get something you like. Again you can use the `sdk reload` console command after you've changed these to reload the plugin with these new values.
58+
5659
When the game updates you might need to update the `master.bank` file, it is located in the base.scs file for the specific game, in that file it is located in `/sound/master/`
5760

5861
# Supported FMOD events and parameters

dist/ts-fmod-plugin.dll

71.5 KB
Binary file not shown.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"master": 0.5,
3+
"engine": 0.5,
4+
"exhaust": 0.5,
5+
"turbo": 0.5,
6+
"interior": 1,
7+
"exterior_when_windows_closed": 0.75
8+
}

ts-fmod-plugin/consts.h

Lines changed: 0 additions & 8 deletions
This file was deleted.

ts-fmod-plugin/dllmain.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,28 @@ SCSAPI_VOID telemetry_tick(const scs_event_t event, const void* const event_info
125125
const auto window_pos = unk_window_parent->get_window_state();
126126
if (window_pos.x >= 0 && window_pos.x <= 1) fmod_manager_instance->set_global_parameter("wnd_left", window_pos.x);
127127
if (window_pos.y >= 0 && window_pos.y <= 1) fmod_manager_instance->set_global_parameter("wnd_right", window_pos.y);
128-
if (common::cmpf(window_pos.x, 0) && common::cmpf(window_pos.y, 0)) // not sure what to to with this (sound levels when windows close(d)) yet / maybe fade audio the more it closes/opens
128+
if (common::cmpf(window_pos.x, 0) && common::cmpf(window_pos.y, 0))
129129
{
130-
fmod_manager_instance->set_bus_volume("outside", consts::window_closed_volume);
131-
fmod_manager_instance->set_bus_volume("exterior", consts::window_closed_volume); // backward compatibility
130+
fmod_manager_instance->set_bus_volume("outside", fmod_manager_instance->sound_levels.windows_closed);
131+
fmod_manager_instance->set_bus_volume("exterior", fmod_manager_instance->sound_levels.windows_closed); // backward compatibility
132132
}
133133
else
134134
{
135-
fmod_manager_instance->set_bus_volume("outside", consts::window_open_volume);
136-
fmod_manager_instance->set_bus_volume("exterior", consts::window_open_volume); // backward compatibility
135+
fmod_manager_instance->set_bus_volume("outside", 1);
136+
fmod_manager_instance->set_bus_volume("exterior", 1); // backward compatibility
137+
}
138+
139+
if (unk_window_parent->get_is_camera_inside())
140+
{
141+
fmod_manager_instance->set_bus_volume("cabin/interior", fmod_manager_instance->sound_levels.interior);
142+
}
143+
else if (unk_window_parent->get_is_on_interior_cam())
144+
{
145+
fmod_manager_instance->set_bus_volume("cabin/interior", fmod_manager_instance->sound_levels.interior / 2.0f);
146+
}
147+
else
148+
{
149+
fmod_manager_instance->set_bus_volume("cabin/interior", 0);
137150
}
138151

139152
fmod_manager_instance->set_global_parameter("surr_type", unk_window_parent->get_has_echo());

ts-fmod-plugin/fmod_manager.cpp

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,16 @@ bool fmod_manager::init()
7878
return false;
7979
}
8080

81-
set_bus_volume("outside", consts::window_closed_volume);
82-
set_bus_volume("exterior", consts::window_closed_volume); // backward compatibility for 1.37 sound mods
81+
load_sound_levels(plugin_files_dir);
82+
83+
set_bus_volume("", sound_levels.master);
84+
set_bus_volume("outside/exterior/truck_engine", sound_levels.engine);
85+
set_bus_volume("outside/exterior/truck_exhaust", sound_levels.exhaust);
86+
set_bus_volume("outside/exterior/truck_turbo", sound_levels.turbo);
87+
set_bus_volume("cabin/interior", sound_levels.interior);
88+
89+
set_bus_volume("outside", sound_levels.windows_closed);
90+
set_bus_volume("exterior", sound_levels.windows_closed); // backward compatibility for 1.37 sound mods
8391

8492
return true;
8593
}
@@ -127,6 +135,73 @@ bool fmod_manager::init_channels(const std::string& plugin_files_dir)
127135
return true;
128136
}
129137

138+
float fmod_manager::get_sound_level_from_json(json j, const char* key, float defaultValue = 1.0f)
139+
{
140+
141+
std::stringstream ss;
142+
143+
float val = defaultValue;
144+
if (j.contains(key) && j[key].is_number())
145+
{
146+
val = j[key].get<float>();
147+
if (val < 0.0f)
148+
{
149+
ss << "[ts-fmod-plugin] Invalid value for sound level '" << key << "', value should be more than 0. Defaulting to " << defaultValue;
150+
scs_log_(SCS_LOG_TYPE_error, ss.str().c_str());
151+
val = defaultValue;
152+
}
153+
}
154+
else
155+
{
156+
ss.clear();
157+
ss << "[ts-fmod-plugin] Could not read sound level '" << key << "', defaulting to " << defaultValue;
158+
scs_log_(SCS_LOG_TYPE_error, ss.str().c_str());
159+
}
160+
161+
return val / 2;
162+
}
163+
164+
bool fmod_manager::load_sound_levels(const std::string& plugin_files_dir)
165+
{
166+
const auto sound_levels_file_path = plugin_files_dir + "sound_levels.txt";
167+
168+
if (!fs::exists(sound_levels_file_path))
169+
{
170+
scs_log_(SCS_LOG_TYPE_error, "[ts-fmod-plugin] Could not find the 'sound_levels.txt' file");
171+
return false;
172+
}
173+
174+
std::ifstream sound_levels_file(sound_levels_file_path);
175+
std::string line;
176+
177+
if (!sound_levels_file.is_open())
178+
{
179+
scs_log_(SCS_LOG_TYPE_error, "[ts-fmod-plugin] Could not read the 'sound_levels.txt' file");
180+
return false;
181+
}
182+
183+
json j;
184+
185+
try {
186+
sound_levels_file >> j;
187+
}
188+
catch (json::parse_error& e)
189+
{
190+
scs_log_(SCS_LOG_TYPE_error, "[ts-fmod-plugin] Could not parse JSON from 'sound_levels.txt' ");
191+
return false;
192+
}
193+
194+
195+
sound_levels.master = get_sound_level_from_json(j, "master");
196+
sound_levels.engine = get_sound_level_from_json(j, "engine");
197+
sound_levels.exhaust = get_sound_level_from_json(j, "exhaust");
198+
sound_levels.turbo = get_sound_level_from_json(j, "turbo");
199+
sound_levels.interior = get_sound_level_from_json(j, "interior");
200+
sound_levels.windows_closed = get_sound_level_from_json(j, "exterior_when_windows_closed", 0.7f);
201+
202+
return true;
203+
}
204+
130205
void fmod_manager::set_paused(const bool state)
131206
{
132207
pause_bus("", state); // pause/unpause the main bus ('bus:/')

ts-fmod-plugin/fmod_manager.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
#pragma once
22
#include <scssdk/scssdk.h>
3+
#include "nlohmann/json.hpp"
4+
5+
using json = nlohmann::json;
36

47
#include "fmod_event.h"
58

9+
struct sound_levels_t {
10+
float master = 0.25;
11+
float engine = 0.25;
12+
float exhaust = 0.25;
13+
float turbo = 0.25;
14+
float interior = 0.5;
15+
float windows_closed = 0.35;
16+
};
17+
618
class fmod_manager
719
{
820
FMOD::Studio::System* system_ = nullptr;
@@ -18,7 +30,12 @@ class fmod_manager
1830
bool load_selected_bank(const std::string& plugin_files_dir);
1931
bool init_channels(const std::string& plugin_files_dir);
2032

33+
float get_sound_level_from_json(json j, const char* key, float defaultValue);
34+
bool load_sound_levels(const std::string& plugin_files_dir);
35+
2136
public:
37+
sound_levels_t sound_levels;
38+
2239
explicit fmod_manager(scs_log_t scs_log);
2340
~fmod_manager();
2441

ts-fmod-plugin/memory_structure.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,16 @@ class unk_window // still need to figure out what this actually is
148148
{
149149
return window_state;
150150
}
151+
152+
bool get_is_camera_inside() const
153+
{
154+
return is_camera_inside;
155+
}
156+
157+
bool get_is_on_interior_cam() const
158+
{
159+
return interior_camera;
160+
}
151161
};
152162

153163
class economy_base_t

0 commit comments

Comments
 (0)