implement switch assist

This commit is contained in:
Martin Michelsen
2022-04-01 00:45:50 -07:00
parent edd9f4ea8f
commit 345820145e
4 changed files with 36 additions and 2 deletions
+11
View File
@@ -459,6 +459,7 @@ static void command_cheat(shared_ptr<ServerState>, shared_ptr<Lobby> l,
}
c->infinite_hp = false;
c->infinite_tp = false;
c->switch_assist = false;
}
memset(&l->next_drop_item, 0, sizeof(l->next_drop_item));
}
@@ -866,6 +867,15 @@ static void command_infinite_tp(shared_ptr<ServerState>, shared_ptr<Lobby> l,
send_text_message_printf(c, "$C6Infinite TP %s", c->infinite_tp ? "enabled" : "disabled");
}
static void command_switch_assist(shared_ptr<ServerState>, shared_ptr<Lobby> l,
shared_ptr<Client> c, const char16_t*) {
check_is_game(l, true);
check_cheats_enabled(l);
c->switch_assist = !c->switch_assist;
send_text_message_printf(c, "$C6Switch assist %s", c->switch_assist ? "enabled" : "disabled");
}
static void command_item(shared_ptr<ServerState>, shared_ptr<Lobby> l,
shared_ptr<Client> c, const char16_t* args) {
check_is_game(l, true);
@@ -927,6 +937,7 @@ static const unordered_map<u16string, ChatCommandDefinition> chat_commands({
{u"secid" , {command_secid , u"Usage:\nsecid [section ID]\nomit section ID to\nrevert to normal"}},
{u"silence" , {command_silence , u"Usage:\nsilence <name-or-number>"}},
{u"song" , {command_song , u"Usage:\nsong <song-number>"}},
{u"swa" , {command_switch_assist , u"Usage:\nswa"}},
{u"type" , {command_lobby_type , u"Usage:\ntype <name>"}},
{u"warp" , {command_warp , u"Usage:\nwarp <area-number>"}},
});
+2 -1
View File
@@ -41,8 +41,9 @@ Client::Client(
override_section_id(-1),
infinite_hp(false),
infinite_tp(false),
switch_assist(false),
can_chat(true) {
memset(&this->last_switch_enabled_subcommand, 0, sizeof(this->last_switch_enabled_subcommand));
int fd = bufferevent_getfd(this->bev);
if (fd < 0) {
this->is_virtual_connection = true;
+3
View File
@@ -9,6 +9,7 @@
#include "PSOEncryption.hh"
#include "Text.hh"
#include "PSOProtocol.hh"
@@ -80,6 +81,8 @@ struct Client {
int16_t override_section_id; // valid if >= 0
bool infinite_hp; // cheats enabled
bool infinite_tp; // cheats enabled
bool switch_assist; // cheats enabled
PSOSubcommand last_switch_enabled_subcommand[3];
bool can_chat;
std::string pending_bb_save_username;
uint8_t pending_bb_save_player_index;
+20 -1
View File
@@ -200,6 +200,25 @@ static void process_subcommand_use_technique(shared_ptr<ServerState>,
}
}
static void process_subcommand_switch_state_changed(shared_ptr<ServerState>,
shared_ptr<Lobby> l, shared_ptr<Client> c, uint8_t command, uint8_t flag,
const PSOSubcommand* p, size_t count) {
if (!l->is_game() || (p->byte[1] != count)) {
return;
}
forward_subcommand(l, c, command, flag, p, count);
if ((count == 3) && (p[2].byte[3] == 1)) { // If this is a switch enable command
if ((l->flags & LobbyFlag::CHEATS_ENABLED) && c->switch_assist &&
(c->last_switch_enabled_subcommand[0].byte[0] == 0x05)) {
log(INFO, "[Switch assist] Replaying previous enable command");
forward_subcommand(l, c, command, flag, c->last_switch_enabled_subcommand, 3);
send_command(c, command, flag, c->last_switch_enabled_subcommand,
sizeof(c->last_switch_enabled_subcommand));
}
memcpy(&c->last_switch_enabled_subcommand, p, sizeof(c->last_switch_enabled_subcommand));
}
}
////////////////////////////////////////////////////////////////////////////////
// BB Item commands
@@ -922,7 +941,7 @@ subcommand_handler_t subcommand_handlers[0x100] = {
/* 02 */ process_subcommand_unimplemented,
/* 03 */ process_subcommand_unimplemented,
/* 04 */ process_subcommand_unimplemented,
/* 05 */ process_subcommand_forward_check_size_game, // Switch flipped (door lock / lights / poison gas), or room unlocked when all enemied defeated
/* 05 */ process_subcommand_switch_state_changed,
/* 06 */ process_subcommand_send_guild_card,
/* 07 */ process_subcommand_symbol_chat,
/* 08 */ process_subcommand_unimplemented,