diff --git a/src/sdk/ec/csup.h b/src/sdk/ec/csup.h new file mode 100644 index 000000000..96bfae2c5 --- /dev/null +++ b/src/sdk/ec/csup.h @@ -0,0 +1,78 @@ +#include + +enum ECOperation { + EC_OP_Invalid = 0, + EC_OP_PurchaseTitle = 1, + EC_OP_Unused1 = 2, + EC_OP_SyncTickets = 3, + EC_OP_RefreshCachedBalance = 4, + EC_OP_PurchasePoints = 5, + EC_OP_GetTitle = 6, + EC_OP_CheckRegistration = 7, + EC_OP_Register = 8, + EC_OP_Unregister = 9, + EC_OP_Transfer = 10, + EC_OP_DeleteOwnership = 11, + EC_OP_PurchaseGiftTitle = 12, + EC_OP_AcceptGiftTitle = 13, + EC_OP_CheckDeviceStatus = 14, + EC_OP_SyncRegistration = 15, + EC_OP_Connect = 16, + EC_OP_DownloadContents = 17, + EC_OP_Subscribe = 18, + EC_OP_GetChallenge = 19, + EC_OP_UpdateStatus = 20, + EC_OP_ListTitles = 21, + EC_OP_ListContentSets = 22, + EC_OP_ListSubscriptionPricings = 23, + EC_OP_ListPointsPricings = 24, + EC_OP_ListECardItems = 25, + EC_OP_ListTitleContents = 26, +}; + +enum ECOpPhase { + EC_PHASE_NoPhase = 0, + EC_PHASE_Starting = 1, + EC_PHASE_Done = 2, + EC_PHASE_PurchasingTitle = 3, + EC_PHASE_Unused1 = 4, + EC_PHASE_DownloadingContent = 5, + EC_PHASE_GettingTicketsFromServer = 6, + EC_PHASE_GettingPointsBalance = 7, + EC_PHASE_PurchasingPoints = 8, + EC_PHASE_CheckingRegistrationStatus = 9, + EC_PHASE_Registering = 10, + EC_PHASE_Unregistering = 11, + EC_PHASE_Transfer = 12, + EC_PHASE_DeletingOwnership = 13, + EC_PHASE_AcceptingGiftTitle = 14, + EC_PHASE_GettingDeviceStatus = 15, + EC_PHASE_SyncingRegistration = 16, + EC_PHASE_Connecting = 17, + EC_PHASE_UpdatingStatus = 18, + EC_PHASE_ListingTitles = 19, + EC_PHASE_ListingContentSets = 20, + EC_PHASE_ListingSubscriptionPricings = 21, + EC_PHASE_ListingPointsPricings = 22, + EC_PHASE_ListingECardItems = 23, + EC_PHASE_GettingECardBalance = 24, + EC_PHASE_Subscribing = 25, + EC_PHASE_GettingChallenge = 26, + EC_PHASE_ListingTitleContents = 27, +}; + +struct ECProgress { + // total size: 0x9C + ECResult status; // offset 0x0, size 0x4 + enum ECOperation operation; // offset 0x4, size 0x4 + enum ECOpPhase phase; // offset 0x8, size 0x4 + long isCancelRequested; // offset 0xC, size 0x4 + unsigned long totalSize; // offset 0x10, size 0x4 + unsigned long downloadedSize; // offset 0x14, size 0x4 + long errCode; // offset 0x18, size 0x4 + char errInfo[128]; // offset 0x1C, size 0x80 +}; + +namespace ec { + unsigned long getExternalErrCode(ECProgress *progress); +} \ No newline at end of file diff --git a/src/sdk/ec/result.h b/src/sdk/ec/result.h index a9deaf910..c72015397 100644 --- a/src/sdk/ec/result.h +++ b/src/sdk/ec/result.h @@ -5,8 +5,61 @@ enum ECResult { ECResult_Success = 0, ECResult_Failure = -1, + + ECResult_UnkFail = -2, - ECResult_InvalidBufHeap = -4004, + ECResult_ECFail = -4001, /* Generic error */ + ECResult_NotSupported = -4002, /* Feature not implemented */ + ECResult_InsufficientResource = -4003, + ECResult_InvalidBufHeap = -4004, + ECResult_NoMemory = -4005, + ECResult_NotFound = -4006, + ECResult_NotBusy = -4007, /* no active async operation */ + ECResult_Busy = -4008, + ECResult_NotDone = -4009, + + ECResult_NetNotAvailable = -4013, /* Internet access not available */ + ECResult_WebServiceError = -4015, /* Server reports a problem */ + ECResult_InvalidECard = -4017, /* Invalid eCard */ + ECResult_Overflow = -4018, /* Output too big for buf provided */ + /* Should never see EC_E~~RROR_OVERFLOW */ + ECResult_ContentRecvErr = -4019, /* Error getting content from server */ + ECResult_ContentSizeMismatch = -4020, /* Downloaded content size doesn't match tmd */ + + ECResult_WebServiceResError = -4034, /* invalid web service response */ + ECResult_TicketImportErr = -4035, /* problem importing ticket */ + ECResult_TMDImportErr = -4036, /* problem importing title */ + ECResult_ContentImportErr = -4037, /* problem importing title content */ + ECResult_Canceled = -4038, /* an extended operation was canceled */ + ECResult_AlreadyInitialized = -4039, /* one time only action was previously done */ + ECResult_Init = -4041, /* library has not been initialized */ + ECResult_NotRegistered = -4042, /* device is not registered */ + ECResult_RecvWSErr = -4043, /* recv error on web service response */ + ECResult_NotActive = -4044, /* expected operation is not active op */ + ECResult_FileRead = -4045, + ECResult_FileWrite = -4046, + ECResult_TitleNotOwned = -4050, /* Title is not owned */ + ECResult_BadHeap = -4051, /* Bad heap */ + ECResult_HeaderParseErr = -4052, /* Could not parse http header */ + ECResult_ConfigErr = -4053, /* Invalid configuration (e.g. url is invalid) */ + ECResult_CancelFailed = -4054, /* Could not cancel asynchronous operaton */ + ECResult_UserINodes = -4055, /* Operation would exceed max user inodes */ + ECResult_UserBlocks = -4056, /* Operation would exceed max user blocks */ + ECResult_SystemINodes = -4057, /* Operation would exceed max sys inodes */ + ECResult_SystemBlocks = -4058, /* Operation would exceed max sys blocks */ + ECResult_NoDeviceCode = -4065, /* Operation requires device code */ + ECResult_NeedTicketSync = -4066, /* Operation requres ticket sync */ + ECResult_NeedECConnect = -4069, /* Operation requires EC_Connect() */ + ECResult_NoTMD = -4070, /* Title TMD is not on device */ + ECResult_NeedFirmwareUpdate = -4071, /* Title requires updated firmware */ + ECResult_PCPassIncorrect = -4074, /* Parental control password doesn't match */ + ECResult_NoPC = -4075, /* Parental control is not enabled */ + ECResult_NeedEULA = -4076, /* Customer has not agreed to EULA */ + ECResult_AgeRestricted = -4077, /* Opration requires parental control password */ + ECResult_PointsRestricted = -4078, /* Opration requires parental control password */ + ECResult_TitleOwned = -4079, /* Attempt purchase already owned item */ + ECResult_InsufficientFunds = -4081, /* Not enough funds to purchase the item */ + }; #define EC_SUCCESS(expr) ((expr) >= 0) diff --git a/src/sdk/ec/src/ec_csup.cpp b/src/sdk/ec/src/ec_csup.cpp new file mode 100644 index 000000000..88a1f2a86 --- /dev/null +++ b/src/sdk/ec/src/ec_csup.cpp @@ -0,0 +1,59 @@ +#include + +int EC_GetCustomerSupportCode(int p1) { + int code; + if (p1 >= 0) { + code = 0; + } else { + code = 200000; + if (-p1 <= 9999) { + code = code - p1; + } + } + return code; +} + +namespace ec { + unsigned long getExternalErrCode(ECProgress *progress) { + ECResult status = progress->status; + long errCode = progress->errCode; + if (ECResult_WebServiceResError < status) { + if (status != ECResult_WebServiceError) { + if (status < ECResult_WebServiceError) { + if (status == ECResult_InvalidECard) goto label1; + } else if (status == ECResult_NotDone || (-4010 < status && ECResult_Failure < status)) { + errCode = 0; + goto label3; + } + goto label2; + } + goto label1; + } + if (status == ECResult_TitleOwned) goto label1; + if (status < ECResult_TitleOwned) { + if (status == ECResult_InsufficientFunds) goto label1; + } else if (status == ECResult_AgeRestricted) goto label1; + if (status == ECResult_NotRegistered) { + if (errCode <= 0) goto label2; +label1: + if (errCode <= 0) goto someLabel; + errCode = errCode + 205000; + if (206999 < errCode) errCode = 205000; + goto label3; + } +label2: + if ((status == ECResult_ContentRecvErr || status == ECResult_ECFail || status == ECResult_RecvWSErr) && errCode < 0) { + errCode = 200000 - errCode; + if (204999 < errCode) errCode = 200000; + goto label3; + } +someLabel: + if (status < ECResult_Success && (errCode = 200000 - status, 204999 < errCode)) { + errCode = 200000; + } +label3: + if (errCode == 0) return 0; + if (9998 >= errCode - 200001U) return -(errCode - 200000); + return -10000; + }; +} \ No newline at end of file