Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sound Enhancement for Valthrun ? #104

Open
CremaHD opened this issue Nov 4, 2023 · 0 comments
Open

Sound Enhancement for Valthrun ? #104

CremaHD opened this issue Nov 4, 2023 · 0 comments

Comments

@CremaHD
Copy link

CremaHD commented Nov 4, 2023

Hi everyone,

I'm a beginner programmer who is still learning English. I wanted to contribute to the Valthrun CS2 project, so I created a mod that increases the volume of enemy sounds.

I used an AI to generate the code, so I'm not sure if it's the best way to do it. I also don't know if the mod is actually useful or not.

I'm posting this mod here in case it's helpful to anyone. I'm always looking for feedback, so please let me know if you have any suggestions.

Thanks!

Description:

This mod increases the volume of enemy sounds by a percentage. This can be useful for players who want to be able to hear enemy footsteps and other sounds more easily.

use crate::settings::AppSettings;

pub trait Enhancement {
fn update(&mut self, ctx: &UpdateContext) -> anyhow::Result<()>;

fn update_settings(
    &mut self,
    ui: &imgui::Ui,
    settings: &mut AppSettings,
) -> anyhow::Result<bool>;

}

mod bomb;
pub use bomb::*;

mod player;
pub use player::*;

mod trigger;
pub use trigger::*;

mod spectators_list;
pub use spectators_list::*;

mod aim;
pub use aim::*;

use crate::{
view::ViewController,
UpdateContext,
};

enum SoundVolumeIncrease {
None,
Percent(f32),
}

impl SoundVolumeIncrease {
fn from_settings(settings: &AppSettings) -> Self {
if settings.enemies_sound_volume_enabled {
if settings.enemies_sound_volume_increase_percent == 0.0 {
SoundVolumeIncrease::None
} else {
SoundVolumeIncrease::Percent(settings.enemies_sound_volume_increase_percent)
}
} else {
SoundVolumeIncrease::None
}
}
}

impl Enhancement for SoundVolumeEnhancement {
fn update(&mut self, ctx: &UpdateContext) -> anyhow::Result<()> {
let enemies_sound_volume = match SoundVolumeIncrease::from_settings(&ctx.settings) {
SoundVolumeIncrease::None => 1.0,
SoundVolumeIncrease::Percent(percent) => percent,
};

    for entity_identity in ctx.cs2_entities.all_identities() {
        let class_name = ctx
            .class_name_cache
            .lookup(&entity_identity.entity_class_info()?)
            .context("class name")?;

        if class_name == "C_BaseEntity" && entity_identity.team() != ctx.player_info.team {
            let entity = entity_identity
                .entity_ptr::<C_BaseEntity>()?
                .read_schema()?;

            // Update enemy sound volume for the entity
            entity.m_flSoundVolume()? = enemies_sound_volume;
        }
    }

    Ok(false)
}

fn update_settings(
    &mut self,
    ui: &imgui::Ui,
    settings: &mut AppSettings,
) -> anyhow::Result<bool> {
    if ui.collapsing_header("Sound Enhancement") {
        // Enable/disable mode
        let mut checkbox = ui.checkbox("Enable Mode", &mut settings.enemies_sound_volume_enabled);
        if checkbox.changed() {
            // Update mode state
            settings.enemies_sound_volume_enabled = checkbox.checked();
        }

        // Increase factor setting
        let mut slider = ui.slider_float("Increase Factor", &mut settings.enemies_sound_volume_increase_percent, 0.0, 100.0);
        if slider.changed() {
            // Update increase factor
            settings.enemies_sound_volume_increase_percent = slider.value();
        }

        // Information
        ui.text("This mod increases the volume of enemy sounds by a percentage.");
        ui.text("A value of 0 means that the sounds are not modified.");
        ui.text("A value of 1 means that the sounds are 1% louder.");
        ui.text("A value of 100 means that the sounds are twice as loud.");
    }

    Ok(false)
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant