Moving reused adhoc function out of sceNet function to prevent getting extra SCENET log

This commit is contained in:
ANR2ME 2020-08-08 03:53:55 +07:00
parent ee3b822c0e
commit 8dec09703f
4 changed files with 110 additions and 92 deletions

View File

@ -917,9 +917,7 @@ static int sceNetApctlGetInfo(int code, u32 pInfoAddr) {
return hleLogSuccessI(SCENET, 0);
}
// TODO: How many handlers can the PSP actually have for Apctl?
// TODO: Should we allow the same handler to be added more than once?
static u32 sceNetApctlAddHandler(u32 handlerPtr, u32 handlerArg) {
int NetApctl_AddHandler(u32 handlerPtr, u32 handlerArg) {
bool foundHandler = false;
u32 retval = 0;
struct ApctlHandler handler;
@ -931,41 +929,53 @@ static u32 sceNetApctlAddHandler(u32 handlerPtr, u32 handlerArg) {
handler.entryPoint = handlerPtr;
handler.argument = handlerArg;
for(std::map<int, ApctlHandler>::iterator it = apctlHandlers.begin(); it != apctlHandlers.end(); it++) {
if(it->second.entryPoint == handlerPtr) {
for (std::map<int, ApctlHandler>::iterator it = apctlHandlers.begin(); it != apctlHandlers.end(); it++) {
if (it->second.entryPoint == handlerPtr) {
foundHandler = true;
break;
}
}
if(!foundHandler && Memory::IsValidAddress(handlerPtr)) {
if(apctlHandlers.size() >= MAX_APCTL_HANDLERS) {
ERROR_LOG(SCENET, "UNTESTED sceNetApctlAddHandler(%x, %x): Too many handlers", handlerPtr, handlerArg);
if (!foundHandler && Memory::IsValidAddress(handlerPtr)) {
if (apctlHandlers.size() >= MAX_APCTL_HANDLERS) {
ERROR_LOG(SCENET, "Failed to Add handler(%x, %x): Too many handlers", handlerPtr, handlerArg);
retval = ERROR_NET_ADHOCCTL_TOO_MANY_HANDLERS; // TODO: What's the proper error code for Apctl's TOO_MANY_HANDLERS?
return retval;
}
apctlHandlers[retval] = handler;
WARN_LOG(SCENET, "UNTESTED sceNetApctlAddHandler(%x, %x): added handler %d", handlerPtr, handlerArg, retval);
WARN_LOG(SCENET, "Added Apctl handler(%x, %x): %d", handlerPtr, handlerArg, retval);
}
else {
ERROR_LOG(SCENET, "UNTESTED sceNetApctlAddHandler(%x, %x): Same handler already exists", handlerPtr, handlerArg);
ERROR_LOG(SCENET, "Existing Apctl handler(%x, %x)", handlerPtr, handlerArg);
}
// The id to return is the number of handlers currently registered
return retval;
}
static int sceNetApctlDelHandler(u32 handlerID) {
if(apctlHandlers.find(handlerID) != apctlHandlers.end()) {
// TODO: How many handlers can the PSP actually have for Apctl?
// TODO: Should we allow the same handler to be added more than once?
static u32 sceNetApctlAddHandler(u32 handlerPtr, u32 handlerArg) {
INFO_LOG(SCENET, "%s(%08x, %08x)", __FUNCTION__, handlerPtr, handlerArg);
return NetApctl_AddHandler(handlerPtr, handlerArg);
}
int NetApctl_DelHandler(u32 handlerID) {
if (apctlHandlers.find(handlerID) != apctlHandlers.end()) {
apctlHandlers.erase(handlerID);
WARN_LOG(SCENET, "UNTESTED sceNetapctlDelHandler(%d): deleted handler %d", handlerID, handlerID);
WARN_LOG(SCENET, "Deleted Apctl handler: %d", handlerID);
}
else {
ERROR_LOG(SCENET, "UNTESTED sceNetapctlDelHandler(%d): asked to delete invalid handler %d", handlerID, handlerID);
ERROR_LOG(SCENET, "Invalid Apctl handler: %d", handlerID);
}
return 0;
}
static int sceNetApctlDelHandler(u32 handlerID) {
INFO_LOG(SCENET, "%s(%d)", __FUNCTION__, handlerID);
return NetApctl_DelHandler(handlerID);
}
static int sceNetInetInetAton(const char *hostname, u32 addrPtr) {
ERROR_LOG(SCENET, "UNIMPL sceNetInetInetAton(%s, %08x)", hostname, addrPtr);
return -1;
@ -1067,7 +1077,7 @@ static int sceNetInetConnect(int socket, u32 sockAddrInternetPtr, int addressLen
return -1;
}
static int sceNetApctlConnect(int connIndex) {
int sceNetApctlConnect(int connIndex) {
ERROR_LOG(SCENET, "UNIMPL %s(%i)", __FUNCTION__, connIndex);
// Is this connIndex is the index to the scanning's result data or sceNetApctlGetBSSDescIDListUser result?
__UpdateApctlHandlers(0, 0, PSP_NET_APCTL_EVENT_CONNECT_REQUEST, 0);
@ -1083,15 +1093,17 @@ static int sceNetApctlDisconnect() {
return 0;
}
int NetApctl_GetState() {
return netApctlState;
}
static int sceNetApctlGetState(u32 pStateAddr) {
WARN_LOG(SCENET, "UNTESTED %s(%08x)", __FUNCTION__, pStateAddr);
//if (!netApctlInited) return hleLogError(SCENET, ERROR_NET_APCTL_NOT_IN_BSS, "apctl not in bss");
// Valid Arguments
if (Memory::IsValidAddress(pStateAddr)) {
// Return Thread Status
Memory::Write_U32(netApctlState, pStateAddr);
Memory::Write_U32(NetApctl_GetState(), pStateAddr);
// Return Success
return hleLogSuccessI(SCENET, 0);
}
@ -1099,9 +1111,7 @@ static int sceNetApctlGetState(u32 pStateAddr) {
return hleLogError(SCENET, -1, "apctl invalid arg");
}
static int sceNetApctlScanUser() {
ERROR_LOG(SCENET, "UNIMPL %s()", __FUNCTION__);
int NetApctl_ScanUser() {
// Scan probably only works when not in connected state, right?
if (netApctlState != PSP_NET_APCTL_STATE_DISCONNECTED)
return hleLogError(SCENET, ERROR_NET_APCTL_NOT_DISCONNECTED, "apctl not disconnected");
@ -1110,6 +1120,11 @@ static int sceNetApctlScanUser() {
return 0;
}
static int sceNetApctlScanUser() {
ERROR_LOG(SCENET, "UNIMPL %s()", __FUNCTION__);
return NetApctl_ScanUser();
}
static int sceNetApctlGetBSSDescIDListUser(u32 sizeAddr, u32 bufAddr) {
WARN_LOG(SCENET, "UNTESTED %s(%08x, %08x)", __FUNCTION__, sizeAddr, bufAddr);
@ -1183,13 +1198,7 @@ static int sceNetApctlGetBSSDescEntryUser(int entryId, int infoId, u32 resultAdd
static int sceNetApctlScanSSID2() {
ERROR_LOG(SCENET, "UNIMPL %s()", __FUNCTION__);
// Scan probably only works when not in connected state, right?
if (netApctlState != PSP_NET_APCTL_STATE_DISCONNECTED)
return hleLogError(SCENET, ERROR_NET_APCTL_NOT_DISCONNECTED, "apctl not disconnected");
__UpdateApctlHandlers(0, 0, PSP_NET_APCTL_EVENT_SCAN_REQUEST, 0);
return 0;
return NetApctl_ScanUser();
}
static int sceNetApctlGetBSSDescIDList2(u32 Arg1, u32 Arg2, u32 Arg3, u32 Arg4) {
@ -1209,13 +1218,13 @@ static int sceNetResolverInit()
static int sceNetApctlAddInternalHandler(u32 handlerPtr, u32 handlerArg) {
ERROR_LOG(SCENET, "UNIMPL %s(%08x, %08x)", __FUNCTION__, handlerPtr, handlerArg);
// This seems to be a 2nd kind of handler
return sceNetApctlAddHandler(handlerPtr, handlerArg);
return NetApctl_AddHandler(handlerPtr, handlerArg);
}
static int sceNetApctlDelInternalHandler(u32 handlerID) {
ERROR_LOG(SCENET, "UNIMPL %s(%i)", __FUNCTION__, handlerID);
// This seems to be a 2nd kind of handler
return sceNetApctlDelHandler(handlerID);
return NetApctl_DelHandler(handlerID);
}
static int sceNetApctl_A7BB73DF(u32 handlerPtr, u32 handlerArg) {
@ -1241,7 +1250,7 @@ static int sceNetApctl_lib2_4C19731F(int code, u32 pInfoAddr) {
static int sceNetApctlScan() {
ERROR_LOG(SCENET, "UNIMPL %s()", __FUNCTION__);
return sceNetApctlScanUser();
return NetApctl_ScanUser();
}
static int sceNetApctlGetBSSDescIDList(u32 sizeAddr, u32 bufAddr) {

View File

@ -233,6 +233,9 @@ void __NetInit();
void __NetShutdown();
void __NetDoState(PointerWrap &p);
int NetApctl_GetState();
int sceNetApctlConnect(int connIndex);
int sceNetInetPoll(void *fds, u32 nfds, int timeout);
int sceNetInetTerm();
int sceNetApctlTerm();

View File

@ -274,23 +274,24 @@ static u32 sceNetAdhocctlInit(int stackSize, int prio, u32 productAddr) {
return 0;
}
int NetAdhocctl_GetState() {
return threadStatus;
}
static int sceNetAdhocctlGetState(u32 ptrToStatus) {
// Library initialized
if (netAdhocctlInited) {
// Valid Arguments
if (Memory::IsValidAddress(ptrToStatus)) {
// Return Thread Status
Memory::Write_U32(threadStatus, ptrToStatus);
// Return Success
return 0;
}
// Invalid Arguments
return ERROR_NET_ADHOCCTL_INVALID_ARG;
}
// Library uninitialized
return ERROR_NET_ADHOCCTL_NOT_INITIALIZED;
if (!netAdhocctlInited)
return ERROR_NET_ADHOCCTL_NOT_INITIALIZED;
// Invalid Arguments
if (!Memory::IsValidAddress(ptrToStatus))
return ERROR_NET_ADHOCCTL_INVALID_ARG;
// Return Thread Status
Memory::Write_U32(NetAdhocctl_GetState(), ptrToStatus);
// Return Success
return hleLogSuccessVerboseI(SCENET, 0);
}
/**
@ -1431,34 +1432,6 @@ static int sceNetAdhocctlGetNameByAddr(const char *mac, u32 nameAddr) {
return ERROR_NET_ADHOCCTL_NOT_INITIALIZED;
}
static int sceNetAdhocctlJoin(u32 scanInfoAddr) {
WARN_LOG(SCENET, "UNTESTED sceNetAdhocctlJoin(%08x) at %08x", scanInfoAddr, currentMIPS->pc);
if (!g_Config.bEnableWlan) {
return -1;
}
// Library initialized
if (netAdhocctlInited)
{
// Valid Argument
if (Memory::IsValidAddress(scanInfoAddr))
{
SceNetAdhocctlScanInfoEmu * sinfo = (SceNetAdhocctlScanInfoEmu *)Memory::GetPointer(scanInfoAddr);
//while (true) sleep_ms(1);
// We can ignore minor connection process differences here
// TODO: Adhoc Server may need to be changed to differentiate between Host/Create and Join, otherwise it can't support multiple Host using the same Group name, thus causing one of the Host to be confused being treated as Join.
return sceNetAdhocctlCreate((const char*)&sinfo->group_name);
}
// Invalid Argument
return ERROR_NET_ADHOCCTL_INVALID_ARG;
}
// Uninitialized Library
return ERROR_NET_ADHOCCTL_NOT_INITIALIZED;
}
int sceNetAdhocctlGetPeerInfo(const char *mac, int size, u32 peerInfoAddr) {
VERBOSE_LOG(SCENET, "sceNetAdhocctlGetPeerInfo(%s, %i, %08x) at %08x", mac2str((SceNetEtherAddr*)mac).c_str(), size, peerInfoAddr, currentMIPS->pc);
if (!g_Config.bEnableWlan) {
@ -1528,20 +1501,8 @@ int sceNetAdhocctlGetPeerInfo(const char *mac, int size, u32 peerInfoAddr) {
return ERROR_NET_ADHOCCTL_NOT_INITIALIZED;
}
/**
* Create and / or Join a Virtual Network of the specified Name
* @param group_name Virtual Network Name
* @return 0 on success or... ADHOCCTL_NOT_INITIALIZED, ADHOCCTL_INVALID_ARG, ADHOCCTL_BUSY
*/
int sceNetAdhocctlCreate(const char *groupName) {
char grpName[9] = { 0 };
memcpy(grpName, groupName, ADHOCCTL_GROUPNAME_LEN); // Copied to null-terminated var to prevent unexpected behaviour on Logs
INFO_LOG(SCENET, "sceNetAdhocctlCreate(%s) at %08x", grpName, currentMIPS->pc);
if (!g_Config.bEnableWlan) {
return -1;
}
const SceNetAdhocctlGroupName * groupNameStruct = (const SceNetAdhocctlGroupName *)groupName;
int NetAdhocctl_Create(const char* groupName) {
const SceNetAdhocctlGroupName* groupNameStruct = (const SceNetAdhocctlGroupName*)groupName;
// Library initialized
if (netAdhocctlInited) {
// Valid Argument
@ -1578,7 +1539,7 @@ int sceNetAdhocctlCreate(const char *groupName) {
// Acquire Network Lock
// Send Packet
int iResult = send(metasocket, (const char *)&packet, sizeof(packet), 0);
int iResult = send(metasocket, (const char*)&packet, sizeof(packet), 0);
if (iResult == SOCKET_ERROR) {
ERROR_LOG(SCENET, "Socket error (%i) when sending", errno);
//return ERROR_NET_ADHOCCTL_NOT_INITIALIZED; // ERROR_NET_ADHOCCTL_DISCONNECTED; // ERROR_NET_ADHOCCTL_BUSY;
@ -1614,11 +1575,11 @@ int sceNetAdhocctlCreate(const char *groupName) {
// Return Success
return 0;
}
// Connected State
return ERROR_NET_ADHOCCTL_BUSY; // ERROR_NET_ADHOCCTL_BUSY may trigger the game (ie. Ford Street Racing) to call sceNetAdhocctlDisconnect
}
// Invalid Argument
return ERROR_NET_ADHOC_INVALID_ARG;
}
@ -1626,6 +1587,22 @@ int sceNetAdhocctlCreate(const char *groupName) {
return ERROR_NET_ADHOCCTL_NOT_INITIALIZED;
}
/**
* Create and / or Join a Virtual Network of the specified Name
* @param group_name Virtual Network Name
* @return 0 on success or... ADHOCCTL_NOT_INITIALIZED, ADHOCCTL_INVALID_ARG, ADHOCCTL_BUSY
*/
int sceNetAdhocctlCreate(const char *groupName) {
char grpName[9] = { 0 };
memcpy(grpName, groupName, ADHOCCTL_GROUPNAME_LEN); // Copied to null-terminated var to prevent unexpected behaviour on Logs
INFO_LOG(SCENET, "sceNetAdhocctlCreate(%s) at %08x", grpName, currentMIPS->pc);
if (!g_Config.bEnableWlan) {
return -1;
}
return NetAdhocctl_Create(groupName);
}
static int sceNetAdhocctlConnect(u32 ptrToGroupName) {
if (Memory::IsValidAddress(ptrToGroupName)) {
const char* groupName = Memory::GetCharPointer(ptrToGroupName);
@ -1633,12 +1610,40 @@ static int sceNetAdhocctlConnect(u32 ptrToGroupName) {
memcpy(grpName, groupName, ADHOCCTL_GROUPNAME_LEN); // Copied to null-terminated var to prevent unexpected behaviour on Logs
INFO_LOG(SCENET, "sceNetAdhocctlConnect(groupName=%s) at %08x", grpName, currentMIPS->pc);
return sceNetAdhocctlCreate(groupName);
return NetAdhocctl_Create(groupName);
}
return ERROR_NET_ADHOC_INVALID_ARG; // ERROR_NET_ADHOC_INVALID_ADDR;
}
static int sceNetAdhocctlJoin(u32 scanInfoAddr) {
WARN_LOG(SCENET, "UNTESTED sceNetAdhocctlJoin(%08x) at %08x", scanInfoAddr, currentMIPS->pc);
if (!g_Config.bEnableWlan) {
return -1;
}
// Library initialized
if (netAdhocctlInited)
{
// Valid Argument
if (Memory::IsValidAddress(scanInfoAddr))
{
SceNetAdhocctlScanInfoEmu* sinfo = (SceNetAdhocctlScanInfoEmu*)Memory::GetPointer(scanInfoAddr);
//while (true) sleep_ms(1);
// We can ignore minor connection process differences here
// TODO: Adhoc Server may need to be changed to differentiate between Host/Create and Join, otherwise it can't support multiple Host using the same Group name, thus causing one of the Host to be confused being treated as Join.
return NetAdhocctl_Create((const char*)&sinfo->group_name);
}
// Invalid Argument
return ERROR_NET_ADHOCCTL_INVALID_ARG;
}
// Uninitialized Library
return ERROR_NET_ADHOCCTL_NOT_INITIALIZED;
}
// Connect to the Adhoc control game mode (as a Host)
static int sceNetAdhocctlCreateEnterGameMode(const char *groupName, int unknown, int playerNum, u32 macsAddr, int timeout, int unknown2) {
char grpName[9] = { 0 };

View File

@ -62,4 +62,5 @@ extern u32_le matchingThreadCode[3];
int NetAdhocMatching_Term();
int NetAdhocctl_Term();
int NetAdhocctl_GetState();
int NetAdhoc_Term();