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

Alias spectate command to camera2 in SP, add help strings for cheat commands #287

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

GooberRF
Copy link
Contributor

This PR:

  • Makes spectate set the camera to free look (same as camera2) when issued in single player (as opposed to just kicking back an error)
  • Adds missing help strings to the camera1, camera2, camera3, and heehoo builtin cheat commands. In the case of heehoo, this is displayed using hud_msg just like vivalahelvig and bighugmug. For the cameraX commands, the help text is printed to the console so that when a player wants to go back to first person, they'll know how.

Resolves #206

@is-this-c
Copy link
Contributor

Personally I do not see usefulness especially for camera1 camera2 camera3 and heehoo.

@GooberRF
Copy link
Contributor Author

Personally I do not see usefulness especially for camera1 camera2 camera3 and heehoo.

  • heehoo: both vivalahelvig and bighugmug have similar HUD messages, heehoo is the odd one out and should be standardized.
  • cameraX: With the amount of times I've heard people (even relatively experienced players) make comments like "wait, how do I get back to first person?" after entering camera2 or camera3, I have absolutely no reservations about adding help strings that do nothing but simply inform those who may be unaware.

@is-this-c
Copy link
Contributor

I do not like check_can_use_cheat_cmd. It can print to console but it is supposed to be just a check. It also checks if the level is loaded which should not be part of its scope.

Further handle_camera_command can be simplified. It does not need to take mode. It can call call_target and then check the camera mode.

cameraX: With the amount of times I've heard people (even relatively experienced players) make comments like "wait, how do I get back to first person?" after entering camera2 or camera3, I have absolutely no reservations about adding help strings that do nothing but simply inform those who may be unaware.

. cmd exists.

@GooberRF
Copy link
Contributor Author

It can print to console but it is supposed to be just a check.

Good point, fixed.

It also checks if the level is loaded which should not be part of its scope.

I disagree. It's a relevant factor and while the original game does not, it is vastly more intuitive to tell a player who enters a command why that command had no effect, rather than simply telling them nothing.

Further handle_camera_command can be simplified. It does not need to take mode. It can call call_target and then check the camera mode.

Good point as well, I've refactored that code to address this.

. cmd exists.

It does, and I'm a huge fan of it. It does not, however, serve even a somewhat similar purpose or address the same issue that this PR does.

@@ -144,4 +144,5 @@ namespace rf
static auto& hud_weapon_cycle_current_idx = addr_as_ref<int>(0x007C71A8);

static auto& hud_do_frame = addr_as_ref<void(Player*)>(0x00437B80);
static auto& hud_msg = addr_as_ref<void(const char* text, int, int duration, Color*)>(0x004383C0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
static auto& hud_msg = addr_as_ref<void(const char* text, int, int duration, Color*)>(0x004383C0);
static auto& hud_msg = addr_as_ref<void(const char* text, int, int duration, const Color*)>(0x004383C0);

@@ -414,6 +414,7 @@ namespace rf
static auto& entity_fire_init_bones = addr_as_ref<bool(EntityFireInfo *efi, Object *objp)>(0x0042EB20);
static auto& entity_is_swimming = addr_as_ref<bool(Entity* ep)>(0x0042A0A0);
static auto& entity_is_falling = addr_as_ref<bool(Entity* ep)>(0x0042A020);
static auto& entity_is_flying = addr_as_ref<bool(Entity* ep)>(0x0042A060);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
static auto& entity_is_flying = addr_as_ref<bool(Entity* ep)>(0x0042A060);
static auto& entity_is_flying = addr_as_ref<bool(const Entity* ep)>(0x0042A060);

@@ -229,8 +230,15 @@ FunHook<void(rf::Player*)> render_reticle_hook{
ConsoleCommand2 spectate_cmd{
"spectate",
[](std::optional<std::string> player_name) {
if (!(rf::level.flags & rf::LEVEL_LOADED)) {
rf::console::output("No level loaded!", nullptr);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
rf::console::output("No level loaded!", nullptr);
rf::console::print("No level loaded!");

if (!rf::is_multi) {
rf::console::output("Spectate mode is only supported in multiplayer game!", nullptr);
// in single player, just enter free look mode
rf::console::output("Camera mode set to free look. Use `camera1` to return to first person.", nullptr);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
rf::console::output("Camera mode set to free look. Use `camera1` to return to first person.", nullptr);
rf::console::print("Camera mode set to free look. Use `camera1` to return to first person.");

@@ -104,6 +107,59 @@ FunHook<void()> verify_level_cmd_hook{
}
};

void handle_camera_command(FunHook<void()>& hook)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
void handle_camera_command(FunHook<void()>& hook)
void handle_camera_command(const FunHook<void()>& hook)

}

if (rf::is_multi) {
rf::console::print("That command can't be used in multiplayer.");
Copy link
Contributor

Choose a reason for hiding this comment

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

This command?

Comment on lines +124 to +134
const rf::CameraMode current_mode = rf::camera_get_mode(*rf::local_player->cam);

std::string mode_text = (current_mode == rf::CAMERA_FIRST_PERSON) ? "first person"
: (current_mode == rf::CAMERA_THIRD_PERSON) ? "third person"
: (current_mode == rf::CAMERA_FREELOOK) ? "free look"
: "unknown";

std::string helper_text =
(current_mode == rf::CAMERA_FIRST_PERSON) ? "" : " Use `camera1` to return to first person.";

rf::console::print("Camera mode set to {}.{}", mode_text, helper_text);
Copy link
Contributor

Choose a reason for hiding this comment

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

Too much ternary imo. Potential rewrite:

Suggested change
const rf::CameraMode current_mode = rf::camera_get_mode(*rf::local_player->cam);
std::string mode_text = (current_mode == rf::CAMERA_FIRST_PERSON) ? "first person"
: (current_mode == rf::CAMERA_THIRD_PERSON) ? "third person"
: (current_mode == rf::CAMERA_FREELOOK) ? "free look"
: "unknown";
std::string helper_text =
(current_mode == rf::CAMERA_FIRST_PERSON) ? "" : " Use `camera1` to return to first person.";
rf::console::print("Camera mode set to {}.{}", mode_text, helper_text);
std::string_view camera_mode_to_string_view(const rf::CameraMode mode) {
switch (mode) {
switch rf::CAMERA_FIRST_PERSON: return std::string_view{"first person"};
switch rf::CAMERA_FREELOOK: return std::string_view{"free look"};
switch rf::CAMERA_THIRD_PERSON: return std::string_view{"third person"};
default: return std::string_view{"unknown camera mode"};
}
}
const std::string_view mode_text = camera_mode_to_string_view(mode);
if (mode == rf::CAMERA_FIRST_PERSON) {
rf::console::print("Your camera mode was set to {}", mode_text);
} else {
rf::console::print("Your camera mode was set to {}. Use `camera1` to return to first person", mode_text);
}

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

Successfully merging this pull request may close these issues.

Suggestion: Alias spectate command to camera2 when in SP
2 participants