diff --git a/src/adhoc/pspadhoc.c b/src/adhoc/pspadhoc.c index 6128bc4..2d5148c 100644 --- a/src/adhoc/pspadhoc.c +++ b/src/adhoc/pspadhoc.c @@ -229,13 +229,17 @@ void _matchingCB(int unk1, int event, unsigned char *macSource, int size, void * //////////////////////////////////////////////////////////////////////////////////////////////////////// int oslAdhocInit(char *productID) { - if( state != ADHOC_UNINIT) return 0; + if (state != ADHOC_UNINIT) return 0; + + memset(myMacAddress, 0, 8 * sizeof(u8)); + + // Ensure null termination after copying + strncpy(product.product, productID, 8); // Copy up to 8 characters + product.product[8] = '\0'; // Null-terminate explicitly - memset(myMacAddress, 0, 8*sizeof(u8) ); - strncpy(product.product, productID, 9); product.unknown = 0; - matchingHD=-1; - pdpHD=-1; + matchingHD = -1; + pdpHD = -1; port = 0x309; allRemotePSPCount = 0; @@ -245,9 +249,7 @@ int oslAdhocInit(char *productID) if (_getMacAddress() < 0) return ADHOC_ERROR_MAC; - _loadModules(); - /*if (_loadModules()) - return ADHOC_ERROR_MODULES;*/ + _loadModules(); if (_libNetInit() < 0) return ADHOC_ERROR_NET_INIT; diff --git a/src/browser.c b/src/browser.c index 05cf759..28530fb 100755 --- a/src/browser.c +++ b/src/browser.c @@ -18,54 +18,54 @@ static SceUID vpl; static pspUtilityHtmlViewerParam params; static int browserIsActive = 0; -int oslBrowserInit(char *url, char *downloadDir, int browserMemory, unsigned int displaymode, unsigned int options, unsigned int interfacemode, unsigned int connectmode){ - int res; - if (browserMemory <= 0) - browserMemory = BROWSER_MEMORY; +int oslBrowserInit(char *url, char *downloadDir, int browserMemory, unsigned int displaymode, unsigned int options, unsigned int interfacemode, unsigned int connectmode) { + int res; - vpl = sceKernelCreateVpl("BrowserVpl", PSP_MEMORY_PARTITION_USER, 0, browserMemory + 256, NULL); - if (vpl < 0) - return OSL_BROWSER_ERROR_MEMORY; - - memset(¶ms, 0, sizeof(pspUtilityHtmlViewerParam)); - - params.base.size = sizeof(pspUtilityHtmlViewerParam); - - sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_LANGUAGE, ¶ms.base.language); - sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_UNKNOWN, ¶ms.base.buttonSwap); - - params.base.graphicsThread = 17; - params.base.accessThread = 19; - params.base.fontThread = 18; - params.base.soundThread = 16; - params.memsize = browserMemory; - params.initialurl = url; - params.numtabs = 1; - params.cookiemode = PSP_UTILITY_HTMLVIEWER_COOKIEMODE_DEFAULT; - params.homeurl = url; - params.textsize = PSP_UTILITY_HTMLVIEWER_TEXTSIZE_NORMAL; - params.displaymode = displaymode; - params.options = options; - params.interfacemode = interfacemode; - params.connectmode = connectmode; - - // WITHOUT 'ms0:' on the paths - params.dldirname = downloadDir; - - res = sceKernelAllocateVpl(vpl, params.memsize, ¶ms.memaddr, NULL); - if (res < 0) - return OSL_BROWSER_ERROR_MEMORY; - - res = sceUtilityHtmlViewerInitStart(¶ms); - if (res < 0) - return res; //<-- STAS: Such a return value is more informative... -// return OSL_BROWSER_ERROR_INIT; - - browserIsActive = 1; - return 0; + if (browserMemory <= 0) { + browserMemory = BROWSER_MEMORY; + } + + vpl = sceKernelCreateVpl("BrowserVpl", PSP_MEMORY_PARTITION_USER, 0, browserMemory + 256, NULL); + if (vpl < 0) + return OSL_BROWSER_ERROR_MEMORY; + + memset(¶ms, 0, sizeof(pspUtilityHtmlViewerParam)); + + params.base.size = sizeof(pspUtilityHtmlViewerParam); + + sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_LANGUAGE, ¶ms.base.language); + sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_UNKNOWN, ¶ms.base.buttonSwap); + + params.base.graphicsThread = 17; + params.base.accessThread = 19; + params.base.fontThread = 18; + params.base.soundThread = 16; + params.memsize = browserMemory; + params.initialurl = url; + params.numtabs = 1; + params.cookiemode = PSP_UTILITY_HTMLVIEWER_COOKIEMODE_DEFAULT; + params.homeurl = url; + params.textsize = PSP_UTILITY_HTMLVIEWER_TEXTSIZE_NORMAL; + params.displaymode = displaymode; + params.options = options; + params.interfacemode = interfacemode; + params.connectmode = connectmode; + + // WITHOUT 'ms0:' on the paths + params.dldirname = downloadDir; + + res = sceKernelAllocateVpl(vpl, params.memsize, ¶ms.memaddr, NULL); + if (res < 0) + return OSL_BROWSER_ERROR_MEMORY; + + res = sceUtilityHtmlViewerInitStart(¶ms); + if (res < 0) + return res; // This return value is more informative + + browserIsActive = 1; + return 0; } - void oslDrawBrowser() { switch (sceUtilityHtmlViewerGetStatus()){ diff --git a/src/dialog.c b/src/dialog.c index 73b56ae..64d1242 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -98,7 +98,7 @@ int oslDialogGetResult() { } void oslDrawDialog() { - int status; + int status = PSP_UTILITY_DIALOG_NONE; if (dialogType == OSL_DIALOG_MESSAGE || dialogType == OSL_DIALOG_ERROR) { status = sceUtilityMsgDialogGetStatus(); diff --git a/src/net.c b/src/net.c index 745f564..b57e479 100755 --- a/src/net.c +++ b/src/net.c @@ -193,32 +193,36 @@ int oslNetTerm() } int oslGetIPaddress(char *IPaddress){ - union SceNetApctlInfo apctlInfo; + union SceNetApctlInfo apctlInfo; strcpy(IPaddress, ""); - if (sceNetApctlGetInfo(PSP_NET_APCTL_INFO_IP, &apctlInfo)) + + if (sceNetApctlGetInfo(PSP_NET_APCTL_INFO_IP, &apctlInfo)) { return OSL_ERR_APCTL_GETINFO; - strcpy(IPaddress, apctlInfo.ip); + } + + strcpy(IPaddress, apctlInfo.ip); return 0; } - int oslConnectToAP(int config, int timeout, int (*apctlCallback)(int state)){ - int err = 0; - int stateLast = -1; + int err = 0; + int stateLast = -1; - if (!oslIsWlanPowerOn()) + if (!oslIsWlanPowerOn()) { return OSL_ERR_WLAN_OFF; + } - err = sceNetApctlConnect(config); - if (err) - return OSL_ERR_APCTL_CONNECT; + err = sceNetApctlConnect(config); + if (err) + return OSL_ERR_APCTL_CONNECT; time_t startTime; time_t currTime; time(&startTime); - while (!osl_quit){ - //Check timeout: + + while (!osl_quit){ + // Check timeout time(&currTime); if (currTime - startTime >= timeout){ if (apctlCallback != NULL) @@ -227,17 +231,19 @@ int oslConnectToAP(int config, int timeout, err = OSL_ERR_APCTL_TIMEOUT; break; } - int state; - err = sceNetApctlGetState(&state); - if (err){ + + int state; + err = sceNetApctlGetState(&state); + if (err){ if (apctlCallback != NULL) (*apctlCallback)(OSL_ERR_APCTL_GETSTATE); oslDisconnectFromAP(); err = OSL_ERR_APCTL_GETSTATE; break; } - if (state > stateLast){ - stateLast = state; + + if (state > stateLast){ + stateLast = state; if (apctlCallback != NULL){ if ((*apctlCallback)(state)){ err = OSL_USER_ABORTED; @@ -245,12 +251,14 @@ int oslConnectToAP(int config, int timeout, } } } - if (state == PSP_NET_APCTL_STATE_GOT_IP) - break; // connected with static IP - sceKernelDelayThread(50*1000); - } - return err; + if (state == PSP_NET_APCTL_STATE_GOT_IP) + break; // connected with static IP + + sceKernelDelayThread(50*1000); + } + + return err; } int oslDisconnectFromAP(){ @@ -325,7 +333,7 @@ int oslNetGetFile(const char *url, const char *filepath) if(status != 200) return 0; - + /* Strangelove fix ret = sceHttpGetContentLength(request, &contentsize); if(ret < 0) diff --git a/src/shape.c b/src/shape.c index d52e8c5..e41e8aa 100644 --- a/src/shape.c +++ b/src/shape.c @@ -9,19 +9,20 @@ void toggleTexturing(int enable) { } OSL_COLOR oslBlendColors(OSL_COLOR color1, OSL_COLOR color2) { - if (color2 == 0xffffffff) // No blending needed + if (color2 == 0xffffffff) { // No blending needed return color1; + } - if ((color2 & 0x00ffffff) == 0x00ffffff) { - // No tinting, simple alpha blending - return (color1 & 0xffffff) | (((color1 >> 24) * (color2 >> 24) >> 8) << 24); - } else { - return - ((((u64)(color1 & 0xff000000) * (color2 & 0xff000000)) >> 32) & 0xff000000) | - ((((u64)(color1 & 0xff0000) * (color2 & 0xff0000)) >> 24) & 0xff0000) | - ((((color1 & 0xff00) * (color2 & 0xff00)) >> 16) & 0xff00) | - (((color1 & 0xff) * (color2 & 0xff)) >> 8); - } + if ((color2 & 0x00ffffff) == 0x00ffffff) { + // No tinting, simple alpha blending + return (color1 & 0xffffff) | (((color1 >> 24) * (color2 >> 24) >> 8) << 24); + } else { + return + ((((u64)(color1 & 0xff000000) * (color2 & 0xff000000)) >> 32) & 0xff000000) | + ((((u64)(color1 & 0xff0000) * (color2 & 0xff0000)) >> 24) & 0xff0000) | + ((((color1 & 0xff00) * (color2 & 0xff00)) >> 16) & 0xff00) | + (((color1 & 0xff) * (color2 & 0xff)) >> 8); + } } void oslDrawLine(int x0, int y0, int x1, int y1, OSL_COLOR color) {