-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc75ce5
commit 62bfe92
Showing
42 changed files
with
2,450 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Rosalie's Mupen GUI - https://github.com/Rosalie241/RMG | ||
* Copyright (C) 2020 Rosalie Wanders <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 3. | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
#ifdef _WIN32 | ||
#define _CRT_RAND_S | ||
#include <cstdlib> | ||
#endif // _WIN32 | ||
#include "Netplay.hpp" | ||
#include "Error.hpp" | ||
#include "m64p/Api.hpp" | ||
|
||
|
||
|
||
// | ||
// Local Variables | ||
// | ||
|
||
static bool l_HasInitNetplay = false; | ||
|
||
// | ||
// Exported Functions | ||
// | ||
|
||
bool CoreInitNetplay(std::string address, int port, int player) | ||
{ | ||
std::string error; | ||
m64p_error ret; | ||
uint32_t id = 0; | ||
|
||
// initialize random ID | ||
while (id == 0) | ||
{ | ||
#ifdef _WIN32 | ||
rand_s(&id); | ||
#else | ||
id = rand(); | ||
#endif | ||
id &= ~0x7; | ||
id |= player; | ||
} | ||
|
||
uint32_t version; | ||
ret = m64p::Core.DoCommand(M64CMD_NETPLAY_GET_VERSION, 0x010001, &version); | ||
if (ret != M64ERR_SUCCESS) | ||
{ | ||
error = "CoreInitNetplay m64p::Core.DoCommand(M64CMD_NETPLAY_GET_VERSION) Failed: "; | ||
error += m64p::Core.ErrorMessage(ret); | ||
CoreSetError(error); | ||
return false; | ||
} | ||
|
||
ret = m64p::Core.DoCommand(M64CMD_NETPLAY_INIT, port, (void*)address.c_str()); | ||
if (ret != M64ERR_SUCCESS) | ||
{ | ||
error = "CoreInitNetplay m64p::Core.DoCommand(M64CMD_NETPLAY_INIT) Failed: "; | ||
error += m64p::Core.ErrorMessage(ret); | ||
CoreSetError(error); | ||
return false; | ||
} | ||
|
||
ret = m64p::Core.DoCommand(M64CMD_NETPLAY_CONTROL_PLAYER, player, &id); | ||
if (ret != M64ERR_SUCCESS) | ||
{ | ||
error = "CoreInitNetplay m64p::Core.DoCommand(M64CMD_NETPLAY_CONTROL_PLAYER) Failed: "; | ||
error += m64p::Core.ErrorMessage(ret); | ||
CoreSetError(error); | ||
CoreShutdownNetplay(); | ||
return false; | ||
} | ||
|
||
l_HasInitNetplay = true; | ||
return true; | ||
} | ||
|
||
bool CoreHasInitNetplay(void) | ||
{ | ||
return l_HasInitNetplay; | ||
} | ||
|
||
bool CoreShutdownNetplay(void) | ||
{ | ||
std::string error; | ||
m64p_error ret; | ||
|
||
ret = m64p::Core.DoCommand(M64CMD_NETPLAY_CLOSE, 0, nullptr); | ||
if (ret != M64ERR_SUCCESS) | ||
{ | ||
error = "CoreShutdownNetplay m64p::Core.DoCommand(M64CMD_NETPLAY_CLOSE) Failed: "; | ||
error += m64p::Core.ErrorMessage(ret); | ||
CoreSetError(error); | ||
return false; | ||
} | ||
|
||
l_HasInitNetplay = false; | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Rosalie's Mupen GUI - https://github.com/Rosalie241/RMG | ||
* Copyright (C) 2020 Rosalie Wanders <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 3. | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
#ifndef CORE_NETPLAY_HPP | ||
#define CORE_NETPLAY_HPP | ||
|
||
#include <string> | ||
|
||
// attempts to initialize netplay | ||
bool CoreInitNetplay(std::string address, int port, int player); | ||
|
||
// returns whether netplay has been initialized | ||
bool CoreHasInitNetplay(void); | ||
|
||
// attempts to shutdown netplay | ||
bool CoreShutdownNetplay(void); | ||
|
||
#endif // CORE_NETPLAY_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.