diff options
| author | SHAURYASANYAL3 <shauryasanya.21jun@gmail.com> | 2026-11-22 19:44:11 +0530 |
|---|---|---|
| committer | SHAURYASANYAL3 <shauryasanya.21jun@gmail.com> | 2026-11-22 19:45:12 +0530 |
| commit | ea2f274a27b143b2fdd638bbee2ff0a8ca21b781 (patch) | |
| tree | 878152a577094d687fe5a41d40e82db4924c6e74 /runtime | |
| parent | 003e78129303643a3fdc9e5f0e31a01b09759236 (diff) | |
xgameruntime: implement XPackageGetCurrentProcessPackagePath, XPackageIsPackagedProcess, XSystemGetAnalyticsInfo
Diffstat (limited to 'runtime')
| -rw-r--r-- | runtime/shims/xgameruntime.cpp | 71 | ||||
| -rw-r--r-- | runtime/test/xgameruntime_test.cpp | 38 |
2 files changed, 109 insertions, 0 deletions
diff --git a/runtime/shims/xgameruntime.cpp b/runtime/shims/xgameruntime.cpp index 8135589b9..0bd1d879d 100644 --- a/runtime/shims/xgameruntime.cpp +++ b/runtime/shims/xgameruntime.cpp | |||
| @@ -156,6 +156,74 @@ uint64_t __stdcall XSystemGetAppMemoryUsage() { | |||
| 156 | return 0; | 156 | return 0; |
| 157 | } | 157 | } |
| 158 | 158 | ||
| 159 | // XSystemAnalyticsInfo: hardware and OS version telemetry requested during engine startup. | ||
| 160 | struct XSystemAnalyticsInfo { | ||
| 161 | char osVersion[128]; | ||
| 162 | char hostingOsVersion[128]; | ||
| 163 | char family[64]; | ||
| 164 | char form[64]; | ||
| 165 | }; | ||
| 166 | |||
| 167 | // HRESULT XSystemGetAnalyticsInfo(XSystemAnalyticsInfo* info). | ||
| 168 | HRESULT __stdcall XSystemGetAnalyticsInfo(XSystemAnalyticsInfo* info) { | ||
| 169 | if (!info) return E_INVALIDARG; | ||
| 170 | std::memset(info, 0, sizeof(*info)); | ||
| 171 | std::strncpy(info->osVersion, "10.0.22000.0", sizeof(info->osVersion) - 1); | ||
| 172 | std::strncpy(info->hostingOsVersion, "10.0.22000.0", sizeof(info->hostingOsVersion) - 1); | ||
| 173 | std::strncpy(info->family, "Xbox", sizeof(info->family) - 1); | ||
| 174 | |||
| 175 | const uint32_t dt = XSystemGetDeviceType(); | ||
| 176 | if (dt == static_cast<uint32_t>(XSystemDeviceType::XboxScarlettLockhart)) { | ||
| 177 | std::strncpy(info->form, "Lockhart", sizeof(info->form) - 1); | ||
| 178 | } else { | ||
| 179 | std::strncpy(info->form, "Anaconda", sizeof(info->form) - 1); | ||
| 180 | } | ||
| 181 | return S_OK; | ||
| 182 | } | ||
| 183 | |||
| 184 | // ---- XPackage ---- | ||
| 185 | |||
| 186 | // HRESULT XPackageGetCurrentProcessPackagePath(size_t pathSize, char* path). | ||
| 187 | // Retrieves the path of the installed package for the current process. | ||
| 188 | // Reads LEONIDA_GAME_DIR when set, otherwise falls back to the current module's directory. | ||
| 189 | HRESULT __stdcall XPackageGetCurrentProcessPackagePath(size_t pathSize, char* path) { | ||
| 190 | if (!path || pathSize == 0) return E_INVALIDARG; | ||
| 191 | |||
| 192 | char buf[MAX_PATH] = {}; | ||
| 193 | const DWORD n = GetEnvironmentVariableA("LEONIDA_GAME_DIR", buf, sizeof(buf)); | ||
| 194 | if (n == 0 || n >= sizeof(buf)) { | ||
| 195 | const DWORD mod_len = GetModuleFileNameA(nullptr, buf, sizeof(buf)); | ||
| 196 | if (mod_len > 0 && mod_len < sizeof(buf)) { | ||
| 197 | char* slash = std::strrchr(buf, '\\'); | ||
| 198 | char* fslash = std::strrchr(buf, '/'); | ||
| 199 | char* last = slash > fslash ? slash : fslash; | ||
| 200 | if (last) { | ||
| 201 | *last = '\0'; | ||
| 202 | } else { | ||
| 203 | std::strcpy(buf, "."); | ||
| 204 | } | ||
| 205 | } else { | ||
| 206 | std::strcpy(buf, "."); | ||
| 207 | } | ||
| 208 | } | ||
| 209 | |||
| 210 | const size_t len = std::strlen(buf); | ||
| 211 | if (pathSize < len + 1) return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); | ||
| 212 | std::memcpy(path, buf, len + 1); | ||
| 213 | return S_OK; | ||
| 214 | } | ||
| 215 | |||
| 216 | // bool XPackageIsPackagedProcess(). | ||
| 217 | // Returns true on Xbox Series console. LEONIDA_PACKAGED=0 overrides it. | ||
| 218 | bool __stdcall XPackageIsPackagedProcess() { | ||
| 219 | char s[16]; | ||
| 220 | const DWORD n = GetEnvironmentVariableA("LEONIDA_PACKAGED", s, sizeof(s)); | ||
| 221 | if (n > 0 && n < sizeof(s)) { | ||
| 222 | if (std::atoi(s) == 0) return false; | ||
| 223 | } | ||
| 224 | return true; | ||
| 225 | } | ||
| 226 | |||
| 159 | #define XGR(name) {"xgameruntime.dll", #name, reinterpret_cast<void*>(&name)} | 227 | #define XGR(name) {"xgameruntime.dll", #name, reinterpret_cast<void*>(&name)} |
| 160 | 228 | ||
| 161 | } // namespace | 229 | } // namespace |
| @@ -173,6 +241,9 @@ SHIM_TABLE(xgameruntime, | |||
| 173 | XGR(XSystemGetConsoleId), | 241 | XGR(XSystemGetConsoleId), |
| 174 | XGR(XSystemGetAppMemoryUsageLimit), | 242 | XGR(XSystemGetAppMemoryUsageLimit), |
| 175 | XGR(XSystemGetAppMemoryUsage), | 243 | XGR(XSystemGetAppMemoryUsage), |
| 244 | XGR(XSystemGetAnalyticsInfo), | ||
| 245 | XGR(XPackageGetCurrentProcessPackagePath), | ||
| 246 | XGR(XPackageIsPackagedProcess), | ||
| 176 | // XTaskQueue (third_party/xtaskqueue) | 247 | // XTaskQueue (third_party/xtaskqueue) |
| 177 | XGR(XTaskQueueCreate), | 248 | XGR(XTaskQueueCreate), |
| 178 | XGR(XTaskQueueCreateComposite), | 249 | XGR(XTaskQueueCreateComposite), |
diff --git a/runtime/test/xgameruntime_test.cpp b/runtime/test/xgameruntime_test.cpp index ac36f40d9..2508cd123 100644 --- a/runtime/test/xgameruntime_test.cpp +++ b/runtime/test/xgameruntime_test.cpp | |||
| @@ -51,8 +51,20 @@ using AsyncCompleteFn = void(__stdcall*)(XAsyncBlock*, HRESULT, size_t); | |||
| 51 | using AsyncResultSizeFn = HRESULT(__stdcall*)(XAsyncBlock*, size_t*); | 51 | using AsyncResultSizeFn = HRESULT(__stdcall*)(XAsyncBlock*, size_t*); |
| 52 | using AsyncResultFn = HRESULT(__stdcall*)(XAsyncBlock*, const void*, size_t, void*, size_t*); | 52 | using AsyncResultFn = HRESULT(__stdcall*)(XAsyncBlock*, const void*, size_t, void*, size_t*); |
| 53 | 53 | ||
| 54 | struct XSystemAnalyticsInfo { | ||
| 55 | char osVersion[128]; | ||
| 56 | char hostingOsVersion[128]; | ||
| 57 | char family[64]; | ||
| 58 | char form[64]; | ||
| 59 | }; | ||
| 60 | |||
| 61 | using AnalyticsInfoFn = HRESULT(__stdcall*)(XSystemAnalyticsInfo*); | ||
| 62 | using PackagePathFn = HRESULT(__stdcall*)(size_t, char*); | ||
| 63 | using PackagedProcessFn = bool(__stdcall*)(); | ||
| 64 | |||
| 54 | const char* const kNames[] = { | 65 | const char* const kNames[] = { |
| 55 | "XGameRuntimeInitialize", "XGameRuntimeUninitialize", "XSystemGetDeviceType", "XSystemGetConsoleId", | 66 | "XGameRuntimeInitialize", "XGameRuntimeUninitialize", "XSystemGetDeviceType", "XSystemGetConsoleId", |
| 67 | "XSystemGetAnalyticsInfo", "XPackageGetCurrentProcessPackagePath", "XPackageIsPackagedProcess", | ||
| 56 | "XTaskQueueCreate", "XTaskQueueCreateComposite", "XTaskQueueGetPort", "XTaskQueueDuplicateHandle", | 68 | "XTaskQueueCreate", "XTaskQueueCreateComposite", "XTaskQueueGetPort", "XTaskQueueDuplicateHandle", |
| 57 | "XTaskQueueCloseHandle", "XTaskQueueTerminate", "XTaskQueueDispatch", "XTaskQueueSubmitCallback", | 69 | "XTaskQueueCloseHandle", "XTaskQueueTerminate", "XTaskQueueDispatch", "XTaskQueueSubmitCallback", |
| 58 | "XTaskQueueSubmitDelayedCallback", "XTaskQueueRegisterWaiter", "XTaskQueueUnregisterWaiter", | 70 | "XTaskQueueSubmitDelayedCallback", "XTaskQueueRegisterWaiter", "XTaskQueueUnregisterWaiter", |
| @@ -229,6 +241,32 @@ int main() { | |||
| 229 | check(console_id(sizeof(id), id, &used) == S_OK && used == 39 && std::strlen(id) == 38, | 241 | check(console_id(sizeof(id), id, &used) == S_OK && used == 39 && std::strlen(id) == 38, |
| 230 | "XSystemGetConsoleId fills 39 bytes (38 characters and the terminator)"); | 242 | "XSystemGetConsoleId fills 39 bytes (38 characters and the terminator)"); |
| 231 | 243 | ||
| 244 | auto analytics_info = get<AnalyticsInfoFn>("XSystemGetAnalyticsInfo"); | ||
| 245 | check(analytics_info(nullptr) == E_INVALIDARG, "XSystemGetAnalyticsInfo rejects null pointer"); | ||
| 246 | XSystemAnalyticsInfo info{}; | ||
| 247 | check(analytics_info(&info) == S_OK && std::strcmp(info.family, "Xbox") == 0 && | ||
| 248 | std::strcmp(info.osVersion, "10.0.22000.0") == 0 && std::strcmp(info.form, "Anaconda") == 0, | ||
| 249 | "XSystemGetAnalyticsInfo populates Xbox Anaconda analytics info"); | ||
| 250 | |||
| 251 | auto package_path = get<PackagePathFn>("XPackageGetCurrentProcessPackagePath"); | ||
| 252 | check(package_path(0, nullptr) == E_INVALIDARG, "XPackageGetCurrentProcessPackagePath rejects null pointer and size 0"); | ||
| 253 | char pkg_path[MAX_PATH] = {}; | ||
| 254 | check(package_path(0, pkg_path) == E_INVALIDARG, "XPackageGetCurrentProcessPackagePath rejects size 0 with buffer"); | ||
| 255 | check(package_path(10, nullptr) == E_INVALIDARG, "XPackageGetCurrentProcessPackagePath rejects null pointer with size"); | ||
| 256 | |||
| 257 | SetEnvironmentVariableA("LEONIDA_GAME_DIR", "C:\\LeonidaGameDir"); | ||
| 258 | check(package_path(5, pkg_path) == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), | ||
| 259 | "XPackageGetCurrentProcessPackagePath rejects insufficient buffer"); | ||
| 260 | check(package_path(sizeof(pkg_path), pkg_path) == S_OK && std::strcmp(pkg_path, "C:\\LeonidaGameDir") == 0, | ||
| 261 | "XPackageGetCurrentProcessPackagePath returns configured game directory"); | ||
| 262 | SetEnvironmentVariableA("LEONIDA_GAME_DIR", nullptr); | ||
| 263 | |||
| 264 | auto is_packaged = get<PackagedProcessFn>("XPackageIsPackagedProcess"); | ||
| 265 | check(is_packaged() == true, "XPackageIsPackagedProcess returns true by default"); | ||
| 266 | SetEnvironmentVariableA("LEONIDA_PACKAGED", "0"); | ||
| 267 | check(is_packaged() == false, "XPackageIsPackagedProcess respects LEONIDA_PACKAGED=0 override"); | ||
| 268 | SetEnvironmentVariableA("LEONIDA_PACKAGED", nullptr); | ||
| 269 | |||
| 232 | // Work on the thread pool, completions dispatched by the "game loop" on this thread. | 270 | // Work on the thread pool, completions dispatched by the "game loop" on this thread. |
| 233 | auto create = get<QueueCreateFn>("XTaskQueueCreate"); | 271 | auto create = get<QueueCreateFn>("XTaskQueueCreate"); |
| 234 | auto close = get<QueueCloseFn>("XTaskQueueCloseHandle"); | 272 | auto close = get<QueueCloseFn>("XTaskQueueCloseHandle"); |