Compare commits

..

1 Commits

Author SHA1 Message Date
Devin
b85045cd53 esmisc: implement DeleteUnauthorizedData (91.97% fuzzy, allocator tie-break)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-28 11:03:49 +00:00
11 changed files with 1568 additions and 4671 deletions

View File

@@ -1,274 +1,44 @@
#ifndef IPL_SCENE_ADDRESS_H
#define IPL_SCENE_ADDRESS_H
#include "iplSceneUIHeader.h"
#include "scene/button/iplButton.h"
#include "iplSceneHeader.h"
#include <revolution/nwc24.h>
namespace ipl {
namespace nigaoe {
class Object;
}
namespace scene {
class AddressEvent;
class FriendListCache {
public:
enum {
FRIEND_MAX = 100,
};
FriendListCache() : mbOpened(false) {}
BOOL init();
void fin();
void add(u32 index, const NWC24FriendInfo& info);
void update(u32 index, const wchar_t* name, u64 fdId);
void del(u32 index);
void swap(u32 index1, u32 index2);
BOOL isValidId(const NWC24UserId& userId);
BOOL isDupId(const NWC24UserId& userId);
BOOL isDupMail(const char* mailAddr);
void sendRegisterMail(u32 index);
s32 check();
s32 getErrCode() const;
const NWC24FriendInfo& getInfo(int index) const { return mInfos[index]; }
BOOL isThere(u32 index) const { return mbThere[index]; }
u32 getRegFriendNum() const { return mRegFriendNum; }
NWC24UserId getMyUserId() const { return mMyUserId; }
s32 getLastErr() const { return mErrCode; }
private:
NWC24FriendInfo mInfos[FRIEND_MAX]; // 0x0000
u8 mbThere[FRIEND_MAX]; // 0x7D00
NWC24UserId mMyUserId; // 0x7D68
u32 mRegFriendNum; // 0x7D70
u8 mSendWork[0x2000]; // 0x7D74
s32 mErrCode; // 0x9D74
bool mbOpened; // 0x9D78
NWC24FriendInfo mInfos[100];
};
FADER_SCENE_CLASS(Address), public ButtonEventHandlerBase {
FADER_SCENE_CLASS(Address) {
public:
Address(EGG::Heap * heap, int mode);
virtual ~Address();
virtual void prepare();
virtual void create();
virtual void draw();
virtual void destroy();
virtual FaderSceneCommand calcFadein();
virtual void initCalcNormal();
virtual FaderSceneCommand calcNormal();
virtual void initCalcFadeout();
virtual FaderSceneCommand calcFadeout();
virtual void calcCommonAfter();
virtual void onEventDerived(u32 compId, u32 event, const controller::Interface* con);
Address(EGG::Heap * heap, int);
virtual void destroy() override;
enum {
SCENE_ADD_WII = 1,
SCENE_ADD_EMAIL,
};
enum {
BTN_MAX = 5,
BTN_SPACE_MAX = BTN_MAX - 1,
PAGE_MAX = 20,
};
int getChosenFriendIndex() {
return mChosenFriend;
return unk_0xC0;
}
FriendListCache* getFriendCache() {
return mpFriendCache;
return unk_0x274;
}
private:
enum {
FADEIN_STATE_WAIT_OPEN = 0,
FADEIN_STATE_FADEIN,
FADEIN_STATE_DONE,
};
enum {
STATE_INIT = 0,
STATE_COVER_NORMAL,
STATE_COVER_FORWARD,
STATE_COVER_BACKWARD,
STATE_NORMAL,
STATE_FORWARD,
STATE_BACKWARD,
STATE_LOOP_FORWARD,
STATE_LOOP_BACKWARD,
STATE_DECIDE,
STATE_DRAG,
STATE_RELEASE,
STATE_WAIT_CHILD_CST,
STATE_WAIT_CHILD_DST,
STATE_WAIT_CHILD_FADEOUT,
STATE_MSG_NET,
STATE_WAIT_PARENTAL,
STATE_WAIT_PARENTAL_DST,
STATE_MSG_WC,
STATE_WAIT_PARENTAL_WC,
STATE_WAIT_PARENTAL_DST_WC,
STATE_MSG_NWC24_ERROR,
STATE_MSG_FI_FULL,
STATE_MSG_PARENTAL,
STATE_MSG_OPEN_FAILURE,
STATE_WAIT_DIALOG,
STATE_DONE,
};
class MiiObj {
public:
MiiObj();
~MiiObj();
void init(nw4r::lyt::Pane* pane);
void set(u64 fdId);
void reset();
static void create_callback(nigaoe::Object* object, void* work);
GXTexObj mTexObj; // 0x00
nigaoe::Object* mpNigaoe; // 0x20
nw4r::lyt::Material* mpMaterial; // 0x24
};
struct DragInfo {
nw4r::math::VEC2 mPos; // 0x00
int mChan; // 0x08
int mPage; // 0x0C
int mButton; // 0x10
int mNextCount; // 0x14
int mPrevCount; // 0x18
int unk_0x1C; // 0x1C
bool mbDragging; // 0x20
};
void fistt_wait_open();
void fistt_fadein();
void onInitFriendList();
void stt_cover_normal();
void stt_cover_forward();
void stt_cover_backward();
void stt_normal();
void stt_forward();
void stt_backward();
void stt_loop_forward();
void stt_loop_backward();
void stt_decide();
void stt_drag();
void stt_release();
void stt_wait_child_cst();
void stt_wait_child_dst();
void stt_wait_child_fadeout();
void stt_msg_net();
void stt_wait_parental();
void stt_wait_parental_dst();
void stt_msg_wc();
void stt_wait_parental_wc();
void stt_wait_parental_dst_wc();
void stt_msg_nwc24_error();
void stt_msg_fi_full();
void stt_msg_parental();
void stt_msg_open_failure();
void stt_wait_dialog();
void add_translate(nw4r::lyt::Pane* pane, const math::VEC2& offset);
void set_friend(const char* paneName, u32 friendNo, u32 buttonNo, MiiObj& miiObj, bool bDrag);
void set_page_text(const char* paneName, int page);
void set_textbox(const char* paneName, const wchar_t* text);
void set_textbox(const char* paneName, u32 msgId);
void reset_friend();
void start_point_event(const char* paneName, controller::Interface* con);
void start_left_event(const char* paneName);
void start_trig_event(const char* paneName);
void start_drag_event(const char* paneName, const controller::Interface* con);
void start_drag_point_event(const char* paneName, controller::Interface* con);
void start_drag_left_event(const char* paneName);
void start_release_event(const char* paneName);
void on_point_event(int buttonNo, controller::Interface* con);
void left_point_event(int buttonNo);
int get_button_no(const char* paneName);
int get_button_space_no(const char* paneName);
void reset_gui(bool bKeepPointed);
BOOL is_selectable(u32 friendNo);
void onNextPage();
void onPreviousPage();
void set_err_msg(wchar_t* errMsg, u32 errMsgLen, NWC24Err err);
void entry_friend();
bool isReleasableArea(int page, int buttonNo);
void changePage_onDrag();
void movePane_onDrag();
DragInfo mDrag; // 0x64
int mMode; // 0x88
layout::Object* mpLayout; // 0x8C
int unk_0x90; // 0x90
AddressEvent* mpEvent; // 0x94
gui::PaneManager* mpGui; // 0x98
layout::Object* mpBackLayout; // 0x9C
layout::Object* mpDialogLayout; // 0xA0
int mFadeinState; // 0xA4
int mWaitOpenCount; // 0xA8
int mState; // 0xAC
int mPage; // 0xB0
int mNextPageNum; // 0xB4
int mPrevPageNum; // 0xB8
int mSelectedButton; // 0xBC
u32 mChosenFriend; // 0xC0
bool mbFaceValid[BTN_MAX]; // 0xC4
int mPointCount[BTN_MAX]; // 0xCC
bool mbParentalOK; // 0xE0
bool mbCover; // 0xE1
MiiObj mMiiObj[BTN_MAX]; // 0xE4
MiiObj mNextMiiObj[BTN_MAX]; // 0x1AC
FriendListCache* mpFriendCache; // 0x274
GXTexObj mDragTexObj; // 0x278
u8* mpWork; // 0x298
f32 mDragOffsetX; // 0x29C
static const math::VEC2 smcPageOffset;
friend class AddressEvent;
};
class AddressEvent : public ::gui::EventHandler {
public:
AddressEvent(Address* instance) : ::gui::EventHandler(), mpInstance(instance) {}
virtual void onEvent(u32 compId, u32 event, void* data);
private:
Address* mpInstance; // 0x0C
int mTrigChan; // 0x10
u8 unk_0x58[0x68];
int unk_0xC0;
u8 unk_0xC4[0x1B0];
FriendListCache* unk_0x274;
u8 unk_0x278[0x28];
};
} // namespace scene
} // namespace ipl

View File

@@ -35,14 +35,7 @@ namespace ipl {
virtual void onSend();
virtual int sendMessageByNWC24(NWC24UserId userId, const wchar_t* wcString);
#ifdef IPL_ADDRESS_MATCHING
virtual void setFriendInfo(const NWC24FriendInfo& info) {
mbToFriend = true;
mFriendInfo = info;
}
#else
virtual void setFriendInfo(const NWC24FriendInfo& info);
#endif
virtual void setPhoto(const GXTexObj& texObj);
virtual int sendToWii(NWC24UserId userId, const wchar_t* wcString);

View File

@@ -38,9 +38,6 @@ namespace ipl {
}
const GXTexObj& getIconTexture() const { return mFaceTexObj; }
#ifdef IPL_ADDRESS_MATCHING
u8* getIconImage() const { return mpIconTex; }
#endif
u32 getIndex() const { return mFaceId; }
BOOL created() const { return mbCreated; }

View File

@@ -50,7 +50,7 @@ namespace ipl {
static BOOL IsLastTicketExpired(ESTitleId* titleId);
static void DeleteExpiredFlagFile();
static void DeleteUnauthorizedData(EGG::Heap* heap);
static s32 DeleteUnauthorizedData(EGG::Heap* heap);
static u32 CheckTmdCountryCode(ESTmdView* tmdView);
static u32 CheckTmdParentalControl(ESTmdView* tmdView);

View File

@@ -50,10 +50,6 @@ namespace nw4r {
f32 FrSqrt(f32 x);
u32 CntBit1(u32 x);
#ifdef IPL_ADDRESS_MATCHING
inline f32 FSqrt(f32 x) { return (x <= 0.0f) ? 0.0f : x * FrSqrt(x); }
#endif
} // namespace math
} // namespace nw4r

View File

@@ -118,10 +118,6 @@ namespace nw4r {
return *this;
}
#ifdef IPL_ADDRESS_MATCHING
VEC2 operator-() const { return VEC2(-x, -y); }
#endif
VEC2 operator+(const VEC2& rhs) const { return VEC2(x + rhs.x, y + rhs.y); }
VEC2 operator-(const VEC2& rhs) const { return VEC2(x - rhs.x, y - rhs.y); }
VEC2 operator*(f32 val) const { return VEC2(val * x, val * y); }
@@ -134,10 +130,6 @@ namespace nw4r {
bool operator!=(const VEC2& rhs) const { return x != rhs.x || y != rhs.y; }
} VEC2;
#ifdef IPL_ADDRESS_MATCHING
inline f32 VEC2LenSq(const VEC2* p) { return p->x * p->x + p->y * p->y; }
#endif
typedef struct VEC3 VEC3;
inline VEC3* VEC3Transform(VEC3* pOut, const MTX34* pMtx, const VEC3* pVec);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -884,44 +884,51 @@ namespace ipl {
return ret;
}
void ESMisc::DeleteUnauthorizedData(EGG::Heap* heap) {
u32 titleCount = 0;
DECOMP_FORCE_ACTIVE(iplESMisc_cpp, "verifySavedataZD");
DECOMP_FORCE_ACTIVE(iplESMisc_cpp, "DeleteTicketsForce");
DECOMP_FORCE_ACTIVE(iplESMisc_cpp, "InitSavedata");
s32 ESMisc::DeleteUnauthorizedData(EGG::Heap* heap) {
ESTitleId* titleIds = NULL;
char path[88];
NANDFileInfo fileInfo ALIGN32;
u8 ticketViews[0xe0] ALIGN32;
u32 titleCount = 0;
u32 ticketViewCount;
ESTicketView* ticketViewList;
char path[88];
NANDFileInfo fileInfo;
u8 ticketViews[0xe0] ALIGN32;
s32 result;
s32 ret = ES_ListTitlesOnCard(NULL, &titleCount);
if (ret == ES_ERR_OK) {
titleIds = (ESTitleId*)heap->alloc(OSRoundUp32B(titleCount * sizeof(ESTitleId)), -DEFAULT_ALIGN);
if (titleIds == NULL) {
OSReport("%s::%s: Unable to allocate\n", __FILE__, "InitSavedata");
if (ret != ES_ERR_OK) {
OSReport("%s::%s: Failed to ES_ListTitlesOnCard1: %d\n", __FILE__, "InitSavedata", ret);
} else {
ret = ES_ListTitlesOnCard(titleIds, &titleCount);
if (ret == ES_ERR_OK) {
titleIds = (ESTitleId*)heap->alloc(OSRoundUp32B(titleCount * sizeof(ESTitleId)), -DEFAULT_ALIGN);
if (titleIds == NULL) {
OSReport("%s::%s: Unable to allocate\n", __FILE__, "InitSavedata");
} else {
ret = ES_ListTitlesOnCard(titleIds, &titleCount);
if (ret != ES_ERR_OK) {
OSReport("%s::%s: Failed to ES_ListTitlesOnCard2: %d\n", __FILE__, "InitSavedata", ret);
} else {
ESTicketView* ticketView = (ESTicketView*)ticketViews;
u32 i = 0;
for (u32 titleIdOffset = 0; i < titleCount; titleIdOffset += 8, i++) {
ESTitleId titleId = *(ESTitleId*)((u8*)titleIds + titleIdOffset);
u32 titleIdOffset = 0;
for (u32 i = 0; i < titleCount; i++) {
u32 titleIdHi = *(u32*)((u8*)titleIds + titleIdOffset);
u32 titleIdLo = *(u32*)((u8*)titleIds + titleIdOffset + 4);
if ((titleIdLo & 0xffffff00) == 0x525a4400 && titleIdHi == 0x10000) {
if ((titleId & 0xffffffffffffff00ULL) == 0x00010000525a4400ULL) {
u8* saveData = NULL;
BOOL fileOpen = FALSE;
BOOL deleteSaveData = FALSE;
sprintf(path - 8, "/title/%08x/%08x/data/%s", titleIdHi & 0xffffff, titleIdLo, "zeldaTp.dat");
if (!ChangeUid(((ESTitleId)titleIdHi << 32) | titleIdLo)) {
sprintf(path, "/title/%08x/%08x/data/%s", (u32)((titleId >> 32) & 0xffffff), (u32)(titleId & 0xffffffff), "zeldaTp.dat");
if (!ChangeUid(titleId)) {
OSReport("%s::%s: ChangeUid failed\n", __FILE__, "verifySavedataZD");
DeleteTitle(heap, ((ESTitleId)titleIdHi << 32) | titleIdLo);
DeleteTitle(heap, titleId);
} else {
ret = NANDPrivateOpen(path - 8, (NANDFileInfo*)((u8*)&fileInfo - 0x20), NAND_ACCESS_READ);
if (ret == NAND_RESULT_NOEXISTS) {
OSReport("%s::%s: Does not exist %s: %d\n", __FILE__, "verifySavedataZD", path - 8, ret);
} else if (ret != NAND_RESULT_OK) {
OSReport("%s::%s: Open save data file failed: %d\n", __FILE__, "verifySavedataZD", ret);
result = NANDPrivateOpen(path, &fileInfo, NAND_ACCESS_READ);
if (result == NAND_RESULT_NOEXISTS) {
OSReport("%s::%s: Does not exist %s: %d\n", __FILE__, "verifySavedataZD", path, result);
} else if (result != NAND_RESULT_OK) {
OSReport("%s::%s: Open save data file failed: %d\n", __FILE__, "verifySavedataZD", result);
} else {
fileOpen = TRUE;
saveData = (u8*)heap->alloc(0x4000, -DEFAULT_ALIGN);
@@ -929,11 +936,11 @@ namespace ipl {
OSReport("%s::%s: Alloc failed: %d\n", __FILE__, "verifySavedataZD", -2);
} else {
memset(saveData, 0, 0x4000);
ret = NANDRead((NANDFileInfo*)((u8*)&fileInfo - 0x20), saveData, 0x4000);
if (ret < 0) {
OSReport("%s::%s: Read file failed: %d\n", __FILE__, "verifySavedataZD", ret);
} else if (ret != 0x4000) {
OSReport("%s::%s: File size is not correct: %d\n", __FILE__, "verifySavedataZD", ret);
result = NANDRead(&fileInfo, saveData, 0x4000);
if (result < 0) {
OSReport("%s::%s: Read file failed: %d\n", __FILE__, "verifySavedataZD", result);
} else if (result != 0x4000) {
OSReport("%s::%s: File size is not correct: %d\n", __FILE__, "verifySavedataZD", result);
deleteSaveData = TRUE;
} else {
u32 offset = 8;
@@ -974,15 +981,15 @@ namespace ipl {
if (!valid) {
OSReport("%s::%s: Verify failed for %016llx\n", __FILE__, "verifySavedataZD",
((ESTitleId)titleIdHi << 32) | titleIdLo);
titleId);
deleteSaveData = TRUE;
}
}
NANDClose((NANDFileInfo*)((u8*)&fileInfo - 0x20));
NANDClose(&fileInfo);
fileOpen = FALSE;
if (deleteSaveData) {
DeleteSavedata(((ESTitleId)titleIdHi << 32) | titleIdLo, heap);
DeleteSavedata(titleId, heap);
}
}
}
@@ -992,64 +999,87 @@ namespace ipl {
heap->free(saveData);
}
if (fileOpen) {
NANDClose((NANDFileInfo*)((u8*)&fileInfo - 0x20));
NANDClose(&fileInfo);
}
ChangeUid(SYSMENU_TITLE_ID);
continue;
}
if ((((ESTitleId)titleIdHi << 32) | titleIdLo) == 0x0001000844495343ULL ||
((((ESTitleId)titleIdHi << 32) | titleIdLo) < 0x0001000844495343ULL &&
((((ESTitleId)titleIdHi << 32) | titleIdLo) == 0x000100014a4f4449ULL ||
((((ESTitleId)titleIdHi << 32) | titleIdLo) > 0x000100014a4f4449ULL &&
(((ESTitleId)titleIdHi << 32) | titleIdLo) == 0x0001000148415858ULL))) ||
((((ESTitleId)titleIdHi << 32) | titleIdLo) > 0x0001000844495343ULL &&
((((ESTitleId)titleIdHi << 32) | titleIdLo) == 0x0001000844564458ULL ||
((((ESTitleId)titleIdHi << 32) | titleIdLo) > 0x0001000844564458ULL &&
(((ESTitleId)titleIdHi << 32) | titleIdLo) == 0x000100084449534bULL)))) {
ESTitleId titleId = *(ESTitleId*)((u8*)titleIds + titleIdOffset);
ES_DeleteTitle(titleId);
if (titleId == 0x0001000844495343ULL) {
goto delete_title;
}
if (titleId < 0x0001000844495343ULL) {
if (titleId == 0x000100014a4f4449ULL) {
goto delete_title;
}
if (titleId < 0x000100014a4f4449ULL) {
if (titleId == 0x0001000148415858ULL) {
goto delete_title;
}
continue;
}
continue;
} else {
if (titleId == 0x0001000844564458ULL) {
goto delete_title;
}
if (titleId < 0x0001000844564458ULL) {
if (titleId == 0x000100084449534bULL) {
goto delete_title;
}
continue;
}
continue;
}
goto delete_title_end;
delete_title:
{
ES_DeleteTitle(*(ESTitleId*)((u8*)titleIds + titleIdOffset));
ESTitleId delTitleId = *(ESTitleId*)((u8*)titleIds + titleIdOffset);
ESTicketView* ticketViewList;
ticketViewList = NULL;
memset(ticketViews, 0, sizeof(ticketViews));
ret = ES_GetTicketViews(titleId, NULL, &ticketViewCount);
if (ret != ES_ERR_OK) {
OSReport("%s::%s: ES_GetTicketViews failed: %d for %016llx\n", __FILE__, "DeleteTicketsForce", ret, titleId);
} else if (ticketViewCount != 0) {
ticketViewList = (ESTicketView*)heap->alloc(ticketViewCount * 0xe0, -DEFAULT_ALIGN);
ret = ES_GetTicketViews(titleId, ticketViewList, &ticketViewCount);
if (ret != ES_ERR_OK) {
OSReport("%s::%s: ES_GetTicketViews failed: %d for %016llx\n", __FILE__, "DeleteTicketsForce", ret, titleId);
} else {
for (u32 j = 0; j < ticketViewCount; j++) {
memcpy(ticketViews, (u8*)ticketViewList + j * sizeof(ESTicketView), 0xd8);
ret = ES_DeleteTicket((ESTicketView*)ticketViews);
if (ret != ES_ERR_OK) {
OSReport("%s::%s: ES_DeleteTicket failed: %d for %016llx\n", __FILE__, "DeleteTicketsForce", ret,
((ESTicketView*)ticketViews)->ticketId);
memset(ticketView, 0, sizeof(ticketViews));
result = ES_GetTicketViews(delTitleId, NULL, &ticketViewCount);
if (result != ES_ERR_OK) {
OSReport("%s::%s: ES_GetTicketViews failed: %d for %016llx\n", __FILE__, "DeleteTicketsForce", result, delTitleId);
} else {
if (ticketViewCount != 0) {
goto has_tickets;
}
goto delete_title_end;
has_tickets:
{
ticketViewList = (ESTicketView*)heap->alloc(ticketViewCount * 0xe0, -DEFAULT_ALIGN);
result = ES_GetTicketViews(delTitleId, ticketViewList, &ticketViewCount);
if (result != ES_ERR_OK) {
OSReport("%s::%s: ES_GetTicketViews failed: %d for %016llx\n", __FILE__, "DeleteTicketsForce", result, delTitleId);
} else {
for (u32 j = 0; j < ticketViewCount; j++) {
memcpy(ticketView, (u8*)ticketViewList + j * sizeof(ESTicketView), 0xd8);
result = ES_DeleteTicket(ticketView);
if (result != ES_ERR_OK) {
OSReport("%s::%s: ES_DeleteTicket failed: %d for %016llx\n", __FILE__, "DeleteTicketsForce", result,
ticketView->ticketId);
}
}
}
}
}
if (ticketViewList != NULL) {
heap->free(ticketViewList);
}
}
titleIdOffset += 8;
delete_title_end:
;
}
} else {
OSReport("%s::%s: Failed to ES_ListTitlesOnCard2: %d\n", __FILE__, "InitSavedata", ret);
}
}
}
} else {
OSReport("%s::%s: Failed to ES_ListTitlesOnCard1: %d\n", __FILE__, "InitSavedata", ret);
}
if (titleIds != NULL) {
heap->free(titleIds);
}
return;
return ret;
}
BOOL checkForNullTermination(char* str, u32 len) {

View File

@@ -7,6 +7,8 @@ from odiff import dis, sym
import os
import itertools
os.chdir("/home/cole/projects/tests/wii-ipl")
def main():
unit, name = sys.argv[1], sys.argv[2]