Seregon/ShadPKG

A tool for deriving PKG packet encryption keys for ps4 written in c++

C++/47.3 KB/No license
ps4MEL/ps4_stubs.h
ShadPKG / ps4MEL / ps4_stubs.h
1/*
2 * ╔═══════════════════════════════════════════════════════════════════════════╗
3 * ║ PS4 SYSTEM STUBS - HEADER ║
4 * ╠═══════════════════════════════════════════════════════════════════════════╣
5 * ║ Data structures and declarations based on shadPS4 emulator. ║
6 * ║ Reference: https://github.com/shadps4-emu/shadPS4 ║
7 * ╚═══════════════════════════════════════════════════════════════════════════╝
8 */
9 
10#ifndef PS4_STUBS_H
11#define PS4_STUBS_H
12 
13#pragma once
14 
15#include <cstdint>
16#include <cstring>
17 
18// ═══════════════════════════════════════════════════════════════════════════
19// COMMON TYPES
20// ═══════════════════════════════════════════════════════════════════════════
21 
22using s8 = int8_t;
23using s16 = int16_t;
24using s32 = int32_t;
25using s64 = int64_t;
26using u8 = uint8_t;
27using u16 = uint16_t;
28using u32 = uint32_t;
29using u64 = uint64_t;
30 
31#define ORBIS_OK 0
32 
33// ═══════════════════════════════════════════════════════════════════════════
34// PAD (CONTROLLER) STRUCTURES - Based on shadPS4
35// ═══════════════════════════════════════════════════════════════════════════
36 
37constexpr int ORBIS_PAD_MAX_TOUCH_NUM = 2;
38constexpr int ORBIS_PAD_MAX_DEVICE_UNIQUE_DATA_SIZE = 12;
39constexpr int ORBIS_PAD_PORT_TYPE_STANDARD = 0;
40constexpr int ORBIS_PAD_PORT_TYPE_SPECIAL = 2;
41constexpr int ORBIS_PAD_PORT_TYPE_REMOTE_CONTROL = 16;
42 
43enum class OrbisPadDeviceClass : s32 {
44 Invalid = -1,
45 Standard = 0,
46 Guitar = 1,
47 Drum = 2,
48 DjTurntable = 3,
49 Dancemat = 4,
50 Navigation = 5,
51 SteeringWheel = 6,
52 Stick = 7,
53 FightStick = 8,
54 Gun = 9,
55};
56 
57struct OrbisPadAnalogButtons {
58 u8 l2;
59 u8 r2;
60 u8 padding[2];
61};
62 
63struct OrbisPadAnalogStick {
64 u8 x;
65 u8 y;
66};
67 
68struct OrbisFQuaternion {
69 float x, y, z, w;
70};
71 
72struct OrbisFVector3 {
73 float x, y, z;
74};
75 
76struct OrbisPadTouch {
77 u16 x;
78 u16 y;
79 u8 id;
80 u8 reserve[3];
81};
82 
83struct OrbisPadTouchData {
84 u8 touchNum;
85 u8 reserve[3];
86 u32 reserve1;
87 OrbisPadTouch touch[ORBIS_PAD_MAX_TOUCH_NUM];
88};
89 
90struct OrbisPadExtensionUnitData {
91 u32 extensionUnitId;
92 u8 reserve[1];
93 u8 dataLength;
94 u8 data[10];
95};
96 
97struct OrbisPadData {
98 u32 buttons;
99 OrbisPadAnalogStick leftStick;
100 OrbisPadAnalogStick rightStick;
101 OrbisPadAnalogButtons analogButtons;
102 OrbisFQuaternion orientation;
103 OrbisFVector3 acceleration;
104 OrbisFVector3 angularVelocity;
105 OrbisPadTouchData touchData;
106 bool connected;
107 u64 timestamp;
108 OrbisPadExtensionUnitData extensionUnitData;
109 u8 connectedCount;
110 u8 reserve[2];
111 u8 deviceUniqueDataLen;
112 u8 deviceUniqueData[ORBIS_PAD_MAX_DEVICE_UNIQUE_DATA_SIZE];
113};
114 
115struct OrbisPadTouchPadInformation {
116 float pixelDensity;
117 struct {
118 u16 x;
119 u16 y;
120 } resolution;
121};
122 
123struct OrbisPadStickInformation {
124 u8 deadZoneLeft;
125 u8 deadZoneRight;
126};
127 
128struct OrbisPadControllerInformation {
129 OrbisPadTouchPadInformation touchPadInfo;
130 OrbisPadStickInformation stickInfo;
131 u8 connectionType;
132 u8 connectedCount;
133 bool connected;
134 OrbisPadDeviceClass deviceClass;
135 u8 reserve[8];
136};
137 
138struct OrbisPadOpenParam {
139 u8 reserve[8];
140};
141 
142struct OrbisPadLightBarParam {
143 u8 r;
144 u8 g;
145 u8 b;
146 u8 reserve[1];
147};
148 
149struct OrbisPadVibrationParam {
150 u8 largeMotor;
151 u8 smallMotor;
152};
153 
154// ═══════════════════════════════════════════════════════════════════════════
155// AUDIO OUT STRUCTURES - Based on shadPS4
156// ═══════════════════════════════════════════════════════════════════════════
157 
158constexpr int SCE_AUDIO_OUT_NUM_PORTS = 8;
159constexpr int SCE_AUDIO_OUT_VOLUME_0DB = 32768;
160 
161enum class OrbisAudioOutPort : s32 {
162 Main = 0,
163 Bgm = 1,
164 Voice = 2,
165 Personal = 3,
166 PadSpk = 4,
167 Aux = 127,
168 Audio3d = 128,
169};
170 
171struct OrbisAudioOutPortState {
172 u16 output;
173 u8 channel;
174 u8 reserved8_1[1];
175 s16 volume;
176 u16 rerouteCounter;
177 u64 flag;
178};
179 
180struct OrbisAudioOutOutputParam {
181 s32 handle;
182 void* ptr;
183};
184 
185// ═══════════════════════════════════════════════════════════════════════════
186// VIDEO OUT STRUCTURES - Based on shadPS4
187// ═══════════════════════════════════════════════════════════════════════════
188 
189constexpr int SCE_VIDEO_OUT_BUS_TYPE_MAIN = 0;
190 
191enum class PixelFormat : u32 {
192 A8R8G8B8Srgb = 0x80000000,
193 A8B8G8R8Srgb = 0x80002200,
194 A2R10G10B10 = 0x88060000,
195 A2R10G10B10Srgb = 0x88000000,
196 A2R10G10B10Bt2020Pq = 0x88740000,
197 A16R16G16B16Float = 0xC1060000,
198};
199 
200enum class TilingMode : u32 {
201 Tile = 0,
202 Linear = 1,
203};
204 
205struct BufferAttribute {
206 PixelFormat pixel_format;
207 TilingMode tiling_mode;
208 u32 aspect_ratio;
209 u32 width;
210 u32 height;
211 u32 pitch_in_pixel;
212 u32 option;
213 u32 reserved0;
214 u64 reserved1;
215};
216 
217struct FlipStatus {
218 u64 count;
219 u64 process_time;
220 u64 tsc;
221 s64 flip_arg;
222 u64 submit_tsc;
223 u64 reserved0;
224 s32 gc_queue_num;
225 s32 flip_pending_num;
226 s32 current_buffer;
227 u32 reserved1;
228};
229 
230struct SceVideoOutVblankStatus {
231 u64 count;
232 u64 process_time;
233 u64 tsc;
234 u64 reserved;
235 u8 flags;
236 u8 pad[7];
237};
238 
239struct SceVideoOutResolutionStatus {
240 u32 width;
241 u32 height;
242 u32 paneWidth;
243 u32 paneHeight;
244 u64 refreshRate;
245 float screenSize;
246 u16 flags;
247 u16 reserved0;
248 u32 reserved1[3];
249};
250 
251struct SceVideoOutDeviceCapabilityInfo {
252 u64 capability;
253};
254 
255struct SceVideoOutColorSettings {
256 float gamma;
257};
258 
259// ═══════════════════════════════════════════════════════════════════════════
260// USER SERVICE STRUCTURES
261// ═══════════════════════════════════════════════════════════════════════════
262 
263using OrbisUserServiceUserId = s32;
264 
265// ═══════════════════════════════════════════════════════════════════════════
266// FUNCTION DECLARATIONS
267// ═══════════════════════════════════════════════════════════════════════════
268 
269// ─────────────────────── INDIRECT CALL DISPATCH ───────────────────────
270// Called by decompiler-generated code for 'call rax' / 'call [rax+offset]'.
271// Attempts to cast fn_ptr to the standard int64_t(a1..a6) signature and call it.
272int64_t ps4_indirect_call(void* fn_ptr,
273 int64_t a1 = 0, int64_t a2 = 0, int64_t a3 = 0,
274 int64_t a4 = 0, int64_t a5 = 0, int64_t a6 = 0);
275 
276extern "C" {
277 
278// PAD
279s32 scePadInit();
280s32 scePadOpen(OrbisUserServiceUserId userId, s32 type, s32 index, const OrbisPadOpenParam* pParam);
281s32 scePadClose(s32 handle);
282s32 scePadRead(s32 handle, OrbisPadData* pData, s32 num);
283s32 scePadReadState(s32 handle, OrbisPadData* pData);
284s32 scePadGetControllerInformation(s32 handle, OrbisPadControllerInformation* pInfo);
285s32 scePadSetVibration(s32 handle, const OrbisPadVibrationParam* pParam);
286s32 scePadSetLightBar(s32 handle, const OrbisPadLightBarParam* pParam);
287s32 scePadResetLightBar(s32 handle);
288s32 scePadResetOrientation(s32 handle);
289s32 scePadSetMotionSensorState(s32 handle, bool bEnable);
290s32 scePadGetHandle(OrbisUserServiceUserId userId, s32 type, s32 index);
291 
292// Audio
293s32 sceAudioOutInit();
294s32 sceAudioOutOpen(OrbisUserServiceUserId userId, s32 portType, s32 index, u32 length, u32 sampleRate, u32 paramType);
295s32 sceAudioOutClose(s32 handle);
296s32 sceAudioOutOutput(s32 handle, void* ptr);
297s32 sceAudioOutOutputs(void* param, u32 num);
298s32 sceAudioOutSetVolume(s32 handle, s32 flag, s32* vol);
299s32 sceAudioOutGetPortState(s32 handle, OrbisAudioOutPortState* state);
300s32 sceAudioOutGetLastOutputTime(s32 handle, u64* outputTime);
301 
302// Video
303s32 sceVideoOutOpen(OrbisUserServiceUserId userId, s32 busType, s32 index, const void* param);
304s32 sceVideoOutClose(s32 handle);
305void sceVideoOutSetBufferAttribute(BufferAttribute* attribute, u32 pixelFormat, u32 tilingMode, u32 aspectRatio, u32 width, u32 height, u32 pitchInPixel);
306s32 sceVideoOutRegisterBuffers(s32 handle, s32 startIndex, void* const* addresses, s32 bufferNum, const BufferAttribute* attribute);
307s32 sceVideoOutUnregisterBuffers(s32 handle, s32 attributeIndex);
308s32 sceVideoOutSetFlipRate(s32 handle, s32 rate);
309s32 sceVideoOutSubmitFlip(s32 handle, s32 bufferIndex, s32 flipMode, s64 flipArg);
310s32 sceVideoOutGetFlipStatus(s32 handle, FlipStatus* status);
311s32 sceVideoOutGetVblankStatus(s32 handle, SceVideoOutVblankStatus* status);
312s32 sceVideoOutGetResolutionStatus(s32 handle, SceVideoOutResolutionStatus* status);
313s32 sceVideoOutIsFlipPending(s32 handle);
314s32 sceVideoOutWaitVblank(s32 handle);
315s32 sceVideoOutGetDeviceCapabilityInfo(s32 handle, SceVideoOutDeviceCapabilityInfo* info);
316s32 sceVideoOutColorSettingsSetGamma(SceVideoOutColorSettings* settings, float gamma);
317s32 sceVideoOutAdjustColor(s32 handle, const SceVideoOutColorSettings* settings);
318 
319// GNM
320s32 sceGnmSubmitCommandBuffers(u32 count, void** dcbGpuAddrs, u32* dcbSizesInBytes, void** ccbGpuAddrs, u32* ccbSizesInBytes);
321s32 sceGnmSubmitAndFlipCommandBuffers(u32 count, void** dcbGpuAddrs, u32* dcbSizesInBytes, void** ccbGpuAddrs, u32* ccbSizesInBytes, s32 videoHandle, s32 bufferIndex, s32 flipMode, s64 flipArg);
322u32 sceGnmGetGpuCoreClockFrequency();
323s32 sceGnmFlushGarlic();
324 
325// User Service
326s32 sceUserServiceInitialize(void* params);
327s32 sceUserServiceTerminate();
328s32 sceUserServiceGetInitialUser(OrbisUserServiceUserId* userId);
329s32 sceUserServiceGetLoginUserIdList(OrbisUserServiceUserId* userIdList);
330s32 sceUserServiceGetUserName(OrbisUserServiceUserId userId, char* userName, size_t size);
331 
332// System Service
333s32 sceSystemServiceHideSplashScreen();
334s32 sceSystemServiceParamGetInt(s32 paramId, s32* value);
335s32 sceSystemServiceParamGetString(s32 paramId, char* buf, size_t bufSize);
336s32 sceSystemServiceGetStatus(void* status);
337 
338// Save Data
339s32 sceSaveDataInitialize3(void* params);
340s32 sceSaveDataMount(void* mount);
341s32 sceSaveDataUmount(void* umount);
342s32 sceSaveDataDirNameSearch(void* search);
343 
344// Common Dialog
345s32 sceCommonDialogInitialize();
346s32 sceMsgDialogInitialize();
347s32 sceMsgDialogOpen(void* param);
348s32 sceMsgDialogUpdateStatus();
349s32 sceMsgDialogTerminate();
350s32 sceMsgDialogGetResult(void* result);
351 
352// Network
353s32 sceNpSetNpTitleId(void* titleId, void* titleSecret);
354s32 sceNpCheckCallback();
355s32 sceNetInit();
356s32 sceNetCtlInit();
357s32 sceNetCtlTerm();
358s32 sceNetCtlGetInfo(s32 code, void* info);
359 
360// IME
361s32 sceImeDialogInit(void* param, void* extended);
362s32 sceImeDialogGetStatus();
363s32 sceImeDialogTerm();
364 
365// Sysmodule
366s32 sceSysmoduleLoadModule(s32 id);
367s32 sceSysmoduleUnloadModule(s32 id);
368s32 sceSysmoduleIsLoaded(s32 id);
369 
370} // extern "C"
371 
372#endif // PS4_STUBS_H
373