Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <mt19937.h>
- #define RAND_INIT(s) init_MT(s)
- #define RAND() rand_int32_MT()
- /* p2p */
- #define MAX_CHAT_CHAR (40) /* 1 byte char */
- #define MAX_CHAT_MESSAGE (3)
- #define APP_VPORT (1)
- #define APP_TCPPORT (9332)
- #define OSK_LIMIT_LENGTH (MAX_CHAT_CHAR / 2)
- #define OSK_MESSAGE (L"chat message")
- #define OSK_INIT_TEXT (L"")
- /* mFlags */
- #define OSK_IN_USE (0x00000001)
- typedef enum osk_callback_type {
- OSK_CALLBACK_TYPE_MESSAGE,
- OSK_CALLBACK_TYPE_CLOSE,
- OSK_CALLBACK_TYPE_MAX
- } osk_callback_type_t;
- typedef struct osk_callback_data {
- osk_callback_type_t type;
- wchar_t *message;
- int len;
- } osk_callback_data_t;
- typedef void(*osk_callback_t)(osk_callback_data_t *data, void *arg);
- class COsk
- {
- public:
- COsk();
- ~COsk();
- bool initClass(void);
- bool termClass(void);
- bool startOsk(osk_callback_t func, void *arg);
- bool abortOsk(void);
- private:
- static const int sSlot = 2; /* 0, 1: in use or reserved */
- wchar_t mpTextBuffer[OSK_LIMIT_LENGTH + 1];
- osk_callback_t mOskCallbackFunc;
- void *mOskCallbackArg;
- uint32_t mFlags;
- static void sysutilCb(uint64_t status, uint64_t param, void * userdata);
- void sysutilCbInternal(uint64_t status);
- void stopOsk(void);
- void closeOsk(void);
- };
- COsk::COsk()
- {
- }
- COsk::~COsk()
- {
- }
- bool COsk::initClass(void)
- {
- memset(mpTextBuffer, 0, sizeof(*mpTextBuffer));
- mFlags = 0;
- return (true);
- }
- bool COsk::termClass(void)
- {
- return (true);
- }
- bool COsk::startOsk(osk_callback_t func, void *arg)
- {
- CellOskDialogInputFieldInfo info;
- CellOskDialogParam param;
- CellOskDialogPoint pos;
- int ret;
- if (mFlags & OSK_IN_USE) {
- return (true);
- }
- if (func == NULL) {
- _sys_printf("%s, invalid func\n", __FUNCTION__);
- goto fail10;
- }
- ret = cellSysutilRegisterCallback(sSlot, sysutilCb, this);
- if (ret != CELL_OK) {
- _sys_printf("cellSysutilRegisterCallback() = 0x%x\n", ret);
- goto fail20;
- }
- info.message = (uint16_t *)OSK_MESSAGE;
- info.init_text = (uint16_t *)OSK_INIT_TEXT;
- info.limit_length = OSK_LIMIT_LENGTH;
- pos.x = 0.0f;
- pos.y = 0.0f;
- param.allowOskPanelFlg =
- CELL_OSKDIALOG_PANELMODE_KOREAN |
- CELL_OSKDIALOG_PANELMODE_ALPHABET |
- CELL_OSKDIALOG_PANELMODE_NUMERAL_FULL_WIDTH |
- CELL_OSKDIALOG_PANELMODE_NUMERAL |
- CELL_OSKDIALOG_PANELMODE_JAPANESE |
- CELL_OSKDIALOG_PANELMODE_JAPANESE_KATAKANA |
- CELL_OSKDIALOG_PANELMODE_ENGLISH;
- param.firstViewPanel = CELL_OSKDIALOG_PANELMODE_ALPHABET;
- param.controlPoint = pos;
- param.prohibitFlgs = CELL_OSKDIALOG_NO_RETURN;
- ret = cellOskDialogAddSupportLanguage(CELL_OSKDIALOG_PANELMODE_KOREAN);
- if (ret < 0) {
- _sys_printf("cellOskDialogAddSupportLanguage() failed. ret = 0x%x\n", ret);
- goto fail30;
- }
- ret = cellOskDialogSetKeyLayoutOption(CELL_OSKDIALOG_10KEY_PANEL |
- CELL_OSKDIALOG_FULLKEY_PANEL);
- if (ret < 0) {
- _sys_printf("cellOskDialogSetKeyLayoutOption() failed. ret = 0x%x\n", ret);
- goto fail30;
- }
- ret = cellOskDialogLoadAsync(SYS_MEMORY_CONTAINER_ID_INVALID,
- ¶m, &info);
- if (ret < 0) {
- _sys_printf("cellOskDialogLoadAsync() failed. ret = 0x%x \n", ret);
- goto fail30;
- }
- mOskCallbackFunc = func;
- mOskCallbackArg = arg;
- mFlags |= OSK_IN_USE;
- return (true);
- fail30:
- cellSysutilUnregisterCallback(sSlot);
- fail20:
- fail10:
- CGame::getCPad()->unlockKey();
- return (false);
- }
- bool COsk::abortOsk(void)
- {
- int ret;
- if ((mFlags & OSK_IN_USE) == 0) {
- return (false);
- }
- ret = cellOskDialogAbort();
- if (ret < 0) {
- _sys_printf("cellOskDialogAbort() failed. ret = 0x%x \n", ret);
- }
- return (true);
- }
- void COsk::stopOsk(void)
- {
- CellOskDialogCallbackReturnParam param;
- osk_callback_data_t data;
- int ret;
- param.result = CELL_OSKDIALOG_INPUT_FIELD_RESULT_OK;
- param.numCharsResultString = OSK_LIMIT_LENGTH;
- param.pResultString = (uint16_t *)mpTextBuffer;
- ret = cellOskDialogUnloadAsync(¶m);
- if (ret < 0) {
- _sys_printf("cellOskDialogUnloadAsync() failed. ret = 0x%x \n", ret);
- }
- if (param.result == CELL_OSKDIALOG_INPUT_FIELD_RESULT_OK) {
- if (wcslen(mpTextBuffer) > 0) {
- memset(&data, 0, sizeof(data));
- data.type = OSK_CALLBACK_TYPE_MESSAGE;
- data.message = mpTextBuffer;
- data.len = wcslen(mpTextBuffer) * 2;
- (*mOskCallbackFunc)(&data, mOskCallbackArg);
- }
- }
- mFlags &= ~OSK_IN_USE;
- }
- void COsk::closeOsk(void)
- {
- osk_callback_data_t data;
- int ret;
- ret = cellSysutilUnregisterCallback(sSlot);
- if (ret < 0) {
- _sys_printf("cellSysutilUnregisterCallback() failed. ret = 0x%x\n", ret);
- }
- memset(&data, 0, sizeof(data));
- data.type = OSK_CALLBACK_TYPE_CLOSE;
- (*mOskCallbackFunc)(&data, mOskCallbackArg);
- }
- void COsk::sysutilCbInternal(uint64_t status)
- {
- switch (status) {
- case CELL_SYSUTIL_OSKDIALOG_LOADED:
- break;
- case CELL_SYSUTIL_OSKDIALOG_FINISHED:
- stopOsk();
- break;
- case CELL_SYSUTIL_OSKDIALOG_UNLOADED:
- closeOsk();
- break;
- default:
- break;
- }
- }
- void COsk::sysutilCb(uint64_t status, uint64_t param, void * userdata)
- {
- COsk *self = static_cast<COsk *>(userdata);
- (void)param;
- self->sysutilCbInternal(status);
- }
- class CGame
- {
- public:
- static COsk *getCOsk(void)
- {
- return (&spApplication->mOsk);
- }
- private:
- static CGame *spApplication;
- COsk mOsk;
- };
- typedef struct game_matching_chat_message {
- bool f_use;
- p2p_chat_t chat;
- wchar_t message[MAX_CHAT_CHAR / 2 + 1];
- } game_matching_chat_message_t;
- void setMessage(int *p2pchat, void *data, int size)
- {
- game_matching_chat_message_t *chat_msg;
- //messageLock();
- chat_msg = &mpChatMessage[mChatIndex];
- memcpy(&chat_msg->chat, p2pchat, sizeof(*p2pchat));
- memset(chat_msg->message, 0, sizeof(chat_msg->message));
- memcpy(chat_msg->message, data, size);
- chat_msg->f_use = true;
- mChatIndex = (mChatIndex + 1) % MAX_CHAT_MESSAGE;
- //messageUnlock();
- }
- void oskCbMessage(wchar_t *message, int len)
- {
- p2p_chat_t p2pchat;
- memcpy(p2pchat.name, CGame::getCNp()->getNpId()->handle.data,
- sizeof(p2pchat.name));
- setMessage(&p2pchat, (void *)message, len);
- CGame::getCNpSignaling()->sendChat(NULL, message, len);
- }
- void oskCb(osk_callback_data_t *data, void *arg)
- {
- osk_callback_data_t *ptr = static_cast<osk_callback_data_t *>(data);
- //CGameMatching *self = static_cast<CGameMatching *>(arg);
- switch (ptr->type) {
- case OSK_CALLBACK_TYPE_MESSAGE:
- oskCbMessage(ptr->message, ptr->len);
- break;
- case OSK_CALLBACK_TYPE_CLOSE:
- break;
- default:
- break;
- }
- }
- void doChat(void)
- {
- CGame::getCOsk()->startOsk(oskCb, this);
- }
- enum {
- MODE_IDLE = 0,
- MODE_OPEN,
- MODE_RUNNING,
- MODE_CLOSE,
- MODE_ENTERED,
- MODE_CANCELED,
- SET_ABORT_TIMER,
- CHANGE_PANEL_MODE,
- CHANGE_SCALE,
- SET_CALLBACK,
- MODE_EXIT,
- START_DIALOG_TYPE,
- START_SEPARATE_TYPE_1,
- START_SEPARATE_TYPE_2,
- };
- static int oskdialog_mode = MODE_IDLE;
- int getkbLen(char* str)
- {
- int nullCount = 0;
- int i = 0; //num of chars..
- for (i = 0; i < 64; i++)
- {
- if (nullCount == 2) { break; }
- if (*(str + i) == 0x00) { nullCount++; }
- else { nullCount = 0; }
- }
- return i;
- }
- void makekbStr(char* str, char* dest, int len)
- {
- int nulls = 0;
- for (int i = 0; i < len; i++)
- {
- if (*(str + i) == 0x00) { nulls++; }
- else { *(dest + i - nulls) = *(str + i); }
- }
- *(dest + len + 1 - nulls) = 0x00; //make sure its nulled...
- }
- static void sysutil_callback(uint64_t status, uint64_t param, void *userdata)
- {
- (void)param;
- (void)userdata;
- int ret = 0;
- switch (status) {
- case CELL_SYSUTIL_OSKDIALOG_LOADED:
- break;
- case CELL_SYSUTIL_OSKDIALOG_FINISHED:
- oskdialog_mode = MODE_CLOSE;
- break;
- case CELL_SYSUTIL_OSKDIALOG_UNLOADED:
- break;
- case CELL_SYSUTIL_REQUEST_EXITGAME:
- oskdialog_mode = MODE_EXIT;
- break;
- case CELL_SYSUTIL_DRAWING_BEGIN:
- break;
- case CELL_SYSUTIL_DRAWING_END:
- break;
- case CELL_SYSUTIL_OSKDIALOG_INPUT_ENTERED:
- oskdialog_mode = MODE_ENTERED;
- break;
- case CELL_SYSUTIL_OSKDIALOG_INPUT_CANCELED:
- oskdialog_mode = MODE_CANCELED;
- break;
- case CELL_SYSUTIL_OSKDIALOG_INPUT_DEVICE_CHANGED:
- break;
- case CELL_SYSUTIL_OSKDIALOG_DISPLAY_CHANGED:
- break;
- case CELL_SYSUTIL_SYSTEM_MENU_CLOSE:
- break;
- case CELL_SYSUTIL_SYSTEM_MENU_OPEN:
- break;
- default:
- break;
- }
- }
- int keyboard(char* dest, char* INIT_TEXT, char* MESSAGE)
- {
- int ret;
- CellOskDialogInputFieldInfo inputFieldInfo;
- inputFieldInfo.message = (uint16_t*)MESSAGE;
- inputFieldInfo.init_text = (uint16_t*)INIT_TEXT;
- inputFieldInfo.limit_length = CELL_OSKDIALOG_STRING_SIZE;
- CellOskDialogCallbackReturnParam OutputInfo;
- OutputInfo.result = CELL_OSKDIALOG_INPUT_FIELD_RESULT_OK;
- OutputInfo.numCharsResultString = 32;
- uint16_t Result_Text_Buffer[CELL_OSKDIALOG_STRING_SIZE + 1];
- OutputInfo.pResultString = Result_Text_Buffer;
- ret = cellOskDialogSetKeyLayoutOption(CELL_OSKDIALOG_10KEY_PANEL | CELL_OSKDIALOG_FULLKEY_PANEL);
- CellOskDialogPoint pos;
- pos.x = 0.0; pos.y = 0.0;
- int32_t LayoutMode = CELL_OSKDIALOG_LAYOUTMODE_X_ALIGN_CENTER | CELL_OSKDIALOG_LAYOUTMODE_Y_ALIGN_TOP;
- ret = cellOskDialogSetLayoutMode(LayoutMode);
- CellOskDialogParam dialogParam;
- dialogParam.allowOskPanelFlg = CELL_OSKDIALOG_PANELMODE_KOREAN |
- CELL_OSKDIALOG_PANELMODE_ALPHABET |
- CELL_OSKDIALOG_PANELMODE_NUMERAL_FULL_WIDTH |
- CELL_OSKDIALOG_PANELMODE_NUMERAL |
- CELL_OSKDIALOG_PANELMODE_JAPANESE |
- CELL_OSKDIALOG_PANELMODE_JAPANESE_KATAKANA |
- CELL_OSKDIALOG_PANELMODE_ENGLISH;
- /*E Panel to display first */
- dialogParam.firstViewPanel = CELL_OSKDIALOG_PANELMODE_ALPHABET;
- /* E Initial display position of the on-screen keyboard dialog */
- dialogParam.controlPoint = pos;
- /*E Prohibited operation flag(s) (ex. CELL_OSKDIALOG_NO_SPACE) */
- dialogParam.prohibitFlgs = 0;
- sys_timer_usleep(16 * 1000);
- ret = cellSysutilCheckCallback();
- if (oskdialog_mode == MODE_OPEN)
- {
- if (cellSysutilRegisterCallback(0, sysutil_callback, NULL) != 0) {}
- ret = cellOskDialogLoadAsync(SYS_MEMORY_CONTAINER_ID_INVALID, &dialogParam, &inputFieldInfo);
- oskdialog_mode = MODE_RUNNING;
- }
- if (oskdialog_mode == MODE_ENTERED)
- {
- ret = cellOskDialogGetInputText(&OutputInfo);
- oskdialog_mode = MODE_RUNNING;
- }
- if (oskdialog_mode == MODE_CLOSE)
- {
- ret = cellOskDialogUnloadAsync(&OutputInfo);
- int strLen = getkbLen((char*)(*(&OutputInfo.pResultString)));
- makekbStr((char*)(*(&OutputInfo.pResultString)), dest, strLen);
- inputFieldInfo.init_text = (uint16_t*)INIT_TEXT;
- if (cellSysutilUnregisterCallback(0) != 0) {}
- oskdialog_mode = MODE_EXIT;
- }
- return 0;
- }
- void _useage()
- {
- char retText[32]; //our buffer
- oskdialog_mode = MODE_OPEN;
- while (oskdialog_mode != Keyboard::MODE_EXIT)
- {
- keyboard(retText, "Title", "Preset Text");
- }
- }
Add Comment
Please, Sign In to add comment