Seregon/ShadPKG

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

C++/47.3 KB/No license
ps4MEL/sdl_backend.h
ShadPKG / ps4MEL / sdl_backend.h
1/*
2 * ╔═══════════════════════════════════════════════════════════════════════════╗
3 * ║ SDL BACKEND FOR PS4 EMULATION ║
4 * ╠═══════════════════════════════════════════════════════════════════════════╣
5 * ║ Provides window, rendering, and input for decompiled PS4 games. ║
6 * ╚═══════════════════════════════════════════════════════════════════════════╝
7 */
8 
9#ifndef SDL_BACKEND_H
10#define SDL_BACKEND_H
11 
12#include <cstdint>
13#include <string>
14 
15namespace PS4Emu {
16namespace SDL {
17 
18// ═══════════════════════════════════════════════════════════════════════════
19// INITIALIZATION
20// ═══════════════════════════════════════════════════════════════════════════
21 
22bool Initialize(const std::string& title = "PS4 Game", int width = 1920, int height = 1080);
23void Shutdown();
24bool IsInitialized();
25 
26// ═══════════════════════════════════════════════════════════════════════════
27// WINDOW & RENDERING
28// ═══════════════════════════════════════════════════════════════════════════
29 
30void* GetWindowHandle();
31void* GetRendererHandle();
32 
33// Frame buffer operations
34void* CreateFrameBuffer(int width, int height);
35void DestroyFrameBuffer(void* buffer);
36void UpdateFrameBuffer(void* buffer, const void* pixels, int pitch);
37void PresentFrameBuffer(void* buffer);
38 
39// Simple rendering
40void ClearScreen(uint8_t r, uint8_t g, uint8_t b);
41void Present();
42void SetVSync(bool enabled);
43 
44// Text and dialog rendering
45void DrawText(const char* text, int x, int y, uint8_t r, uint8_t g, uint8_t b);
46void DrawRect(int x, int y, int w, int h, uint8_t r, uint8_t g, uint8_t b, bool filled = true);
47void ShowDialog(const char* title, const char* message);
48void SetDialogMessage(const char* message);
49const char* GetCurrentDialogMessage();
50 
51// ═══════════════════════════════════════════════════════════════════════════
52// INPUT
53// ═══════════════════════════════════════════════════════════════════════════
54 
55struct PadState {
56 uint32_t buttons; // Button bitmask
57 uint8_t leftStickX; // 0-255, 128 = center
58 uint8_t leftStickY;
59 uint8_t rightStickX;
60 uint8_t rightStickY;
61 uint8_t l2; // 0-255
62 uint8_t r2;
63 bool connected;
64};
65 
66// PS4 button masks (matching OrbisPadButtonDataOffset)
67constexpr uint32_t PAD_L3 = 0x0002;
68constexpr uint32_t PAD_R3 = 0x0004;
69constexpr uint32_t PAD_OPTIONS = 0x0008;
70constexpr uint32_t PAD_UP = 0x0010;
71constexpr uint32_t PAD_RIGHT = 0x0020;
72constexpr uint32_t PAD_DOWN = 0x0040;
73constexpr uint32_t PAD_LEFT = 0x0080;
74constexpr uint32_t PAD_L2 = 0x0100;
75constexpr uint32_t PAD_R2 = 0x0200;
76constexpr uint32_t PAD_L1 = 0x0400;
77constexpr uint32_t PAD_R1 = 0x0800;
78constexpr uint32_t PAD_TRIANGLE = 0x1000;
79constexpr uint32_t PAD_CIRCLE = 0x2000;
80constexpr uint32_t PAD_CROSS = 0x4000;
81constexpr uint32_t PAD_SQUARE = 0x8000;
82constexpr uint32_t PAD_TOUCHPAD = 0x100000;
83 
84void PollEvents();
85bool ShouldQuit();
86PadState GetPadState();
87 
88// ═══════════════════════════════════════════════════════════════════════════
89// TIMING
90// ═══════════════════════════════════════════════════════════════════════════
91 
92uint64_t GetTicks(); // Milliseconds since init
93void Delay(uint32_t ms);
94void WaitVBlank(); // Wait for ~16.67ms (60Hz)
95 
96} // namespace SDL
97} // namespace PS4Emu
98 
99#endif // SDL_BACKEND_H
100