dariowouters / ts-fmod-plugin

A telemetry plugin for ATS/ETS2 to use FMOD sound mods (to a limited extent) for example in TruckersMP
MIT License
45 stars 12 forks source link

Implement navigation_sound_event feature #11

Closed puppleStar77 closed 11 months ago

puppleStar77 commented 11 months ago

Euro Truck Simulator 2 (ETS2) has navigation voice sounds in numerous languages. However, there are still unsupported countries and languages, and there are also many low-quality voice instructions. In the Multi-mode(TruckerMP), Eurotruck mode is not available. Therefore, I implemented the navigation_sound_event feature using the provided code. I am not good with English, C++, and reverse engineering, but I have tried my best and put in a lot of effort. This feature allows receiving navigation event sounds. Before proceeding with a pull request, I want to confirm if it is needed and desired by the project maintainers.

The new classes added are:

class sound_event_t
{
    class sound_player* sound_player; //0x0000
    char pad_0008[0x28];              //0x0008
    uint32_t is_playing;              //0x0030  1:playing, 4:stop? maybe?
    uint32_t something;               //0x0034
    class gl* glsl;                   //0x0038
    char pad_003c[0x18];              //0x0040
    class gl* glsl2;                  //0x0060
    char* sound_event_name_with_file; //0x0060
    char pad_0068[0x50];              //0x0068

public:
    uint32_t get_is_playing() const {
        return is_playing;
    }
    const char* const get_sound_event_name_with_file_name() const {
        return sound_event_name_with_file;
    }
};

class navigation_sound_event
{
    uint32_t pad_0000;                  //0x0000
    uint32_t pad_0004;                  //0x0004
    char *event_name;                   //0x0008
    uint32_t pad_0010;                  //0x0010
    uint32_t pad_0014;                  //0x0014
    class navigation* navi_instance;    //0x0018
    sound_event_t *sound_event;          //0x0020

public:
    sound_event_t *get_sound_event() const{
        return sound_event;
    }
    char* get_event_name() const {
        return event_name;
    }
};

To utilize the feature, you can use the following code snippet:

navigation_sound_event** ev = (unk_interior_parent->get_navigation_sound_events());
            for (short i = 0; i < unk_interior_parent->get_navigation_sound_events_count(); i++)
            {
                auto snd = ev + i;
                auto  now = (*snd)->get_sound_event()->get_is_playing();
                if (now == 1)
                {
                    if (played.size() < i)
                    {
                        played.resize(i + 1);
                    }
                    if (now != played[i])
                    {
                        fmod_manager_instance->set_event_state((*snd)->get_event_name(), true, true);
                        {
                            std::stringstream ss;
                            ss << "[ts-fmod-plugin] PlaySound : " << (*snd)->get_event_name();
                            scs_log(0, ss.str().c_str());
                        }
                    }
                }
                if (played.size() < i)
                {
                    played.resize(i + 1);
                }
                played[i] = now;

            }
puppleStar77 commented 11 months ago
class unk_interior // still need to figure out what this actually is
{
    char pad_0000[184]; //0x0000
    bool interior_camera; //0x00B8 1 when camera is set to interior even when head out the window
    bool is_camera_inside; //0x00B9 1 if camera is inside, 0 when head through window
    char pad_00BA[2]; //0x00BA
    float camera_rotation_in_cabin; //0x00BC 0 = head straight, left is -, right is +, maybe different for UK??
    char pad_00C0[24]; //0x00C0
    unk_cabin_t* unk_cabin_ptr; //0x00D8
    vec2s_t window_state; //0x00E0 0 = closed, 1 = open
    char pad_00E8[1648]; //0x00E8
    navigation_sound_event* now_playing_navigation_sound;  // 0x0758
    char pad_0768[88]; //0x0768
    navigation_sound_event** navigation_sound_events; //0x07C0
    int64_t navigation_sound_events_count; //0x07C8
    char pad_07D0[5152]; //0x07D0
    bool should_have_echo; //0x1BF0

I updated the storage location for the currently playing navigation sound object to ensure better sound support.

dariowouters commented 11 months ago

Oh very nice thank you, I've seen multiple people ask about custom navigation sounds before so yes feel free to make a pull request.

puppleStar77 commented 11 months ago

Thank you for your response. I will tidy up the code and submit the pull request soon.

Victoria458 commented 11 months ago

Приветы)как это все сделать незнающему человеку? очень хочу свою навигацию