A lot more logging fixes

This commit is contained in:
Henrik Rydgård 2025-01-19 23:15:27 +01:00
parent 7d2ad6980e
commit e24317b20b
6 changed files with 115 additions and 117 deletions

View file

@ -531,6 +531,7 @@ void HLEReturnFromMipsCall() {
if ((stackData->nextOff & 0x0000000F) != 0 || !Memory::IsValidAddress(sp + stackData->nextOff)) {
ERROR_LOG(Log::HLE, "Corrupt stack on HLE mips call return: %08x", stackData->nextOff);
Core_UpdateState(CORE_RUNTIME_ERROR);
hleNoLogVoid();
return;
}
@ -547,6 +548,7 @@ void HLEReturnFromMipsCall() {
if (finalMarker->nextOff != 0xFFFFFFFF) {
ERROR_LOG(Log::HLE, "Corrupt stack on HLE mips call return action: %08x", finalMarker->nextOff);
Core_UpdateState(CORE_RUNTIME_ERROR);
hleNoLogVoid();
return;
}
@ -583,6 +585,7 @@ void HLEReturnFromMipsCall() {
}
VERBOSE_LOG(Log::HLE, "Finished HLE mips calls, v0=%08x, sp=%08x", currentMIPS->r[MIPS_REG_V0], sp);
hleNoLogVoid();
return;
}
@ -594,6 +597,7 @@ void HLEReturnFromMipsCall() {
currentMIPS->r[MIPS_REG_A0 + i] = Memory::Read_U32(sp + sizeof(HLEMipsCallStack) + i * sizeof(u32));
}
DEBUG_LOG(Log::HLE, "Executing next HLE mips call at %08x, sp=%08x", currentMIPS->pc, sp);
hleNoLogVoid();
}
const static u32 deadbeefRegs[12] = {0xDEADBEEF, 0xDEADBEEF, 0xDEADBEEF, 0xDEADBEEF, 0xDEADBEEF, 0xDEADBEEF, 0xDEADBEEF, 0xDEADBEEF, 0xDEADBEEF, 0xDEADBEEF, 0xDEADBEEF, 0xDEADBEEF};
@ -708,7 +712,11 @@ static void updateSyscallStats(int modulenum, int funcnum, double total)
static void CallSyscallWithFlags(const HLEFunction *info) {
_dbg_assert_(g_stackSize == 0);
g_stack[g_stackSize++] = info;
const int stackSize = g_stackSize;
if (stackSize == 0) {
g_stack[0] = info;
g_stackSize = 1;
}
g_syscallPC = currentMIPS->pc;
const u32 flags = info->flags;
@ -742,7 +750,11 @@ static void CallSyscallWithFlags(const HLEFunction *info) {
static void CallSyscallWithoutFlags(const HLEFunction *info) {
_dbg_assert_(g_stackSize == 0);
g_stack[g_stackSize++] = info;
const int stackSize = g_stackSize;
if (stackSize == 0) {
g_stack[0] = info;
g_stackSize = 1;
}
g_syscallPC = currentMIPS->pc;
info->func();
@ -849,8 +861,12 @@ void hlePushFuncDesc(std::string_view module, std::string_view funcName) {
}
const HLEFunction *func = GetFuncByName(mod, funcName);
_dbg_assert_(func != nullptr);
// Push to the stack.
g_stack[g_stackSize++] = func;
// Push to the stack. Be careful (due to the nasty adhoc thread..)
int stackSize = g_stackSize;
if (stackSize >= 0 && stackSize < ARRAY_SIZE(g_stack)) {
g_stack[stackSize] = func;
g_stackSize = stackSize + 1;
}
}
// TODO: Also add support for argument names.
@ -956,9 +972,10 @@ size_t hleFormatLogArgs(char *message, size_t sz, const char *argmask) {
}
void hleLeave() {
_dbg_assert_(g_stackSize > 0);
if (g_stackSize > 0) {
g_stackSize--;
int stackSize = g_stackSize;
_dbg_assert_(stackSize > 0);
if (stackSize > 0) {
g_stackSize = stackSize - 1;
} // else warn?
}
@ -967,20 +984,21 @@ void hleDoLogInternal(Log t, LogLevel level, u64 res, const char *file, int line
const char *funcName = "?";
u32 funcFlags = 0;
if (!g_stackSize) {
const int stackSize = g_stackSize;
if (!stackSize) {
ERROR_LOG(Log::HLE, "HLE function stack mismatch!");
return;
}
const HLEFunction *hleFunc = g_stack[g_stackSize - 1];
if (g_stackSize) {
if (stackSize) {
_dbg_assert_(hleFunc->argmask != nullptr);
// NOTE: For second stack level, we can't get arguments (unless we somehow get them from the host stack!)
// Need to do something smart in hleCall.
if (g_stackSize == 1) {
if (stackSize == 1) {
hleFormatLogArgs(formatted_args, sizeof(formatted_args), hleFunc->argmask);
} else {
truncate_cpy(formatted_args, "...N/A...");

View file

@ -1162,21 +1162,21 @@ static u32 sceFontOpenUserFile(u32 libHandle, const char *fileName, u32 mode, u3
}
delete f;
// Message was already logged.
return 0;
// Message was already logged (or was it?)
return hleNoLog(0);
}
static int sceFontClose(u32 fontHandle) {
LoadedFont *font = GetLoadedFont(fontHandle, false);
if (font) {
DEBUG_LOG(Log::sceFont, "sceFontClose(%x)", fontHandle);
FontLib *fontLib = font->GetFontLib();
if (fontLib) {
fontLib->CloseFont(font, false);
}
} else
ERROR_LOG(Log::sceFont, "sceFontClose(%x) - font not open?", fontHandle);
return 0;
return hleLogDebug(Log::sceFont, 0);
} else {
return hleLogError(Log::sceFont, 0, "sceFontClose(%x) - font not open?", fontHandle);
}
}
static int sceFontFindOptimumFont(u32 libHandle, u32 fontStylePtr, u32 errorCodePtr) {
@ -1214,7 +1214,7 @@ static int sceFontFindOptimumFont(u32 libHandle, u32 fontStylePtr, u32 errorCode
if (str == "ltn12.pgf") {
optimumFont = internalFonts[j];
*errorCode = 0;
return GetInternalFontIndex(optimumFont);
return hleLogSuccessInfoI(Log::sceFont, GetInternalFontIndex(optimumFont));
}
}
}
@ -1297,30 +1297,26 @@ static int sceFontFindFont(u32 libHandle, u32 fontStylePtr, u32 errorCodePtr) {
continue;
}
*errorCode = 0;
return (int)i;
return hleNoLog((int)i);
}
}
*errorCode = 0;
return -1;
return hleLogWarning(Log::sceFont, -1);
}
static int sceFontGetFontInfo(u32 fontHandle, u32 fontInfoPtr) {
if (!Memory::IsValidAddress(fontInfoPtr)) {
ERROR_LOG(Log::sceFont, "sceFontGetFontInfo(%x, %x): bad fontInfo pointer", fontHandle, fontInfoPtr);
return ERROR_FONT_INVALID_PARAMETER;
return hleLogError(Log::sceFont, ERROR_FONT_INVALID_PARAMETER, "bad fontInfo pointer");
}
LoadedFont *font = GetLoadedFont(fontHandle, true);
if (!font) {
ERROR_LOG_REPORT(Log::sceFont, "sceFontGetFontInfo(%x, %x): bad font", fontHandle, fontInfoPtr);
return ERROR_FONT_INVALID_PARAMETER;
return hleLogError(Log::sceFont, ERROR_FONT_INVALID_PARAMETER, "bad font");
}
DEBUG_LOG(Log::sceFont, "sceFontGetFontInfo(%x, %x)", fontHandle, fontInfoPtr);
auto fi = PSPPointer<PGFFontInfo>::Create(fontInfoPtr);
font->GetPGF()->GetFontInfo(fi);
fi->fontStyle = font->GetFont()->GetFontStyle();
return 0;
return hleLogDebug(Log::sceFont, 0);
}
// It says FontInfo but it means Style - this is like sceFontGetFontList().
@ -1328,36 +1324,31 @@ static int sceFontGetFontInfoByIndexNumber(u32 libHandle, u32 fontInfoPtr, u32 i
auto fontStyle = PSPPointer<PGFFontStyle>::Create(fontInfoPtr);
FontLib *fl = GetFontLib(libHandle);
if (!fl || fl->handle() == 0) {
ERROR_LOG_REPORT(Log::sceFont, "sceFontGetFontInfoByIndexNumber(%08x, %08x, %i): invalid font lib", libHandle, fontInfoPtr, index);
return !fl ? ERROR_FONT_INVALID_LIBID : ERROR_FONT_INVALID_PARAMETER;
int error = !fl ? ERROR_FONT_INVALID_LIBID : ERROR_FONT_INVALID_PARAMETER;
return hleLogError(Log::sceFont, error, "invalid font lib");
}
if (index >= internalFonts.size()) {
ERROR_LOG_REPORT(Log::sceFont, "sceFontGetFontInfoByIndexNumber(%08x, %08x, %i): invalid font index", libHandle, fontInfoPtr, index);
return ERROR_FONT_INVALID_PARAMETER;
return hleLogError(Log::sceFont, ERROR_FONT_INVALID_PARAMETER, "invalid font index");
}
if (!fontStyle.IsValid()) {
ERROR_LOG_REPORT(Log::sceFont, "sceFontGetFontInfoByIndexNumber(%08x, %08x, %i): invalid info pointer", libHandle, fontInfoPtr, index);
return ERROR_FONT_INVALID_PARAMETER;
return hleLogError(Log::sceFont, ERROR_FONT_INVALID_PARAMETER, "invalid info pointer");
}
DEBUG_LOG(Log::sceFont, "sceFontGetFontInfoByIndexNumber(%08x, %08x, %i)", libHandle, fontInfoPtr, index);
auto font = internalFonts[index];
*fontStyle = font->GetFontStyle();
return 0;
return hleLogDebug(Log::sceFont, 0);
}
static int sceFontGetCharInfo(u32 fontHandle, u32 charCode, u32 charInfoPtr) {
charCode &= 0xffff;
if (!Memory::IsValidAddress(charInfoPtr)) {
ERROR_LOG(Log::sceFont, "sceFontGetCharInfo(%08x, %i, %08x): bad charInfo pointer", fontHandle, charCode, charInfoPtr);
return ERROR_FONT_INVALID_PARAMETER;
return hleLogError(Log::sceFont, ERROR_FONT_INVALID_PARAMETER, "bad charInfo pointer");
}
LoadedFont *font = GetLoadedFont(fontHandle, true);
if (!font) {
// The PSP crashes, but we assume it'd work like sceFontGetFontInfo(), and not touch charInfo.
ERROR_LOG_REPORT(Log::sceFont, "sceFontGetCharInfo(%08x, %i, %08x): bad font", fontHandle, charCode, charInfoPtr);
return ERROR_FONT_INVALID_PARAMETER;
return hleLogError(Log::sceFont, ERROR_FONT_INVALID_PARAMETER, "bad font");
}
DEBUG_LOG(Log::sceFont, "sceFontGetCharInfo(%08x, %i, %08x)", fontHandle, charCode, charInfoPtr);
@ -1365,7 +1356,7 @@ static int sceFontGetCharInfo(u32 fontHandle, u32 charCode, u32 charInfoPtr) {
font->GetCharInfo(charCode, charInfo);
if (!useAllocCallbacks)
return 0;
return hleLogDebug(Log::sceFont, 0);
u32 allocSize = charInfo->bitmapWidth * charInfo->bitmapHeight;
if (font->GetFontLib() && (charInfo->sfp26AdvanceH != 0 || charInfo->sfp26AdvanceV != 0)) {
@ -1385,26 +1376,24 @@ static int sceFontGetCharInfo(u32 fontHandle, u32 charCode, u32 charInfoPtr) {
}
}
return 0;
return hleLogDebug(Log::sceFont, 0);
}
static int sceFontGetShadowInfo(u32 fontHandle, u32 charCode, u32 charInfoPtr) {
charCode &= 0xffff;
if (!Memory::IsValidAddress(charInfoPtr)) {
ERROR_LOG(Log::sceFont, "sceFontGetShadowInfo(%08x, %i, %08x): bad charInfo pointer", fontHandle, charCode, charInfoPtr);
return ERROR_FONT_INVALID_PARAMETER;
return hleLogError(Log::sceFont, ERROR_FONT_INVALID_PARAMETER, "bad charInfo pointer");
}
LoadedFont *font = GetLoadedFont(fontHandle, true);
if (!font) {
ERROR_LOG_REPORT(Log::sceFont, "sceFontGetShadowInfo(%08x, %i, %08x): bad font", fontHandle, charCode, charInfoPtr);
return ERROR_FONT_INVALID_PARAMETER;
return hleLogError(Log::sceFont, ERROR_FONT_INVALID_PARAMETER, "bad font");
}
DEBUG_LOG(Log::sceFont, "sceFontGetShadowInfo(%08x, %i, %08x)", fontHandle, charCode, charInfoPtr);
auto charInfo = PSPPointer<PGFCharInfo>::Create(charInfoPtr);
font->GetCharInfo(charCode, charInfo, FONT_PGF_SHADOWGLYPH);
return 0;
return hleLogDebug(Log::sceFont, 0);
}
static int sceFontGetCharImageRect(u32 fontHandle, u32 charCode, u32 charRectPtr) {
@ -1412,20 +1401,17 @@ static int sceFontGetCharImageRect(u32 fontHandle, u32 charCode, u32 charRectPtr
auto charRect = PSPPointer<FontImageRect>::Create(charRectPtr);
LoadedFont *font = GetLoadedFont(fontHandle, true);
if (!font) {
ERROR_LOG_REPORT(Log::sceFont, "sceFontGetCharImageRect(%08x, %i, %08x): bad font", fontHandle, charCode, charRectPtr);
return ERROR_FONT_INVALID_PARAMETER;
return hleLogError(Log::sceFont, ERROR_FONT_INVALID_PARAMETER, "bad font");
}
if (!charRect.IsValid()) {
ERROR_LOG_REPORT(Log::sceFont, "sceFontGetCharImageRect(%08x, %i, %08x): invalid rect pointer", fontHandle, charCode, charRectPtr);
return ERROR_FONT_INVALID_PARAMETER;
return hleLogError(Log::sceFont, ERROR_FONT_INVALID_PARAMETER, "invalid rect pointer");
}
DEBUG_LOG(Log::sceFont, "sceFontGetCharImageRect(%08x, %i, %08x)", fontHandle, charCode, charRectPtr);
PGFCharInfo charInfo;
font->GetCharInfo(charCode, &charInfo);
charRect->width = charInfo.bitmapWidth;
charRect->height = charInfo.bitmapHeight;
return 0;
return hleLogDebug(Log::sceFont, 0, "w: %d h: %d", charInfo.bitmapWidth, charInfo.bitmapHeight);
}
static int sceFontGetShadowImageRect(u32 fontHandle, u32 charCode, u32 charRectPtr) {
@ -1433,12 +1419,10 @@ static int sceFontGetShadowImageRect(u32 fontHandle, u32 charCode, u32 charRectP
auto charRect = PSPPointer<FontImageRect>::Create(charRectPtr);
LoadedFont *font = GetLoadedFont(fontHandle, true);
if (!font) {
ERROR_LOG_REPORT(Log::sceFont, "sceFontGetShadowImageRect(%08x, %i, %08x): bad font", fontHandle, charCode, charRectPtr);
return ERROR_FONT_INVALID_PARAMETER;
return hleLogError(Log::sceFont, ERROR_FONT_INVALID_PARAMETER, "bad font");
}
if (!charRect.IsValid()) {
ERROR_LOG_REPORT(Log::sceFont, "sceFontGetShadowImageRect(%08x, %i, %08x): invalid rect pointer", fontHandle, charCode, charRectPtr);
return ERROR_FONT_INVALID_PARAMETER;
return hleLogError(Log::sceFont, ERROR_FONT_INVALID_PARAMETER, "invalid rect pointer");
}
DEBUG_LOG(Log::sceFont, "sceFontGetShadowImageRect(%08x, %i, %08x)", fontHandle, charCode, charRectPtr);
@ -1457,8 +1441,7 @@ static int sceFontGetCharGlyphImage(u32 fontHandle, u32 charCode, u32 glyphImage
}
LoadedFont *font = GetLoadedFont(fontHandle, true);
if (!font) {
ERROR_LOG_REPORT(Log::sceFont, "sceFontGetCharGlyphImage(%x, %x, %x): bad font", fontHandle, charCode, glyphImagePtr);
return ERROR_FONT_INVALID_PARAMETER;
return hleLogError(Log::sceFont, ERROR_FONT_INVALID_PARAMETER, "bad font");
}
DEBUG_LOG(Log::sceFont, "sceFontGetCharGlyphImage(%x, %x, %x)", fontHandle, charCode, glyphImagePtr);
@ -1493,9 +1476,8 @@ static int sceFontSetAltCharacterCode(u32 fontLibHandle, u32 charCode) {
return ERROR_FONT_INVALID_LIBID;
}
INFO_LOG(Log::sceFont, "sceFontSetAltCharacterCode(%08x, %08x)", fontLibHandle, charCode);
fl->SetAltCharCode(charCode & 0xFFFF);
return 0;
return hleLogSuccessInfoI(Log::sceFont, 0);
}
static int sceFontFlush(u32 fontHandle) {
@ -1534,35 +1516,30 @@ static int sceFontGetFontList(u32 fontLibHandle, u32 fontStylePtr, int numFonts)
fontStyles[i] = internalFonts[i]->GetFontStyle();
}
return hleDelayResult(0, "font list read", 100);
return hleDelayResult(hleLogDebug(Log::sceFont, 0), "font list read", 100);
}
static int sceFontGetNumFontList(u32 fontLibHandle, u32 errorCodePtr) {
auto errorCode = PSPPointer<s32_le>::Create(errorCodePtr);
if (!errorCode.IsValid()) {
ERROR_LOG_REPORT(Log::sceFont, "sceFontGetNumFontList(%08x, %08x): invalid error address", fontLibHandle, errorCodePtr);
return ERROR_FONT_INVALID_PARAMETER;
return hleLogError(Log::sceFont, ERROR_FONT_INVALID_PARAMETER, "invalid error address");
}
FontLib *fl = GetFontLib(fontLibHandle);
if (!fl) {
ERROR_LOG_REPORT(Log::sceFont, "sceFontGetNumFontList(%08x, %08x): invalid font lib", fontLibHandle, errorCodePtr);
*errorCode = ERROR_FONT_INVALID_LIBID;
return 0;
return hleLogError(Log::sceFont, 0, "invalid font lib");
}
DEBUG_LOG(Log::sceFont, "sceFontGetNumFontList(%08x, %08x)", fontLibHandle, errorCodePtr);
*errorCode = 0;
return fl->handle() == 0 ? 0 : (int)internalFonts.size();
return hleLogDebug(Log::sceFont, fl->handle() == 0 ? 0 : (int)internalFonts.size());
}
static int sceFontSetResolution(u32 fontLibHandle, float hRes, float vRes) {
FontLib *fl = GetFontLib(fontLibHandle);
if (!fl) {
ERROR_LOG_REPORT(Log::sceFont, "sceFontSetResolution(%08x, %f, %f): invalid font lib", fontLibHandle, hRes, vRes);
return ERROR_FONT_INVALID_LIBID;
return hleLogError(Log::sceFont, ERROR_FONT_INVALID_LIBID, "invalid font lib");
}
if (hRes <= 0.0f || vRes <= 0.0f) {
ERROR_LOG_REPORT(Log::sceFont, "sceFontSetResolution(%08x, %f, %f): negative value", fontLibHandle, hRes, vRes);
return ERROR_FONT_INVALID_PARAMETER;
return hleLogError(Log::sceFont, ERROR_FONT_INVALID_PARAMETER, "negative value in hRes %f or vRes %f", hRes, vRes);
}
INFO_LOG(Log::sceFont, "sceFontSetResolution(%08x, %f, %f)", fontLibHandle, hRes, vRes);
fl->SetResolution(hRes, vRes);

View file

@ -1036,7 +1036,8 @@ static int sceNetApctlInit(int stackSize, int initPriority) {
prodCode->type = 1; // VT_UTF8 since we're using DiscID instead of product id
memcpy(prodCode->data, discID.c_str(), std::min(ADHOCCTL_ADHOCID_LEN, (int)discID.size()));
}
sceNetAdhocctlInit(stackSize, initPriority, apctlProdCodeAddr);
hleCall(sceNetAdhocctl, int, sceNetAdhocctlInit, stackSize, initPriority, apctlProdCodeAddr);
netApctlInited = true;
@ -1287,7 +1288,7 @@ int sceNetApctlDisconnect() {
// Like its 'sister' function sceNetAdhocctlDisconnect, we need to alert Apctl handlers that a disconnect took place
// or else games like Phantasy Star Portable 2 will hang at certain points (e.g. returning to the main menu after trying to connect to PSN).
// Note: Since we're borrowing AdhocServer for Grouping purpose, we should disconnect too
sceNetAdhocctlDisconnect();
hleCall(sceNetAdhocctl, int, sceNetAdhocctlDisconnect);
// Discards any pending events so we can disconnect immediately
apctlEvents.clear();

View file

@ -205,7 +205,7 @@ static void __GameModeNotify(u64 userdata, int cyclesLate) {
if (it != gameModePeerPorts.end())
port = it->second;
int sent = sceNetAdhocPdpSend(gameModeSocket, (const char*)&gma.mac, port, masterGameModeArea.data, masterGameModeArea.size, 0, ADHOC_F_NONBLOCK);
int sent = hleCall(sceNetAdhoc, int, sceNetAdhocPdpSend, gameModeSocket, (const char*)&gma.mac, port, masterGameModeArea.data, masterGameModeArea.size, 0, ADHOC_F_NONBLOCK);
if (sent != ERROR_NET_ADHOC_WOULD_BLOCK) {
gma.dataSent = 1;
DEBUG_LOG(Log::sceNet, "GameMode: Master data Sent %d bytes to Area #%d [%s]", masterGameModeArea.size, gma.id, mac2str(&gma.mac).c_str());
@ -234,7 +234,7 @@ static void __GameModeNotify(u64 userdata, int cyclesLate) {
if (it != gameModePeerPorts.end())
port = it->second;
sceNetAdhocPdpSend(gameModeSocket, (const char*)&gma.mac, port, masterGameModeArea.data, masterGameModeArea.size, 0, ADHOC_F_NONBLOCK);
hleCall(sceNetAdhoc, int, sceNetAdhocPdpSend, gameModeSocket, (const char*)&gma.mac, port, masterGameModeArea.data, masterGameModeArea.size, 0, ADHOC_F_NONBLOCK);
}
}
}
@ -1279,7 +1279,7 @@ int sceNetAdhocctlInit(int stackSize, int prio, u32 productAddr) {
// FIXME: Sometimes returning 0x80410601 (ERROR_NET_ADHOC_AUTH_ALREADY_INITIALIZED / Library module is already initialized ?) when AdhocctlTerm is not fully done?
if (netAdhocctlInited)
return ERROR_NET_ADHOCCTL_ALREADY_INITIALIZED;
return hleLogError(Log::sceNet, ERROR_NET_ADHOCCTL_ALREADY_INITIALIZED);
auto product = PSPPointer<SceNetAdhocctlAdhocId>::Create(productAddr);
if (product.IsValid()) {
@ -1308,12 +1308,12 @@ int sceNetAdhocctlInit(int stackSize, int prio, u32 productAddr) {
int us = adhocDefaultDelay;
if (g_Config.bEnableWlan && !networkInited) {
AdhocctlRequest dummyreq = { OPCODE_LOGIN, {0} };
return WaitBlockingAdhocctlSocket(dummyreq, us, "adhocctl init");
return hleLogSuccessOrWarn(Log::sceNet, WaitBlockingAdhocctlSocket(dummyreq, us, "adhocctl init"));
}
// Give a little time for friendFinder thread to be ready before the game use the next sceNet functions, should've checked for friendFinderRunning status instead of guessing the time?
hleEatMicro(us);
return 0;
return hleLogDebug(Log::sceNet, 0);
}
int NetAdhocctl_GetState() {
@ -1323,11 +1323,11 @@ int NetAdhocctl_GetState() {
int sceNetAdhocctlGetState(u32 ptrToStatus) {
// Library uninitialized
if (!netAdhocctlInited)
return ERROR_NET_ADHOCCTL_NOT_INITIALIZED;
return hleLogError(Log::sceNet, ERROR_NET_ADHOCCTL_NOT_INITIALIZED);
// Invalid Arguments
if (!Memory::IsValidAddress(ptrToStatus))
return ERROR_NET_ADHOCCTL_INVALID_ARG;
return hleLogError(Log::sceNet, ERROR_NET_ADHOCCTL_INVALID_ARG);
int state = NetAdhocctl_GetState();
// Output Adhocctl State
@ -2534,9 +2534,7 @@ int sceNetAdhocctlDisconnect() {
char grpName[9] = { 0 };
memcpy(grpName, parameter.group_name.data, ADHOCCTL_GROUPNAME_LEN); // Copied to null-terminated var to prevent unexpected behaviour on Logs
int ret = NetAdhocctl_Disconnect();
INFO_LOG(Log::sceNet, "%08x=sceNetAdhocctlDisconnect() at %08x [group=%s]", ret, currentMIPS->pc, grpName);
return ret;
return hleLogSuccessI(Log::sceNet, ret, "group=%s", grpName);
}
static u32 sceNetAdhocctlDelHandler(u32 handlerID) {
@ -4627,7 +4625,7 @@ static int sceNetAdhocGameModeUpdateReplica(int id, u32 infoAddr) {
}
hleEatMicro(100);
return 0;
return hleLogDebug(Log::sceNet, 0);
}
static int sceNetAdhocGameModeDeleteReplica(int id) {
@ -4653,7 +4651,7 @@ static int sceNetAdhocGameModeDeleteReplica(int id) {
//gameModeSocket = (int)INVALID_SOCKET;
}
return 0;
return hleLogDebug(Log::sceNet, 0);
}
int sceNetAdhocGetSocketAlert(int id, u32 flagPtr) {
@ -4751,12 +4749,14 @@ void __NetTriggerCallbacks()
adhocctlEvents.pop_front();
// Since we don't have beforeAction, simulate it using ScheduleEvent
ScheduleAdhocctlState(flags, newState, delayus, "adhocctl callback state");
hleNoLogVoid();
return;
}
}
// Must be delayed long enough whenever there is a pending callback. Should it be 100-500ms for Adhocctl Events? or Not Less than the delays on sceNetAdhocctl HLE?
hleCall(ThreadManForUser, int, sceKernelDelayThread, adhocDefaultDelay);
hleNoLogVoid();
}
const HLEFunction sceNetAdhoc[] = {

View file

@ -106,7 +106,8 @@ void __UpdateAdhocctlHandlers(u32 flags, u32 error);
bool __NetAdhocConnected();
// I have to call this from netdialog
// Called from netdialog
// NOTE: use hleCall for sceNet* ones!
int sceNetAdhocctlGetState(u32 ptrToStatus);
int sceNetAdhocctlCreate(const char * groupName);
int sceNetAdhocctlConnect(const char* groupName);
@ -142,8 +143,10 @@ extern u32 matchingThreadHackAddr;
extern u32_le matchingThreadCode[3];
// Exposing those for the matching routines
// NOTE: use hleCall for sceNet* ones!
int sceNetAdhocPdpSend(int id, const char* mac, u32 port, void* data, int len, int timeout, int flag);
int sceNetAdhocPdpRecv(int id, void* addr, void* port, void* buf, void* dataLength, u32 timeout, int flag);
int sceNetAdhocPdpCreate(const char* mac, int port, int bufferSize, u32 flag);
int NetAdhoc_SetSocketAlert(int id, s32_le flag);
int NetAdhocPdp_Delete(int id, int unknown);

View file

@ -145,7 +145,7 @@ void broadcastPingMessage(SceNetAdhocMatchingContext * context) {
port = it->second;
context->socketlock->lock();
sceNetAdhocPdpSend(context->socket, (const char*)&peer->mac_addr, port, &ping, sizeof(ping), 0, ADHOC_F_NONBLOCK);
hleCall(sceNetAdhoc, int, sceNetAdhocPdpSend, context->socket, (const char*)&peer->mac_addr, port, &ping, (u32)sizeof(ping), 0, ADHOC_F_NONBLOCK);
context->socketlock->unlock();
}
}
@ -203,7 +203,7 @@ void broadcastHelloMessage(SceNetAdhocMatchingContext * context) {
port = it->second;
context->socketlock->lock();
sceNetAdhocPdpSend(context->socket, (const char*)&peer->mac_addr, port, hello, 5 + context->hellolen, 0, ADHOC_F_NONBLOCK);
hleCall(sceNetAdhoc, int, sceNetAdhocPdpSend, context->socket, (const char*)&peer->mac_addr, port, hello, 5 + context->hellolen, 0, ADHOC_F_NONBLOCK);
context->socketlock->unlock();
}
peerlock.unlock();
@ -281,7 +281,7 @@ void sendAcceptPacket(SceNetAdhocMatchingContext * context, SceNetEtherAddr * ma
// Send Data
context->socketlock->lock();
sceNetAdhocPdpSend(context->socket, (const char*)mac, (*context->peerPort)[*mac], accept, 9 + optlen + siblingbuflen, 0, ADHOC_F_NONBLOCK);
hleCall(sceNetAdhoc, int, sceNetAdhocPdpSend, context->socket, (const char*)mac, (*context->peerPort)[*mac], accept, 9 + optlen + siblingbuflen, 0, ADHOC_F_NONBLOCK);
context->socketlock->unlock();
// Free Memory
@ -329,7 +329,7 @@ void sendJoinPacket(SceNetAdhocMatchingContext * context, SceNetEtherAddr * mac,
// Send Data
context->socketlock->lock();
sceNetAdhocPdpSend(context->socket, (const char*)mac, (*context->peerPort)[*mac], join, 5 + optlen, 0, ADHOC_F_NONBLOCK);
hleCall(sceNetAdhoc, int, sceNetAdhocPdpSend, context->socket, (const char*)mac, (*context->peerPort)[*mac], join, 5 + optlen, 0, ADHOC_F_NONBLOCK);
context->socketlock->unlock();
// Free Memory
@ -363,7 +363,7 @@ void sendCancelPacket(SceNetAdhocMatchingContext * context, SceNetEtherAddr * ma
// Send Data
context->socketlock->lock();
sceNetAdhocPdpSend(context->socket, (const char*)mac, (*context->peerPort)[*mac], cancel, 5 + optlen, 0, ADHOC_F_NONBLOCK);
hleCall(sceNetAdhoc, int, sceNetAdhocPdpSend, context->socket, (const char*)mac, (*context->peerPort)[*mac], cancel, 5 + optlen, 0, ADHOC_F_NONBLOCK);
context->socketlock->unlock();
// Free Memory
@ -432,7 +432,7 @@ void sendBulkDataPacket(SceNetAdhocMatchingContext * context, SceNetEtherAddr *
// Send Data
context->socketlock->lock();
sceNetAdhocPdpSend(context->socket, (const char*)mac, (*context->peerPort)[*mac], send, 5 + datalen, 0, ADHOC_F_NONBLOCK);
hleCall(sceNetAdhoc, int, sceNetAdhocPdpSend, context->socket, (const char*)mac, (*context->peerPort)[*mac], send, 5 + datalen, 0, ADHOC_F_NONBLOCK);
context->socketlock->unlock();
// Free Memory
@ -484,7 +484,7 @@ void sendBirthPacket(SceNetAdhocMatchingContext * context, SceNetEtherAddr * mac
// Send Packet
context->socketlock->lock();
int sent = sceNetAdhocPdpSend(context->socket, (const char*)&peer->mac, (*context->peerPort)[peer->mac], packet, sizeof(packet), 0, ADHOC_F_NONBLOCK);
int sent = hleCall(sceNetAdhoc, int, sceNetAdhocPdpSend, context->socket, (const char*)&peer->mac, (*context->peerPort)[peer->mac], packet, (u32)sizeof(packet), 0, ADHOC_F_NONBLOCK);
context->socketlock->unlock();
// Log Send Success
@ -528,7 +528,7 @@ void sendDeathPacket(SceNetAdhocMatchingContext * context, SceNetEtherAddr * mac
// Send Bye Packet
context->socketlock->lock();
sceNetAdhocPdpSend(context->socket, (const char*)&peer->mac, (*context->peerPort)[peer->mac], packet, sizeof(packet[0]), 0, ADHOC_F_NONBLOCK);
hleCall(sceNetAdhoc, int, sceNetAdhocPdpSend, context->socket, (const char*)&peer->mac, (*context->peerPort)[peer->mac], packet, (u32)sizeof(packet[0]), 0, ADHOC_F_NONBLOCK);
context->socketlock->unlock();
}
else {
@ -539,7 +539,7 @@ void sendDeathPacket(SceNetAdhocMatchingContext * context, SceNetEtherAddr * mac
// Send Death Packet
context->socketlock->lock();
sceNetAdhocPdpSend(context->socket, (const char*)&peer->mac, (*context->peerPort)[peer->mac], packet, sizeof(packet), 0, ADHOC_F_NONBLOCK);
hleCall(sceNetAdhoc, int, sceNetAdhocPdpSend, context->socket, (const char*)&peer->mac, (*context->peerPort)[peer->mac], packet, (u32)sizeof(packet), 0, ADHOC_F_NONBLOCK);
context->socketlock->unlock();
}
}
@ -567,7 +567,7 @@ void sendByePacket(SceNetAdhocMatchingContext * context) {
// Send Bye Packet
context->socketlock->lock();
sceNetAdhocPdpSend(context->socket, (const char*)&peer->mac, (*context->peerPort)[peer->mac], &opcode, sizeof(opcode), 0, ADHOC_F_NONBLOCK);
hleCall(sceNetAdhoc, int, sceNetAdhocPdpSend, context->socket, (const char*)&peer->mac, (*context->peerPort)[peer->mac], &opcode, (u32)sizeof(opcode), 0, ADHOC_F_NONBLOCK);
context->socketlock->unlock();
}
}
@ -1136,6 +1136,7 @@ void actOnByePacket(SceNetAdhocMatchingContext * context, SceNetEtherAddr * send
/**
* TODO: This really should be a callback or event!
* Matching Event Dispatcher Thread
* @param args sizeof(SceNetAdhocMatchingContext *)
* @param argp SceNetAdhocMatchingContext *
@ -1854,7 +1855,7 @@ int NetAdhocMatching_Start(int matchingId, int evthPri, int evthPartitionId, int
if (item == NULL) {
// return ERROR_NET_ADHOC_MATCHING_INVALID_ID; //Faking success to prevent GTA:VCS from stuck unable to choose host/join menu
return 0;
return hleLogDebug(Log::sceNet, 0);
}
//sceNetAdhocMatchingSetHelloOpt(matchingId, optLen, optDataAddr); //SetHelloOpt only works when context is running
@ -1872,7 +1873,7 @@ int NetAdhocMatching_Start(int matchingId, int evthPri, int evthPartitionId, int
//else return ERROR_NET_ADHOC_MATCHING_INVALID_ARG; // ERROR_NET_ADHOC_MATCHING_INVALID_OPTLEN; // Returning Not Success will cause GTA:VC stuck unable to choose host/join menu
// Create PDP Socket
int sock = sceNetAdhocPdpCreate((const char*)&item->mac, static_cast<int>(item->port), item->rxbuflen, 0);
int sock = hleCall(sceNetAdhoc, int, sceNetAdhocPdpCreate, (const char*)&item->mac, static_cast<int>(item->port), item->rxbuflen, 0);
item->socket = sock;
if (sock < 1) {
return hleLogError(Log::sceNet, ERROR_NET_ADHOC_MATCHING_PORT_IN_USE, "adhoc matching port in use");
@ -1881,10 +1882,10 @@ int NetAdhocMatching_Start(int matchingId, int evthPri, int evthPartitionId, int
// Create & Start the Fake PSP Thread ("matching_ev%d" and "matching_io%d")
netAdhocMatchingValidateLoopMemory();
std::string thrname = std::string("MatchingThr") + std::to_string(matchingId);
matchingThreads[item->matching_thid] = sceKernelCreateThread(thrname.c_str(), matchingThreadHackAddr, evthPri, evthStack, 0, 0);
matchingThreads[item->matching_thid] = hleCall(ThreadManForUser, int, sceKernelCreateThread, thrname.c_str(), matchingThreadHackAddr, evthPri, evthStack, 0, 0);
//item->matchingThread = new HLEHelperThread(thrname.c_str(), "sceNetAdhocMatching", "__NetMatchingCallbacks", inthPri, inthStack);
if (matchingThreads[item->matching_thid] > 0) {
sceKernelStartThread(matchingThreads[item->matching_thid], 0, 0); //sceKernelStartThread(context->event_thid, sizeof(context), &context);
hleCall(ThreadManForUser, int, sceKernelStartThread, matchingThreads[item->matching_thid], 0, 0); //sceKernelStartThread(context->event_thid, sizeof(context), &context);
//item->matchingThread->Start(matchingId, 0);
}
@ -1901,7 +1902,7 @@ int NetAdhocMatching_Start(int matchingId, int evthPri, int evthPartitionId, int
item->running = 1;
netAdhocMatchingStarted++;
return 0;
return hleLogDebug(Log::sceNet, 0);
}
#define KERNEL_PARTITION_ID 1
@ -2004,7 +2005,7 @@ static int sceNetAdhocMatchingSelectTarget(int matchingId, const char *macAddres
sendAcceptMessage(context, peer, optLen, opt);
// Return Success
return 0;
return hleLogDebug(Log::sceNet, 0);
}
}
@ -2025,7 +2026,7 @@ static int sceNetAdhocMatchingSelectTarget(int matchingId, const char *macAddres
sendJoinRequest(context, peer, optLen, opt);
// Return Success
return 0;
return hleLogDebug(Log::sceNet, 0);
}
}
@ -2046,7 +2047,7 @@ static int sceNetAdhocMatchingSelectTarget(int matchingId, const char *macAddres
sendJoinRequest(context, peer, optLen, opt);
// Return Success
return 0;
return hleLogDebug(Log::sceNet, 0);
}
// Requesting Peer
@ -2060,7 +2061,7 @@ static int sceNetAdhocMatchingSelectTarget(int matchingId, const char *macAddres
sendAcceptMessage(context, peer, optLen, opt);
// Return Success
return 0;
return hleLogDebug(Log::sceNet, 0);
}
}
@ -2103,7 +2104,7 @@ int NetAdhocMatching_CancelTargetWithOpt(int matchingId, const char* macAddress,
// Peer not found
//return hleLogError(Log::sceNet, ERROR_NET_ADHOC_MATCHING_UNKNOWN_TARGET, "adhocmatching unknown target");
// Faking success to prevent the game (ie. Soul Calibur) to repeatedly calling this function when the other player is disconnected
return 0;
return hleLogDebug(Log::sceNet, 0);
}
// Valid Peer Mode
@ -2131,13 +2132,13 @@ int NetAdhocMatching_CancelTargetWithOpt(int matchingId, const char* macAddress,
hleEatCycles(adhocDefaultDelay);
// Return Success
return 0;
return hleLogDebug(Log::sceNet, 0);
}
// Peer not found
//return hleLogError(Log::sceNet, ERROR_NET_ADHOC_MATCHING_UNKNOWN_TARGET, "adhocmatching unknown target");
// Faking success to prevent the game (ie. Soul Calibur) to repeatedly calling this function when the other player is disconnected
return 0;
return hleLogDebug(Log::sceNet, 0);
}
int sceNetAdhocMatchingCancelTargetWithOpt(int matchingId, const char *macAddress, int optLen, u32 optDataPtr) {
@ -2157,7 +2158,6 @@ int sceNetAdhocMatchingCancelTarget(int matchingId, const char *macAddress) {
}
int sceNetAdhocMatchingGetHelloOpt(int matchingId, u32 optLenAddr, u32 optDataAddr) {
WARN_LOG(Log::sceNet, "UNTESTED sceNetAdhocMatchingGetHelloOpt(%i, %08x, %08x)", matchingId, optLenAddr, optDataAddr);
if (!g_Config.bEnableWlan) {
return hleLogError(Log::sceNet, -1, "WLAN off");
}
@ -2187,11 +2187,10 @@ int sceNetAdhocMatchingGetHelloOpt(int matchingId, u32 optLenAddr, u32 optDataAd
// Multithreading Unlock
peerlock.unlock();
return 0;
return hleLogDebug(Log::sceNet, 0);
}
int sceNetAdhocMatchingSetHelloOpt(int matchingId, int optLenAddr, u32 optDataAddr) {
VERBOSE_LOG(Log::sceNet, "UNTESTED sceNetAdhocMatchingSetHelloOpt(%i, %i, %08x) at %08x", matchingId, optLenAddr, optDataAddr, currentMIPS->pc);
if (!g_Config.bEnableWlan) {
return hleLogError(Log::sceNet, -1, "WLAN off");
}
@ -2259,7 +2258,7 @@ int sceNetAdhocMatchingSetHelloOpt(int matchingId, int optLenAddr, u32 optDataAd
}
// Return Success
return 0;
return hleLogDebug(Log::sceNet, 0);
}
static int sceNetAdhocMatchingGetMembers(int matchingId, u32 sizeAddr, u32 buf) {
@ -2453,7 +2452,7 @@ static int sceNetAdhocMatchingGetMembers(int matchingId, u32 sizeAddr, u32 buf)
}
// Return Success
return hleDelayResult(0, "delay 100 ~ 1000us", 100); // seems to have different thread running within the delay duration
return hleDelayResult(hleLogDebug(Log::sceNet, 0), "delay 100 ~ 1000us", 100); // seems to have different thread running within the delay duration
}
// Gran Turismo may replace the 1st bit of the 1st byte of MAC address's OUI with 0 (unicast bit), or replace the whole 6-bytes of MAC address with all 00 (invalid mac) for unknown reason
@ -2522,7 +2521,7 @@ int sceNetAdhocMatchingSendData(int matchingId, const char *mac, int dataLen, u3
sendBulkDataPacket(context, &peer->mac, dataLen, data);
// Return Success
return 0;
return hleLogDebug(Log::sceNet, 0);
}
int sceNetAdhocMatchingAbortSendData(int matchingId, const char *mac) {
@ -2572,12 +2571,11 @@ int sceNetAdhocMatchingAbortSendData(int matchingId, const char *mac) {
}
// Return Success
return 0;
return hleLogDebug(Log::sceNet, 0);
}
// Get the maximum memory usage by the matching library
static int sceNetAdhocMatchingGetPoolMaxAlloc() {
ERROR_LOG(Log::sceNet, "UNIMPL sceNetAdhocMatchingGetPoolMaxAlloc() at %08x", currentMIPS->pc);
if (!g_Config.bEnableWlan) {
return hleLogError(Log::sceNet, -1, "WLAN off");
}
@ -2587,7 +2585,6 @@ static int sceNetAdhocMatchingGetPoolMaxAlloc() {
}
int sceNetAdhocMatchingGetPoolStat(u32 poolstatPtr) {
DEBUG_LOG(Log::sceNet, "UNTESTED sceNetAdhocMatchingGetPoolStat(%08x) at %08x", poolstatPtr, currentMIPS->pc);
if (!g_Config.bEnableWlan) {
return hleLogError(Log::sceNet, -1, "WLAN off");
}
@ -2611,7 +2608,7 @@ int sceNetAdhocMatchingGetPoolStat(u32 poolstatPtr) {
poolstat->free = fakePoolSize - poolstat->maximum;
// Return Success
return 0;
return hleLogDebug(Log::sceNet, 0);
}
void __NetMatchingCallbacks() { //(int matchingId)
@ -2650,6 +2647,8 @@ void __NetMatchingCallbacks() { //(int matchingId)
// Must be delayed long enough whenever there is a pending callback. Should it be 10-100ms for Matching Events? or Not Less than the delays on sceNetAdhocMatching HLE?
hleCall(ThreadManForUser, int, sceKernelDelayThread, delayus);
hleNoLogVoid();
}