Fix Benchmark Rotation

This commit is contained in:
TheBrokenRail 2024-06-10 18:55:22 -04:00
parent 69a9613e4f
commit 1bf19268f0
2 changed files with 53 additions and 58 deletions

View File

@ -122,17 +122,19 @@ static void Minecraft_update_injection(Minecraft *minecraft) {
} }
// Rotate Player // Rotate Player
static long long int rotate_point = BENCHMARK_ROTATION_INTERVAL; static long long int rotation_so_far = 0;
if (current_time >= rotate_point) { long long int ideal_rotation = (BENCHMARK_ROTATION_AMOUNT * current_time) / BENCHMARK_ROTATION_INTERVAL;
long long int rotation_diff = ideal_rotation - rotation_so_far;
if (rotation_diff >= BENCHMARK_ROTATION_AMOUNT) {
SDL_Event event; SDL_Event event;
event.type = SDL_MOUSEMOTION; event.type = SDL_MOUSEMOTION;
event.motion.x = 0; event.motion.x = 0;
event.motion.y = 0; event.motion.y = 0;
event.motion.xrel = BENCHMARK_ROTATION_AMOUNT; event.motion.xrel = (rotation_diff > INT16_MAX) ? INT16_MAX : int16_t(rotation_diff);
event.motion.yrel = 0; event.motion.yrel = 0;
SDL_PushEvent(&event); SDL_PushEvent(&event);
// Reset Rotation Timer // Reset Rotation Timer
rotate_point += BENCHMARK_ROTATION_INTERVAL; rotation_so_far += event.motion.xrel;
} }
// Check If Benchmark Is Over // Check If Benchmark Is Over

View File

@ -32,7 +32,7 @@ std::string get_death_message(Player *player, Entity *cause, bool was_shot = fal
message += monster_names[type_id - 32]; message += monster_names[type_id - 32];
} else { } else {
// Unknown creature // Unknown creature
message += "a Mysterious Beast"; message += "a mysterious beast";
} }
return message; return message;
} else if (aux) { } else if (aux) {
@ -59,9 +59,6 @@ std::string get_death_message(Player *player, Entity *cause, bool was_shot = fal
// Anything else // Anything else
return message + " has died"; return message + " has died";
} }
// Return
return message;
} }
static bool is_hurt = false; static bool is_hurt = false;
@ -73,67 +70,63 @@ static bool Mob_hurt_injection(Mob_hurt_t original, Mob *mob, Entity *source, in
} }
// Death Message Logic // Death Message Logic
#define Player_die_injections(type, original_method_self) \ template <typename Self, typename ParentSelf>
static void type##_die_injection(original_method_self##_die_t original, type *player, Entity *cause) { \ static void Player_die_injection(std::function<void(ParentSelf *, Entity *)> original, Self *player, Entity *cause) {
/* Call Original Method */ \ // Call Original Method
original((original_method_self *) player, cause); \ original((ParentSelf *) player, cause);
\
/* Get Variable */ \ // Get Variable
RakNetInstance *rak_net_instance = player->minecraft->rak_net_instance; \ RakNetInstance *rak_net_instance = player->minecraft->rak_net_instance;
/* Only Run On Server-Side */ \ // Only Run On Server-Side
if (rak_net_instance->isServer()) { \ if (rak_net_instance->isServer()) {
/* Get Death Message */ \ // Get Death Message
std::string message = get_death_message((Player *) player, cause); \ std::string message = get_death_message((Player *) player, cause);
\
/* Post Death Message */ \ // Post Death Message
ServerSideNetworkHandler *server_side_network_handler = (ServerSideNetworkHandler *) player->minecraft->network_handler; \ ServerSideNetworkHandler *server_side_network_handler = (ServerSideNetworkHandler *) player->minecraft->network_handler;
server_side_network_handler->displayGameMessage(&message); \ server_side_network_handler->displayGameMessage(&message);
} \
} }
#define Player_actuallyHurt_injections(type) \ }
static void type##_actuallyHurt_injection(type *player, int32_t damage) { \ template <typename Self>
/* Store Old Health */ \ static void Player_actuallyHurt_injection(Self *player, int32_t damage) {
int32_t old_health = player->health; \ // Store Old Health
\ int32_t old_health = player->health;
/* Call Original Method */ \
(*Mob_actuallyHurt_vtable_addr)((Mob *) player, damage); \ // Call Original Method
if (is_hurt == true) return; \ (*Mob_actuallyHurt_vtable_addr)((Mob *) player, damage);
\ if (is_hurt) {
/* Store New Health */ \ return;
int32_t new_health = player->health; \
\
/* Get Variables */ \
RakNetInstance *rak_net_instance = player->minecraft->rak_net_instance; \
/* Only Run On Server-Side */ \
if (rak_net_instance->isServer()) { \
/* Check Health */ \
if (new_health < 1 && old_health >= 1) { \
/* Get Death Message */ \
std::string message = get_death_message((Player *) player, nullptr); \
\
/* Post Death Message */ \
ServerSideNetworkHandler *server_side_network_handler = (ServerSideNetworkHandler *) player->minecraft->network_handler; \
server_side_network_handler->displayGameMessage(&message); \
} \
} \
} }
Player_die_injections(LocalPlayer, LocalPlayer) // Store New Health
Player_die_injections(ServerPlayer, Player) int32_t new_health = player->health;
Player_actuallyHurt_injections(LocalPlayer) // Get Variables
Player_actuallyHurt_injections(ServerPlayer) RakNetInstance *rak_net_instance = player->minecraft->rak_net_instance;
// Only Run On Server-Side
if (rak_net_instance->isServer()) {
// Check Health
if (new_health < 1 && old_health >= 1) {
// Get Death Message
std::string message = get_death_message((Player *) player, nullptr);
// Post Death Message
ServerSideNetworkHandler *server_side_network_handler = (ServerSideNetworkHandler *) player->minecraft->network_handler;
server_side_network_handler->displayGameMessage(&message);
}
}
}
// Init // Init
void init_death() { void init_death() {
// Death Messages // Death Messages
if (feature_has("Implement Death Messages", server_auto)) { if (feature_has("Implement Death Messages", server_auto)) {
patch_vtable(ServerPlayer_die, [](ServerPlayer *player, Entity *cause) { patch_vtable(ServerPlayer_die, [](ServerPlayer *player, Entity *cause) {
ServerPlayer_die_injection(*Player_die_vtable_addr, player, cause); Player_die_injection<ServerPlayer, Player>(*Player_die_vtable_addr, player, cause);
}); });
overwrite_calls(LocalPlayer_die, LocalPlayer_die_injection); overwrite_calls(LocalPlayer_die, Player_die_injection<LocalPlayer, LocalPlayer>);
patch_vtable(LocalPlayer_actuallyHurt, LocalPlayer_actuallyHurt_injection); patch_vtable(LocalPlayer_actuallyHurt, Player_actuallyHurt_injection);
patch_vtable(ServerPlayer_actuallyHurt, ServerPlayer_actuallyHurt_injection); patch_vtable(ServerPlayer_actuallyHurt, Player_actuallyHurt_injection);
overwrite_calls(Mob_hurt, Mob_hurt_injection); overwrite_calls(Mob_hurt, Mob_hurt_injection);
} }