void MDFNI_NetplayStop(void) { if(MDFNnetplay) { Joined = false; MDFNnetplay = 0; MDFN_FlushGameCheats(1); /* Don't save netplay cheats. */ MDFN_LoadGameCheats(0); /* Reload our original cheats. */ if(OurNick) { free(OurNick); OurNick = NULL; } } else puts("Check your code!"); }
void MDFNI_CloseGame(void) { if(MDFNGameInfo) { if(MDFNnetplay) MDFNI_NetplayStop(); MDFNMOV_Stop(); if(MDFNGameInfo->GameType != GMT_PLAYER) MDFN_FlushGameCheats(0); MDFNGameInfo->CloseGame(); if(MDFNGameInfo->name) { free(MDFNGameInfo->name); MDFNGameInfo->name=0; } MDFNMP_Kill(); MDFNGameInfo = NULL; MDFN_StateEvilEnd(); for(unsigned i = 0; i < CDInterfaces.size(); i++) delete CDInterfaces[i]; CDInterfaces.clear(); } TBlur_Kill(); #ifdef WANT_DEBUGGER MDFNDBG_Kill(); #endif for(unsigned int x = 0; x < sizeof(PortDeviceCache) / sizeof(char *); x++) { if(PortDeviceCache[x]) { free(PortDeviceCache[x]); PortDeviceCache[x] = NULL; } } memset(PortDataCache, 0, sizeof(PortDataCache)); memset(PortDataLenCache, 0, sizeof(PortDataLenCache)); memset(PortDeviceCache, 0, sizeof(PortDeviceCache)); }
void MDFNI_CloseGame(void) { if(!MDFNGameInfo) return; MDFN_FlushGameCheats(0); MDFNGameInfo->CloseGame(); if(MDFNGameInfo->name) free(MDFNGameInfo->name); MDFNGameInfo->name = NULL; MDFNMP_Kill(); MDFNGameInfo = NULL; }
int NetplayStart(const char *PortDeviceCache[16], const uint32 PortDataLenCache[16]) { try { const char *emu_id = PACKAGE " " MEDNAFEN_VERSION; const uint32 local_players = MDFN_GetSettingUI("netplay.localplayers"); const std::string nickname = MDFN_GetSettingS("netplay.nick"); const std::string game_key = MDFN_GetSettingS("netplay.gamekey"); const std::string connect_password = MDFN_GetSettingS("netplay.password"); login_data_t *ld = NULL; std::vector<uint8> sendbuf; MDFNnetplay = true; sendbuf.resize(4 + sizeof(login_data_t) + nickname.size() + strlen(emu_id)); MDFN_en32lsb(&sendbuf[0], sendbuf.size() - 4); ld = (login_data_t*)&sendbuf[4]; if(game_key != "") { md5_context md5; uint8 md5out[16]; md5.starts(); md5.update(MDFNGameInfo->MD5, 16); md5.update((uint8 *)game_key.c_str(), game_key.size()); md5.finish(md5out); memcpy(ld->gameid, md5out, 16); } else memcpy(ld->gameid, MDFNGameInfo->MD5, 16); if(connect_password != "") { md5_context md5; uint8 md5out[16]; md5.starts(); md5.update((uint8*)connect_password.c_str(), connect_password.size()); md5.finish(md5out); memcpy(ld->password, md5out, 16); } assert(MDFNGameInfo->InputInfo->InputPorts <= 16); ld->protocol_version = 3; // Set input device number thingies here. ld->total_controllers = MDFNGameInfo->InputInfo->InputPorts; // Total number of ports MDFN_en32lsb(ld->emu_name_len, strlen(emu_id)); // Controller data sizes. for(int x = 0; x < MDFNGameInfo->InputInfo->InputPorts; x++) ld->controller_data_size[x] = PortDataLenCache[x]; // Controller types for(int x = 0; x < MDFNGameInfo->InputInfo->InputPorts; x++) { unsigned ct = 0; for(int d = 0; d < MDFNGameInfo->InputInfo->Types[x].NumTypes; d++) { if(!strcasecmp(MDFNGameInfo->InputInfo->Types[x].DeviceInfo[d].ShortName, PortDeviceCache[x])) { ct = d; break; } } //printf("%d, 0x%02x\n", x, ct); ld->controller_type[x] = ct; } ld->local_players = local_players; if(nickname != "") memcpy(&sendbuf[4 + sizeof(login_data_t)], nickname.c_str(), nickname.size()); memcpy(&sendbuf[4 + sizeof(login_data_t) + nickname.size()], emu_id, strlen(emu_id)); MDFND_SendData(&sendbuf[0], sendbuf.size()); TotalInputStateSize = 0; for(int x = 0; x < MDFNGameInfo->InputInfo->InputPorts; x++) TotalInputStateSize += PortDataLenCache[x]; // Hack so the server can always encode its command data length properly(a matching "hack" exists in the server). if(TotalInputStateSize < 4) TotalInputStateSize = 4; TotalInputStateSize = TotalInputStateSize; LocalPlayersMask = 0; LocalInputStateSize = 0; Joined = false; // // // MDFN_FlushGameCheats(0); /* Save our pre-netplay cheats. */ if(MDFNMOV_IsPlaying()) /* Recording's ok during netplay, playback is not. */ MDFNMOV_Stop(); } catch(std::exception &e) { NetError("%s", e.what()); return(false); } //printf("%d\n", TotalInputStateSize); return(1); }