aboutsummaryrefslogtreecommitdiff
path: root/src/core/hle/service/frd/frd.h
blob: bb5199cb724a5786137165e0d972a4102defa9e1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
// Copyright 2015 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#pragma once

#include <memory>
#include "common/common_types.h"
#include "core/hle/service/service.h"

namespace Core {
class System;
}

namespace Kernel {
class Event;
}

namespace Service::FRD {

struct FriendKey {
    u32 friend_id;
    u32 unknown;
    u64 friend_code;

private:
    template <class Archive>
    void serialize(Archive& ar, const unsigned int) {
        ar& friend_id;
        ar& unknown;
        ar& friend_code;
    }
    friend class boost::serialization::access;
};

struct MyPresence {
    u8 unknown[0x12C];

private:
    template <class Archive>
    void serialize(Archive& ar, const unsigned int) {
        ar& unknown;
    }
    friend class boost::serialization::access;
};

struct Profile {
    u8 region;
    u8 country;
    u8 area;
    u8 language;
    u8 platform;
    INSERT_PADDING_BYTES(0x3);
};
static_assert(sizeof(Profile) == 0x8, "Profile has incorrect size");

struct Game {
    u64 title_id;
    u16 version;
    INSERT_PADDING_BYTES(0x6);
};
static_assert(sizeof(Game) == 0x10, "Game has inccorect size");

struct ScreenName {
    // 20 bytes according to 3dbrew
    std::array<char16_t, 10> name;
};
static_assert(sizeof(ScreenName) == 0x14, "ScreenName has inccorect size");

struct Comment {
    // 32 bytes according to 3dbrew
    std::array<char16_t, 16> name;
};
static_assert(sizeof(Comment) == 0x20, "Comment has inccorect size");

class Module final {
public:
    explicit Module(Core::System& system);
    ~Module();

    class Interface : public ServiceFramework<Interface> {
    public:
        Interface(std::shared_ptr<Module> frd, const char* name, u32 max_session);
        ~Interface();

    protected:
        /**
         * FRD::GetMyPresence service function
         *  Inputs:
         *      64 : sizeof (MyPresence) << 14 | 2
         *      65 : Address of MyPresence structure
         *  Outputs:
         *      1 : Result of function, 0 on success, otherwise error code
         */
        void GetMyPresence(Kernel::HLERequestContext& ctx);

        /**
         * FRD::GetFriendKeyList service function
         *  Inputs:
         *      1 : Unknown
         *      2 : Max friends count
         *      65 : Address of FriendKey List
         *  Outputs:
         *      1 : Result of function, 0 on success, otherwise error code
         *      2 : FriendKey count filled
         */
        void GetFriendKeyList(Kernel::HLERequestContext& ctx);

        /**
         * FRD::GetFriendProfile service function
         *  Inputs:
         *      1 : Friends count
         *      2 : Friends count << 18 | 2
         *      3 : Address of FriendKey List
         *      64 : (count * sizeof (Profile)) << 10 | 2
         *      65 : Address of Profiles List
         *  Outputs:
         *      1 : Result of function, 0 on success, otherwise error code
         */
        void GetFriendProfile(Kernel::HLERequestContext& ctx);

        /**
         * FRD::GetFriendAttributeFlags service function
         *  Inputs:
         *      1 : Friends count
         *      2 : Friends count << 18 | 2
         *      3 : Address of FriendKey List
         *      65 : Address of AttributeFlags
         *  Outputs:
         *      1 : Result of function, 0 on success, otherwise error code
         */
        void GetFriendAttributeFlags(Kernel::HLERequestContext& ctx);

        /**
         * FRD::GetMyFriendKey service function
         *  Inputs:
         *      none
         *  Outputs:
         *      1 : Result of function, 0 on success, otherwise error code
         *      2-5 : FriendKey
         */
        void GetMyFriendKey(Kernel::HLERequestContext& ctx);

        /**
         * FRD::GetMyScreenName service function
         *  Outputs:
         *      1 : Result of function, 0 on success, otherwise error code
         *      2 : UTF16 encoded name (max 11 symbols)
         */
        void GetMyScreenName(Kernel::HLERequestContext& ctx);

        /**
         * FRD::GetMyMii service function
         *  Outputs:
         *      1 : Result of function, 0 on success, otherwise error code
         *      2 : MiiStoreData structure
         */
        void GetMyMii(Kernel::HLERequestContext& ctx);

        /**
         * FRD::GetMyProfile service function
         *  Outputs:
         *      1 : Result of function, 0 on success, otherwise error code
         *    2-3 : Profile structure
         */
        void GetMyProfile(Kernel::HLERequestContext& ctx);

        /**
         * FRD::GetMyComment service function
         *  Outputs:
         *      1 : Result of function, 0 on success, otherwise error code
         *      2 : UTF16 encoded comment (max 16 symbols)
         */
        void GetMyComment(Kernel::HLERequestContext& ctx);

        /**
         * FRD::GetMyFavoriteGame service function
         *  Outputs:
         *      1 : Result of function, 0 on success, otherwise error code
         *    2-3 : Game structure
         */
        void GetMyFavoriteGame(Kernel::HLERequestContext& ctx);

        /**
         * FRD::GetMyPlayingGame service function
         *  Outputs:
         *      1 : Result of function, 0 on success, otherwise error code
         *    2-3 : Game structure
         */
        void GetMyPlayingGame(Kernel::HLERequestContext& ctx);

        /**
         * FRD::GetMyPreference service function
         *  Outputs:
         *      1 : Result of function, 0 on success, otherwise error code
         *      2 : Public mode (byte, 0 = private, non-zero = public)
         *      3 : Show current game (byte, 0 = don't show, non-zero = show)
         *      4 : Show game history (byte, 0 = don't show, non-zero = show)
         */
        void GetMyPreference(Kernel::HLERequestContext& ctx);

        /**
         * FRD::UnscrambleLocalFriendCode service function
         *  Inputs:
         *      1 : Friend code count
         *      2 : ((count * 12) << 14) | 0x402
         *      3 : Pointer to encoded friend codes. Each is 12 bytes large
         *      64 : ((count * 8) << 14) | 2
         *      65 : Pointer to write decoded local friend codes to. Each is 8 bytes large.
         *  Outputs:
         *      1 : Result of function, 0 on success, otherwise error code
         */
        void UnscrambleLocalFriendCode(Kernel::HLERequestContext& ctx);

        /**
         * FRD::SetClientSdkVersion service function
         *  Inputs:
         *      1 : Used SDK Version
         *  Outputs:
         *      1 : Result of function, 0 on success, otherwise error code
         */
        void SetClientSdkVersion(Kernel::HLERequestContext& ctx);

        /**
         * FRD::Login service function
         *  Inputs:
         *      65 : Address of unknown event
         *  Outputs:
         *      1  : Result of function, 0 on success, otherwise error code
         */
        void Login(Kernel::HLERequestContext& ctx);

        /**
         * FRD::IsOnline service function
         *  Inputs:
         *      none
         *  Outputs:
         *      1  : Result of function, 0 on success, otherwise error code
         *      2  : Online state (8-bit, 0 = not online, non-zero = online)
         */
        void IsOnline(Kernel::HLERequestContext& ctx);

        /**
         * FRD::HasLoggedIn service function
         *  Outputs:
         *      1 : Result of function, 0 on success, otherwise error code
         *      2 : If the user has logged in 1, otherwise 0
         */
        void HasLoggedIn(Kernel::HLERequestContext& ctx);

        /**
         * FRD::GetLastResponseResult service function
         *  Inputs:
         *      none
         *  Outputs:
         *      1 : Result of function, 0 on success, otherwise error code
         */
        void GetLastResponseResult(Kernel::HLERequestContext& ctx);

    protected:
        std::shared_ptr<Module> frd;
    };

private:
    FriendKey my_friend_key = {0, 0, 0ull};
    MyPresence my_presence = {};
    bool logged_in = false;
    std::shared_ptr<Kernel::Event> login_event;
    Core::TimingEventType* login_delay_event;
    Core::System& system;

    template <class Archive>
    void serialize(Archive& ar, const unsigned int) {
        ar& my_friend_key;
        ar& my_presence;
        ar& logged_in;
    }
    friend class boost::serialization::access;
};

void InstallInterfaces(Core::System& system);

} // namespace Service::FRD

SERVICE_CONSTRUCT(Service::FRD::Module)