2020-11-04 14:56:12 +03:00
|
|
|
#!/usr/bin/env python3
|
2018-01-18 19:24:05 +03:00
|
|
|
|
|
|
|
#NOTE: If you make modifications here, consider whether they should
|
|
|
|
#be duplicated in ../vrclient/gen_wrapper.py
|
|
|
|
|
2023-09-16 01:09:09 +03:00
|
|
|
CLANG_PATH='/usr/lib/clang/15'
|
2019-05-13 19:46:07 +03:00
|
|
|
|
2023-09-23 23:31:13 +03:00
|
|
|
from clang.cindex import Cursor, CursorKind, Index, TypeKind
|
2022-06-14 17:21:49 +03:00
|
|
|
from collections import namedtuple
|
2023-09-16 21:13:49 +03:00
|
|
|
import concurrent.futures
|
2018-01-18 19:24:05 +03:00
|
|
|
import os
|
|
|
|
import re
|
|
|
|
|
2023-09-20 22:02:50 +03:00
|
|
|
SDK_VERSIONS = [
|
2023-09-18 16:58:31 +03:00
|
|
|
"158",
|
2023-05-02 11:47:29 +03:00
|
|
|
"157",
|
2023-05-02 11:45:34 +03:00
|
|
|
"156",
|
2023-02-23 23:59:37 +03:00
|
|
|
"155",
|
2023-02-23 23:58:28 +03:00
|
|
|
"154",
|
2021-12-20 18:48:44 +03:00
|
|
|
"153a",
|
2021-09-15 22:52:44 +03:00
|
|
|
"152",
|
2021-03-01 19:04:28 +03:00
|
|
|
"151",
|
2020-09-29 17:19:06 +03:00
|
|
|
"150",
|
2020-08-11 20:39:33 +03:00
|
|
|
"149",
|
2020-06-02 18:30:04 +03:00
|
|
|
"148a",
|
2019-12-06 23:19:37 +03:00
|
|
|
"147",
|
2019-08-16 16:39:30 +03:00
|
|
|
"146",
|
2019-08-16 15:44:08 +03:00
|
|
|
"145",
|
2019-05-13 19:46:07 +03:00
|
|
|
"144",
|
|
|
|
"143y",
|
|
|
|
"143x",
|
2019-02-25 18:44:23 +03:00
|
|
|
"143",
|
2018-01-18 19:24:05 +03:00
|
|
|
"142",
|
|
|
|
"141",
|
|
|
|
"140",
|
|
|
|
"139",
|
|
|
|
"138a",
|
|
|
|
"138",
|
|
|
|
"137",
|
|
|
|
"136",
|
|
|
|
"135a",
|
|
|
|
"135",
|
|
|
|
"134",
|
2019-02-05 23:28:59 +03:00
|
|
|
"133x",
|
2018-01-18 19:24:05 +03:00
|
|
|
"133b",
|
|
|
|
"133a",
|
|
|
|
"133",
|
2019-02-05 23:34:33 +03:00
|
|
|
"132x",
|
2018-01-18 19:24:05 +03:00
|
|
|
"132",
|
|
|
|
"131",
|
2019-02-06 20:48:47 +03:00
|
|
|
"130x",
|
2018-01-18 19:24:05 +03:00
|
|
|
"130",
|
|
|
|
"129a",
|
|
|
|
"129",
|
2019-02-05 23:43:00 +03:00
|
|
|
"128x",
|
2018-01-18 19:24:05 +03:00
|
|
|
"128",
|
|
|
|
"127",
|
|
|
|
"126a",
|
|
|
|
"126",
|
|
|
|
"125",
|
|
|
|
"124",
|
|
|
|
"123a",
|
|
|
|
"123",
|
|
|
|
"122",
|
2019-02-05 23:50:20 +03:00
|
|
|
"121x",
|
2018-01-18 19:24:05 +03:00
|
|
|
"121",
|
|
|
|
"120",
|
2019-02-05 23:55:55 +03:00
|
|
|
"119x",
|
2018-01-18 19:24:05 +03:00
|
|
|
"119",
|
|
|
|
"118",
|
|
|
|
"117",
|
2019-02-05 23:58:14 +03:00
|
|
|
"116x",
|
2018-01-18 19:24:05 +03:00
|
|
|
"116",
|
|
|
|
"115",
|
|
|
|
"114",
|
|
|
|
"113",
|
2019-02-06 00:01:51 +03:00
|
|
|
"112x",
|
2018-01-18 19:24:05 +03:00
|
|
|
"112",
|
2019-02-06 00:06:21 +03:00
|
|
|
"111x",
|
2018-01-18 19:24:05 +03:00
|
|
|
"111",
|
|
|
|
"110",
|
|
|
|
"109",
|
|
|
|
"108",
|
|
|
|
"107",
|
|
|
|
"106",
|
|
|
|
"105",
|
|
|
|
"104",
|
|
|
|
"103",
|
2019-02-06 17:27:56 +03:00
|
|
|
"102x",
|
2018-01-18 19:24:05 +03:00
|
|
|
"102",
|
2019-02-06 17:31:48 +03:00
|
|
|
"101x",
|
2018-01-18 19:24:05 +03:00
|
|
|
"101",
|
|
|
|
"100",
|
2019-02-06 18:19:39 +03:00
|
|
|
"099y",
|
2019-02-06 20:15:19 +03:00
|
|
|
"099x",
|
2019-02-07 22:23:50 +03:00
|
|
|
"099w",
|
2019-02-07 22:30:29 +03:00
|
|
|
"099v",
|
2019-02-07 22:33:17 +03:00
|
|
|
"099u",
|
2018-01-18 19:24:05 +03:00
|
|
|
]
|
|
|
|
|
2023-09-16 21:13:49 +03:00
|
|
|
ABIS = ['u32', 'u64', 'w32', 'w64']
|
|
|
|
|
2023-09-20 22:15:40 +03:00
|
|
|
SDK_SOURCES = {
|
|
|
|
"steam_api.h": [
|
2018-01-18 19:24:05 +03:00
|
|
|
"ISteamApps",
|
|
|
|
"ISteamAppList",
|
|
|
|
"ISteamClient",
|
|
|
|
"ISteamController",
|
2019-05-17 18:27:59 +03:00
|
|
|
"ISteamGameSearch",
|
2018-01-18 19:24:05 +03:00
|
|
|
"ISteamFriends",
|
|
|
|
"ISteamHTMLSurface",
|
|
|
|
"ISteamHTTP",
|
2019-02-25 18:53:13 +03:00
|
|
|
"ISteamInput",
|
2018-01-18 19:24:05 +03:00
|
|
|
"ISteamInventory",
|
|
|
|
"ISteamMatchmaking",
|
|
|
|
"ISteamMatchmakingServers",
|
|
|
|
"ISteamMusic",
|
|
|
|
"ISteamMusicRemote",
|
|
|
|
"ISteamNetworking",
|
2019-02-25 18:50:52 +03:00
|
|
|
"ISteamParties",
|
2019-08-16 16:51:27 +03:00
|
|
|
"ISteamRemotePlay",
|
2018-01-18 19:24:05 +03:00
|
|
|
"ISteamRemoteStorage",
|
|
|
|
"ISteamScreenshots",
|
|
|
|
"ISteamUGC",
|
|
|
|
"ISteamUnifiedMessages",
|
|
|
|
"ISteamUser",
|
|
|
|
"ISteamUserStats",
|
|
|
|
"ISteamUtils",
|
|
|
|
"ISteamVideo"
|
2023-09-20 22:15:40 +03:00
|
|
|
],
|
|
|
|
"isteamappticket.h": [
|
2018-01-18 19:24:05 +03:00
|
|
|
"ISteamAppTicket"
|
2023-09-20 22:15:40 +03:00
|
|
|
],
|
|
|
|
"isteamgameserver.h": [
|
2018-01-18 19:24:05 +03:00
|
|
|
"ISteamGameServer"
|
2023-09-20 22:15:40 +03:00
|
|
|
],
|
|
|
|
"isteamgameserverstats.h": [
|
2018-01-18 19:24:05 +03:00
|
|
|
"ISteamGameServerStats"
|
2023-09-20 22:15:40 +03:00
|
|
|
],
|
|
|
|
"isteamgamestats.h": [
|
2019-02-16 00:06:17 +03:00
|
|
|
"ISteamGameStats"
|
2023-09-20 22:15:40 +03:00
|
|
|
],
|
|
|
|
"isteammasterserverupdater.h": [
|
2018-01-18 19:24:05 +03:00
|
|
|
"ISteamMasterServerUpdater"
|
2023-09-20 22:15:40 +03:00
|
|
|
],
|
|
|
|
"isteamgamecoordinator.h": [
|
2018-01-18 19:24:05 +03:00
|
|
|
"ISteamGameCoordinator"
|
2023-09-20 22:15:40 +03:00
|
|
|
],
|
|
|
|
"isteamparentalsettings.h": [
|
2018-01-18 19:24:05 +03:00
|
|
|
"ISteamParentalSettings"
|
2023-09-20 22:15:40 +03:00
|
|
|
],
|
|
|
|
"isteamnetworkingmessages.h": [
|
2020-09-29 17:40:02 +03:00
|
|
|
"ISteamNetworkingMessages"
|
2023-09-20 22:15:40 +03:00
|
|
|
],
|
|
|
|
"isteamnetworkingsockets.h": [
|
2019-05-16 19:23:30 +03:00
|
|
|
"ISteamNetworkingSockets"
|
2023-09-20 22:15:40 +03:00
|
|
|
],
|
|
|
|
"isteamnetworkingsocketsserialized.h": [
|
2019-02-07 17:54:56 +03:00
|
|
|
"ISteamNetworkingSocketsSerialized"
|
2023-09-20 22:15:40 +03:00
|
|
|
],
|
|
|
|
"isteamnetworkingutils.h": [
|
2019-05-17 17:33:44 +03:00
|
|
|
"ISteamNetworkingUtils"
|
2023-09-20 22:15:40 +03:00
|
|
|
],
|
|
|
|
"steamnetworkingfakeip.h": [
|
2021-12-20 18:48:44 +03:00
|
|
|
"ISteamNetworkingFakeUDPPort"
|
2023-09-20 22:15:40 +03:00
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
SDK_CLASSES = {klass: source for source, klasses in SDK_SOURCES.items()
|
|
|
|
for klass in klasses}
|
2018-01-18 19:24:05 +03:00
|
|
|
|
2023-09-20 22:02:50 +03:00
|
|
|
VERSION_ALIASES = {
|
2019-02-05 23:00:41 +03:00
|
|
|
#these interfaces are undocumented and binary compatible
|
2020-06-02 18:30:04 +03:00
|
|
|
#"target interface": ["alias 1", "alias 2"],
|
2019-02-05 23:00:41 +03:00
|
|
|
"SteamUtils004":["SteamUtils003"],
|
|
|
|
"SteamUtils002":["SteamUtils001"],
|
2019-02-06 20:54:19 +03:00
|
|
|
"SteamGameServer008":["SteamGameServer007","SteamGameServer006"],
|
2019-02-07 17:54:56 +03:00
|
|
|
"SteamNetworkingSocketsSerialized002":["SteamNetworkingSocketsSerialized001"],
|
2019-02-07 22:53:55 +03:00
|
|
|
"STEAMAPPS_INTERFACE_VERSION001":["SteamApps001"],
|
2020-06-02 18:30:04 +03:00
|
|
|
"SteamNetworkingSockets002":["SteamNetworkingSockets003"],
|
2018-01-18 19:24:05 +03:00
|
|
|
}
|
|
|
|
|
2018-10-29 19:38:13 +03:00
|
|
|
# these structs are manually confirmed to be equivalent
|
2023-09-20 18:27:42 +03:00
|
|
|
EXEMPT_STRUCTS = {
|
2023-09-20 22:02:50 +03:00
|
|
|
"CSteamID",
|
|
|
|
"CGameID",
|
|
|
|
"CCallbackBase",
|
2023-09-20 18:27:42 +03:00
|
|
|
"SteamIPAddress_t",
|
2023-09-20 22:02:50 +03:00
|
|
|
"SteamPS3Params_t",
|
|
|
|
"ValvePackingSentinel_t"
|
2023-09-20 18:27:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# structs for which the size is important, either because of arrays or size parameters
|
|
|
|
SIZED_STRUCTS = {
|
|
|
|
"SteamPartyBeaconLocation_t",
|
|
|
|
"SteamItemDetails_t",
|
|
|
|
}
|
2018-01-18 19:24:05 +03:00
|
|
|
|
2019-05-16 19:23:30 +03:00
|
|
|
# we have converters for these written by hand because they're too complicated to generate
|
2023-09-20 22:02:50 +03:00
|
|
|
MANUAL_STRUCTS = [
|
|
|
|
"SteamNetworkingMessage_t"
|
2019-05-16 19:23:30 +03:00
|
|
|
]
|
|
|
|
|
2022-06-14 17:21:49 +03:00
|
|
|
Method = namedtuple('Method', ['name', 'version_func'], defaults=[lambda _: True])
|
|
|
|
|
2023-09-20 22:02:50 +03:00
|
|
|
MANUAL_METHODS = {
|
|
|
|
#TODO: 001 005 007
|
|
|
|
#NOTE: 003 never appeared in a public SDK, but is an alias for 002 (the version in SDK 1.45 is actually 004 but incorrectly versioned as 003)
|
|
|
|
"cppISteamNetworkingSockets_SteamNetworkingSockets": [
|
|
|
|
Method("ReceiveMessagesOnConnection"),
|
|
|
|
Method("ReceiveMessagesOnListenSocket"),
|
|
|
|
Method("ReceiveMessagesOnPollGroup"),
|
|
|
|
Method("SendMessages"),
|
|
|
|
Method("CreateFakeUDPPort"),
|
|
|
|
],
|
|
|
|
"cppISteamNetworkingUtils_SteamNetworkingUtils": [
|
|
|
|
Method("AllocateMessage"),
|
|
|
|
Method("SetConfigValue", lambda version: version >= 3)
|
|
|
|
],
|
|
|
|
"cppISteamNetworkingMessages_SteamNetworkingMessages": [
|
|
|
|
Method("ReceiveMessagesOnChannel"),
|
|
|
|
],
|
|
|
|
"cppISteamInput_SteamInput": [
|
|
|
|
Method("EnableActionEventCallbacks"),
|
|
|
|
Method("GetGlyphForActionOrigin"),
|
|
|
|
Method("GetGlyphPNGForActionOrigin"),
|
|
|
|
Method("GetGlyphSVGForActionOrigin"),
|
|
|
|
Method("GetGlyphForActionOrigin_Legacy"),
|
|
|
|
Method("GetGlyphForXboxOrigin"),
|
|
|
|
],
|
|
|
|
"cppISteamController_SteamController": [
|
|
|
|
Method("GetGlyphForActionOrigin"),
|
|
|
|
Method("GetGlyphForXboxOrigin"),
|
|
|
|
],
|
|
|
|
"cppISteamNetworkingFakeUDPPort_SteamNetworkingFakeUDPPort": [
|
|
|
|
Method("DestroyFakeUDPPort"),
|
|
|
|
Method("ReceiveMessages"),
|
|
|
|
],
|
2023-09-19 22:30:14 +03:00
|
|
|
"cppISteamClient_SteamClient": [
|
|
|
|
Method("Set_SteamAPI_CCheckCallbackRegisteredInProcess", lambda version: version >= 20),
|
|
|
|
],
|
2023-08-25 05:42:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-20 22:02:50 +03:00
|
|
|
POST_EXEC_FUNCS = {
|
|
|
|
"ISteamClient_BShutdownIfAllPipesClosed" : "after_shutdown",
|
|
|
|
"ISteamClient_CreateSteamPipe" : "after_steam_pipe_create",
|
2019-05-30 18:28:09 +03:00
|
|
|
}
|
|
|
|
|
2022-06-14 17:21:49 +03:00
|
|
|
INTERFACE_NAME_VERSION = re.compile(r'^(?P<name>.+?)(?P<version>\d*)$')
|
2023-09-20 22:22:29 +03:00
|
|
|
DEFINE_INTERFACE_VERSION = re.compile(r'^#define\s*(?P<name>STEAM(?:\w*)_VERSION(?:\w*))\s*"(?P<version>.*)"')
|
2022-06-14 17:21:49 +03:00
|
|
|
|
|
|
|
def method_needs_manual_handling(interface_with_version, method_name):
|
|
|
|
match_dict = INTERFACE_NAME_VERSION.match(interface_with_version).groupdict()
|
|
|
|
interface = match_dict['name']
|
|
|
|
version = int(match_dict['version']) if match_dict['version'] else None
|
|
|
|
|
2023-09-20 22:02:50 +03:00
|
|
|
method_list = MANUAL_METHODS.get(interface, [])
|
2022-06-14 17:21:49 +03:00
|
|
|
method = next(filter(lambda m: m.name == method_name, method_list), None)
|
|
|
|
|
|
|
|
return method and method.version_func(version)
|
|
|
|
|
2023-08-25 05:42:23 +03:00
|
|
|
def post_execution_function(classname, method_name):
|
2023-09-27 15:34:23 +03:00
|
|
|
return POST_EXEC_FUNCS.get(classname + "_" + method_name, None)
|
2023-08-25 05:42:23 +03:00
|
|
|
|
2019-05-17 22:48:34 +03:00
|
|
|
# manual converters for simple types (function pointers)
|
2023-09-20 22:02:50 +03:00
|
|
|
MANUAL_TYPES = [
|
|
|
|
"FSteamNetworkingSocketsDebugOutput",
|
|
|
|
"SteamAPIWarningMessageHook_t",
|
2023-09-19 22:30:14 +03:00
|
|
|
"SteamAPI_CheckCallbackRegistered_t",
|
|
|
|
"SteamAPI_PostAPIResultInProcess_t",
|
|
|
|
"void ()",
|
2019-05-17 22:48:34 +03:00
|
|
|
]
|
|
|
|
|
2019-06-17 18:50:11 +03:00
|
|
|
# manual converters for specific parameters
|
2023-09-20 22:02:50 +03:00
|
|
|
MANUAL_PARAMS = [
|
|
|
|
"nNativeKeyCode"
|
2019-06-17 18:50:11 +03:00
|
|
|
]
|
|
|
|
|
2019-05-17 17:33:44 +03:00
|
|
|
converted_structs = []
|
|
|
|
|
2018-10-29 21:23:17 +03:00
|
|
|
# callback classes for which we have a linux wrapper
|
2023-09-20 22:02:50 +03:00
|
|
|
WRAPPED_CLASSES = [
|
|
|
|
"ISteamMatchmakingServerListResponse",
|
|
|
|
"ISteamMatchmakingPingResponse",
|
|
|
|
"ISteamMatchmakingPlayersResponse",
|
|
|
|
"ISteamMatchmakingRulesResponse",
|
|
|
|
"ISteamNetworkingFakeUDPPort",
|
2023-09-20 18:27:42 +03:00
|
|
|
"ISteamNetworkingConnectionCustomSignaling",
|
|
|
|
"ISteamNetworkingCustomSignalingRecvContext",
|
2018-10-29 21:23:17 +03:00
|
|
|
]
|
|
|
|
|
2023-09-21 21:33:54 +03:00
|
|
|
all_classes = {}
|
2023-09-20 23:21:42 +03:00
|
|
|
all_records = {}
|
|
|
|
all_sources = {}
|
2023-09-20 18:27:42 +03:00
|
|
|
all_structs = {}
|
2023-09-20 23:21:42 +03:00
|
|
|
all_versions = {}
|
2023-09-29 10:58:05 +03:00
|
|
|
unique_structs = []
|
|
|
|
|
2023-09-20 23:21:42 +03:00
|
|
|
|
2023-09-23 23:31:13 +03:00
|
|
|
PATH_CONV_METHODS_UTOW = {
|
|
|
|
"ISteamAppList_GetAppInstallDir": {
|
|
|
|
"pchDirectory": {"len": "cchNameMax", "url": False},
|
|
|
|
"ret_size": True,
|
2023-09-20 22:02:50 +03:00
|
|
|
},
|
2023-09-23 23:31:13 +03:00
|
|
|
"ISteamApps_GetAppInstallDir": {
|
|
|
|
"pchFolder": {"len": "cchFolderBufferSize", "url": False},
|
|
|
|
"ret_size": True,
|
2023-09-20 22:02:50 +03:00
|
|
|
},
|
2023-09-23 23:31:13 +03:00
|
|
|
"ISteamUGC_GetQueryUGCAdditionalPreview": {
|
|
|
|
"pchURLOrVideoID": {"len": "cchURLSize", "url": True},
|
2023-09-20 22:02:50 +03:00
|
|
|
},
|
2023-09-23 23:31:13 +03:00
|
|
|
"ISteamUGC_GetItemInstallInfo": {
|
|
|
|
"pchFolder": {"len": "cchFolderSize", "url": False},
|
2023-09-20 22:02:50 +03:00
|
|
|
},
|
2023-09-23 23:31:13 +03:00
|
|
|
"ISteamUser_GetUserDataFolder": {
|
|
|
|
"pchBuffer": {"len": "cubBuffer", "url": False},
|
2023-09-20 22:02:50 +03:00
|
|
|
},
|
2023-09-23 23:31:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PATH_CONV_METHODS_WTOU = {
|
|
|
|
"ISteamApps_GetFileDetails": {
|
|
|
|
"pszFileName": {"array": False, "url": False},
|
2023-09-20 22:02:50 +03:00
|
|
|
},
|
2023-09-23 23:31:13 +03:00
|
|
|
### ISteamGameServer::SetModDir - "Just the folder name, not the whole path. I.e. "Spacewar"."
|
|
|
|
"ISteamHTMLSurface_LoadURL": {
|
|
|
|
"pchURL": {"array": False, "url": True},
|
2023-09-20 22:02:50 +03:00
|
|
|
},
|
2023-09-23 23:31:13 +03:00
|
|
|
"ISteamHTMLSurface_FileLoadDialogResponse": {
|
|
|
|
"pchSelectedFiles": {"array": True, "url": False},
|
2023-09-20 22:02:50 +03:00
|
|
|
},
|
2023-09-23 23:31:13 +03:00
|
|
|
"ISteamRemoteStorage_PublishWorkshopFile": {
|
|
|
|
"pchFile": {"array": False, "url": False},
|
|
|
|
"pchPreviewFile": {"array": False, "url": False},
|
2023-09-20 22:02:50 +03:00
|
|
|
},
|
2023-09-23 23:31:13 +03:00
|
|
|
"ISteamRemoteStorage_UpdatePublishedFileFile": {
|
|
|
|
"pchFile": {"array": False, "url": False},
|
2023-09-20 22:02:50 +03:00
|
|
|
},
|
2023-09-23 23:31:13 +03:00
|
|
|
"ISteamRemoteStorage_UpdatePublishedFilePreviewFile": {
|
|
|
|
"pchPreviewFile": {"array": False, "url": False},
|
2023-09-20 22:02:50 +03:00
|
|
|
},
|
2023-09-23 23:31:13 +03:00
|
|
|
"ISteamRemoteStorage_PublishVideo": {
|
|
|
|
"pchPreviewFile": {"array": False, "url": False},
|
2023-09-20 22:02:50 +03:00
|
|
|
},
|
2023-09-23 23:31:13 +03:00
|
|
|
"ISteamScreenshots_AddScreenshotToLibrary": {
|
|
|
|
"pchFilename": {"array": False, "url": False},
|
|
|
|
"pchThumbnailFilename": {"array": False, "url": False},
|
2023-09-20 22:02:50 +03:00
|
|
|
},
|
2023-09-23 23:31:13 +03:00
|
|
|
"ISteamScreenshots_AddVRScreenshotToLibrary": {
|
|
|
|
"pchFilename": {"array": False, "url": False},
|
|
|
|
"pchVRFilename": {"array": False, "url": False},
|
2023-09-20 22:02:50 +03:00
|
|
|
},
|
2023-09-23 23:31:13 +03:00
|
|
|
"ISteamRemoteStorage_UGCDownloadToLocation": {
|
|
|
|
"pchLocation": {"array": False, "url": False},
|
2023-09-20 22:02:50 +03:00
|
|
|
},
|
2023-09-23 23:31:13 +03:00
|
|
|
"ISteamUGC_SetItemContent": {
|
|
|
|
"pszContentFolder": {"array": False, "url": False},
|
2023-09-20 22:02:50 +03:00
|
|
|
},
|
2023-09-23 23:31:13 +03:00
|
|
|
"ISteamUGC_SetItemPreview": {
|
|
|
|
"pszPreviewFile": {"array": False, "url": False},
|
2023-09-20 22:02:50 +03:00
|
|
|
},
|
2023-09-23 23:31:13 +03:00
|
|
|
"ISteamUGC_AddItemPreviewFile": {
|
|
|
|
"pszPreviewFile": {"array": False, "url": False},
|
2023-09-20 22:02:50 +03:00
|
|
|
},
|
2023-09-23 23:31:13 +03:00
|
|
|
"ISteamUGC_UpdateItemPreviewFile": {
|
|
|
|
"pszPreviewFile": {"array": False, "url": False},
|
2023-09-20 22:02:50 +03:00
|
|
|
},
|
2023-09-23 23:31:13 +03:00
|
|
|
"ISteamUGC_BInitWorkshopForGameServer": {
|
|
|
|
"pszFolder": {"array": False, "url": False},
|
2023-09-20 22:02:50 +03:00
|
|
|
},
|
2023-09-23 23:31:13 +03:00
|
|
|
"ISteamUtils_CheckFileSignature": {
|
|
|
|
"szFileName": {"array": False, "url": False},
|
2023-09-20 22:02:50 +03:00
|
|
|
},
|
2023-09-23 23:31:13 +03:00
|
|
|
"ISteamController_Init": {
|
|
|
|
"pchAbsolutePathToControllerConfigVDF": {"array": False, "url": False},
|
2023-09-20 22:02:50 +03:00
|
|
|
},
|
2023-09-23 23:31:13 +03:00
|
|
|
"ISteamInput_SetInputActionManifestFilePath": {
|
|
|
|
"pchInputActionManifestAbsolutePath": {"array": False, "url": False},
|
2023-09-20 22:02:50 +03:00
|
|
|
},
|
2023-09-23 23:31:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PATH_CONV_STRUCTS = {
|
|
|
|
"HTML_StartRequest_t": {
|
|
|
|
"pchURL": True,
|
2023-09-20 22:02:50 +03:00
|
|
|
},
|
2023-09-23 23:31:13 +03:00
|
|
|
"HTML_URLChanged_t": {
|
|
|
|
"pchURL": True,
|
2023-09-20 22:02:50 +03:00
|
|
|
},
|
2023-09-23 23:31:13 +03:00
|
|
|
"HTML_FinishedRequest_t": {
|
|
|
|
"pchURL": True,
|
2023-09-20 22:02:50 +03:00
|
|
|
},
|
2023-09-23 23:31:13 +03:00
|
|
|
"HTML_OpenLinkInNewTab_t": {
|
|
|
|
"pchURL": True,
|
2023-09-20 22:02:50 +03:00
|
|
|
},
|
2023-09-23 23:31:13 +03:00
|
|
|
"HTML_LinkAtPosition_t": {
|
|
|
|
"pchURL": True,
|
2023-09-20 22:02:50 +03:00
|
|
|
},
|
2023-09-23 23:31:13 +03:00
|
|
|
"HTML_FileOpenDialog_t": {
|
|
|
|
"pchInitialFile": True,
|
2023-09-20 22:02:50 +03:00
|
|
|
},
|
2023-09-23 23:31:13 +03:00
|
|
|
"HTML_NewWindow_t": {
|
|
|
|
"pchURL": True,
|
2023-09-20 22:02:50 +03:00
|
|
|
},
|
2023-09-23 23:31:13 +03:00
|
|
|
}
|
2018-11-20 20:10:12 +03:00
|
|
|
|
2023-09-21 20:39:53 +03:00
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
class Padding:
|
|
|
|
def __init__(self, offset, size):
|
|
|
|
self.offset = offset
|
|
|
|
self.size = size
|
|
|
|
|
|
|
|
|
|
|
|
class Field:
|
|
|
|
def __init__(self, cursor, struct, type, offset, name=None):
|
|
|
|
self._cursor = cursor
|
|
|
|
self._type = type
|
|
|
|
|
|
|
|
self.name = cursor.spelling if not name else name
|
|
|
|
self.type = cursor.type
|
|
|
|
self.size = self.type.get_size()
|
|
|
|
self.offset = offset
|
|
|
|
|
|
|
|
def needs_conversion(self, other):
|
|
|
|
return self._type.needs_conversion(other._type)
|
|
|
|
|
|
|
|
|
|
|
|
class BasicType:
|
|
|
|
def __init__(self, type, abi):
|
|
|
|
self._type = type.get_canonical()
|
|
|
|
self._abi = abi
|
2023-09-29 10:58:05 +03:00
|
|
|
self._decl_order = 0
|
|
|
|
self._conv_cache = {}
|
|
|
|
|
|
|
|
self.size = self._type.get_size()
|
|
|
|
self.id = self._type.spelling
|
|
|
|
|
|
|
|
@property
|
|
|
|
def order(self):
|
|
|
|
return self._decl_order
|
|
|
|
|
|
|
|
def set_used(self, order=-1):
|
|
|
|
if self._decl_order <= order:
|
|
|
|
return
|
|
|
|
self._decl_order = order
|
2023-09-20 18:27:42 +03:00
|
|
|
|
|
|
|
def needs_conversion(self, other):
|
2023-09-29 10:58:05 +03:00
|
|
|
if self._type.kind == TypeKind.POINTER and self._type.get_pointee().kind == TypeKind.FUNCTIONPROTO:
|
|
|
|
return self._abi != other._abi
|
2023-09-20 18:27:42 +03:00
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
class Struct:
|
|
|
|
def __init__(self, sdkver, abi, cursor):
|
|
|
|
self._cursor = cursor
|
|
|
|
self._sdkver = sdkver
|
|
|
|
self._abi = abi
|
|
|
|
self._fields = None
|
2023-09-29 10:58:05 +03:00
|
|
|
self._decl_order = 0
|
2023-09-16 20:24:46 +03:00
|
|
|
self._conv_cache = {}
|
2023-09-20 18:27:42 +03:00
|
|
|
|
|
|
|
self.name = canonical_typename(self._cursor)
|
|
|
|
self.type = self._cursor.type.get_canonical()
|
|
|
|
self.size = self.type.get_size()
|
|
|
|
self.align = self.type.get_align()
|
2023-09-16 20:24:46 +03:00
|
|
|
self.id = f'{abi}_{self.name}_{sdkver}'
|
2023-09-20 18:27:42 +03:00
|
|
|
|
|
|
|
if self.name in EXEMPT_STRUCTS:
|
|
|
|
self._fields = [Padding(0, self.size)]
|
|
|
|
|
2023-09-29 10:58:05 +03:00
|
|
|
@property
|
|
|
|
def order(self):
|
|
|
|
return self._decl_order
|
|
|
|
|
|
|
|
def set_used(self, order=-1):
|
|
|
|
if self._decl_order <= order:
|
|
|
|
return
|
|
|
|
self._decl_order = order
|
|
|
|
[f._type.set_used(order - 1) for f in self.fields]
|
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
@property
|
|
|
|
def padded_fields(self):
|
|
|
|
if self._fields: return self._fields
|
|
|
|
|
|
|
|
size, self._fields = 0, []
|
|
|
|
for cursor in self._cursor.get_children():
|
|
|
|
if cursor.kind == CursorKind.CXX_BASE_SPECIFIER \
|
|
|
|
and len(list(cursor.type.get_fields())) > 0:
|
|
|
|
base_type = Type(cursor.type, self._sdkver, self._abi)
|
|
|
|
self._fields += base_type.padded_fields
|
|
|
|
size = cursor.type.get_size()
|
|
|
|
break
|
|
|
|
|
|
|
|
for cursor in self.type.get_fields():
|
|
|
|
assert not cursor.is_bitfield()
|
|
|
|
offset = self.type.get_offset(cursor.spelling)
|
|
|
|
assert offset % 8 == 0
|
|
|
|
offset = offset // 8
|
|
|
|
# assert offset >= size or type(self) is Union
|
|
|
|
|
|
|
|
if size < offset: self._fields.append(Padding(size, offset - size))
|
|
|
|
field_type = Type(cursor.type, self._sdkver, self._abi)
|
|
|
|
self._fields.append(Field(cursor, self, field_type, offset))
|
|
|
|
size = max(size, offset + cursor.type.get_size())
|
|
|
|
|
|
|
|
if size < self.size: self._fields.append(Padding(size, self.size - size))
|
|
|
|
return self._fields
|
|
|
|
|
|
|
|
@property
|
|
|
|
def fields(self):
|
|
|
|
return [f for f in self.padded_fields if type(f) is not Padding]
|
|
|
|
|
2023-09-28 23:22:25 +03:00
|
|
|
def write_definition(self, out, prefix, converters):
|
2023-09-24 00:51:24 +03:00
|
|
|
version = all_versions[sdkver][self.name]
|
|
|
|
kind = 'union' if type(self) is Union else 'struct'
|
|
|
|
wrapped = len(prefix) > 0
|
|
|
|
|
|
|
|
out(f'#pragma pack( push, {self.align} )\n')
|
|
|
|
out(f'{kind} {prefix}{version}\n')
|
|
|
|
out(u'{\n')
|
|
|
|
for f in self.padded_fields:
|
|
|
|
if type(f) is Field:
|
|
|
|
out(f' {declspec(f._cursor, f.name, prefix, wrapped)};\n')
|
|
|
|
else:
|
|
|
|
out(f' uint8_t __pad_{f.offset}[{f.size}];\n')
|
2023-09-28 23:22:25 +03:00
|
|
|
for conv in converters:
|
|
|
|
out(u'#ifdef __cplusplus\n')
|
|
|
|
out(f' operator {conv}{version}() const;\n')
|
|
|
|
out(u'#endif /* __cplusplus */\n')
|
2023-09-24 00:51:24 +03:00
|
|
|
out(u'};\n')
|
|
|
|
out(u'#pragma pack( pop )\n\n')
|
|
|
|
|
|
|
|
def write_checks(self, out, prefix):
|
|
|
|
version = all_versions[sdkver][self.name]
|
|
|
|
|
|
|
|
out(f'C_ASSERT( sizeof({prefix}{version}) >= {self.size} );\n')
|
|
|
|
for f in self.fields:
|
|
|
|
out(f'C_ASSERT( offsetof({prefix}{version}, {f.name}) == {f.offset} );\n')
|
|
|
|
out(f'C_ASSERT( sizeof({prefix}{version}().{f.name}) >= {f.size} );\n')
|
|
|
|
out(u'\n')
|
|
|
|
|
2023-09-28 23:22:25 +03:00
|
|
|
def write_converter(self, prefix, path_conv_fields):
|
|
|
|
version = all_versions[sdkver][self.name]
|
|
|
|
out(f'{self._abi}_{version}::operator {prefix}{version}() const\n')
|
|
|
|
out(u'{\n')
|
|
|
|
out(f' {prefix}{version} ret;\n')
|
|
|
|
for field in self.fields:
|
|
|
|
if field.name not in path_conv_fields:
|
|
|
|
out(f' ret.{field.name} = this->{field.name};\n')
|
|
|
|
else:
|
|
|
|
out(f' steamclient_unix_path_to_dos_path(1, this->{field.name}, g_tmppath, sizeof(g_tmppath), 1);\n')
|
|
|
|
out(f' ret.{field.name} = g_tmppath;\n')
|
|
|
|
out(u' return ret;\n')
|
|
|
|
out(u'}\n')
|
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
def needs_conversion(self, other):
|
2023-09-16 20:24:46 +03:00
|
|
|
if other.id in self._conv_cache:
|
|
|
|
return self._conv_cache[other.id]
|
|
|
|
self._conv_cache[other.id] = other._conv_cache[self.id] = True
|
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
if self.name in PATH_CONV_STRUCTS and self._abi[0] != other._abi[0]:
|
|
|
|
return True
|
|
|
|
if self.name in SIZED_STRUCTS and self.size != other.size:
|
|
|
|
return True
|
|
|
|
if len(self.fields) != len(other.fields):
|
|
|
|
return True
|
|
|
|
if any([a.offset != b.offset or a.needs_conversion(b)
|
|
|
|
for a, b in zip(self.fields, other.fields)]):
|
|
|
|
return True
|
|
|
|
|
2023-09-16 20:24:46 +03:00
|
|
|
self._conv_cache[other.id] = other._conv_cache[self.id] = False
|
2023-09-20 18:27:42 +03:00
|
|
|
return False
|
|
|
|
|
|
|
|
def get_children(self):
|
|
|
|
return self._cursor.get_children()
|
|
|
|
|
|
|
|
|
|
|
|
class Union(Struct):
|
|
|
|
def __init__(self, sdkver, abi, cursor):
|
|
|
|
super().__init__(sdkver, abi, cursor)
|
|
|
|
|
|
|
|
def needs_conversion(self, other):
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2023-09-23 21:31:45 +03:00
|
|
|
class Method:
|
|
|
|
def __init__(self, sdkver, abi, cursor, index, override):
|
|
|
|
self._sdkver = sdkver
|
|
|
|
self._abi = abi
|
|
|
|
|
|
|
|
self._cursor = cursor
|
|
|
|
self._index = index
|
|
|
|
self._override = override
|
|
|
|
|
|
|
|
self.result_type = cursor.result_type
|
|
|
|
self.spelling = cursor.spelling
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
if self._override > 1: return f'{self.spelling}_{self._override}'
|
|
|
|
return self.spelling
|
|
|
|
|
|
|
|
def get_arguments(self):
|
|
|
|
return self._cursor.get_arguments()
|
|
|
|
|
|
|
|
def get_children(self):
|
|
|
|
return self._cursor.get_children()
|
|
|
|
|
|
|
|
|
|
|
|
class Destructor(Method):
|
|
|
|
def __init__(self, sdkver, abi, cursor, index, override):
|
|
|
|
super().__init__(sdkver, abi, cursor, index, override)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
if self._override > 1: return f'destructor_{self._override}'
|
|
|
|
return 'destructor'
|
|
|
|
|
|
|
|
|
2023-09-23 20:44:47 +03:00
|
|
|
class Class:
|
|
|
|
def __init__(self, sdkver, abi, cursor):
|
2023-09-20 18:27:42 +03:00
|
|
|
self._cursor = cursor
|
2023-09-23 20:44:47 +03:00
|
|
|
self._sdkver = sdkver
|
|
|
|
self._abi = abi
|
2023-09-20 18:27:42 +03:00
|
|
|
self._methods = None
|
2023-09-29 10:58:05 +03:00
|
|
|
self._decl_order = 0
|
2023-09-23 20:44:47 +03:00
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
self.name = cursor.spelling
|
|
|
|
self.filename = SDK_CLASSES.get(self.name, None)
|
|
|
|
versions = all_versions[sdkver]
|
|
|
|
self.version = self.name[1:].upper()
|
|
|
|
self.version = versions.get(self.version, "")
|
2023-09-23 20:44:47 +03:00
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
self.type = self._cursor.type.get_canonical()
|
2023-09-29 10:58:05 +03:00
|
|
|
self.id = f'{abi}_{self.name}_{sdkver}'
|
2023-09-23 21:31:45 +03:00
|
|
|
|
|
|
|
@property
|
|
|
|
def methods(self):
|
|
|
|
if self._methods:
|
|
|
|
return self._methods
|
|
|
|
|
|
|
|
overrides = {}
|
|
|
|
is_method = lambda c: c.kind == CursorKind.CXX_METHOD and c.is_virtual_method()
|
|
|
|
in_vtable = lambda c: is_method(c) or c.kind == CursorKind.DESTRUCTOR
|
|
|
|
|
|
|
|
self._methods = []
|
|
|
|
for i, method in enumerate(filter(in_vtable, self._cursor.get_children())):
|
|
|
|
index, override = overrides.get(method.spelling, (i, 1))
|
|
|
|
overrides[method.spelling] = (index, override + 1)
|
|
|
|
if method.kind == CursorKind.DESTRUCTOR:
|
|
|
|
self._methods.append(Destructor(self._sdkver, self._abi, method, index, override))
|
|
|
|
else:
|
|
|
|
self._methods.append(Method(self._sdkver, self._abi, method, index, override))
|
|
|
|
|
|
|
|
return self._methods
|
|
|
|
|
2023-09-24 00:44:45 +03:00
|
|
|
@property
|
|
|
|
def full_name(self):
|
2023-09-20 18:27:42 +03:00
|
|
|
if len(self.version) == 0:
|
|
|
|
return self.name
|
|
|
|
return f'{self.name}_{self.version}'
|
|
|
|
|
2023-09-29 10:58:05 +03:00
|
|
|
@property
|
|
|
|
def order(self):
|
|
|
|
return self._decl_order
|
|
|
|
|
|
|
|
def set_used(self, order=-1):
|
|
|
|
if self._decl_order <= order:
|
|
|
|
return
|
|
|
|
self._decl_order = order
|
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
def needs_conversion(self, other):
|
|
|
|
return self._abi[0] != other._abi[0]
|
2023-09-24 00:44:45 +03:00
|
|
|
|
|
|
|
def write_definition(self, out, prefix):
|
|
|
|
out(f'struct {prefix}{self.full_name}\n')
|
|
|
|
out(u'{\n')
|
|
|
|
out(u'#ifdef __cplusplus\n')
|
|
|
|
for method in self.methods:
|
2023-09-30 15:02:30 +03:00
|
|
|
types = [declspec(p, "", prefix) for p in method.get_arguments()]
|
2023-09-28 20:02:26 +03:00
|
|
|
|
|
|
|
# CGameID -> CGameID &
|
|
|
|
# Windows side follows the prototype in the header while Linux
|
|
|
|
# steamclient treats gameID parameter as pointer
|
|
|
|
if self.full_name == 'ISteamUser_SteamUser008' \
|
|
|
|
and method.name == 'InitiateGameConnection':
|
|
|
|
types[3] = 'CGameID *'
|
|
|
|
|
2023-09-24 00:44:45 +03:00
|
|
|
if type(method) is Destructor:
|
|
|
|
out(f' virtual ~{prefix}{self.full_name}( {", ".join(types)} ) = 0;\n')
|
|
|
|
else:
|
2023-09-30 15:02:30 +03:00
|
|
|
method_name = f'{declspec(method.result_type, "", prefix)} {method.spelling}'
|
2023-09-24 00:44:45 +03:00
|
|
|
out(f' virtual {method_name}( {", ".join(types)} ) = 0;\n')
|
|
|
|
out(u'#endif /* __cplusplus */\n')
|
|
|
|
out(u'};\n\n')
|
|
|
|
|
2023-09-23 20:44:47 +03:00
|
|
|
def get_children(self):
|
|
|
|
return self._cursor.get_children()
|
|
|
|
|
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
def Record(sdkver, abi, cursor):
|
|
|
|
if cursor.type.get_declaration().kind == CursorKind.UNION_DECL:
|
|
|
|
return Union(sdkver, abi, cursor)
|
|
|
|
|
|
|
|
method_kinds = (CursorKind.CXX_METHOD, CursorKind.DESTRUCTOR)
|
|
|
|
is_method = lambda c: c.kind in method_kinds and c.is_virtual_method()
|
|
|
|
for _ in filter(is_method, cursor.get_children()):
|
|
|
|
return Class(sdkver, abi, cursor)
|
|
|
|
|
|
|
|
return Struct(sdkver, abi, cursor)
|
|
|
|
|
|
|
|
|
|
|
|
def Type(decl, sdkver, abi):
|
|
|
|
name = canonical_typename(decl)
|
|
|
|
if name not in all_structs:
|
|
|
|
return BasicType(decl, abi)
|
|
|
|
return all_structs[name][sdkver][abi]
|
|
|
|
|
|
|
|
|
2023-09-21 20:39:53 +03:00
|
|
|
def canonical_typename(cursor):
|
2023-09-20 18:27:42 +03:00
|
|
|
if type(cursor) in (Struct, Class, Cursor):
|
2023-09-21 20:39:53 +03:00
|
|
|
return canonical_typename(cursor.type)
|
|
|
|
|
|
|
|
name = cursor.get_canonical().spelling
|
|
|
|
return name.removeprefix("const ")
|
|
|
|
|
2018-10-29 19:21:49 +03:00
|
|
|
|
2023-09-27 15:09:21 +03:00
|
|
|
def underlying_typename(decl):
|
|
|
|
return canonical_typename(underlying_type(decl))
|
|
|
|
|
|
|
|
|
2023-09-21 23:13:09 +03:00
|
|
|
def find_struct_abis(name):
|
2023-09-20 18:27:42 +03:00
|
|
|
if not name in all_structs:
|
|
|
|
return None
|
|
|
|
structs = all_structs[name]
|
|
|
|
if not sdkver in structs:
|
|
|
|
return None
|
|
|
|
return structs[sdkver]
|
2018-10-30 16:09:46 +03:00
|
|
|
|
2019-06-13 17:12:28 +03:00
|
|
|
|
2023-09-16 20:24:46 +03:00
|
|
|
def struct_needs_conversion(struct):
|
2023-09-21 20:39:53 +03:00
|
|
|
name = canonical_typename(struct)
|
|
|
|
if name in EXEMPT_STRUCTS:
|
2018-10-30 16:09:46 +03:00
|
|
|
return False
|
2023-09-21 20:39:53 +03:00
|
|
|
if name in MANUAL_STRUCTS:
|
2019-05-16 19:23:30 +03:00
|
|
|
return True
|
2023-09-20 18:27:42 +03:00
|
|
|
if name in PATH_CONV_STRUCTS:
|
2023-09-21 23:13:09 +03:00
|
|
|
return True
|
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
abis = find_struct_abis(name)
|
|
|
|
if abis is None: return False
|
|
|
|
if abis['w32'].needs_conversion(abis['u32']):
|
2023-09-21 23:13:09 +03:00
|
|
|
return True
|
2023-09-20 18:27:42 +03:00
|
|
|
if abis['w64'].needs_conversion(abis['u64']):
|
2018-11-20 20:10:12 +03:00
|
|
|
return True
|
2018-10-30 16:09:46 +03:00
|
|
|
return False
|
|
|
|
|
2023-09-21 23:13:09 +03:00
|
|
|
|
2023-09-23 17:11:42 +03:00
|
|
|
def underlying_type(decl):
|
|
|
|
if type(decl) is Cursor:
|
|
|
|
decl = decl.type
|
|
|
|
if decl.kind == TypeKind.LVALUEREFERENCE: return underlying_type(decl.get_pointee())
|
|
|
|
if decl.kind == TypeKind.CONSTANTARRAY: return underlying_type(decl.element_type)
|
|
|
|
if decl.kind == TypeKind.POINTER: return underlying_type(decl.get_pointee())
|
|
|
|
return decl
|
|
|
|
|
|
|
|
|
2022-10-22 18:28:35 +03:00
|
|
|
def param_needs_conversion(decl):
|
2023-09-23 17:11:42 +03:00
|
|
|
decl = underlying_type(decl)
|
2022-10-22 18:28:35 +03:00
|
|
|
return decl.spelling not in WRAPPED_CLASSES and \
|
|
|
|
decl.kind == TypeKind.RECORD and \
|
|
|
|
struct_needs_conversion(decl)
|
|
|
|
|
|
|
|
|
2023-09-24 00:44:45 +03:00
|
|
|
def callconv(cursor, prefix):
|
2023-09-30 15:02:30 +03:00
|
|
|
if type(cursor) is not Cursor:
|
2023-09-19 22:24:23 +03:00
|
|
|
return ''
|
|
|
|
canon = cursor.type.get_canonical()
|
|
|
|
if canon.kind != TypeKind.POINTER:
|
|
|
|
return ''
|
|
|
|
canon = canon.get_pointee()
|
|
|
|
if canon.kind != TypeKind.FUNCTIONPROTO:
|
|
|
|
return ''
|
|
|
|
if cursor.type.kind == TypeKind.TYPEDEF:
|
|
|
|
cursor = cursor.type.get_declaration()
|
|
|
|
|
|
|
|
tokens = cursor.get_tokens()
|
|
|
|
while next(tokens).spelling != '(': pass
|
2023-09-19 22:30:14 +03:00
|
|
|
token = next(tokens).spelling.strip('_')
|
|
|
|
token = token.replace('*', 'stdcall')
|
|
|
|
token = token.replace('S_CALLTYPE', 'cdecl')
|
|
|
|
return f'{prefix[0].upper()}_{token.upper()} '
|
2023-09-19 22:24:23 +03:00
|
|
|
|
|
|
|
|
2023-09-24 00:44:45 +03:00
|
|
|
def declspec_func(decl, name, prefix):
|
2023-09-24 00:51:24 +03:00
|
|
|
ret = declspec(decl.get_result(), "", prefix, False)
|
|
|
|
params = [declspec(a, "", prefix, False) for a in decl.argument_types()]
|
2023-09-19 22:24:23 +03:00
|
|
|
params = ", ".join(params) if len(params) else "void"
|
|
|
|
return f'{ret} ({name})({params})'
|
|
|
|
|
|
|
|
|
2023-09-24 00:51:24 +03:00
|
|
|
def declspec(decl, name, prefix, wrapped=False):
|
2023-09-24 00:44:45 +03:00
|
|
|
call = callconv(decl, prefix)
|
2022-10-22 18:28:35 +03:00
|
|
|
if type(decl) is Cursor:
|
|
|
|
decl = decl.type
|
2023-09-19 20:59:23 +03:00
|
|
|
decl = decl.get_canonical()
|
2022-10-22 18:28:35 +03:00
|
|
|
|
|
|
|
const = 'const ' if decl.is_const_qualified() else ''
|
2023-09-19 20:59:23 +03:00
|
|
|
if decl.kind == TypeKind.FUNCTIONPROTO:
|
2023-09-24 00:44:45 +03:00
|
|
|
return declspec_func(decl, name, prefix)
|
2022-10-22 18:28:35 +03:00
|
|
|
if decl.kind in (TypeKind.POINTER, TypeKind.LVALUEREFERENCE):
|
|
|
|
decl = decl.get_pointee()
|
2023-09-24 00:51:24 +03:00
|
|
|
spec = declspec(decl, f"*{call}{const}{name}", prefix, False)
|
|
|
|
if wrapped:
|
|
|
|
return f'{prefix.upper()}PTR({spec}, {name})'
|
|
|
|
return spec
|
2022-10-22 18:28:35 +03:00
|
|
|
if decl.kind == TypeKind.CONSTANTARRAY:
|
|
|
|
decl, count = decl.element_type, decl.element_count
|
2023-09-24 00:51:24 +03:00
|
|
|
if wrapped:
|
|
|
|
spec = declspec(decl, const, prefix, False)
|
|
|
|
return f'{prefix.upper()}ARRAY({spec}, {count}, {name})'
|
|
|
|
return declspec(decl, f"({const}{name})[{count}]", prefix, False)
|
2022-10-22 18:28:35 +03:00
|
|
|
|
|
|
|
if len(name):
|
|
|
|
name = f' {name}'
|
|
|
|
|
|
|
|
if decl.kind in (TypeKind.UNEXPOSED, TypeKind.FUNCTIONPROTO):
|
|
|
|
return f'void{name}'
|
|
|
|
if decl.kind == TypeKind.ENUM:
|
2023-09-14 17:22:47 +03:00
|
|
|
return f'uint{decl.get_size() * 8}_t{name}'
|
2022-10-22 18:28:35 +03:00
|
|
|
|
2023-09-14 15:53:26 +03:00
|
|
|
type_name = decl.spelling.removeprefix("const ")
|
2023-09-30 15:02:30 +03:00
|
|
|
if decl.kind == TypeKind.RECORD \
|
2023-09-24 00:51:24 +03:00
|
|
|
and type_name in all_versions[sdkver] \
|
|
|
|
and type_name not in EXEMPT_STRUCTS:
|
|
|
|
if type_name in unique_structs:
|
|
|
|
return f'{const}{all_versions[sdkver][type_name]}{name}'
|
|
|
|
return f'{const}{prefix}{all_versions[sdkver][type_name]}{name}'
|
|
|
|
|
2023-09-23 23:07:08 +03:00
|
|
|
if type_name.startswith('ISteam'):
|
|
|
|
return f'{const}void /*{type_name}*/{name}'
|
2023-09-14 15:53:26 +03:00
|
|
|
if type_name in ('void', 'bool', 'char', 'float', 'double'):
|
|
|
|
return f'{const}{type_name}{name}'
|
|
|
|
if type_name.startswith(('int', 'long', 'short', 'signed')):
|
|
|
|
return f'{const}int{decl.get_size() * 8}_t{name}'
|
|
|
|
if type_name.startswith(('uint', 'unsigned')):
|
|
|
|
return f'{const}uint{decl.get_size() * 8}_t{name}'
|
2023-09-23 23:07:08 +03:00
|
|
|
|
2023-09-24 00:51:24 +03:00
|
|
|
if 'unnamed union' in decl.spelling:
|
|
|
|
return f'{const}struct {{ uint8_t _[{decl.get_size()}]; }}{name}'
|
2022-10-22 18:28:35 +03:00
|
|
|
return f'{decl.spelling}{name}'
|
|
|
|
|
|
|
|
|
2023-09-23 23:57:23 +03:00
|
|
|
def handle_method_hpp(method, cppname, out):
|
2023-09-27 15:34:23 +03:00
|
|
|
returns_record = method.result_type.get_canonical().kind == TypeKind.RECORD
|
2022-10-22 18:28:35 +03:00
|
|
|
|
2023-09-27 15:34:23 +03:00
|
|
|
ret = "*_ret" if returns_record else "_ret"
|
2023-09-30 15:02:30 +03:00
|
|
|
ret = f'{declspec(method.result_type, ret, "w_")}'
|
2022-10-22 18:28:35 +03:00
|
|
|
|
2023-09-27 15:34:23 +03:00
|
|
|
names = [p.spelling if p.spelling != "" else f'_{chr(0x61 + i)}'
|
|
|
|
for i, p in enumerate(method.get_arguments())]
|
2023-09-30 15:02:30 +03:00
|
|
|
params = [declspec(p, names[i], "w_") for i, p in enumerate(method.get_arguments())]
|
2023-09-27 15:34:23 +03:00
|
|
|
|
|
|
|
if method.result_type.kind != TypeKind.VOID:
|
|
|
|
params = [ret] + params
|
|
|
|
params = ['void *linux_side'] + params
|
|
|
|
|
|
|
|
out(f'struct {cppname}_{method.name}_params\n')
|
|
|
|
out(u'{\n')
|
|
|
|
for param in params:
|
|
|
|
out(f' {param};\n')
|
|
|
|
out(u'};\n')
|
|
|
|
out(f'extern void {cppname}_{method.name}( struct {cppname}_{method.name}_params *params );\n\n')
|
2022-10-22 18:28:35 +03:00
|
|
|
|
|
|
|
|
2023-09-23 23:57:23 +03:00
|
|
|
def handle_method_cpp(method, classname, cppname, out):
|
2023-09-23 22:44:20 +03:00
|
|
|
returns_void = method.result_type.kind == TypeKind.VOID
|
2023-09-27 15:34:23 +03:00
|
|
|
returns_record = method.result_type.get_canonical().kind == TypeKind.RECORD
|
2018-10-29 19:21:49 +03:00
|
|
|
|
2023-09-23 17:11:42 +03:00
|
|
|
names = [p.spelling if p.spelling != "" else f'_{chr(0x61 + i)}'
|
|
|
|
for i, p in enumerate(method.get_arguments())]
|
2021-11-12 22:13:03 +03:00
|
|
|
|
2023-09-23 17:29:04 +03:00
|
|
|
need_convert = {n: p for n, p in zip(names, method.get_arguments())
|
|
|
|
if param_needs_conversion(p)}
|
2023-09-29 12:03:44 +03:00
|
|
|
need_wrapper = {n: p for n, p in zip(names, method.get_arguments())
|
|
|
|
if underlying_typename(p) in WRAPPED_CLASSES}
|
2023-09-23 17:29:04 +03:00
|
|
|
manual_convert = {n: p for n, p in zip(names, method.get_arguments())
|
|
|
|
if underlying_type(p).spelling in MANUAL_TYPES
|
|
|
|
or p.spelling in MANUAL_PARAMS}
|
|
|
|
|
2023-09-23 17:11:42 +03:00
|
|
|
names = ['linux_side'] + names
|
|
|
|
|
2023-09-27 15:34:23 +03:00
|
|
|
out(f'void {cppname}_{method.name}( struct {cppname}_{method.name}_params *params )\n')
|
2023-09-23 23:57:23 +03:00
|
|
|
out(u'{\n')
|
2023-09-30 15:02:30 +03:00
|
|
|
out(f' struct u_{klass.full_name} *iface = (struct u_{klass.full_name} *)params->linux_side;\n')
|
2023-09-23 17:11:42 +03:00
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
params = list(zip(names[1:], method.get_arguments()))
|
|
|
|
for i, (name, param) in enumerate(params[:-1]):
|
|
|
|
if underlying_type(param).kind != TypeKind.RECORD:
|
|
|
|
continue
|
|
|
|
next_name, next_param = params[i + 1]
|
|
|
|
if not any(w in next_name.lower() for w in ('count', 'len', 'size', 'num')):
|
|
|
|
continue
|
|
|
|
assert underlying_typename(param) in SIZED_STRUCTS | EXEMPT_STRUCTS
|
|
|
|
|
|
|
|
for i, (name, param) in enumerate(params[1:]):
|
|
|
|
if underlying_type(param).kind != TypeKind.RECORD:
|
|
|
|
continue
|
|
|
|
prev_name, prev_param = params[i - 1]
|
|
|
|
if not any(w in prev_name.lower() for w in ('count', 'len', 'size', 'num')):
|
|
|
|
continue
|
|
|
|
if underlying_typename(param) not in SIZED_STRUCTS | EXEMPT_STRUCTS:
|
|
|
|
print('Warning:', underlying_typename(param), name, 'following', prev_name)
|
|
|
|
|
2023-09-27 15:09:21 +03:00
|
|
|
need_output = {}
|
|
|
|
|
2023-09-23 17:29:04 +03:00
|
|
|
for name, param in sorted(need_convert.items()):
|
2023-09-27 15:09:21 +03:00
|
|
|
if param.type.kind != TypeKind.POINTER:
|
2023-09-30 15:02:30 +03:00
|
|
|
out(f' {declspec(param.type, f"u_{name}", "u_")} = params->{name};\n')
|
2023-09-27 15:09:21 +03:00
|
|
|
continue
|
|
|
|
|
|
|
|
pointee = param.type.get_pointee()
|
|
|
|
if pointee.kind == TypeKind.POINTER:
|
|
|
|
need_output[name] = param
|
2023-09-30 15:02:30 +03:00
|
|
|
out(f' {declspec(pointee, f"lin_{name}", "u_")};\n')
|
2023-09-27 15:09:21 +03:00
|
|
|
continue
|
|
|
|
|
|
|
|
if not pointee.is_const_qualified():
|
|
|
|
need_output[name] = param
|
|
|
|
|
2023-09-30 15:02:30 +03:00
|
|
|
out(f' {declspec(pointee, f"u_{name}", "u_")} = *params->{name};\n')
|
2023-09-23 17:29:04 +03:00
|
|
|
|
|
|
|
for name, param in sorted(manual_convert.items()):
|
|
|
|
if name in MANUAL_PARAMS:
|
2023-09-30 15:02:30 +03:00
|
|
|
out(f' {declspec(param, f"u_{name}", "u_")} = manual_convert_{name}( params->{name} );\n')
|
2019-06-17 18:50:11 +03:00
|
|
|
else:
|
2023-09-30 15:02:30 +03:00
|
|
|
out(f' {declspec(param, f"u_{name}", "u_")} = manual_convert_{method.name}_{name}( params->{name} );\n')
|
2018-01-18 19:24:05 +03:00
|
|
|
|
2023-09-29 12:03:44 +03:00
|
|
|
for name, param in sorted(need_wrapper.items()):
|
2023-09-30 15:02:30 +03:00
|
|
|
out(f' {declspec(param, f"u_{name}", "u_")} = create_Linux{underlying_type(param.type).spelling}( params->{name}, "{classname}_{klass.version}" );\n')
|
2023-09-29 12:03:44 +03:00
|
|
|
|
2023-09-23 22:44:20 +03:00
|
|
|
if returns_void:
|
2023-09-23 23:57:23 +03:00
|
|
|
out(u' ')
|
2023-09-27 15:34:23 +03:00
|
|
|
elif returns_record:
|
|
|
|
out(u' *params->_ret = ')
|
2018-10-29 19:21:49 +03:00
|
|
|
else:
|
2023-09-27 15:34:23 +03:00
|
|
|
out(u' params->_ret = ')
|
2023-08-25 05:42:23 +03:00
|
|
|
|
2023-09-23 17:29:04 +03:00
|
|
|
def param_call(name, param):
|
|
|
|
pfx = '&' if param.type.kind == TypeKind.POINTER else ''
|
2023-09-30 15:02:30 +03:00
|
|
|
if name in need_convert: return f"{pfx}u_{name}"
|
|
|
|
if name in manual_convert: return f"u_{name}"
|
|
|
|
if name in need_wrapper: return f"u_{name}"
|
2023-09-24 00:44:45 +03:00
|
|
|
return f'params->{name}'
|
2023-08-25 05:42:23 +03:00
|
|
|
|
2023-09-23 17:29:04 +03:00
|
|
|
params = [param_call(n, p) for n, p in zip(names[1:], method.get_arguments())]
|
2023-09-28 20:02:26 +03:00
|
|
|
|
|
|
|
# CGameID -> CGameID &
|
|
|
|
# Windows side follows the prototype in the header while Linux
|
|
|
|
# steamclient treats gameID parameter as pointer
|
|
|
|
if klass.full_name == 'ISteamUser_SteamUser008' \
|
|
|
|
and method.name == 'InitiateGameConnection':
|
|
|
|
params[3] = f'&{params[3]}'
|
|
|
|
|
2023-09-24 00:44:45 +03:00
|
|
|
out(f'iface->{method.spelling}( {", ".join(params)} );\n')
|
2023-09-23 17:29:04 +03:00
|
|
|
|
2023-09-27 15:09:21 +03:00
|
|
|
for name, param in sorted(need_output.items()):
|
2023-09-30 15:02:30 +03:00
|
|
|
out(f' *params->{name} = u_{name};\n')
|
2023-09-23 22:44:20 +03:00
|
|
|
|
|
|
|
if method.result_type.kind != TypeKind.VOID:
|
|
|
|
post_exec = post_execution_function(classname, method.spelling)
|
2023-09-27 15:34:23 +03:00
|
|
|
if post_exec: out(f' params->_ret = {post_exec}( params->_ret );\n')
|
2023-09-23 23:57:23 +03:00
|
|
|
out(u'}\n\n')
|
2023-09-22 01:06:40 +03:00
|
|
|
|
|
|
|
|
2023-09-23 23:57:23 +03:00
|
|
|
def handle_thiscall_wrapper(klass, method, out):
|
2023-09-23 21:52:28 +03:00
|
|
|
returns_record = method.result_type.get_canonical().kind == TypeKind.RECORD
|
|
|
|
|
|
|
|
def param_stack_size(param):
|
|
|
|
if param.type.kind == TypeKind.LVALUEREFERENCE: return 4
|
|
|
|
return ((param.type.get_size() + 3) // 4) * 4
|
|
|
|
|
|
|
|
size = 4 + sum(param_stack_size(p) for p in method.get_arguments())
|
|
|
|
if returns_record: size += 4
|
|
|
|
|
2023-09-24 00:44:45 +03:00
|
|
|
name = f'win{klass.full_name}_{method.name}'
|
2023-09-23 23:57:23 +03:00
|
|
|
out(f'DEFINE_THISCALL_WRAPPER({name}, {size})\n')
|
2023-09-23 21:52:28 +03:00
|
|
|
|
|
|
|
|
2023-09-23 23:57:23 +03:00
|
|
|
def handle_method_c(method, winclassname, cppname, out):
|
2023-09-23 22:44:20 +03:00
|
|
|
returns_void = method.result_type.kind == TypeKind.VOID
|
2023-09-22 01:06:40 +03:00
|
|
|
returns_record = method.result_type.get_canonical().kind == TypeKind.RECORD
|
2023-09-23 21:54:51 +03:00
|
|
|
|
2023-09-23 23:07:08 +03:00
|
|
|
ret = "*" if returns_record else ""
|
2023-09-30 15:02:30 +03:00
|
|
|
ret = f'{declspec(method.result_type, ret, "w_")} '
|
2023-09-23 21:54:51 +03:00
|
|
|
|
|
|
|
names = [p.spelling if p.spelling != "" else f'_{chr(0x61 + i)}'
|
|
|
|
for i, p in enumerate(method.get_arguments())]
|
2023-09-30 15:02:30 +03:00
|
|
|
params = [declspec(p, names[i], "w_") for i, p in enumerate(method.get_arguments())]
|
2023-09-23 21:54:51 +03:00
|
|
|
|
2023-09-22 01:06:40 +03:00
|
|
|
if returns_record:
|
2023-09-30 15:02:30 +03:00
|
|
|
params = [f'{declspec(method.result_type, "*_ret", "w_")}'] + params
|
2023-09-23 22:44:20 +03:00
|
|
|
names = ['_ret'] + names
|
2023-09-23 21:54:51 +03:00
|
|
|
|
2023-09-24 15:50:45 +03:00
|
|
|
params = ['struct w_steam_iface *_this'] + params
|
2023-09-23 21:54:51 +03:00
|
|
|
names = ['_this'] + names
|
|
|
|
|
2023-09-23 23:57:23 +03:00
|
|
|
out(f'{ret}__thiscall {winclassname}_{method.name}({", ".join(params)})\n')
|
|
|
|
out(u'{\n')
|
2023-09-23 21:54:51 +03:00
|
|
|
|
2023-09-27 15:34:23 +03:00
|
|
|
out(f' struct {cppname}_{method.name}_params params =\n')
|
|
|
|
out(u' {\n')
|
|
|
|
out(u' .linux_side = _this->u_iface,\n')
|
2023-09-29 12:03:44 +03:00
|
|
|
for name in names[1:]: out(f' .{name} = {name},\n')
|
2023-09-27 15:34:23 +03:00
|
|
|
out(u' };\n')
|
2023-09-23 22:44:20 +03:00
|
|
|
|
2023-09-23 21:55:11 +03:00
|
|
|
should_gen_callback = "GetAPICallResult" in method.name
|
|
|
|
if should_gen_callback:
|
2023-09-27 15:34:23 +03:00
|
|
|
out(u' int w_callback_len = cubCallback;\n')
|
|
|
|
out(u' void *w_callback = pCallback;\n')
|
2023-09-23 21:55:11 +03:00
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
path_conv_utow = PATH_CONV_METHODS_UTOW.get(f'{klass.name}_{method.spelling}', {})
|
|
|
|
path_conv_wtou = PATH_CONV_METHODS_WTOU.get(f'{klass.name}_{method.spelling}', {})
|
2023-09-22 01:06:40 +03:00
|
|
|
|
2023-09-23 23:31:13 +03:00
|
|
|
for name, conv in filter(lambda x: x[0] in names, path_conv_wtou.items()):
|
|
|
|
if conv['array']:
|
2023-09-27 15:34:23 +03:00
|
|
|
out(f' params.{name} = steamclient_dos_to_unix_path_array( {name} );\n')
|
2023-09-23 23:31:13 +03:00
|
|
|
else:
|
2023-09-27 15:34:23 +03:00
|
|
|
out(f' params.{name} = steamclient_dos_to_unix_path( {name}, {int(conv["url"])} );\n')
|
2023-09-22 01:06:40 +03:00
|
|
|
|
2023-09-23 23:57:23 +03:00
|
|
|
out(u' TRACE("%p\\n", _this);\n')
|
2023-09-22 01:06:40 +03:00
|
|
|
|
2023-09-23 21:55:11 +03:00
|
|
|
if should_gen_callback:
|
2023-09-27 15:34:23 +03:00
|
|
|
out(u' if (!(params.pCallback = alloc_callback_wtou(iCallbackExpected, w_callback, ¶ms.cubCallback))) return FALSE;\n')
|
2023-09-23 21:55:11 +03:00
|
|
|
|
2023-09-27 15:34:23 +03:00
|
|
|
out(f' {cppname}_{method.name}( ¶ms );\n')
|
2023-09-22 01:06:40 +03:00
|
|
|
|
2023-09-23 21:31:45 +03:00
|
|
|
should_gen_wrapper = not method_needs_manual_handling(cppname, method.name) and \
|
2023-09-22 01:06:40 +03:00
|
|
|
(method.result_type.spelling.startswith("ISteam") or \
|
2023-09-23 21:31:45 +03:00
|
|
|
method.name.startswith("GetISteamGenericInterface"))
|
2023-09-23 21:55:11 +03:00
|
|
|
if should_gen_wrapper:
|
2023-09-27 15:34:23 +03:00
|
|
|
out(u' params._ret = create_win_interface( pchVersion, params._ret );\n')
|
2023-09-23 21:55:11 +03:00
|
|
|
|
|
|
|
if should_gen_callback:
|
2023-09-27 15:34:23 +03:00
|
|
|
out(u' if (params._ret && params.pCallback != w_callback)\n')
|
2023-09-23 23:57:23 +03:00
|
|
|
out(u' {\n')
|
2023-09-27 15:34:23 +03:00
|
|
|
out(u' convert_callback_utow(iCallbackExpected, params.pCallback, params.cubCallback, w_callback, w_callback_len);\n')
|
|
|
|
out(u' HeapFree(GetProcessHeap(), 0, params.pCallback);\n')
|
2023-09-23 23:57:23 +03:00
|
|
|
out(u' }\n\n')
|
2023-09-23 21:55:11 +03:00
|
|
|
|
2023-09-23 23:31:13 +03:00
|
|
|
for name, conv in filter(lambda x: x[0] in names, path_conv_utow.items()):
|
|
|
|
out(u' ')
|
|
|
|
if "ret_size" in path_conv_utow:
|
2023-09-27 15:34:23 +03:00
|
|
|
out(u'params._ret = ')
|
|
|
|
out(f'steamclient_unix_path_to_dos_path( params._ret, {name}, {name}, {conv["len"]}, {int(conv["url"])} );\n')
|
2023-09-23 23:31:13 +03:00
|
|
|
|
|
|
|
for name, conv in filter(lambda x: x[0] in names, path_conv_wtou.items()):
|
|
|
|
if conv["array"]:
|
2023-09-27 15:34:23 +03:00
|
|
|
out(f' steamclient_free_path_array( params.{name} );\n')
|
2023-09-24 11:19:52 +03:00
|
|
|
else:
|
2023-09-27 15:34:23 +03:00
|
|
|
out(f' steamclient_free_path( params.{name} );\n')
|
2023-09-23 22:44:20 +03:00
|
|
|
|
|
|
|
if not returns_void:
|
2023-09-27 15:34:23 +03:00
|
|
|
out(u' return params._ret;\n')
|
2023-09-23 23:57:23 +03:00
|
|
|
out(u'}\n\n')
|
2018-01-18 19:24:05 +03:00
|
|
|
|
2023-09-21 00:21:06 +03:00
|
|
|
|
2023-09-23 20:44:47 +03:00
|
|
|
def handle_class(klass):
|
2023-09-24 00:44:45 +03:00
|
|
|
cppname = f"cpp{klass.full_name}"
|
2023-09-24 00:11:56 +03:00
|
|
|
|
2023-09-24 12:11:25 +03:00
|
|
|
ext = "cpp"
|
|
|
|
for method in klass.methods:
|
|
|
|
if type(method) is Destructor:
|
|
|
|
continue
|
|
|
|
if method_needs_manual_handling(cppname, method.name):
|
|
|
|
ext = "hpp"
|
|
|
|
|
2023-09-24 00:11:56 +03:00
|
|
|
with open(f"{cppname}.h", "w") as file:
|
|
|
|
out = file.write
|
|
|
|
|
2023-09-30 15:02:30 +03:00
|
|
|
out(u'/* This file is auto-generated, do not edit. */\n')
|
|
|
|
out(u'#include <stdarg.h>\n')
|
|
|
|
out(u'#include <stddef.h>\n')
|
|
|
|
out(u'#include <stdint.h>\n')
|
|
|
|
out(u'\n')
|
|
|
|
out(u'#ifdef __cplusplus\n')
|
|
|
|
out(u'extern "C" {\n')
|
|
|
|
out(u'#endif /* __cplusplus */\n')
|
|
|
|
out(u'\n')
|
2023-09-24 00:44:45 +03:00
|
|
|
|
2023-09-24 00:11:56 +03:00
|
|
|
for method in klass.methods:
|
|
|
|
if type(method) is Destructor:
|
|
|
|
continue
|
|
|
|
handle_method_hpp(method, cppname, out)
|
|
|
|
|
2023-09-30 15:02:30 +03:00
|
|
|
out(u'#ifdef __cplusplus\n')
|
|
|
|
out(u'} /* extern "C" */\n')
|
|
|
|
out(u'#endif /* __cplusplus */\n')
|
|
|
|
|
2023-09-24 12:11:25 +03:00
|
|
|
with open(f"{cppname}.{ext}", "w") as file:
|
2023-09-24 00:11:56 +03:00
|
|
|
out = file.write
|
|
|
|
|
2023-09-30 15:02:30 +03:00
|
|
|
out(u'/* This file is auto-generated, do not edit. */\n')
|
|
|
|
out(u'#include "unix_private.h"\n')
|
2023-09-24 00:44:45 +03:00
|
|
|
out(f'#include "{cppname}.h"\n\n')
|
|
|
|
|
2023-09-30 15:02:30 +03:00
|
|
|
klass.write_definition(out, "u_")
|
2023-09-24 00:11:56 +03:00
|
|
|
|
|
|
|
for method in klass.methods:
|
|
|
|
if type(method) is Destructor:
|
|
|
|
continue
|
|
|
|
if method_needs_manual_handling(cppname, method.spelling):
|
|
|
|
continue
|
2023-09-20 18:27:42 +03:00
|
|
|
handle_method_cpp(method, klass.name, cppname, out)
|
2023-09-24 00:11:56 +03:00
|
|
|
|
|
|
|
|
2023-09-24 00:44:45 +03:00
|
|
|
winclassname = f"win{klass.full_name}"
|
2023-09-20 18:27:42 +03:00
|
|
|
with open(f"win{klass.name}.c", "a") as file:
|
2023-09-24 00:20:53 +03:00
|
|
|
out = file.write
|
2023-09-24 00:11:56 +03:00
|
|
|
|
2023-09-24 15:50:45 +03:00
|
|
|
out(f'#include "{cppname}.h"\n')
|
|
|
|
out(u'\n')
|
2019-02-26 18:05:29 +03:00
|
|
|
|
2023-09-24 00:20:53 +03:00
|
|
|
for method in klass.methods:
|
|
|
|
handle_thiscall_wrapper(klass, method, out)
|
|
|
|
out('\n')
|
2018-01-18 19:24:05 +03:00
|
|
|
|
2023-09-24 00:20:53 +03:00
|
|
|
for method in klass.methods:
|
|
|
|
if type(method) is Destructor:
|
2023-09-24 15:50:45 +03:00
|
|
|
out(f'void __thiscall {winclassname}_{method.name}(struct w_steam_iface *_this)\n{{/* never called */}}\n\n')
|
2023-09-24 00:20:53 +03:00
|
|
|
else:
|
|
|
|
handle_method_c(method, winclassname, cppname, out)
|
2018-01-18 19:24:05 +03:00
|
|
|
|
2023-09-24 00:20:53 +03:00
|
|
|
out(f'extern vtable_ptr {winclassname}_vtable;\n')
|
|
|
|
out(u'\n')
|
|
|
|
out(u'#ifndef __GNUC__\n')
|
|
|
|
out(u'void __asm_dummy_vtables(void) {\n')
|
|
|
|
out(u'#endif\n')
|
|
|
|
out(f' __ASM_VTABLE({winclassname},\n')
|
|
|
|
for method in sorted(klass.methods, key=lambda x: (x._index, -x._override)):
|
|
|
|
out(f' VTABLE_ADD_FUNC({winclassname}_{method.name})\n')
|
|
|
|
out(u' );\n')
|
|
|
|
out(u'#ifndef __GNUC__\n')
|
|
|
|
out(u'}\n')
|
|
|
|
out(u'#endif\n')
|
|
|
|
out(u'\n')
|
2023-09-24 15:50:45 +03:00
|
|
|
out(f'struct w_steam_iface *create_{winclassname}(void *u_iface)\n')
|
2023-09-24 00:20:53 +03:00
|
|
|
out(u'{\n')
|
2023-09-20 18:27:42 +03:00
|
|
|
if klass.name in WRAPPED_CLASSES:
|
2023-09-24 15:50:45 +03:00
|
|
|
out(u' struct w_steam_iface *r = HeapAlloc(GetProcessHeap(), 0, sizeof(struct w_steam_iface));\n')
|
2023-09-23 21:31:45 +03:00
|
|
|
else:
|
2023-09-24 15:50:45 +03:00
|
|
|
out(f' struct w_steam_iface *r = alloc_mem_for_iface(sizeof(struct w_steam_iface), "{klass.version}");\n')
|
2023-09-24 00:20:53 +03:00
|
|
|
out(u' TRACE("-> %p\\n", r);\n')
|
|
|
|
out(f' r->vtable = alloc_vtable(&{winclassname}_vtable, {len(klass.methods)}, "{klass.version}");\n')
|
2023-09-24 15:50:45 +03:00
|
|
|
out(u' r->u_iface = u_iface;\n')
|
2023-09-24 00:20:53 +03:00
|
|
|
out(u' return r;\n')
|
|
|
|
out(u'}\n\n')
|
2018-01-18 19:24:05 +03:00
|
|
|
|
|
|
|
constructors = open("win_constructors.h", "a")
|
2023-09-24 15:50:45 +03:00
|
|
|
constructors.write(f"extern struct w_steam_iface *create_{winclassname}(void *);\n")
|
2018-01-18 19:24:05 +03:00
|
|
|
|
|
|
|
constructors = open("win_constructors_table.dat", "a")
|
2023-09-23 20:44:47 +03:00
|
|
|
for alias in VERSION_ALIASES.get(klass.version, []):
|
2023-09-21 00:21:06 +03:00
|
|
|
constructors.write(f" {{\"{alias}\", &create_{winclassname}}}, /* alias */\n")
|
2023-09-23 20:44:47 +03:00
|
|
|
constructors.write(f" {{\"{klass.version}\", &create_{winclassname}}},\n")
|
2018-01-18 19:24:05 +03:00
|
|
|
|
|
|
|
|
|
|
|
generated_cb_handlers = []
|
|
|
|
generated_cb_ids = []
|
|
|
|
cpp_files_need_close_brace = []
|
|
|
|
cb_table = {}
|
2019-06-13 17:12:28 +03:00
|
|
|
cb_table64 = {}
|
2018-01-18 19:24:05 +03:00
|
|
|
|
2019-05-30 23:20:14 +03:00
|
|
|
def get_field_attribute_str(field):
|
2023-09-21 23:13:09 +03:00
|
|
|
if field.type.kind != TypeKind.RECORD: return ""
|
|
|
|
name = canonical_typename(field)
|
2023-09-20 18:27:42 +03:00
|
|
|
return f" __attribute__((aligned({find_struct_abis(name)['w32'].align})))"
|
2019-05-30 23:20:14 +03:00
|
|
|
|
2018-01-18 19:24:05 +03:00
|
|
|
#because of struct packing differences between win32 and linux, we
|
|
|
|
#need to convert these structs from their linux layout to the win32
|
|
|
|
#layout.
|
2018-10-29 17:28:28 +03:00
|
|
|
def handle_struct(sdkver, struct):
|
|
|
|
members = struct.get_children()
|
|
|
|
cb_num = None
|
2018-10-29 18:15:32 +03:00
|
|
|
has_fields = False
|
2018-10-29 17:28:28 +03:00
|
|
|
for c in members:
|
2021-12-21 12:41:34 +03:00
|
|
|
if c.kind == CursorKind.ENUM_DECL:
|
2018-10-29 17:28:28 +03:00
|
|
|
enums = c.get_children()
|
|
|
|
for e in enums:
|
|
|
|
if e.displayname == "k_iCallback":
|
|
|
|
cb_num = e.enum_value
|
2021-12-21 12:41:34 +03:00
|
|
|
if c.kind == CursorKind.FIELD_DECL:
|
2018-10-29 18:15:32 +03:00
|
|
|
has_fields = True
|
|
|
|
|
|
|
|
w2l_handler_name = None
|
|
|
|
l2w_handler_name = None
|
2018-01-18 19:24:05 +03:00
|
|
|
|
2023-09-16 20:24:46 +03:00
|
|
|
name = canonical_typename(struct)
|
|
|
|
abis = find_struct_abis(name)
|
|
|
|
|
2019-06-13 17:12:28 +03:00
|
|
|
def dump_win_struct(to_file, name):
|
2019-02-26 18:05:29 +03:00
|
|
|
to_file.write("#pragma pack( push, 8 )\n")
|
2021-11-12 19:14:14 +03:00
|
|
|
to_file.write(f"struct win{name} {{\n")
|
2019-02-26 18:05:29 +03:00
|
|
|
for m in struct.get_children():
|
2021-12-21 12:41:34 +03:00
|
|
|
if m.kind == CursorKind.FIELD_DECL:
|
|
|
|
if m.type.kind == TypeKind.CONSTANTARRAY:
|
2021-11-12 19:14:14 +03:00
|
|
|
to_file.write(f" {m.type.element_type.spelling} {m.displayname}[{m.type.element_count}];\n")
|
2021-12-21 12:41:34 +03:00
|
|
|
elif m.type.kind == TypeKind.RECORD and \
|
2019-02-26 18:05:29 +03:00
|
|
|
struct_needs_conversion(m.type):
|
2021-11-12 19:14:14 +03:00
|
|
|
to_file.write(f" win{m.type.spelling}_{sdkver} {m.displayname};\n")
|
2019-02-26 18:05:29 +03:00
|
|
|
else:
|
2021-12-21 12:41:34 +03:00
|
|
|
if m.type.kind == TypeKind.POINTER and \
|
2021-03-01 19:52:59 +03:00
|
|
|
(m.type.get_pointee().kind == TypeKind.UNEXPOSED or m.type.get_pointee().kind == TypeKind.FUNCTIONPROTO):
|
2021-11-12 19:14:14 +03:00
|
|
|
to_file.write(f" void *{m.displayname}; /*fn pointer*/\n")
|
2019-05-16 19:23:30 +03:00
|
|
|
else:
|
2021-11-12 19:14:14 +03:00
|
|
|
to_file.write(f" {m.type.spelling} {m.displayname}{get_field_attribute_str(m)};\n")
|
2019-02-26 18:05:29 +03:00
|
|
|
to_file.write("} __attribute__ ((ms_struct));\n")
|
|
|
|
to_file.write("#pragma pack( pop )\n")
|
|
|
|
|
2018-10-29 17:28:28 +03:00
|
|
|
if cb_num is None:
|
2019-02-26 18:05:29 +03:00
|
|
|
hfile = open("struct_converters.h", "a")
|
2018-10-30 16:09:46 +03:00
|
|
|
|
2018-10-29 18:15:32 +03:00
|
|
|
if not has_fields:
|
|
|
|
return
|
2023-09-20 18:27:42 +03:00
|
|
|
if struct.name == "":
|
2018-10-30 16:09:46 +03:00
|
|
|
return
|
|
|
|
if not struct_needs_conversion(struct.type):
|
2018-10-29 18:15:32 +03:00
|
|
|
return
|
2018-10-30 16:09:46 +03:00
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
struct_name = f"{struct.name}_{sdkver}"
|
2019-05-17 17:33:44 +03:00
|
|
|
|
|
|
|
if struct_name in converted_structs:
|
|
|
|
return
|
|
|
|
converted_structs.append(struct_name)
|
|
|
|
|
2021-11-12 19:14:14 +03:00
|
|
|
w2l_handler_name = f"win_to_lin_struct_{struct_name}"
|
|
|
|
l2w_handler_name = f"lin_to_win_struct_{struct_name}"
|
2019-06-13 17:12:28 +03:00
|
|
|
l2w_handler_name64 = None
|
2018-10-29 19:38:13 +03:00
|
|
|
|
2021-11-12 19:14:14 +03:00
|
|
|
hfile.write(f"#if defined(SDKVER_{sdkver}) || !defined(__cplusplus)\n")
|
2019-06-13 17:12:28 +03:00
|
|
|
dump_win_struct(hfile, struct_name)
|
2021-11-12 19:14:14 +03:00
|
|
|
hfile.write(f"typedef struct win{struct_name} win{struct_name};\n")
|
2023-09-20 18:27:42 +03:00
|
|
|
hfile.write(f"struct {struct.name};\n")
|
2019-02-26 18:05:29 +03:00
|
|
|
|
2023-09-21 20:39:53 +03:00
|
|
|
if canonical_typename(struct) in MANUAL_STRUCTS:
|
2019-05-16 19:23:30 +03:00
|
|
|
hfile.write("#endif\n\n")
|
|
|
|
return
|
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
hfile.write(f"extern void {w2l_handler_name}(const struct win{struct_name} *w, struct {struct.name} *l);\n")
|
|
|
|
hfile.write(f"extern void {l2w_handler_name}(const struct {struct.name} *l, struct win{struct_name} *w);\n")
|
2019-02-26 18:05:29 +03:00
|
|
|
hfile.write("#endif\n\n")
|
2018-10-29 17:28:28 +03:00
|
|
|
else:
|
2018-10-30 16:09:46 +03:00
|
|
|
#for callbacks, we use the windows struct size in the cb dispatch switch
|
2023-09-20 18:27:42 +03:00
|
|
|
size = {a: abis[a].size for a in abis.keys()}
|
2023-09-21 21:02:34 +03:00
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
struct_name = f"{struct.name}_{size['w32']}"
|
2021-11-12 19:14:14 +03:00
|
|
|
l2w_handler_name = f"cb_{struct_name}"
|
2023-09-21 23:13:09 +03:00
|
|
|
if size['w64'] != size['w32']:
|
2023-09-20 18:27:42 +03:00
|
|
|
struct_name64 = f"{struct.name}_{size['w64']}"
|
2021-11-12 19:14:14 +03:00
|
|
|
l2w_handler_name64 = f"cb_{struct_name64}"
|
2019-06-13 17:12:28 +03:00
|
|
|
else:
|
|
|
|
l2w_handler_name64 = None
|
2018-10-29 18:15:32 +03:00
|
|
|
if l2w_handler_name in generated_cb_handlers:
|
2018-10-29 17:28:28 +03:00
|
|
|
# we already have a handler for the callback struct of this size
|
|
|
|
return
|
2018-10-30 16:09:46 +03:00
|
|
|
if not struct_needs_conversion(struct.type):
|
2018-10-29 17:28:28 +03:00
|
|
|
return
|
|
|
|
|
2023-09-21 23:13:09 +03:00
|
|
|
cb_id = cb_num | (size['u32'] << 16)
|
|
|
|
cb_id64 = cb_num | (size['u64'] << 16)
|
2018-10-29 17:28:28 +03:00
|
|
|
if cb_id in generated_cb_ids:
|
|
|
|
# either this cb changed name, or steam used the same ID for different structs
|
|
|
|
return
|
|
|
|
|
|
|
|
generated_cb_ids.append(cb_id)
|
|
|
|
|
2018-10-29 19:38:13 +03:00
|
|
|
datfile = open("cb_converters.dat", "a")
|
2019-06-13 17:12:28 +03:00
|
|
|
if l2w_handler_name64:
|
|
|
|
datfile.write("#ifdef __i386__\n")
|
2023-09-21 23:13:09 +03:00
|
|
|
datfile.write(f"case 0x{cb_id:08x}: win_msg->m_cubParam = {size['w32']}; win_msg->m_pubParam = HeapAlloc(GetProcessHeap(), 0, win_msg->m_cubParam); {l2w_handler_name}((void*)lin_msg.m_pubParam, (void*)win_msg->m_pubParam); break;\n")
|
2019-06-13 17:12:28 +03:00
|
|
|
datfile.write("#endif\n")
|
|
|
|
|
|
|
|
datfile.write("#ifdef __x86_64__\n")
|
2023-09-21 23:13:09 +03:00
|
|
|
datfile.write(f"case 0x{cb_id64:08x}: win_msg->m_cubParam = {size['w64']}; win_msg->m_pubParam = HeapAlloc(GetProcessHeap(), 0, win_msg->m_cubParam); {l2w_handler_name64}((void*)lin_msg.m_pubParam, (void*)win_msg->m_pubParam); break;\n")
|
2019-06-13 17:12:28 +03:00
|
|
|
datfile.write("#endif\n")
|
|
|
|
else:
|
2023-09-21 23:13:09 +03:00
|
|
|
datfile.write(f"case 0x{cb_id:08x}: win_msg->m_cubParam = {size['w32']}; win_msg->m_pubParam = HeapAlloc(GetProcessHeap(), 0, win_msg->m_cubParam); {l2w_handler_name}((void*)lin_msg.m_pubParam, (void*)win_msg->m_pubParam); break;\n")
|
2018-10-29 17:28:28 +03:00
|
|
|
|
2018-10-29 18:15:32 +03:00
|
|
|
generated_cb_handlers.append(l2w_handler_name)
|
2018-10-29 17:28:28 +03:00
|
|
|
|
|
|
|
if not cb_num in cb_table.keys():
|
2018-10-30 16:09:46 +03:00
|
|
|
# latest SDK linux size, list of windows struct sizes and names
|
2023-09-21 23:13:09 +03:00
|
|
|
cb_table[cb_num] = (size['u32'], [])
|
2019-06-13 17:12:28 +03:00
|
|
|
if l2w_handler_name64:
|
2023-09-21 23:13:09 +03:00
|
|
|
cb_table64[cb_num] = (size['u64'], [])
|
2019-06-27 16:59:19 +03:00
|
|
|
else:
|
2023-09-21 23:13:09 +03:00
|
|
|
cb_table64[cb_num] = (size['u32'], [])
|
|
|
|
cb_table[cb_num][1].append((size['w32'], struct_name))
|
2019-06-27 16:59:19 +03:00
|
|
|
if l2w_handler_name64:
|
2023-09-21 23:13:09 +03:00
|
|
|
cb_table64[cb_num][1].append((size['w64'], struct_name64))
|
2019-06-27 16:59:19 +03:00
|
|
|
else:
|
2023-09-21 23:13:09 +03:00
|
|
|
cb_table64[cb_num][1].append((size['w32'], struct_name))
|
2018-01-18 19:24:05 +03:00
|
|
|
|
2018-10-29 19:38:13 +03:00
|
|
|
hfile = open("cb_converters.h", "a")
|
2023-09-20 18:27:42 +03:00
|
|
|
hfile.write(f"struct {struct.name};\n")
|
2019-06-13 17:12:28 +03:00
|
|
|
if l2w_handler_name64:
|
|
|
|
hfile.write("#ifdef __i386__\n")
|
2021-11-12 19:14:14 +03:00
|
|
|
hfile.write(f"struct win{struct_name};\n")
|
2023-09-20 18:27:42 +03:00
|
|
|
hfile.write(f"extern void {l2w_handler_name}(const struct {struct.name} *l, struct win{struct_name} *w);\n")
|
2019-06-13 17:12:28 +03:00
|
|
|
hfile.write("#endif\n")
|
|
|
|
hfile.write("#ifdef __x86_64__\n")
|
2021-11-12 19:14:14 +03:00
|
|
|
hfile.write(f"struct win{struct_name64};\n")
|
2023-09-20 18:27:42 +03:00
|
|
|
hfile.write(f"extern void {l2w_handler_name64}(const struct {struct.name} *l, struct win{struct_name64} *w);\n")
|
2019-06-13 17:12:28 +03:00
|
|
|
hfile.write("#endif\n\n")
|
|
|
|
else:
|
2021-11-12 19:14:14 +03:00
|
|
|
hfile.write(f"struct win{struct_name};\n")
|
2023-09-20 18:27:42 +03:00
|
|
|
hfile.write(f"extern void {l2w_handler_name}(const struct {struct.name} *l, struct win{struct_name} *w);\n\n")
|
2018-10-29 19:38:13 +03:00
|
|
|
|
2021-11-12 19:14:14 +03:00
|
|
|
cppname = f"struct_converters_{sdkver}.cpp"
|
2018-01-18 19:24:05 +03:00
|
|
|
file_exists = os.path.isfile(cppname)
|
|
|
|
cppfile = open(cppname, "a")
|
|
|
|
if not file_exists:
|
|
|
|
cppfile.write("#include \"steam_defs.h\"\n")
|
2019-08-16 17:00:45 +03:00
|
|
|
cppfile.write("#pragma push_macro(\"__cdecl\")\n")
|
|
|
|
cppfile.write("#undef __cdecl\n")
|
2023-05-02 11:43:23 +03:00
|
|
|
cppfile.write("#define __cdecl\n")
|
2021-11-12 19:14:14 +03:00
|
|
|
cppfile.write(f"#include \"steamworks_sdk_{sdkver}/steam_api.h\"\n")
|
|
|
|
cppfile.write(f"#include \"steamworks_sdk_{sdkver}/isteamgameserver.h\"\n")
|
|
|
|
if os.path.isfile(f"steamworks_sdk_{sdkver}/isteamnetworkingsockets.h"):
|
|
|
|
cppfile.write(f"#include \"steamworks_sdk_{sdkver}/isteamnetworkingsockets.h\"\n")
|
|
|
|
if os.path.isfile(f"steamworks_sdk_{sdkver}/isteamgameserverstats.h"):
|
|
|
|
cppfile.write(f"#include \"steamworks_sdk_{sdkver}/isteamgameserverstats.h\"\n")
|
|
|
|
if os.path.isfile(f"steamworks_sdk_{sdkver}/isteamgamecoordinator.h"):
|
|
|
|
cppfile.write(f"#include \"steamworks_sdk_{sdkver}/isteamgamecoordinator.h\"\n")
|
|
|
|
if os.path.isfile(f"steamworks_sdk_{sdkver}/steamnetworkingtypes.h"):
|
|
|
|
cppfile.write(f"#include \"steamworks_sdk_{sdkver}/steamnetworkingtypes.h\"\n")
|
2019-08-16 17:00:45 +03:00
|
|
|
cppfile.write("#pragma pop_macro(\"__cdecl\")\n")
|
2023-09-30 15:02:30 +03:00
|
|
|
cppfile.write("#include \"unixlib.h\"\n")
|
2018-01-18 19:24:05 +03:00
|
|
|
cppfile.write("extern \"C\" {\n")
|
2021-11-12 19:14:14 +03:00
|
|
|
cppfile.write(f"#define SDKVER_{sdkver}\n")
|
2019-02-26 18:05:29 +03:00
|
|
|
cppfile.write("#include \"struct_converters.h\"\n")
|
2018-01-18 19:24:05 +03:00
|
|
|
cpp_files_need_close_brace.append(cppname)
|
|
|
|
|
2023-09-23 23:31:13 +03:00
|
|
|
path_conv_fields = PATH_CONV_STRUCTS.get(struct.type.spelling, {})
|
2018-11-20 20:10:12 +03:00
|
|
|
|
2018-10-29 18:15:32 +03:00
|
|
|
def handle_field(m, src, dst):
|
2021-12-21 12:41:34 +03:00
|
|
|
if m.kind == CursorKind.FIELD_DECL:
|
|
|
|
if m.type.kind == TypeKind.CONSTANTARRAY:
|
|
|
|
assert(m.type.element_type.kind != TypeKind.RECORD or \
|
2018-10-30 16:09:46 +03:00
|
|
|
not struct_needs_conversion(m.type.element_type))
|
2021-11-12 19:14:14 +03:00
|
|
|
cppfile.write(f" memcpy({dst}->{m.displayname}, {src}->{m.displayname}, sizeof({dst}->{m.displayname}));\n")
|
2021-12-21 12:41:34 +03:00
|
|
|
elif m.type.kind == TypeKind.RECORD and \
|
2018-10-30 16:09:46 +03:00
|
|
|
struct_needs_conversion(m.type):
|
2021-11-12 19:14:14 +03:00
|
|
|
cppfile.write(f" {src}_to_{dst}_struct_{m.type.spelling}_{sdkver}(&{src}->{m.displayname}, &{dst}->{m.displayname});\n")
|
2023-09-23 23:31:13 +03:00
|
|
|
elif m.displayname in path_conv_fields:
|
|
|
|
cppfile.write(f" steamclient_unix_path_to_dos_path(1, {src}->{m.displayname}, g_tmppath, sizeof(g_tmppath), 1);\n")
|
2021-11-12 19:14:14 +03:00
|
|
|
cppfile.write(f" {dst}->{m.displayname} = g_tmppath;\n")
|
2018-01-18 19:24:05 +03:00
|
|
|
else:
|
2021-11-12 19:14:14 +03:00
|
|
|
cppfile.write(f" {dst}->{m.displayname} = {src}->{m.displayname};\n")
|
2018-10-29 18:15:32 +03:00
|
|
|
|
2019-02-26 18:05:29 +03:00
|
|
|
if not cb_num is None:
|
2019-06-13 17:12:28 +03:00
|
|
|
if l2w_handler_name64:
|
|
|
|
cppfile.write("#ifdef __i386__\n")
|
|
|
|
dump_win_struct(cppfile, struct_name)
|
|
|
|
cppfile.write("#endif\n")
|
|
|
|
cppfile.write("#ifdef __x86_64__\n")
|
|
|
|
dump_win_struct(cppfile, struct_name64)
|
|
|
|
cppfile.write("#endif\n")
|
|
|
|
else:
|
|
|
|
dump_win_struct(cppfile, struct_name)
|
2019-02-26 18:05:29 +03:00
|
|
|
|
2018-10-29 18:15:32 +03:00
|
|
|
if w2l_handler_name:
|
2023-09-20 18:27:42 +03:00
|
|
|
cppfile.write(f"void {w2l_handler_name}(const struct win{struct_name} *win, struct {struct.name} *lin)\n{{\n")
|
2018-10-29 18:15:32 +03:00
|
|
|
for m in struct.get_children():
|
|
|
|
handle_field(m, "win", "lin")
|
|
|
|
cppfile.write("}\n\n")
|
|
|
|
|
2019-06-13 17:12:28 +03:00
|
|
|
if l2w_handler_name64:
|
|
|
|
cppfile.write("#ifdef __x86_64__\n")
|
2023-09-20 18:27:42 +03:00
|
|
|
cppfile.write(f"void {l2w_handler_name64}(const struct {struct.name} *lin, struct win{struct_name64} *win)\n{{\n")
|
2019-06-13 17:12:28 +03:00
|
|
|
for m in struct.get_children():
|
|
|
|
handle_field(m, "lin", "win")
|
|
|
|
cppfile.write("}\n")
|
|
|
|
cppfile.write("#endif\n\n")
|
|
|
|
|
2018-10-29 18:15:32 +03:00
|
|
|
if l2w_handler_name:
|
2019-06-13 17:12:28 +03:00
|
|
|
if l2w_handler_name64:
|
|
|
|
cppfile.write("#ifdef __i386__\n")
|
2023-09-20 18:27:42 +03:00
|
|
|
cppfile.write(f"void {l2w_handler_name}(const struct {struct.name} *lin, struct win{struct_name} *win)\n{{\n")
|
2018-10-29 18:15:32 +03:00
|
|
|
for m in struct.get_children():
|
|
|
|
handle_field(m, "lin", "win")
|
2019-06-13 17:12:28 +03:00
|
|
|
cppfile.write("}\n")
|
|
|
|
if l2w_handler_name64:
|
|
|
|
cppfile.write("#endif\n\n")
|
|
|
|
else:
|
|
|
|
cppfile.write("\n")
|
2018-01-18 19:24:05 +03:00
|
|
|
|
2023-09-16 16:24:23 +03:00
|
|
|
|
2023-09-21 21:33:54 +03:00
|
|
|
def parse(sources, sdkver, abi):
|
2023-09-16 16:24:23 +03:00
|
|
|
args = [f'-m{abi[1:]}', '-I' + CLANG_PATH + '/include/']
|
|
|
|
if abi[0] == 'w':
|
|
|
|
args += ["-D_WIN32", "-U__linux__"]
|
|
|
|
args += ["-fms-extensions", "-mms-bitfields"]
|
|
|
|
args += ["-Wno-ignored-attributes", "-Wno-incompatible-ms-struct"]
|
|
|
|
if abi[0] == 'u':
|
|
|
|
args += ["-DGNUC"]
|
|
|
|
|
|
|
|
index = Index.create()
|
|
|
|
build = index.parse("source.cpp", args=args, unsaved_files=sources.items())
|
|
|
|
diagnostics = list(build.diagnostics)
|
|
|
|
for diag in diagnostics: print(diag)
|
|
|
|
assert len(diagnostics) == 0
|
|
|
|
|
2023-09-21 21:33:54 +03:00
|
|
|
return sdkver, abi, build
|
2023-09-16 16:24:23 +03:00
|
|
|
|
|
|
|
|
2023-09-20 23:21:42 +03:00
|
|
|
def load(sdkver):
|
2022-01-06 17:52:49 +03:00
|
|
|
sdkdir = f"steamworks_sdk_{sdkver}"
|
|
|
|
|
|
|
|
sources = {}
|
2023-09-20 23:21:42 +03:00
|
|
|
versions = {}
|
2022-01-06 17:52:49 +03:00
|
|
|
for file in os.listdir(sdkdir):
|
2020-11-04 14:56:12 +03:00
|
|
|
# Some files from Valve have non-UTF-8 stuff in the comments
|
|
|
|
# (typically the copyright symbol); therefore we ignore UTF-8
|
|
|
|
# encoding errors
|
2022-01-06 17:52:49 +03:00
|
|
|
lines = open(f"{sdkdir}/{file}", "r", errors="replace").readlines()
|
2023-09-20 22:22:29 +03:00
|
|
|
if """#error "This file isn't used any more"\n""" in lines:
|
|
|
|
sources[f"{sdkdir}/{file}"] = ""
|
|
|
|
|
|
|
|
results = (DEFINE_INTERFACE_VERSION.match(l) for l in lines)
|
|
|
|
for result in (r.groupdict() for r in results if r):
|
|
|
|
name, version = result['name'], result['version']
|
|
|
|
name = name.replace('_INTERFACE_VERSION', '')
|
|
|
|
name = name.replace('_VERSION', '')
|
|
|
|
versions[name] = version
|
2018-01-18 19:24:05 +03:00
|
|
|
|
2023-09-20 22:15:40 +03:00
|
|
|
source = [f'#if __has_include("{sdkdir}/{file}")\n'
|
|
|
|
f'#include "{sdkdir}/{file}"\n'
|
|
|
|
f'#endif\n'
|
|
|
|
for file in SDK_SOURCES.keys()]
|
2022-01-06 17:52:49 +03:00
|
|
|
sources["source.cpp"] = "\n".join(source)
|
|
|
|
|
2023-09-20 23:21:42 +03:00
|
|
|
return versions, sources
|
|
|
|
|
|
|
|
|
2023-09-29 10:58:05 +03:00
|
|
|
def classify_struct(name):
|
|
|
|
if name in EXEMPT_STRUCTS:
|
|
|
|
return None
|
|
|
|
structs = all_structs[name]
|
|
|
|
|
|
|
|
prev = []
|
|
|
|
versions = {}
|
|
|
|
unique = True
|
|
|
|
|
|
|
|
for sdkver in filter(lambda v: v in structs, reversed(SDK_VERSIONS)):
|
|
|
|
abis = [structs[sdkver][a] for a in ABIS]
|
|
|
|
|
|
|
|
if any(abis[0].needs_conversion(a) for a in abis[1:]):
|
|
|
|
unique = False
|
|
|
|
|
|
|
|
def is_always_compatible(other):
|
|
|
|
for a, b in zip(abis, other):
|
|
|
|
if a.needs_conversion(b):
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
compat = next((k for k, v in prev if is_always_compatible(v)), None)
|
|
|
|
if compat:
|
|
|
|
versions[sdkver] = versions[compat]
|
|
|
|
else:
|
|
|
|
[abi.set_used() for abi in abis] # make sure order is computed
|
|
|
|
versions[sdkver] = f"{name}_{sdkver}"
|
|
|
|
prev += [(sdkver, abis)]
|
|
|
|
|
|
|
|
if unique:
|
|
|
|
unique_structs.append(name)
|
|
|
|
|
|
|
|
if len(set(versions.values())) == 1:
|
|
|
|
versions = {sdkver: name for sdkver in versions.keys()}
|
|
|
|
return versions
|
|
|
|
|
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
def generate(sdkver, structs):
|
2023-09-20 23:21:42 +03:00
|
|
|
print(f'generating SDK version {sdkver}...')
|
2023-09-20 18:27:42 +03:00
|
|
|
for child in structs['u32'].values():
|
2023-09-21 21:33:54 +03:00
|
|
|
handle_struct(sdkver, child)
|
2018-01-18 19:24:05 +03:00
|
|
|
|
2023-09-20 23:21:42 +03:00
|
|
|
|
|
|
|
for i, sdkver in enumerate(SDK_VERSIONS):
|
|
|
|
print(f'loading SDKs... {i * 100 // len(SDK_VERSIONS)}%', end='\r')
|
|
|
|
all_versions[sdkver], all_sources[sdkver] = load(sdkver)
|
2023-09-16 21:13:49 +03:00
|
|
|
print('loading SDKs... 100%')
|
|
|
|
|
2023-09-21 21:33:54 +03:00
|
|
|
|
|
|
|
tmp_classes = {}
|
|
|
|
|
2023-09-16 21:13:49 +03:00
|
|
|
with concurrent.futures.ThreadPoolExecutor() as executor:
|
|
|
|
arg0 = [sdkver for sdkver in SDK_VERSIONS for abi in ABIS]
|
|
|
|
arg1 = [abi for sdkver in SDK_VERSIONS for abi in ABIS]
|
|
|
|
def parse_map(sdkver, abi):
|
2023-09-21 21:33:54 +03:00
|
|
|
return parse(all_sources[sdkver], sdkver, abi)
|
2023-09-16 21:13:49 +03:00
|
|
|
|
|
|
|
results = executor.map(parse_map, arg0, arg1)
|
|
|
|
for i, result in enumerate(results):
|
|
|
|
print(f'parsing SDKs... {i * 100 // len(arg0)}%', end='\r')
|
2023-09-21 21:33:54 +03:00
|
|
|
sdkver, abi, build = result
|
2023-09-16 21:13:49 +03:00
|
|
|
if sdkver not in all_records: all_records[sdkver] = {}
|
2023-09-21 21:33:54 +03:00
|
|
|
if sdkver not in tmp_classes: tmp_classes[sdkver] = {}
|
2023-09-16 21:13:49 +03:00
|
|
|
|
2023-09-21 21:33:54 +03:00
|
|
|
versions = all_versions[sdkver]
|
2023-09-21 00:21:06 +03:00
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
structs = build.cursor.get_children()
|
|
|
|
structs = filter(lambda c: c.is_definition(), structs)
|
|
|
|
structs = filter(lambda c: c.type.get_canonical().kind == TypeKind.RECORD, structs)
|
|
|
|
structs = filter(lambda c: c.kind != CursorKind.TYPEDEF_DECL, structs)
|
|
|
|
structs = filter(lambda c: c.spelling not in SDK_CLASSES, structs)
|
|
|
|
structs = [Record(sdkver, abi, c) for c in structs]
|
|
|
|
structs = {c.name: c for c in structs}
|
2023-09-21 21:33:54 +03:00
|
|
|
|
|
|
|
classes = build.cursor.get_children()
|
|
|
|
classes = filter(lambda c: c.is_definition(), classes)
|
|
|
|
classes = filter(lambda c: c.kind == CursorKind.CLASS_DECL, classes)
|
|
|
|
classes = filter(lambda c: c.spelling in SDK_CLASSES, classes)
|
|
|
|
classes = filter(lambda c: c.spelling[1:].upper() in versions, classes)
|
2023-09-23 20:44:47 +03:00
|
|
|
classes = [Class(sdkver, abi, c) for c in classes]
|
|
|
|
classes = {c.version: c for c in classes}
|
2023-09-21 21:33:54 +03:00
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
all_records[sdkver][abi] = structs
|
2023-09-21 21:33:54 +03:00
|
|
|
tmp_classes[sdkver][abi] = classes
|
2023-09-21 00:21:06 +03:00
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
for name, struct in structs.items():
|
|
|
|
if name not in all_structs:
|
|
|
|
all_structs[name] = {}
|
|
|
|
if sdkver not in all_structs[name]:
|
|
|
|
all_structs[name][sdkver] = {}
|
|
|
|
all_structs[name][sdkver][abi] = struct
|
|
|
|
|
2023-09-21 00:58:12 +03:00
|
|
|
for i, sdkver in enumerate(reversed(SDK_VERSIONS)):
|
2023-09-21 21:33:54 +03:00
|
|
|
all_classes.update(tmp_classes[sdkver]['u32'])
|
|
|
|
|
|
|
|
print('parsing SDKs... 100%')
|
2023-09-21 00:21:06 +03:00
|
|
|
|
|
|
|
|
2023-09-29 10:58:05 +03:00
|
|
|
tmp_structs = {}
|
|
|
|
|
|
|
|
for i, name in enumerate(all_structs.keys()):
|
|
|
|
print(f'classifying structs... {i * 100 // len(all_structs.keys())}%', end='\r')
|
|
|
|
versions = classify_struct(name)
|
|
|
|
for sdkver in SDK_VERSIONS:
|
|
|
|
if not versions or sdkver not in versions: continue
|
|
|
|
all_versions[sdkver][name] = versions[sdkver]
|
|
|
|
|
2023-09-24 00:51:24 +03:00
|
|
|
def struct_order(x):
|
|
|
|
name, structs = x if type(x) is tuple else (x, all_structs[x])
|
2023-09-29 10:58:05 +03:00
|
|
|
order = (struct.order for abis in structs.values()
|
|
|
|
for struct in abis.values())
|
|
|
|
return (min(order), name)
|
|
|
|
|
|
|
|
for name, structs in sorted(all_structs.items(), key=struct_order):
|
|
|
|
tmp_structs[name] = {}
|
|
|
|
for sdkver in filter(lambda v: v in structs, SDK_VERSIONS):
|
|
|
|
tmp_structs[name][sdkver] = {a: structs[sdkver][a] for a in ABIS}
|
|
|
|
|
|
|
|
all_structs = tmp_structs
|
|
|
|
|
|
|
|
print('classifying structs... 100%')
|
|
|
|
|
|
|
|
|
2023-09-24 00:20:53 +03:00
|
|
|
for klass in all_classes.values():
|
2023-09-20 18:27:42 +03:00
|
|
|
with open(f"win{klass.name}.c", "w") as file:
|
2023-09-24 00:20:53 +03:00
|
|
|
out = file.write
|
|
|
|
|
|
|
|
out(u'/* This file is auto-generated, do not edit. */\n')
|
|
|
|
out(u'#include "steamclient_private.h"\n')
|
|
|
|
out(u'\n')
|
|
|
|
out(u'WINE_DEFAULT_DEBUG_CHANNEL(steamclient);\n')
|
|
|
|
out(u'\n')
|
|
|
|
|
|
|
|
|
2023-09-23 20:44:47 +03:00
|
|
|
for _, klass in sorted(all_classes.items()):
|
|
|
|
sdkver = klass._sdkver
|
|
|
|
handle_class(klass)
|
2023-09-21 00:21:06 +03:00
|
|
|
|
|
|
|
|
2023-09-24 12:11:25 +03:00
|
|
|
with open('struct_converters.h', 'w') as file:
|
|
|
|
out = file.write
|
|
|
|
|
|
|
|
out(u'#ifndef __STRUCT_CONVERTERS_H\n')
|
|
|
|
out(u'#define __STRUCT_CONVERTERS_H\n')
|
|
|
|
|
2023-09-16 21:13:49 +03:00
|
|
|
for sdkver in SDK_VERSIONS:
|
|
|
|
generate(sdkver, all_records[sdkver])
|
2023-09-20 23:21:42 +03:00
|
|
|
|
2018-01-18 19:24:05 +03:00
|
|
|
for f in cpp_files_need_close_brace:
|
|
|
|
m = open(f, "a")
|
|
|
|
m.write("\n}\n")
|
|
|
|
|
2023-09-24 12:11:25 +03:00
|
|
|
with open('struct_converters.h', 'a') as file:
|
|
|
|
out = file.write
|
|
|
|
|
|
|
|
out(u'#endif /* __STRUCT_CONVERTERS_H */\n')
|
|
|
|
|
2023-09-24 00:51:24 +03:00
|
|
|
|
|
|
|
declared = {}
|
|
|
|
|
|
|
|
with open('steamclient_structs_generated.h', 'w') as file:
|
|
|
|
out = file.write
|
|
|
|
|
|
|
|
for name in sorted(unique_structs, key=struct_order):
|
|
|
|
if name in EXEMPT_STRUCTS: continue
|
|
|
|
for sdkver, abis in all_structs[name].items():
|
|
|
|
if name not in all_versions[sdkver]: continue
|
|
|
|
|
|
|
|
version = all_versions[sdkver][name]
|
|
|
|
if f'struct {version}' in declared: continue
|
|
|
|
declared[f'struct {version}'] = True
|
|
|
|
|
|
|
|
kind = 'union' if type(abis['w64']) is Union else 'struct'
|
|
|
|
|
|
|
|
out(f'typedef {kind} {version} {version};\n')
|
2023-09-28 23:22:25 +03:00
|
|
|
abis['w64'].write_definition(out, "", [])
|
2023-09-24 00:51:24 +03:00
|
|
|
|
|
|
|
for name, structs in all_structs.items():
|
|
|
|
if name in EXEMPT_STRUCTS: continue
|
|
|
|
if name in unique_structs: continue
|
|
|
|
for sdkver, abis in structs.items():
|
|
|
|
if name not in all_versions[sdkver]: continue
|
|
|
|
|
|
|
|
version = all_versions[sdkver][name]
|
|
|
|
if f'typedef {version}' in declared: continue
|
|
|
|
declared[f'typedef {version}'] = True
|
|
|
|
|
|
|
|
kind = 'union' if type(abis['w64']) is Union else 'struct'
|
|
|
|
|
|
|
|
if type(abis['w64']) is Class:
|
|
|
|
out(f'typedef {kind} u_{version} u_{version};\n')
|
|
|
|
out(f'typedef {kind} u_{version} u64_{version};\n')
|
|
|
|
out(f'typedef {kind} u_{version} u32_{version};\n')
|
|
|
|
out(f'typedef {kind} w_{version} w_{version};\n')
|
|
|
|
out(f'typedef {kind} w_{version} w64_{version};\n')
|
|
|
|
out(f'typedef {kind} w_{version} w32_{version};\n')
|
|
|
|
continue
|
|
|
|
|
|
|
|
if abis["w64"].needs_conversion(abis["u64"]):
|
|
|
|
out(f'typedef {kind} u64_{version} u64_{version};\n')
|
|
|
|
else:
|
|
|
|
out(f'typedef {kind} w64_{version} u64_{version};\n')
|
|
|
|
out(f'typedef {kind} w64_{version} w64_{version};\n')
|
|
|
|
|
|
|
|
if abis["w32"].needs_conversion(abis["u32"]):
|
|
|
|
out(f'typedef {kind} u32_{version} u32_{version};\n')
|
|
|
|
else:
|
|
|
|
out(f'typedef {kind} w32_{version} u32_{version};\n')
|
|
|
|
out(f'typedef {kind} w32_{version} w32_{version};\n')
|
|
|
|
|
|
|
|
for name, structs in all_structs.items():
|
|
|
|
if name in EXEMPT_STRUCTS: continue
|
|
|
|
if name in unique_structs: continue
|
|
|
|
for sdkver, abis in structs.items():
|
|
|
|
if name not in all_versions[sdkver]: continue
|
|
|
|
|
|
|
|
version = all_versions[sdkver][name]
|
|
|
|
if f'struct {version}' in declared: continue
|
|
|
|
declared[f'struct {version}'] = True
|
|
|
|
|
|
|
|
kind = 'union' if type(abis['w64']) is Union else 'struct'
|
|
|
|
|
|
|
|
if type(abis['w64']) is Class:
|
|
|
|
abis['w64'].write_definition(out, "w_")
|
|
|
|
abis['u64'].write_definition(out, "u_")
|
|
|
|
continue
|
|
|
|
|
2023-09-28 23:22:25 +03:00
|
|
|
if not abis["w64"].needs_conversion(abis["u64"]):
|
|
|
|
abis['w64'].write_definition(out, "w64_", [])
|
|
|
|
else:
|
|
|
|
abis['w64'].write_definition(out, "w64_", ["u64_"])
|
|
|
|
abis['u64'].write_definition(out, "u64_", ["w64_"])
|
2023-09-24 00:51:24 +03:00
|
|
|
|
2023-09-28 23:22:25 +03:00
|
|
|
if not abis["w32"].needs_conversion(abis["u32"]):
|
|
|
|
abis['w32'].write_definition(out, "w32_", [])
|
|
|
|
else:
|
|
|
|
abis['w32'].write_definition(out, "w32_", ["u32_"])
|
|
|
|
abis['u32'].write_definition(out, "u32_", ["w32_"])
|
2023-09-24 00:51:24 +03:00
|
|
|
|
|
|
|
out(u'#ifdef __i386__\n')
|
|
|
|
out(f'typedef w32_{version} w_{version};\n')
|
|
|
|
out(f'typedef u32_{version} u_{version};\n')
|
|
|
|
out(u'#endif\n')
|
|
|
|
out(u'#ifdef __x86_64__\n')
|
|
|
|
out(f'typedef w64_{version} w_{version};\n')
|
|
|
|
out(f'typedef u64_{version} u_{version};\n')
|
|
|
|
out(u'#endif\n')
|
|
|
|
out(u'\n')
|
|
|
|
|
|
|
|
|
|
|
|
with open('unixlib_generated.cpp', 'w') as file:
|
|
|
|
out = file.write
|
|
|
|
|
|
|
|
out(u'/* This file is auto-generated, do not edit. */\n\n')
|
2023-09-30 15:02:30 +03:00
|
|
|
out(u'#include "unix_private.h"\n\n')
|
2023-09-24 00:51:24 +03:00
|
|
|
|
|
|
|
for name in sorted(unique_structs, key=struct_order):
|
|
|
|
for sdkver, abis in all_structs[name].items():
|
|
|
|
if name not in all_versions[sdkver]: continue
|
|
|
|
|
|
|
|
version = all_versions[sdkver][name]
|
|
|
|
if f'checks {version}' in declared: continue
|
|
|
|
declared[f'checks {version}'] = True
|
|
|
|
|
|
|
|
abis['w64'].write_checks(out, "")
|
|
|
|
|
|
|
|
for name, structs in all_structs.items():
|
|
|
|
if name in EXEMPT_STRUCTS: continue
|
|
|
|
if name in unique_structs: continue
|
|
|
|
for sdkver, abis in structs.items():
|
|
|
|
if name not in all_versions[sdkver]: continue
|
|
|
|
|
|
|
|
version = all_versions[sdkver][name]
|
|
|
|
if f'checks {version}' in declared: continue
|
|
|
|
declared[f'checks {version}'] = True
|
|
|
|
|
|
|
|
if type(abis['w64']) is Class:
|
|
|
|
continue
|
|
|
|
|
|
|
|
abis['w64'].write_checks(out, "w64_")
|
|
|
|
abis['u64'].write_checks(out, "u64_")
|
|
|
|
abis['w32'].write_checks(out, "w32_")
|
|
|
|
abis['u32'].write_checks(out, "u32_")
|
|
|
|
|
2023-09-28 23:22:25 +03:00
|
|
|
if name in MANUAL_STRUCTS: continue
|
|
|
|
|
|
|
|
for sdkver, abis in structs.items():
|
|
|
|
if name not in all_versions[sdkver]: continue
|
|
|
|
|
|
|
|
version = all_versions[sdkver][name]
|
|
|
|
if f'struct {version} convert' in declared: continue
|
|
|
|
declared[f'struct {version} convert'] = True
|
|
|
|
|
|
|
|
if type(abis['w64']) in (Class, Union):
|
|
|
|
continue
|
|
|
|
|
|
|
|
path_conv_fields = PATH_CONV_STRUCTS.get(name, {})
|
|
|
|
|
|
|
|
if abis["w64"].needs_conversion(abis["u64"]):
|
|
|
|
out(u'#ifdef __x86_64__\n')
|
|
|
|
abis['w64'].write_converter('u64_', {})
|
|
|
|
out(u'\n')
|
|
|
|
abis['u64'].write_converter('w64_', path_conv_fields)
|
|
|
|
out(u'#endif\n\n')
|
|
|
|
|
|
|
|
if abis["w32"].needs_conversion(abis["u32"]):
|
|
|
|
out(u'#ifdef __i386__\n')
|
|
|
|
abis['w32'].write_converter('u32_', {})
|
|
|
|
out(u'\n')
|
|
|
|
abis['u32'].write_converter('w32_', path_conv_fields)
|
|
|
|
out(u'#endif\n\n')
|
|
|
|
|
|
|
|
|
2018-01-18 19:24:05 +03:00
|
|
|
getapifile = open("cb_getapi_table.dat", "w")
|
|
|
|
cbsizefile = open("cb_getapi_sizes.dat", "w")
|
2019-06-13 17:12:28 +03:00
|
|
|
|
|
|
|
cbsizefile.write("#ifdef __i386__\n")
|
|
|
|
getapifile.write("#ifdef __i386__\n")
|
2020-11-04 14:46:07 +03:00
|
|
|
for cb in sorted(cb_table.keys()):
|
2021-11-12 19:14:14 +03:00
|
|
|
cbsizefile.write(f"case {cb}: /* {cb_table[cb][1][0][1]} */\n")
|
|
|
|
cbsizefile.write(f" return {cb_table[cb][0]};\n")
|
|
|
|
getapifile.write(f"case {cb}:\n")
|
2018-01-18 19:24:05 +03:00
|
|
|
getapifile.write(" switch(callback_len){\n")
|
|
|
|
getapifile.write(" default:\n") # the first one should be the latest, should best support future SDK versions
|
2018-10-30 16:09:46 +03:00
|
|
|
for (size, name) in cb_table[cb][1]:
|
2021-11-12 19:14:14 +03:00
|
|
|
getapifile.write(f" case {size}: cb_{name}(lin_callback, callback); break;\n")
|
2018-01-18 19:24:05 +03:00
|
|
|
getapifile.write(" }\n break;\n")
|
2019-06-13 17:12:28 +03:00
|
|
|
cbsizefile.write("#endif\n")
|
|
|
|
getapifile.write("#endif\n")
|
|
|
|
|
|
|
|
cbsizefile.write("#ifdef __x86_64__\n")
|
|
|
|
getapifile.write("#ifdef __x86_64__\n")
|
2020-11-04 14:46:07 +03:00
|
|
|
for cb in sorted(cb_table64.keys()):
|
2021-11-12 19:14:14 +03:00
|
|
|
cbsizefile.write(f"case {cb}: /* {cb_table64[cb][1][0][1]} */\n")
|
|
|
|
cbsizefile.write(f" return {cb_table64[cb][0]};\n")
|
|
|
|
getapifile.write(f"case {cb}:\n")
|
2019-06-13 17:12:28 +03:00
|
|
|
getapifile.write(" switch(callback_len){\n")
|
|
|
|
getapifile.write(" default:\n") # the first one should be the latest, should best support future SDK versions
|
|
|
|
for (size, name) in cb_table64[cb][1]:
|
2021-11-12 19:14:14 +03:00
|
|
|
getapifile.write(f" case {size}: cb_{name}(lin_callback, callback); break;\n")
|
2019-06-13 17:12:28 +03:00
|
|
|
getapifile.write(" }\n break;\n")
|
|
|
|
cbsizefile.write("#endif\n")
|
|
|
|
getapifile.write("#endif\n")
|