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

Add console command to toggle muzzle flashes #296

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common/include/common/config/GameConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ struct GameConfig
CfgVar<bool> true_color_textures = true;
CfgVar<bool> damage_screen_flash = true;
CfgVar<bool> mesh_static_lighting = true;
CfgVar<bool> muzzle_flash = true;
CfgVar<bool> glares = true;
CfgVar<bool> show_enemy_bullets = true;

Expand Down
1 change: 1 addition & 0 deletions common/src/config/GameConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ bool GameConfig::visit_vars(T&& visitor, bool is_save)
result &= visitor(dash_faction_key, "Big HUD", big_hud);
result &= visitor(dash_faction_key, "Reticle Scale", reticle_scale);
result &= visitor(dash_faction_key, "Mesh Static Lighting", mesh_static_lighting);
result &= visitor(dash_faction_key, "Muzzle Flash Lights", muzzle_flash);
result &= visitor(dash_faction_key, "Player Join Beep", player_join_beep);
result &= visitor(dash_faction_key, "Autosave", autosave);

Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Version 1.9.0 (not released yet)
- Add level filename to "Level Initializing" console message
- Properly handle WM_PAINT in dedicated server, may improve performance (DF bug)
- Fix crash when `verify_level` command is run without a level being loaded
- Add `muzzle_flash` command

Version 1.8.0 (released 2022-09-17)
-----------------------------------
Expand Down
24 changes: 24 additions & 0 deletions game_patch/object/obj_light.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <cassert>
#include <xlog/xlog.h>
#include <patch_common/FunHook.h>
#include <patch_common/CallHook.h>
#include <common/utils/list-utils.h>
#include "../rf/object.h"
#include "../rf/item.h"
Expand Down Expand Up @@ -133,6 +134,25 @@ ConsoleCommand2 mesh_static_lighting_cmd{
"Toggle mesh static lighting calculation",
};

CallHook<void(rf::Entity&)> entity_update_muzzle_flash_light_hook{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it belongs to this file. obj_light.cpp is related to generating vertex colors for meshes so they become lit (think of it as a lightmap but less expensive).
This feature has nothing to do with that. The function name starts with entity so a good candidate would be entity.cpp. I generally try to layout the code the same as it was in original RF code. From IDA you can see that this function is close to other entity related functions. Keeping things grouped based on RF modules make it easier to avoid collisions between patches

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I will move it.

0x0041E814,
[](rf::Entity& ep) {
if (g_game_config.muzzle_flash) {
GooberRF marked this conversation as resolved.
Show resolved Hide resolved
entity_update_muzzle_flash_light_hook.call_target(ep);
}
},
};

ConsoleCommand2 muzzle_flash_cmd{
"muzzle_flash",
[]() {
g_game_config.muzzle_flash = !g_game_config.muzzle_flash;
g_game_config.save();
rf::console::print("Muzzle flash lights are {}", g_game_config.muzzle_flash ? "enabled" : "disabled");
},
"Toggle muzzle flash dynamic lights",
};

void obj_light_apply_patch()
{
// Fix/improve items and clutters static lighting calculation: fix matrices being zero and use static lights
Expand All @@ -143,6 +163,10 @@ void obj_light_apply_patch()
// Fix invalid vertex offset in mesh lighting calculation
write_mem<int8_t>(0x005042F0 + 2, sizeof(rf::Vector3));

// Don't create muzzle flash lights
entity_update_muzzle_flash_light_hook.install();

// Commands
mesh_static_lighting_cmd.register_cmd();
muzzle_flash_cmd.register_cmd();
}