Please indicate the source of reprint

The wechat account and the king of Glory game are two. When you visit the Garden, you need to log in the game every day. It is too troublesome to switch the account and input the account password, so I wrote a plug-in for switching

I wrote it based on Tweak

The first step is to add a cell for switching accounts on the Settings screen

#import "src/WeChatHeader.h"

#import "substrate.h"
int myValue = 0;
%hook NewSettingViewController

- (void)reloadTableData {

%orig;
MMTableViewInfo *tableViewInfo = MSHookIvar<id>(self, "m_tableViewInfo");

MMTableViewSectionInfo *sectionInfo = [%c(MMTableViewSectionInfo) sectionInfoDefaut];

MMTableViewCellInfo *settingCell = [%c(MMTableViewCellInfo) normalCellForSel:@selector(switchAccount) target:self title:@"Switch accounts" accessoryType:1];
[sectionInfo addCell:settingCell];

[tableViewInfo insertSection:sectionInfo At:0];

MMTableView *tableView = [tableViewInfo getTableView];
[tableView reloadData];
}

Copy the code
Step 2, the cell click event
// Click event %new - (void)switchAccount {UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"Confirm switch?" preferredStyle:UIAlertControllerStyleAlert];


UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"Sure" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSLog(@"Sure");


myValue = 1;

WCActionSheet * sheet = MSHookIvar<id>(self,"m_logOutActionSheet");
NSLog(@"Sure 111");

[self actionSheet:sheet clickedButtonAtIndex:1];

NSLog(@"Sure 222");


}];

UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
NSLog(@"Cancel");

}];

[alertController addAction:action1];
[alertController addAction:action2];

[self presentViewController:alertController animated:YES completion:nil];

}


%end
Copy the code
Effect:

The login button is -(void)onNext and the account, password, and phone number are all assigned to the WCAccountTextFieldItem -(void)setText:(id)arg1 method
The third step, in the normal exit interface, click the method of switching accounts, extracted

What is the value? The difference between a normal exit switch and an automatic plugin switch

%hook WCAccountLoginLastUserViewController

- (void)viewDidLoad
{
%orig;

NSLog(@"Myvalue 🐦 = % d",myValue);


if(myValue)
{


WCAccountLoginControlLogic * change = [[%c(WCAccountLoginControlLogic) alloc]init];

WCUIActionSheet * action = [[%c(WCUIActionSheet) alloc]init];

[change onLastUserChangeAccount:action];
}

}




%end


Copy the code
Step 4: Click the switch and enter your mobile phone number/QQ account

Because one of my accounts is QQ and password login, the other is mobile phone number + password, so I will decide which interface to use to login

%hook WCAccountMainLoginViewController

- (void)viewDidLoad
{
%orig;
    if(myValue) {//(CAppUtil) getLastPhoneNumber getLastPhoneNumber getLastPhoneNumber getLastPhoneNumber getLastPhoneNumber getLastPhoneNumber getLastPhoneNumber getLastPhoneNumberif([[%c(CAppUtil) getLastPhoneNumber] isEqualToString:@"+ 8618201301234"])
        {
            WCAccountTextFieldItem * phone = MSHookIvar<id>(self,"_textFieldPhoneNumberItem");

            [phone setText:@"15000471234"];

            [self onNext];
        }
        else if([[%c(CAppUtil) getLastPhoneNumber] isEqualToString:@"+ 8615000471234"])
        {
            WCAccountTextFieldItem * username = MSHookIvar<id>(self,"_textFieldUserNameItem");
            WCAccountTextFieldItem * pwd = MSHookIvar<id>(self,"_textFieldUserPwdItem");

            [username setText:@"775931234"];
            [pwd setText:@"1234456"];
            [self switchToUserLogin];
            [self onNext];
        }

    }

}

%end
Copy the code
SwitchToUserLogin is to switch to the QQ id and password interface and then call onNext for that interface
The last step, login,myValue = 0; Return to normal state so as not to affect the login after normal exit
%hook WCAccountNewPhoneVerifyViewController

- (void)viewDidLoad
{
%orig;



if(myValue)
{
WCAccountTextFieldItem * phone = MSHookIvar<id>(self,"_textFieldPwdItem");

[phone setText:@"1234456"];

[self onNext];
myValue = 0;
}


}


%end
Copy the code
Oh, and there’s a header called wechaTheader.h
@interface CAppUtil : NSObject
+ (id)getLastPhoneNumber;

@end


@interface WCAccountLoginControlLogic : UIViewController
- (void)onLastUserChangeAccount:(id)arg1;
@end


@interface WCAccountLoginLastUserViewController : UIViewController
- (void)actionSheet:(id)arg1 clickedButtonAtIndex:(long long)arg2;
- (void)showInView:(id)arg1;


@end


@interface WCActionSheet : UIActionSheet
- (void)showInView:(id)arg1;

@end
@interface WCUIActionSheet : WCActionSheet

@end

@interface WCAccountTextFieldItem : NSObject
- (void)setText:(id)arg1; - (id)getTextField; @end @interface WCAccountMainLoginViewController : UIViewController - (void)onNext; - (void)switchToUserLogin; @end @interface WCAccountNewPhoneVerifyViewController : UIViewController //@property (nonatomic ,strong) WCAccountTextFieldItem *textFieldPwdItem; // //@property (nonatomic ,strong) WCAccountTextFieldItem *textFieldVerifyCodeItem; - (void)onNext; @end @interface NewSettingViewController: MMUIViewController - (void)reloadTableData; - (void)actionSheet:(id)arg1 clickedButtonAtIndex:(long long)arg2; - (void)tryQuit; - (void)finalQuit; @endCopy the code

Finally, there may be bugs, which may not apply to you. The idea is such a way of thinking and method for your reference. It is mainly for my situation, which is very convenient and can be switched quickly