2020-11-04 12:56:12 +01:00
|
|
|
#!/usr/bin/env python3
|
2018-01-18 17:24:05 +01:00
|
|
|
|
|
|
|
#NOTE: If you make modifications here, consider whether they should
|
|
|
|
#be duplicated in ../vrclient/gen_wrapper.py
|
|
|
|
|
2018-08-24 09:18:36 +02:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2022-06-10 11:22:17 +02:00
|
|
|
CLANG_PATH='/usr/lib/clang/13.0.1'
|
2019-05-13 18:46:07 +02:00
|
|
|
|
2021-12-21 10:41:34 +01:00
|
|
|
from clang.cindex import CursorKind, Index, Type, TypeKind
|
2022-06-14 16:21:49 +02:00
|
|
|
from collections import namedtuple
|
2018-01-18 17:24:05 +01:00
|
|
|
import pprint
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import re
|
2019-01-04 16:58:11 +01:00
|
|
|
import math
|
2018-01-18 17:24:05 +01:00
|
|
|
|
|
|
|
sdk_versions = [
|
2021-12-20 16:48:44 +01:00
|
|
|
"153a",
|
2021-09-15 21:52:44 +02:00
|
|
|
"152",
|
2021-03-01 17:04:28 +01:00
|
|
|
"151",
|
2020-09-29 16:19:06 +02:00
|
|
|
"150",
|
2020-08-11 19:39:33 +02:00
|
|
|
"149",
|
2020-06-02 17:30:04 +02:00
|
|
|
"148a",
|
2019-12-06 21:19:37 +01:00
|
|
|
"147",
|
2019-08-16 15:39:30 +02:00
|
|
|
"146",
|
2019-08-16 14:44:08 +02:00
|
|
|
"145",
|
2019-05-13 18:46:07 +02:00
|
|
|
"144",
|
|
|
|
"143y",
|
|
|
|
"143x",
|
2019-02-25 16:44:23 +01:00
|
|
|
"143",
|
2018-01-18 17:24:05 +01:00
|
|
|
"142",
|
|
|
|
"141",
|
|
|
|
"140",
|
|
|
|
"139",
|
|
|
|
"138a",
|
|
|
|
"138",
|
|
|
|
"137",
|
|
|
|
"136",
|
|
|
|
"135a",
|
|
|
|
"135",
|
|
|
|
"134",
|
2019-02-05 21:28:59 +01:00
|
|
|
"133x",
|
2018-01-18 17:24:05 +01:00
|
|
|
"133b",
|
|
|
|
"133a",
|
|
|
|
"133",
|
2019-02-05 21:34:33 +01:00
|
|
|
"132x",
|
2018-01-18 17:24:05 +01:00
|
|
|
"132",
|
|
|
|
"131",
|
2019-02-06 18:48:47 +01:00
|
|
|
"130x",
|
2018-01-18 17:24:05 +01:00
|
|
|
"130",
|
|
|
|
"129a",
|
|
|
|
"129",
|
2019-02-05 21:43:00 +01:00
|
|
|
"128x",
|
2018-01-18 17:24:05 +01:00
|
|
|
"128",
|
|
|
|
"127",
|
|
|
|
"126a",
|
|
|
|
"126",
|
|
|
|
"125",
|
|
|
|
"124",
|
|
|
|
"123a",
|
|
|
|
"123",
|
|
|
|
"122",
|
2019-02-05 21:50:20 +01:00
|
|
|
"121x",
|
2018-01-18 17:24:05 +01:00
|
|
|
"121",
|
|
|
|
"120",
|
2019-02-05 21:55:55 +01:00
|
|
|
"119x",
|
2018-01-18 17:24:05 +01:00
|
|
|
"119",
|
|
|
|
"118",
|
|
|
|
"117",
|
2019-02-05 21:58:14 +01:00
|
|
|
"116x",
|
2018-01-18 17:24:05 +01:00
|
|
|
"116",
|
|
|
|
"115",
|
|
|
|
"114",
|
|
|
|
"113",
|
2019-02-05 22:01:51 +01:00
|
|
|
"112x",
|
2018-01-18 17:24:05 +01:00
|
|
|
"112",
|
2019-02-05 22:06:21 +01:00
|
|
|
"111x",
|
2018-01-18 17:24:05 +01:00
|
|
|
"111",
|
|
|
|
"110",
|
|
|
|
"109",
|
|
|
|
"108",
|
|
|
|
"107",
|
|
|
|
"106",
|
|
|
|
"105",
|
|
|
|
"104",
|
|
|
|
"103",
|
2019-02-06 15:27:56 +01:00
|
|
|
"102x",
|
2018-01-18 17:24:05 +01:00
|
|
|
"102",
|
2019-02-06 15:31:48 +01:00
|
|
|
"101x",
|
2018-01-18 17:24:05 +01:00
|
|
|
"101",
|
|
|
|
"100",
|
2019-02-06 16:19:39 +01:00
|
|
|
"099y",
|
2019-02-06 18:15:19 +01:00
|
|
|
"099x",
|
2019-02-07 20:23:50 +01:00
|
|
|
"099w",
|
2019-02-07 20:30:29 +01:00
|
|
|
"099v",
|
2019-02-07 20:33:17 +01:00
|
|
|
"099u",
|
2018-01-18 17:24:05 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
files = [
|
|
|
|
("steam_api.h", [
|
|
|
|
"ISteamApps",
|
|
|
|
"ISteamAppList",
|
|
|
|
"ISteamClient",
|
|
|
|
"ISteamController",
|
2019-05-17 17:27:59 +02:00
|
|
|
"ISteamGameSearch",
|
2018-01-18 17:24:05 +01:00
|
|
|
"ISteamFriends",
|
|
|
|
"ISteamHTMLSurface",
|
|
|
|
"ISteamHTTP",
|
2019-02-25 16:53:13 +01:00
|
|
|
"ISteamInput",
|
2018-01-18 17:24:05 +01:00
|
|
|
"ISteamInventory",
|
|
|
|
"ISteamMatchmaking",
|
|
|
|
"ISteamMatchmakingServers",
|
|
|
|
"ISteamMusic",
|
|
|
|
"ISteamMusicRemote",
|
|
|
|
"ISteamNetworking",
|
2019-02-25 16:50:52 +01:00
|
|
|
"ISteamParties",
|
2019-08-16 15:51:27 +02:00
|
|
|
"ISteamRemotePlay",
|
2018-01-18 17:24:05 +01:00
|
|
|
"ISteamRemoteStorage",
|
|
|
|
"ISteamScreenshots",
|
|
|
|
"ISteamUGC",
|
|
|
|
"ISteamUnifiedMessages",
|
|
|
|
"ISteamUser",
|
|
|
|
"ISteamUserStats",
|
|
|
|
"ISteamUtils",
|
|
|
|
"ISteamVideo"
|
|
|
|
]),
|
|
|
|
("isteamappticket.h", [
|
|
|
|
"ISteamAppTicket"
|
|
|
|
]),
|
|
|
|
("isteamgameserver.h", [
|
|
|
|
"ISteamGameServer"
|
|
|
|
]),
|
|
|
|
("isteamgameserverstats.h", [
|
|
|
|
"ISteamGameServerStats"
|
|
|
|
]),
|
2019-02-15 22:06:17 +01:00
|
|
|
("isteamgamestats.h", [
|
|
|
|
"ISteamGameStats"
|
|
|
|
]),
|
2018-01-18 17:24:05 +01:00
|
|
|
("isteammasterserverupdater.h", [
|
|
|
|
"ISteamMasterServerUpdater"
|
|
|
|
]),
|
|
|
|
("isteamgamecoordinator.h", [
|
|
|
|
"ISteamGameCoordinator"
|
|
|
|
]),
|
|
|
|
("isteamparentalsettings.h", [
|
|
|
|
"ISteamParentalSettings"
|
|
|
|
]),
|
2020-09-29 16:40:02 +02:00
|
|
|
("isteamnetworkingmessages.h", [
|
|
|
|
"ISteamNetworkingMessages"
|
|
|
|
]),
|
2019-05-16 18:23:30 +02:00
|
|
|
("isteamnetworkingsockets.h", [
|
|
|
|
"ISteamNetworkingSockets"
|
|
|
|
]),
|
2019-02-07 15:54:56 +01:00
|
|
|
("isteamnetworkingsocketsserialized.h", [
|
|
|
|
"ISteamNetworkingSocketsSerialized"
|
|
|
|
]),
|
2019-05-17 16:33:44 +02:00
|
|
|
("isteamnetworkingutils.h", [
|
|
|
|
"ISteamNetworkingUtils"
|
|
|
|
]),
|
2021-12-20 16:48:44 +01:00
|
|
|
("steamnetworkingfakeip.h", [
|
|
|
|
"ISteamNetworkingFakeUDPPort"
|
|
|
|
]),
|
2018-01-18 17:24:05 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
aliases = {
|
2019-02-05 21:00:41 +01:00
|
|
|
#these interfaces are undocumented and binary compatible
|
2020-06-02 17:30:04 +02:00
|
|
|
#"target interface": ["alias 1", "alias 2"],
|
2019-02-05 21:00:41 +01:00
|
|
|
"SteamUtils004":["SteamUtils003"],
|
|
|
|
"SteamUtils002":["SteamUtils001"],
|
2019-02-06 18:54:19 +01:00
|
|
|
"SteamGameServer008":["SteamGameServer007","SteamGameServer006"],
|
2019-02-07 15:54:56 +01:00
|
|
|
"SteamNetworkingSocketsSerialized002":["SteamNetworkingSocketsSerialized001"],
|
2019-02-07 20:53:55 +01:00
|
|
|
"STEAMAPPS_INTERFACE_VERSION001":["SteamApps001"],
|
2020-06-02 17:30:04 +02:00
|
|
|
"STEAMAPPS_INTERFACE_VERSION001":["SteamApps001"],
|
|
|
|
"SteamNetworkingSockets002":["SteamNetworkingSockets003"],
|
2018-01-18 17:24:05 +01:00
|
|
|
}
|
|
|
|
|
2018-10-29 17:38:13 +01:00
|
|
|
# these structs are manually confirmed to be equivalent
|
|
|
|
exempt_structs = [
|
|
|
|
"CSteamID",
|
|
|
|
"CGameID",
|
2018-10-29 19:26:08 +01:00
|
|
|
"CCallbackBase",
|
|
|
|
"SteamPS3Params_t",
|
|
|
|
"ValvePackingSentinel_t"
|
2018-01-18 17:24:05 +01:00
|
|
|
]
|
|
|
|
|
2019-05-16 18:23:30 +02:00
|
|
|
# we have converters for these written by hand because they're too complicated to generate
|
|
|
|
manually_handled_structs = [
|
|
|
|
"SteamNetworkingMessage_t"
|
|
|
|
]
|
|
|
|
|
2022-06-14 16:21:49 +02:00
|
|
|
Method = namedtuple('Method', ['name', 'version_func'], defaults=[lambda _: True])
|
|
|
|
|
2019-05-30 17:28:09 +02:00
|
|
|
manually_handled_methods = {
|
2022-06-14 16:21:49 +02:00
|
|
|
#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"),
|
2020-09-29 16:40:02 +02:00
|
|
|
],
|
2022-06-14 16:21:49 +02:00
|
|
|
"cppISteamNetworkingUtils_SteamNetworkingUtils": [
|
|
|
|
Method("AllocateMessage"),
|
|
|
|
Method("SetConfigValue", lambda version: version >= 3)
|
2021-10-08 18:09:30 +02:00
|
|
|
],
|
2022-06-14 16:21:49 +02:00
|
|
|
"cppISteamNetworkingMessages_SteamNetworkingMessages": [
|
|
|
|
Method("ReceiveMessagesOnChannel"),
|
2021-10-08 18:09:30 +02:00
|
|
|
],
|
2022-06-14 16:21:49 +02:00
|
|
|
"cppISteamInput_SteamInput": [
|
|
|
|
Method("EnableActionEventCallbacks"),
|
|
|
|
Method("GetGlyphForActionOrigin"),
|
|
|
|
Method("GetGlyphPNGForActionOrigin"),
|
|
|
|
Method("GetGlyphSVGForActionOrigin"),
|
|
|
|
Method("GetGlyphForActionOrigin_Legacy"),
|
|
|
|
Method("GetGlyphForXboxOrigin"),
|
2021-10-08 18:09:30 +02:00
|
|
|
],
|
2022-06-14 16:21:49 +02:00
|
|
|
"cppISteamController_SteamController": [
|
|
|
|
Method("GetGlyphForActionOrigin"),
|
|
|
|
Method("GetGlyphForXboxOrigin"),
|
2022-06-10 11:28:21 +02:00
|
|
|
],
|
2022-06-14 16:21:49 +02:00
|
|
|
"cppISteamNetworkingFakeUDPPort_SteamNetworkingFakeUDPPort": [
|
|
|
|
Method("DestroyFakeUDPPort"),
|
|
|
|
Method("ReceiveMessages"),
|
2021-10-08 18:09:30 +02:00
|
|
|
],
|
2022-06-14 16:21:49 +02:00
|
|
|
"cppISteamUser_SteamUser": [
|
|
|
|
#TODO: Do we need the the value -> pointer conversion for other versions of the interface?
|
|
|
|
Method("InitiateGameConnection", lambda version: version == 8),
|
2022-03-31 16:48:31 +02:00
|
|
|
],
|
2019-05-30 17:28:09 +02:00
|
|
|
}
|
|
|
|
|
2022-06-14 16:21:49 +02:00
|
|
|
INTERFACE_NAME_VERSION = re.compile(r'^(?P<name>.+?)(?P<version>\d*)$')
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
method_list = manually_handled_methods.get(interface, [])
|
|
|
|
method = next(filter(lambda m: m.name == method_name, method_list), None)
|
|
|
|
|
|
|
|
return method and method.version_func(version)
|
|
|
|
|
2019-05-17 21:48:34 +02:00
|
|
|
# manual converters for simple types (function pointers)
|
|
|
|
manual_type_converters = [
|
2019-08-15 21:50:30 +02:00
|
|
|
"FSteamNetworkingSocketsDebugOutput",
|
2022-06-15 00:54:51 +02:00
|
|
|
"SteamAPIWarningMessageHook_t",
|
2019-08-15 21:50:30 +02:00
|
|
|
"SteamAPI_CheckCallbackRegistered_t"
|
2019-05-17 21:48:34 +02:00
|
|
|
]
|
|
|
|
|
2019-06-17 17:50:11 +02:00
|
|
|
# manual converters for specific parameters
|
|
|
|
manual_param_converters = [
|
|
|
|
"nNativeKeyCode"
|
|
|
|
]
|
|
|
|
|
2018-10-30 14:09:46 +01:00
|
|
|
#struct_conversion_cache = {
|
|
|
|
# '142': {
|
|
|
|
# 'SteamUGCDetails_t': True,
|
|
|
|
# 'SteamUGCQueryCompleted_t': False
|
|
|
|
# }
|
|
|
|
#}
|
|
|
|
struct_conversion_cache = {}
|
|
|
|
|
2019-05-17 16:33:44 +02:00
|
|
|
converted_structs = []
|
|
|
|
|
2018-10-29 19:23:17 +01:00
|
|
|
# callback classes for which we have a linux wrapper
|
|
|
|
wrapped_classes = [
|
|
|
|
"ISteamMatchmakingServerListResponse",
|
|
|
|
"ISteamMatchmakingPingResponse",
|
|
|
|
"ISteamMatchmakingPlayersResponse",
|
2021-12-20 16:48:44 +01:00
|
|
|
"ISteamMatchmakingRulesResponse",
|
|
|
|
"ISteamNetworkingFakeUDPPort",
|
2018-10-29 19:23:17 +01:00
|
|
|
]
|
|
|
|
|
2018-01-18 17:24:05 +01:00
|
|
|
print_sizes = []
|
|
|
|
|
|
|
|
class_versions = {}
|
|
|
|
|
2018-11-20 18:10:12 +01:00
|
|
|
path_conversions = [
|
|
|
|
{
|
|
|
|
"parent_name": "GetAppInstallDir",
|
|
|
|
"l2w_names": ["pchDirectory"],
|
|
|
|
"l2w_lens": ["cchNameMax"],
|
2019-06-17 20:05:41 +02:00
|
|
|
"l2w_urls": [False],
|
2018-11-20 18:10:12 +01:00
|
|
|
"w2l_names": [],
|
|
|
|
"w2l_arrays": [],
|
2019-06-17 20:05:41 +02:00
|
|
|
"w2l_urls": [],
|
2018-11-20 18:10:12 +01:00
|
|
|
"return_is_size": True
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "GetAppInstallDir",
|
|
|
|
"l2w_names": ["pchFolder"],
|
|
|
|
"l2w_lens": ["cchFolderBufferSize"],
|
2019-06-17 20:05:41 +02:00
|
|
|
"l2w_urls": [False],
|
2018-11-20 18:10:12 +01:00
|
|
|
"w2l_names": [],
|
|
|
|
"w2l_arrays": [],
|
2019-06-17 20:05:41 +02:00
|
|
|
"w2l_urls": [],
|
2018-11-20 18:10:12 +01:00
|
|
|
"return_is_size": True
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "GetFileDetails",
|
|
|
|
"l2w_names": [],
|
|
|
|
"l2w_lens": [],
|
2019-06-17 20:05:41 +02:00
|
|
|
"l2w_urls": [],
|
2018-11-20 18:10:12 +01:00
|
|
|
"w2l_names": ["pszFileName"],
|
|
|
|
"w2l_arrays": [False],
|
2019-06-17 20:05:41 +02:00
|
|
|
"w2l_urls": [False],
|
2018-11-20 18:10:12 +01:00
|
|
|
"return_is_size": True
|
|
|
|
},
|
|
|
|
### ISteamGameServer::SetModDir - "Just the folder name, not the whole path. I.e. "Spacewar"."
|
2019-06-17 20:05:41 +02:00
|
|
|
{
|
|
|
|
"parent_name": "LoadURL",
|
|
|
|
"l2w_names": [],
|
|
|
|
"l2w_lens": [],
|
|
|
|
"l2w_urls": [],
|
|
|
|
"w2l_names": ["pchURL"],
|
|
|
|
"w2l_arrays": [False],
|
|
|
|
"w2l_urls": [True],
|
|
|
|
"return_is_size": False
|
|
|
|
},
|
2018-11-20 18:10:12 +01:00
|
|
|
{
|
|
|
|
"parent_name": "FileLoadDialogResponse",
|
|
|
|
"l2w_names": [],
|
|
|
|
"l2w_lens": [],
|
2019-06-17 20:05:41 +02:00
|
|
|
"l2w_urls": [],
|
2018-11-20 18:10:12 +01:00
|
|
|
"w2l_names": ["pchSelectedFiles"],
|
|
|
|
"w2l_arrays": [True],
|
2019-06-17 20:05:41 +02:00
|
|
|
"w2l_urls": [False],
|
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "HTML_StartRequest_t",
|
|
|
|
"l2w_names": ["pchURL"],
|
|
|
|
"l2w_lens": [None],
|
|
|
|
"l2w_urls": [True],
|
|
|
|
"w2l_names": [],
|
|
|
|
"w2l_arrays": [],
|
|
|
|
"w2l_urls": [],
|
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "HTML_URLChanged_t",
|
|
|
|
"l2w_names": ["pchURL"],
|
|
|
|
"l2w_lens": [None],
|
|
|
|
"l2w_urls": [True],
|
|
|
|
"w2l_names": [],
|
|
|
|
"w2l_arrays": [],
|
|
|
|
"w2l_urls": [],
|
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "HTML_FinishedRequest_t",
|
|
|
|
"l2w_names": ["pchURL"],
|
|
|
|
"l2w_lens": [None],
|
|
|
|
"l2w_urls": [True],
|
|
|
|
"w2l_names": [],
|
|
|
|
"w2l_arrays": [],
|
|
|
|
"w2l_urls": [],
|
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "HTML_OpenLinkInNewTab_t",
|
|
|
|
"l2w_names": ["pchURL"],
|
|
|
|
"l2w_lens": [None],
|
|
|
|
"l2w_urls": [True],
|
|
|
|
"w2l_names": [],
|
|
|
|
"w2l_arrays": [],
|
|
|
|
"w2l_urls": [],
|
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "HTML_LinkAtPosition_t",
|
|
|
|
"l2w_names": ["pchURL"],
|
|
|
|
"l2w_lens": [None],
|
|
|
|
"l2w_urls": [True],
|
|
|
|
"w2l_names": [],
|
|
|
|
"w2l_arrays": [],
|
|
|
|
"w2l_urls": [],
|
2018-11-20 18:10:12 +01:00
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "HTML_FileOpenDialog_t",
|
|
|
|
"l2w_names": ["pchInitialFile"],
|
|
|
|
"l2w_lens": [None],
|
2019-06-17 20:05:41 +02:00
|
|
|
"l2w_urls": [True],
|
2018-11-20 18:10:12 +01:00
|
|
|
"w2l_names": [],
|
|
|
|
"w2l_arrays": [],
|
2019-06-17 20:05:41 +02:00
|
|
|
"w2l_urls": [],
|
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "HTML_NewWindow_t",
|
|
|
|
"l2w_names": ["pchURL"],
|
|
|
|
"l2w_lens": [None],
|
|
|
|
"l2w_urls": [True],
|
|
|
|
"w2l_names": [],
|
|
|
|
"w2l_arrays": [],
|
|
|
|
"w2l_urls": [],
|
2018-11-20 18:10:12 +01:00
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "PublishWorkshopFile",
|
|
|
|
"l2w_names": [],
|
|
|
|
"l2w_lens": [],
|
2019-06-17 20:05:41 +02:00
|
|
|
"l2w_urls": [],
|
2018-11-20 18:10:12 +01:00
|
|
|
"w2l_names": ["pchFile", "pchPreviewFile"],
|
|
|
|
"w2l_arrays": [False, False],
|
2019-06-17 20:05:41 +02:00
|
|
|
"w2l_urls": [False, False],
|
2018-11-20 18:10:12 +01:00
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "UpdatePublishedFileFile",
|
|
|
|
"l2w_names": [],
|
|
|
|
"l2w_lens": [],
|
2019-06-17 20:05:41 +02:00
|
|
|
"l2w_urls": [],
|
2018-11-20 18:10:12 +01:00
|
|
|
"w2l_names": ["pchFile"],
|
|
|
|
"w2l_arrays": [False],
|
2019-06-17 20:05:41 +02:00
|
|
|
"w2l_urls": [False],
|
2018-11-20 18:10:12 +01:00
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "UpdatePublishedFilePreviewFile",
|
|
|
|
"l2w_names": [],
|
|
|
|
"l2w_lens": [],
|
2019-06-17 20:05:41 +02:00
|
|
|
"l2w_urls": [],
|
2018-11-20 18:10:12 +01:00
|
|
|
"w2l_names": ["pchPreviewFile"],
|
|
|
|
"w2l_arrays": [False],
|
2019-06-17 20:05:41 +02:00
|
|
|
"w2l_urls": [False],
|
2018-11-20 18:10:12 +01:00
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "PublishVideo",
|
|
|
|
"l2w_names": [],
|
|
|
|
"l2w_lens": [],
|
2019-06-17 20:05:41 +02:00
|
|
|
"l2w_urls": [],
|
2018-11-20 18:10:12 +01:00
|
|
|
"w2l_names": ["pchPreviewFile"],
|
|
|
|
"w2l_arrays": [False],
|
2019-06-17 20:05:41 +02:00
|
|
|
"w2l_urls": [False],
|
2018-11-20 18:10:12 +01:00
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "AddScreenshotToLibrary",
|
|
|
|
"l2w_names": [],
|
|
|
|
"l2w_lens": [],
|
2019-06-17 20:05:41 +02:00
|
|
|
"l2w_urls": [],
|
2018-11-20 18:10:12 +01:00
|
|
|
"w2l_names": ["pchFilename", "pchThumbnailFilename"],
|
|
|
|
"w2l_arrays": [False, False],
|
2019-06-17 20:05:41 +02:00
|
|
|
"w2l_urls": [False, False],
|
2018-11-20 18:10:12 +01:00
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "AddVRScreenshotToLibrary",
|
|
|
|
"l2w_names": [],
|
|
|
|
"l2w_lens": [],
|
2019-06-17 20:05:41 +02:00
|
|
|
"l2w_urls": [],
|
2018-11-20 18:10:12 +01:00
|
|
|
"w2l_names": ["pchFilename", "pchVRFilename"],
|
|
|
|
"w2l_arrays": [False, False],
|
2019-06-17 20:05:41 +02:00
|
|
|
"w2l_urls": [False, False],
|
2018-11-20 18:10:12 +01:00
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "UGCDownloadToLocation",
|
|
|
|
"l2w_names": [],
|
|
|
|
"l2w_lens": [],
|
2019-06-17 20:05:41 +02:00
|
|
|
"l2w_urls": [],
|
2018-11-20 18:10:12 +01:00
|
|
|
"w2l_names": ["pchLocation"],
|
|
|
|
"w2l_arrays": [False],
|
2019-06-17 20:05:41 +02:00
|
|
|
"w2l_urls": [False],
|
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "GetQueryUGCAdditionalPreview",
|
|
|
|
"l2w_names": ["pchURLOrVideoID"],
|
|
|
|
"l2w_lens": ["cchURLSize"],
|
|
|
|
"l2w_urls": [True],
|
|
|
|
"w2l_names": [],
|
|
|
|
"w2l_arrays": [],
|
|
|
|
"w2l_urls": [],
|
2018-11-20 18:10:12 +01:00
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "SetItemContent",
|
|
|
|
"l2w_names": [],
|
|
|
|
"l2w_lens": [],
|
2019-06-17 20:05:41 +02:00
|
|
|
"l2w_urls": [],
|
2018-11-20 18:10:12 +01:00
|
|
|
"w2l_names": ["pszContentFolder"],
|
|
|
|
"w2l_arrays": [False],
|
2019-06-17 20:05:41 +02:00
|
|
|
"w2l_urls": [False],
|
2018-11-20 18:10:12 +01:00
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "SetItemPreview",
|
|
|
|
"l2w_names": [],
|
|
|
|
"l2w_lens": [],
|
2019-06-17 20:05:41 +02:00
|
|
|
"l2w_urls": [],
|
2018-11-20 18:10:12 +01:00
|
|
|
"w2l_names": ["pszPreviewFile"],
|
|
|
|
"w2l_arrays": [False],
|
2019-06-17 20:05:41 +02:00
|
|
|
"w2l_urls": [False],
|
2018-11-20 18:10:12 +01:00
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "AddItemPreviewFile",
|
|
|
|
"l2w_names": [],
|
|
|
|
"l2w_lens": [],
|
2019-06-17 20:05:41 +02:00
|
|
|
"l2w_urls": [],
|
2018-11-20 18:10:12 +01:00
|
|
|
"w2l_names": ["pszPreviewFile"],
|
|
|
|
"w2l_arrays": [False],
|
2019-06-17 20:05:41 +02:00
|
|
|
"w2l_urls": [False],
|
2018-11-20 18:10:12 +01:00
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "UpdateItemPreviewFile",
|
|
|
|
"l2w_names": [],
|
|
|
|
"l2w_lens": [],
|
2019-06-17 20:05:41 +02:00
|
|
|
"l2w_urls": [],
|
2018-11-20 18:10:12 +01:00
|
|
|
"w2l_names": ["pszPreviewFile"],
|
|
|
|
"w2l_arrays": [False],
|
2019-06-17 20:05:41 +02:00
|
|
|
"w2l_urls": [False],
|
2018-11-20 18:10:12 +01:00
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "GetItemInstallInfo",
|
|
|
|
"l2w_names": ["pchFolder"],
|
|
|
|
"l2w_lens": ["cchFolderSize"],
|
2019-06-17 20:05:41 +02:00
|
|
|
"l2w_urls": [False],
|
2018-11-20 18:10:12 +01:00
|
|
|
"w2l_names": [],
|
|
|
|
"w2l_arrays": [],
|
2019-06-17 20:05:41 +02:00
|
|
|
"w2l_urls": [],
|
2018-11-20 18:10:12 +01:00
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "BInitWorkshopForGameServer",
|
|
|
|
"l2w_names": [],
|
|
|
|
"l2w_lens": [],
|
2019-06-17 20:05:41 +02:00
|
|
|
"l2w_urls": [],
|
2018-11-20 18:10:12 +01:00
|
|
|
"w2l_names": ["pszFolder"],
|
|
|
|
"w2l_arrays": [False],
|
2019-06-17 20:05:41 +02:00
|
|
|
"w2l_urls": [False],
|
2018-11-20 18:10:12 +01:00
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "GetUserDataFolder",
|
|
|
|
"l2w_names": ["pchBuffer"],
|
|
|
|
"l2w_lens": ["cubBuffer"],
|
2019-06-17 20:05:41 +02:00
|
|
|
"l2w_urls": [False],
|
2018-11-20 18:10:12 +01:00
|
|
|
"w2l_names": [],
|
|
|
|
"w2l_arrays": [],
|
2019-06-17 20:05:41 +02:00
|
|
|
"w2l_urls": [],
|
2018-11-20 18:10:12 +01:00
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "CheckFileSignature",
|
|
|
|
"l2w_names": [],
|
|
|
|
"l2w_lens": [],
|
2019-06-17 20:05:41 +02:00
|
|
|
"l2w_urls": [],
|
2018-11-20 18:10:12 +01:00
|
|
|
"w2l_names": ["szFileName"],
|
|
|
|
"w2l_arrays": [False],
|
2019-06-17 20:05:41 +02:00
|
|
|
"w2l_urls": [False],
|
2018-11-20 18:10:12 +01:00
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "Init",
|
|
|
|
"l2w_names": [],
|
|
|
|
"l2w_lens": [],
|
2019-06-17 20:05:41 +02:00
|
|
|
"l2w_urls": [],
|
2018-11-20 18:10:12 +01:00
|
|
|
"w2l_names": ["pchAbsolutePathToControllerConfigVDF"],
|
|
|
|
"w2l_arrays": [False],
|
2019-06-17 20:05:41 +02:00
|
|
|
"w2l_urls": [False],
|
2018-11-20 18:10:12 +01:00
|
|
|
"return_is_size": False
|
2021-10-08 16:38:27 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "SetInputActionManifestFilePath",
|
|
|
|
"l2w_names": [],
|
|
|
|
"l2w_lens": [],
|
|
|
|
"l2w_urls": [],
|
|
|
|
"w2l_names": ["pchInputActionManifestAbsolutePath"],
|
|
|
|
"w2l_arrays": [False],
|
|
|
|
"w2l_urls": [False],
|
|
|
|
"return_is_size": False
|
|
|
|
},
|
2018-11-20 18:10:12 +01:00
|
|
|
]
|
|
|
|
|
2018-10-29 17:21:49 +01:00
|
|
|
def strip_const(typename):
|
|
|
|
return typename.replace("const ", "", 1)
|
|
|
|
|
2021-12-14 18:31:34 +01:00
|
|
|
windows_structs32 = {}
|
2018-10-30 14:09:46 +01:00
|
|
|
def find_windows_struct(struct):
|
2021-12-14 18:31:34 +01:00
|
|
|
return windows_structs32.get(strip_const(struct.spelling), None)
|
2018-10-30 14:09:46 +01:00
|
|
|
|
2021-12-14 18:31:34 +01:00
|
|
|
windows_structs64 = {}
|
2019-06-13 16:12:28 +02:00
|
|
|
def find_windows64_struct(struct):
|
2021-12-14 18:31:34 +01:00
|
|
|
return windows_structs64.get(strip_const(struct.spelling), None)
|
2019-06-13 16:12:28 +02:00
|
|
|
|
2021-12-14 18:31:34 +01:00
|
|
|
linux_structs64 = {}
|
2019-06-13 16:12:28 +02:00
|
|
|
def find_linux64_struct(struct):
|
2021-12-14 18:31:34 +01:00
|
|
|
return linux_structs64.get(strip_const(struct.spelling), None)
|
2019-06-13 16:12:28 +02:00
|
|
|
|
2018-10-30 14:09:46 +01:00
|
|
|
def struct_needs_conversion_nocache(struct):
|
|
|
|
if strip_const(struct.spelling) in exempt_structs:
|
|
|
|
return False
|
2019-05-16 18:23:30 +02:00
|
|
|
if strip_const(struct.spelling) in manually_handled_structs:
|
|
|
|
return True
|
2019-06-13 16:12:28 +02:00
|
|
|
|
|
|
|
#check 32-bit compat
|
2018-10-30 14:09:46 +01:00
|
|
|
windows_struct = find_windows_struct(struct)
|
2021-09-15 21:52:44 +02:00
|
|
|
if windows_struct is None:
|
|
|
|
print("Couldn't find windows struct for " + struct.spelling)
|
2018-10-30 14:09:46 +01:00
|
|
|
assert(not windows_struct is None) #must find windows_struct
|
|
|
|
for field in struct.get_fields():
|
|
|
|
if struct.get_offset(field.spelling) != windows_struct.get_offset(field.spelling):
|
|
|
|
return True
|
2021-12-21 10:41:34 +01:00
|
|
|
if field.type.kind == TypeKind.RECORD and \
|
2018-10-30 14:09:46 +01:00
|
|
|
struct_needs_conversion(field.type):
|
|
|
|
return True
|
2019-06-13 16:12:28 +02:00
|
|
|
|
|
|
|
#check 64-bit compat
|
|
|
|
windows_struct = find_windows64_struct(struct)
|
|
|
|
assert(not windows_struct is None) #must find windows_struct
|
|
|
|
lin64_struct = find_linux64_struct(struct)
|
|
|
|
assert(not lin64_struct is None) #must find lin64_struct
|
|
|
|
for field in lin64_struct.get_fields():
|
|
|
|
if lin64_struct.get_offset(field.spelling) != windows_struct.get_offset(field.spelling):
|
|
|
|
return True
|
2021-12-21 10:41:34 +01:00
|
|
|
if field.type.kind == TypeKind.RECORD and \
|
2019-06-13 16:12:28 +02:00
|
|
|
struct_needs_conversion(field.type):
|
|
|
|
return True
|
|
|
|
|
|
|
|
#check if any members need path conversion
|
2018-11-20 18:10:12 +01:00
|
|
|
path_conv = get_path_converter(struct)
|
|
|
|
if path_conv:
|
|
|
|
return True
|
2018-10-30 14:09:46 +01:00
|
|
|
return False
|
|
|
|
|
|
|
|
def struct_needs_conversion(struct):
|
|
|
|
if not sdkver in struct_conversion_cache:
|
|
|
|
struct_conversion_cache[sdkver] = {}
|
|
|
|
if not strip_const(struct.spelling) in struct_conversion_cache[sdkver]:
|
|
|
|
struct_conversion_cache[sdkver][strip_const(struct.spelling)] = struct_needs_conversion_nocache(struct)
|
|
|
|
return struct_conversion_cache[sdkver][strip_const(struct.spelling)]
|
|
|
|
|
2018-01-29 20:58:39 +01:00
|
|
|
def handle_destructor(cfile, classname, winclassname, method):
|
2021-11-12 17:14:14 +01:00
|
|
|
cfile.write(f"DEFINE_THISCALL_WRAPPER({winclassname}_destructor, 4)\n")
|
|
|
|
cfile.write(f"void __thiscall {winclassname}_destructor({winclassname} *_this)\n{{/* never called */}}\n\n")
|
2018-01-29 20:58:39 +01:00
|
|
|
return "destructor"
|
|
|
|
|
2018-11-20 18:10:12 +01:00
|
|
|
def get_path_converter(parent):
|
|
|
|
for conv in path_conversions:
|
|
|
|
if conv["parent_name"] in parent.spelling:
|
|
|
|
if None in conv["l2w_names"]:
|
|
|
|
return conv
|
2021-12-21 10:41:34 +01:00
|
|
|
if type(parent) == Type:
|
2018-11-20 18:10:12 +01:00
|
|
|
children = list(parent.get_fields())
|
|
|
|
else:
|
|
|
|
children = list(parent.get_children())
|
|
|
|
for child in children:
|
|
|
|
if child.spelling in conv["w2l_names"] or \
|
|
|
|
child.spelling in conv["l2w_names"]:
|
|
|
|
return conv
|
|
|
|
return None
|
|
|
|
|
2019-05-30 17:28:09 +02:00
|
|
|
class DummyWriter(object):
|
|
|
|
def write(self, s):
|
|
|
|
#noop
|
|
|
|
pass
|
|
|
|
|
2019-06-17 20:05:41 +02:00
|
|
|
def to_c_bool(b):
|
|
|
|
if b:
|
|
|
|
return "1"
|
|
|
|
return "0"
|
|
|
|
|
2019-05-30 17:28:09 +02:00
|
|
|
dummy_writer = DummyWriter()
|
|
|
|
|
2018-01-18 17:24:05 +01:00
|
|
|
def handle_method(cfile, classname, winclassname, cppname, method, cpp, cpp_h, existing_methods):
|
|
|
|
used_name = method.spelling
|
2018-09-05 22:10:48 +02:00
|
|
|
if used_name in existing_methods:
|
|
|
|
number = '2'
|
|
|
|
while used_name in existing_methods:
|
|
|
|
idx = existing_methods.index(used_name)
|
2021-11-12 17:14:14 +01:00
|
|
|
used_name = f"{method.spelling}_{number}"
|
2018-09-05 22:10:48 +02:00
|
|
|
number = chr(ord(number) + 1)
|
|
|
|
existing_methods.insert(idx, used_name)
|
|
|
|
else:
|
|
|
|
existing_methods.append(used_name)
|
2021-12-21 10:41:34 +01:00
|
|
|
returns_record = method.result_type.get_canonical().kind == TypeKind.RECORD
|
2018-01-18 17:24:05 +01:00
|
|
|
if returns_record:
|
|
|
|
parambytes = 8 #_this + return pointer
|
|
|
|
else:
|
|
|
|
parambytes = 4 #_this
|
|
|
|
for param in list(method.get_children()):
|
2021-12-21 10:41:34 +01:00
|
|
|
if param.kind == CursorKind.PARM_DECL:
|
|
|
|
if param.type.kind == TypeKind.LVALUEREFERENCE:
|
2021-11-12 20:13:03 +01:00
|
|
|
parambytes += 4
|
|
|
|
else:
|
|
|
|
parambytes += int(math.ceil(param.type.get_size()/4.0) * 4)
|
2022-06-14 16:21:49 +02:00
|
|
|
if method_needs_manual_handling(cppname, used_name):
|
|
|
|
cpp = dummy_writer #just don't write the cpp function
|
2021-11-12 17:14:14 +01:00
|
|
|
cfile.write(f"DEFINE_THISCALL_WRAPPER({winclassname}_{used_name}, {parambytes})\n")
|
2018-01-18 17:24:05 +01:00
|
|
|
cpp_h.write("extern ")
|
|
|
|
if method.result_type.spelling.startswith("ISteam"):
|
2021-11-12 17:14:14 +01:00
|
|
|
cfile.write(f"win{method.result_type.spelling} ")
|
2018-01-18 17:24:05 +01:00
|
|
|
cpp.write("void *")
|
|
|
|
cpp_h.write("void *")
|
|
|
|
elif returns_record:
|
2021-11-12 17:14:14 +01:00
|
|
|
cfile.write(f"{method.result_type.spelling} *")
|
|
|
|
cpp.write(f"{method.result_type.spelling} ")
|
|
|
|
cpp_h.write(f"{method.result_type.spelling} ")
|
2018-01-18 17:24:05 +01:00
|
|
|
else:
|
2021-11-12 17:14:14 +01:00
|
|
|
cfile.write(f"{method.result_type.spelling} ")
|
|
|
|
cpp.write(f"{method.result_type.spelling} ")
|
|
|
|
cpp_h.write(f"{method.result_type.spelling} ")
|
|
|
|
cfile.write(f'__thiscall {winclassname}_{used_name}({winclassname} *_this')
|
|
|
|
cpp.write(f"{cppname}_{used_name}(void *linux_side")
|
|
|
|
cpp_h.write(f"{cppname}_{used_name}(void *")
|
2018-01-18 17:24:05 +01:00
|
|
|
if returns_record:
|
2021-11-12 17:14:14 +01:00
|
|
|
cfile.write(f", {method.result_type.spelling} *_r")
|
2018-01-18 17:24:05 +01:00
|
|
|
unnamed = 'a'
|
2018-10-29 17:21:49 +01:00
|
|
|
need_convert = []
|
2019-05-17 21:48:34 +02:00
|
|
|
manual_convert = []
|
2018-01-18 17:24:05 +01:00
|
|
|
for param in list(method.get_children()):
|
2021-12-21 10:41:34 +01:00
|
|
|
if param.kind == CursorKind.PARM_DECL:
|
|
|
|
if param.type.kind == TypeKind.POINTER and \
|
2021-03-01 17:52:59 +01:00
|
|
|
(param.type.get_pointee().kind == TypeKind.UNEXPOSED or param.type.get_pointee().kind == TypeKind.FUNCTIONPROTO):
|
2018-01-18 17:24:05 +01:00
|
|
|
#unspecified function pointer
|
|
|
|
typename = "void *"
|
|
|
|
else:
|
2021-11-12 17:14:14 +01:00
|
|
|
typename = param.type.spelling.split("::")[-1]
|
2018-10-29 17:21:49 +01:00
|
|
|
|
2021-11-12 17:14:14 +01:00
|
|
|
real_type = param.type
|
2021-12-21 10:41:34 +01:00
|
|
|
while real_type.kind == TypeKind.POINTER:
|
2018-10-29 17:21:49 +01:00
|
|
|
real_type = real_type.get_pointee()
|
2019-02-26 16:05:29 +01:00
|
|
|
win_name = typename
|
2021-12-21 10:41:34 +01:00
|
|
|
if real_type.kind == TypeKind.RECORD and \
|
2018-10-30 14:09:46 +01:00
|
|
|
not real_type.spelling in wrapped_classes and \
|
|
|
|
struct_needs_conversion(real_type):
|
2018-10-29 17:21:49 +01:00
|
|
|
need_convert.append(param)
|
2019-02-26 16:05:29 +01:00
|
|
|
#preserve pointers
|
2021-11-12 17:14:14 +01:00
|
|
|
win_name = typename.replace(real_type.spelling, f"win{real_type.spelling}_{sdkver}")
|
2019-05-17 21:48:34 +02:00
|
|
|
elif real_type.spelling in manual_type_converters:
|
|
|
|
manual_convert.append(param)
|
2019-06-17 17:50:11 +02:00
|
|
|
elif param.spelling in manual_param_converters:
|
|
|
|
manual_convert.append(param)
|
2018-10-29 17:21:49 +01:00
|
|
|
|
2021-11-12 20:13:03 +01:00
|
|
|
win_name = win_name.replace('&', '*')
|
|
|
|
|
2018-01-18 17:24:05 +01:00
|
|
|
if param.spelling == "":
|
2021-11-12 17:14:14 +01:00
|
|
|
cfile.write(f", {win_name} _{unnamed}")
|
|
|
|
cpp.write(f", {win_name} _{unnamed}")
|
|
|
|
cpp_h.write(f", {win_name}")
|
2018-01-18 17:24:05 +01:00
|
|
|
unnamed = chr(ord(unnamed) + 1)
|
|
|
|
else:
|
2021-11-12 17:14:14 +01:00
|
|
|
cfile.write(f", {win_name} {param.spelling}")
|
|
|
|
cpp.write(f", {win_name} {param.spelling}")
|
|
|
|
cpp_h.write(f", {win_name}")
|
2018-01-18 17:24:05 +01:00
|
|
|
cfile.write(")\n{\n")
|
|
|
|
cpp.write(")\n{\n")
|
|
|
|
cpp_h.write(");\n")
|
|
|
|
|
2018-11-20 18:10:12 +01:00
|
|
|
path_conv = get_path_converter(method)
|
|
|
|
|
|
|
|
if path_conv:
|
|
|
|
for i in range(len(path_conv["w2l_names"])):
|
|
|
|
if path_conv["w2l_arrays"][i]:
|
2021-11-12 17:14:14 +01:00
|
|
|
cfile.write(f" const char **lin_{path_conv['w2l_names'][i]} = steamclient_dos_to_unix_stringlist({path_conv['w2l_names'][i]});\n")
|
2018-11-20 18:10:12 +01:00
|
|
|
# TODO
|
|
|
|
pass
|
|
|
|
else:
|
2021-11-12 17:14:14 +01:00
|
|
|
cfile.write(f" char lin_{path_conv['w2l_names'][i]}[PATH_MAX];\n")
|
|
|
|
cfile.write(f" steamclient_dos_path_to_unix_path({path_conv['w2l_names'][i]}, lin_{path_conv['w2l_names'][i]}, {to_c_bool(path_conv['w2l_urls'][i])});\n")
|
2018-11-20 18:10:12 +01:00
|
|
|
if None in path_conv["l2w_names"]:
|
|
|
|
cfile.write(" const char *path_result;\n")
|
|
|
|
elif path_conv["return_is_size"]:
|
|
|
|
cfile.write(" uint32 path_result;\n")
|
|
|
|
elif len(path_conv["l2w_names"]) > 0:
|
2021-11-12 17:14:14 +01:00
|
|
|
cfile.write(f" {method.result_type.spelling} path_result;\n")
|
2018-01-18 17:24:05 +01:00
|
|
|
|
2018-10-29 17:21:49 +01:00
|
|
|
for param in need_convert:
|
2021-12-21 10:41:34 +01:00
|
|
|
if param.type.kind == TypeKind.POINTER:
|
2018-10-29 17:21:49 +01:00
|
|
|
#handle single pointers, but not double pointers
|
2021-11-12 17:14:14 +01:00
|
|
|
real_type = param.type
|
2021-12-21 10:41:34 +01:00
|
|
|
while real_type.kind == TypeKind.POINTER:
|
2019-05-16 18:23:30 +02:00
|
|
|
real_type = real_type.get_pointee()
|
2021-12-21 10:41:34 +01:00
|
|
|
assert(param.type.get_pointee().kind == TypeKind.RECORD or \
|
2019-05-16 18:23:30 +02:00
|
|
|
strip_const(real_type.spelling) in manually_handled_structs)
|
2021-11-12 17:14:14 +01:00
|
|
|
cpp.write(f" {strip_const(param.type.get_pointee().spelling)} lin_{param.spelling};\n")
|
|
|
|
cpp.write(f" win_to_lin_struct_{strip_const(real_type.spelling)}_{sdkver}({param.spelling}, &lin_{param.spelling});\n")
|
2018-10-29 17:21:49 +01:00
|
|
|
else:
|
|
|
|
#raw structs
|
2021-11-12 17:14:14 +01:00
|
|
|
cpp.write(f" {param.type.spelling} lin_{param.spelling};\n")
|
|
|
|
cpp.write(f" win_to_lin_struct_{param.type.spelling}_{sdkver}(&{param.spelling}, &lin_{param.spelling});\n")
|
2019-05-17 21:48:34 +02:00
|
|
|
for param in manual_convert:
|
2019-06-17 17:50:11 +02:00
|
|
|
if param.spelling in manual_param_converters:
|
2021-11-12 17:14:14 +01:00
|
|
|
cpp.write(f" {param.spelling} = manual_convert_{param.spelling}({param.spelling});\n")
|
2019-06-17 17:50:11 +02:00
|
|
|
else:
|
2021-11-12 17:14:14 +01:00
|
|
|
cpp.write(f" {param.spelling} = ({param.type.spelling})manual_convert_{param.type.spelling}((void*){param.spelling});\n")
|
2018-01-18 17:24:05 +01:00
|
|
|
|
|
|
|
cfile.write(" TRACE(\"%p\\n\", _this);\n")
|
|
|
|
|
2021-12-21 10:41:34 +01:00
|
|
|
if method.result_type.kind == TypeKind.VOID:
|
2018-01-18 17:24:05 +01:00
|
|
|
cfile.write(" ")
|
2018-11-20 18:10:12 +01:00
|
|
|
elif path_conv and (len(path_conv["l2w_names"]) > 0 or path_conv["return_is_size"]):
|
2018-01-18 17:24:05 +01:00
|
|
|
cfile.write(" path_result = ")
|
|
|
|
elif returns_record:
|
|
|
|
cfile.write(" *_r = ")
|
|
|
|
else:
|
|
|
|
cfile.write(" return ")
|
2018-10-29 17:21:49 +01:00
|
|
|
|
2021-12-21 10:41:34 +01:00
|
|
|
if method.result_type.kind == TypeKind.VOID:
|
2018-10-29 17:21:49 +01:00
|
|
|
cpp.write(" ")
|
|
|
|
elif len(need_convert) > 0:
|
2021-11-12 17:14:14 +01:00
|
|
|
cpp.write(f" {method.result_type.spelling} retval = ")
|
2018-10-29 17:21:49 +01:00
|
|
|
else:
|
2018-01-18 17:24:05 +01:00
|
|
|
cpp.write(" return ")
|
|
|
|
|
2018-10-30 17:30:28 +01:00
|
|
|
should_do_cb_wrap = "GetAPICallResult" in used_name
|
2021-12-20 16:48:44 +01:00
|
|
|
should_gen_wrapper = cpp != dummy_writer and \
|
|
|
|
(method.result_type.spelling.startswith("ISteam") or \
|
|
|
|
used_name.startswith("GetISteamGenericInterface"))
|
2018-01-18 17:24:05 +01:00
|
|
|
|
2018-10-30 17:30:28 +01:00
|
|
|
if should_do_cb_wrap:
|
2021-11-12 17:14:14 +01:00
|
|
|
cfile.write(f"do_cb_wrap(0, _this->linux_side, &{cppname}_{used_name}")
|
2018-10-30 17:30:28 +01:00
|
|
|
else:
|
|
|
|
if should_gen_wrapper:
|
|
|
|
cfile.write("create_win_interface(pchVersion,\n ")
|
2021-11-12 17:14:14 +01:00
|
|
|
cfile.write(f"{cppname}_{used_name}(_this->linux_side")
|
|
|
|
cpp.write(f"(({classname}*)linux_side)->{method.spelling}(")
|
2018-01-18 17:24:05 +01:00
|
|
|
unnamed = 'a'
|
|
|
|
first = True
|
|
|
|
for param in list(method.get_children()):
|
2021-12-21 10:41:34 +01:00
|
|
|
if param.kind == CursorKind.PARM_DECL:
|
2018-01-18 17:24:05 +01:00
|
|
|
if not first:
|
|
|
|
cpp.write(", ")
|
|
|
|
else:
|
|
|
|
first = False
|
|
|
|
if param.spelling == "":
|
2021-11-12 17:14:14 +01:00
|
|
|
cfile.write(f", _{unnamed}")
|
|
|
|
cpp.write(f"({param.type.spelling})_{unnamed}")
|
2018-01-18 17:24:05 +01:00
|
|
|
unnamed = chr(ord(unnamed) + 1)
|
2021-12-21 10:41:34 +01:00
|
|
|
elif param.type.kind == TypeKind.POINTER and \
|
2018-10-29 19:23:17 +01:00
|
|
|
param.type.get_pointee().spelling in wrapped_classes:
|
2021-11-12 17:14:14 +01:00
|
|
|
cfile.write(f", create_Linux{param.type.get_pointee().spelling}({param.spelling}, \"{winclassname}\")")
|
|
|
|
cpp.write(f"({param.type.spelling}){param.spelling}")
|
2018-11-20 18:10:12 +01:00
|
|
|
elif path_conv and param.spelling in path_conv["w2l_names"]:
|
2021-11-12 17:14:14 +01:00
|
|
|
cfile.write(f", {param.spelling} ? lin_{param.spelling} : NULL")
|
|
|
|
cpp.write(f"({param.type.spelling}){param.spelling}")
|
2018-10-29 17:21:49 +01:00
|
|
|
elif param in need_convert:
|
2021-11-12 17:14:14 +01:00
|
|
|
cfile.write(f", {param.spelling}")
|
2021-12-21 10:41:34 +01:00
|
|
|
if param.type.kind != TypeKind.POINTER:
|
2021-11-12 17:14:14 +01:00
|
|
|
cpp.write(f"lin_{param.spelling}")
|
2018-10-29 17:21:49 +01:00
|
|
|
else:
|
2021-11-12 17:14:14 +01:00
|
|
|
cpp.write(f"&lin_{param.spelling}")
|
2021-12-21 10:41:34 +01:00
|
|
|
elif param.type.kind == TypeKind.LVALUEREFERENCE:
|
2021-11-12 20:13:03 +01:00
|
|
|
cfile.write(f", {param.spelling}")
|
|
|
|
cpp.write(f"*{param.spelling}")
|
2018-01-18 17:24:05 +01:00
|
|
|
else:
|
2021-11-12 17:14:14 +01:00
|
|
|
cfile.write(f", {param.spelling}")
|
|
|
|
cpp.write(f"({param.type.spelling}){param.spelling}")
|
2018-01-18 17:24:05 +01:00
|
|
|
if should_gen_wrapper:
|
|
|
|
cfile.write(")")
|
|
|
|
cfile.write(");\n")
|
|
|
|
cpp.write(");\n")
|
|
|
|
if returns_record:
|
|
|
|
cfile.write(" return _r;\n")
|
2018-11-20 18:10:12 +01:00
|
|
|
if path_conv and len(path_conv["l2w_names"]) > 0:
|
|
|
|
for i in range(len(path_conv["l2w_names"])):
|
2021-10-08 18:09:30 +02:00
|
|
|
cfile.write(" ")
|
|
|
|
if path_conv["return_is_size"]:
|
|
|
|
cfile.write("path_result = ")
|
2021-11-12 17:14:14 +01:00
|
|
|
cfile.write(f"steamclient_unix_path_to_dos_path(path_result, {path_conv['l2w_names'][i]}, {path_conv['l2w_names'][i]}, {path_conv['l2w_lens'][i]}, {to_c_bool(path_conv['l2w_urls'][i])});\n")
|
2018-11-20 18:10:12 +01:00
|
|
|
cfile.write(" return path_result;\n")
|
|
|
|
if path_conv:
|
|
|
|
for i in range(len(path_conv["w2l_names"])):
|
|
|
|
if path_conv["w2l_arrays"][i]:
|
2021-11-12 17:14:14 +01:00
|
|
|
cfile.write(f" steamclient_free_stringlist(lin_{path_conv['w2l_names'][i]});\n")
|
2018-01-18 17:24:05 +01:00
|
|
|
cfile.write("}\n\n")
|
2018-10-29 17:21:49 +01:00
|
|
|
for param in need_convert:
|
2021-12-21 10:41:34 +01:00
|
|
|
if param.type.kind == TypeKind.POINTER:
|
2018-10-29 19:26:08 +01:00
|
|
|
if not "const " in param.type.spelling: #don't modify const arguments
|
2021-11-12 17:14:14 +01:00
|
|
|
real_type = param.type
|
2021-12-21 10:41:34 +01:00
|
|
|
while real_type.kind == TypeKind.POINTER:
|
2019-05-16 18:23:30 +02:00
|
|
|
real_type = real_type.get_pointee()
|
2021-11-12 17:14:14 +01:00
|
|
|
cpp.write(f" lin_to_win_struct_{real_type.spelling}_{sdkver}(&lin_{param.spelling}, {param.spelling});\n")
|
2018-10-29 17:21:49 +01:00
|
|
|
else:
|
2021-11-12 17:14:14 +01:00
|
|
|
cpp.write(f" lin_to_win_struct_{param.type.spelling}_{sdkver}(&lin_{param.spelling}, &{param.spelling});\n")
|
2021-12-21 10:41:34 +01:00
|
|
|
if method.result_type.kind != TypeKind.VOID and \
|
2018-10-29 17:21:49 +01:00
|
|
|
len(need_convert) > 0:
|
|
|
|
cpp.write(" return retval;\n")
|
2018-01-18 17:24:05 +01:00
|
|
|
cpp.write("}\n\n")
|
|
|
|
|
|
|
|
def get_iface_version(classname):
|
|
|
|
# ISteamClient -> STEAMCLIENT_INTERFACE_VERSION
|
2021-11-12 17:14:14 +01:00
|
|
|
defname = f"{classname[1:].upper()}_INTERFACE_VERSION"
|
2018-01-18 17:24:05 +01:00
|
|
|
if defname in iface_versions.keys():
|
|
|
|
ver = iface_versions[defname]
|
|
|
|
else:
|
2021-11-12 17:14:14 +01:00
|
|
|
defname = f"{classname[1:].upper()}_VERSION"
|
2021-03-01 17:04:28 +01:00
|
|
|
if defname in iface_versions.keys():
|
|
|
|
ver = iface_versions[defname]
|
|
|
|
else:
|
|
|
|
ver = "UNVERSIONED"
|
2018-01-18 17:24:05 +01:00
|
|
|
if classname in class_versions.keys() and ver in class_versions[classname]:
|
|
|
|
return (ver, True)
|
|
|
|
if not classname in class_versions.keys():
|
|
|
|
class_versions[classname] = []
|
|
|
|
class_versions[classname].append(ver)
|
|
|
|
return (ver, False)
|
|
|
|
|
2022-01-06 15:52:49 +01:00
|
|
|
def handle_class(sdkver, classnode, file):
|
2018-01-18 17:24:05 +01:00
|
|
|
children = list(classnode.get_children())
|
|
|
|
if len(children) == 0:
|
|
|
|
return
|
|
|
|
(iface_version, already_generated) = get_iface_version(classnode.spelling)
|
|
|
|
if already_generated:
|
|
|
|
return
|
2021-11-12 17:14:14 +01:00
|
|
|
winname = f"win{classnode.spelling}"
|
|
|
|
cppname = f"cpp{classnode.spelling}_{iface_version}"
|
2018-01-18 17:24:05 +01:00
|
|
|
|
2021-11-12 17:14:14 +01:00
|
|
|
file_exists = os.path.isfile(f"{winname}.c")
|
|
|
|
cfile = open(f"{winname}.c", "a")
|
2018-01-18 17:24:05 +01:00
|
|
|
if not file_exists:
|
|
|
|
cfile.write("""/* This file is auto-generated, do not edit. */
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
#include "cxx.h"
|
|
|
|
|
|
|
|
#include "steam_defs.h"
|
|
|
|
|
|
|
|
#include "steamclient_private.h"
|
|
|
|
|
2019-02-26 16:05:29 +01:00
|
|
|
#include "struct_converters.h"
|
|
|
|
|
2018-01-18 17:24:05 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(steamclient);
|
|
|
|
|
|
|
|
""")
|
|
|
|
|
2021-11-12 17:14:14 +01:00
|
|
|
cpp = open(f"{cppname}.cpp", "w")
|
2018-01-18 17:24:05 +01:00
|
|
|
cpp.write("#include \"steam_defs.h\"\n")
|
2019-08-16 16:00:45 +02:00
|
|
|
cpp.write("#pragma push_macro(\"__cdecl\")\n")
|
|
|
|
cpp.write("#undef __cdecl\n")
|
2021-11-12 17:14:14 +01:00
|
|
|
cpp.write(f"#include \"steamworks_sdk_{sdkver}/steam_api.h\"\n")
|
|
|
|
if os.path.isfile(f"steamworks_sdk_{sdkver}/steamnetworkingtypes.h"):
|
|
|
|
cpp.write(f"#include \"steamworks_sdk_{sdkver}/steamnetworkingtypes.h\"\n")
|
2022-01-06 15:52:49 +01:00
|
|
|
if not file == "steam_api.h":
|
|
|
|
cpp.write(f"#include \"steamworks_sdk_{sdkver}/{file}\"\n")
|
2019-08-16 16:00:45 +02:00
|
|
|
cpp.write("#pragma pop_macro(\"__cdecl\")\n")
|
2018-10-30 20:06:46 +01:00
|
|
|
cpp.write("#include \"steamclient_private.h\"\n")
|
2018-01-18 17:24:05 +01:00
|
|
|
cpp.write("#ifdef __cplusplus\nextern \"C\" {\n#endif\n")
|
2021-11-12 17:14:14 +01:00
|
|
|
cpp.write(f"#define SDKVER_{sdkver}\n")
|
2019-02-26 16:05:29 +01:00
|
|
|
cpp.write("#include \"struct_converters.h\"\n")
|
2021-11-12 17:14:14 +01:00
|
|
|
cpp.write(f"#include \"{cppname}.h\"\n")
|
2018-01-18 17:24:05 +01:00
|
|
|
|
2021-11-12 17:14:14 +01:00
|
|
|
cpp_h = open(f"{cppname}.h", "w")
|
2018-01-18 17:24:05 +01:00
|
|
|
|
2021-11-12 17:14:14 +01:00
|
|
|
winclassname = f"win{classnode.spelling}_{iface_version}"
|
|
|
|
cfile.write(f"#include \"{cppname}.h\"\n\n")
|
|
|
|
cfile.write(f"typedef struct __{winclassname} {{\n")
|
2018-01-18 17:24:05 +01:00
|
|
|
cfile.write(" vtable_ptr *vtable;\n")
|
|
|
|
cfile.write(" void *linux_side;\n")
|
2021-11-12 17:14:14 +01:00
|
|
|
cfile.write(f"}} {winclassname};\n\n")
|
2018-01-18 17:24:05 +01:00
|
|
|
methods = []
|
|
|
|
for child in children:
|
2021-12-21 10:41:34 +01:00
|
|
|
if child.kind == CursorKind.CXX_METHOD and \
|
2019-05-17 16:33:44 +02:00
|
|
|
child.is_virtual_method():
|
2018-09-05 22:10:48 +02:00
|
|
|
handle_method(cfile, classnode.spelling, winclassname, cppname, child, cpp, cpp_h, methods)
|
2021-12-21 10:41:34 +01:00
|
|
|
elif child.kind == CursorKind.DESTRUCTOR:
|
2018-01-29 20:58:39 +01:00
|
|
|
methods.append(handle_destructor(cfile, classnode.spelling, winclassname, child))
|
2018-01-18 17:24:05 +01:00
|
|
|
|
2021-11-12 17:14:14 +01:00
|
|
|
cfile.write(f"extern vtable_ptr {winclassname}_vtable;\n\n")
|
2018-01-18 17:24:05 +01:00
|
|
|
cfile.write("#ifndef __GNUC__\n")
|
|
|
|
cfile.write("void __asm_dummy_vtables(void) {\n")
|
|
|
|
cfile.write("#endif\n")
|
2021-11-12 17:14:14 +01:00
|
|
|
cfile.write(f" __ASM_VTABLE({winclassname},\n")
|
2018-01-18 17:24:05 +01:00
|
|
|
for method in methods:
|
2021-11-12 17:14:14 +01:00
|
|
|
cfile.write(f" VTABLE_ADD_FUNC({winclassname}_{method})\n")
|
2018-01-18 17:24:05 +01:00
|
|
|
cfile.write(" );\n")
|
|
|
|
cfile.write("#ifndef __GNUC__\n")
|
|
|
|
cfile.write("}\n")
|
|
|
|
cfile.write("#endif\n\n")
|
2021-11-12 17:14:14 +01:00
|
|
|
cfile.write(f"{winclassname} *create_{winclassname}(void *linux_side)\n{{\n")
|
2021-12-20 16:48:44 +01:00
|
|
|
if classnode.spelling in wrapped_classes:
|
|
|
|
cfile.write(f" {winclassname} *r = HeapAlloc(GetProcessHeap(), 0, sizeof({winclassname}));\n")
|
|
|
|
else:
|
|
|
|
cfile.write(f" {winclassname} *r = alloc_mem_for_iface(sizeof({winclassname}), \"{iface_version}\");\n")
|
2018-01-18 17:24:05 +01:00
|
|
|
cfile.write(" TRACE(\"-> %p\\n\", r);\n")
|
2022-06-24 05:02:39 +02:00
|
|
|
cfile.write(f" r->vtable = alloc_vtable(&{winclassname}_vtable, {len(methods)}, \"{iface_version}\");\n")
|
2018-01-18 17:24:05 +01:00
|
|
|
cfile.write(" r->linux_side = linux_side;\n")
|
|
|
|
cfile.write(" return r;\n}\n\n")
|
|
|
|
|
|
|
|
cpp.write("#ifdef __cplusplus\n}\n#endif\n")
|
|
|
|
|
|
|
|
constructors = open("win_constructors.h", "a")
|
2021-11-12 17:14:14 +01:00
|
|
|
constructors.write(f"extern void *create_{winclassname}(void *);\n")
|
2018-01-18 17:24:05 +01:00
|
|
|
|
|
|
|
constructors = open("win_constructors_table.dat", "a")
|
2021-11-12 17:14:14 +01:00
|
|
|
constructors.write(f" {{\"{iface_version}\", &create_{winclassname}}},\n")
|
2018-01-18 17:24:05 +01:00
|
|
|
if iface_version in aliases.keys():
|
|
|
|
for alias in aliases[iface_version]:
|
2021-11-12 17:14:14 +01:00
|
|
|
constructors.write(f" {{\"{alias}\", &create_{winclassname}}}, /* alias */\n")
|
2018-01-18 17:24:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
generated_cb_handlers = []
|
|
|
|
generated_cb_ids = []
|
|
|
|
cpp_files_need_close_brace = []
|
|
|
|
cb_table = {}
|
2019-06-13 16:12:28 +02:00
|
|
|
cb_table64 = {}
|
2018-01-18 17:24:05 +01:00
|
|
|
|
2019-05-30 22:20:14 +02:00
|
|
|
def get_field_attribute_str(field):
|
2021-12-21 10:41:34 +01:00
|
|
|
if field.type.kind != TypeKind.RECORD:
|
2019-05-30 22:20:14 +02:00
|
|
|
return ""
|
|
|
|
win_struct = find_windows_struct(field.type)
|
|
|
|
if win_struct is None:
|
|
|
|
align = field.type.get_align()
|
|
|
|
else:
|
|
|
|
align = win_struct.get_align()
|
|
|
|
return " __attribute__((aligned(" + str(align) + ")))"
|
|
|
|
|
2018-01-18 17:24:05 +01: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 15:28:28 +01:00
|
|
|
def handle_struct(sdkver, struct):
|
|
|
|
members = struct.get_children()
|
|
|
|
cb_num = None
|
2018-10-29 16:15:32 +01:00
|
|
|
has_fields = False
|
2018-10-29 15:28:28 +01:00
|
|
|
for c in members:
|
2021-12-21 10:41:34 +01:00
|
|
|
if c.kind == CursorKind.ENUM_DECL:
|
2018-10-29 15:28:28 +01:00
|
|
|
enums = c.get_children()
|
|
|
|
for e in enums:
|
|
|
|
if e.displayname == "k_iCallback":
|
|
|
|
cb_num = e.enum_value
|
2021-12-21 10:41:34 +01:00
|
|
|
if c.kind == CursorKind.FIELD_DECL:
|
2018-10-29 16:15:32 +01:00
|
|
|
has_fields = True
|
|
|
|
|
|
|
|
w2l_handler_name = None
|
|
|
|
l2w_handler_name = None
|
2018-01-18 17:24:05 +01:00
|
|
|
|
2019-06-13 16:12:28 +02:00
|
|
|
def dump_win_struct(to_file, name):
|
2019-02-26 16:05:29 +01:00
|
|
|
to_file.write("#pragma pack( push, 8 )\n")
|
2021-11-12 17:14:14 +01:00
|
|
|
to_file.write(f"struct win{name} {{\n")
|
2019-02-26 16:05:29 +01:00
|
|
|
for m in struct.get_children():
|
2021-12-21 10:41:34 +01:00
|
|
|
if m.kind == CursorKind.FIELD_DECL:
|
|
|
|
if m.type.kind == TypeKind.CONSTANTARRAY:
|
2021-11-12 17:14:14 +01:00
|
|
|
to_file.write(f" {m.type.element_type.spelling} {m.displayname}[{m.type.element_count}];\n")
|
2021-12-21 10:41:34 +01:00
|
|
|
elif m.type.kind == TypeKind.RECORD and \
|
2019-02-26 16:05:29 +01:00
|
|
|
struct_needs_conversion(m.type):
|
2021-11-12 17:14:14 +01:00
|
|
|
to_file.write(f" win{m.type.spelling}_{sdkver} {m.displayname};\n")
|
2019-02-26 16:05:29 +01:00
|
|
|
else:
|
2021-12-21 10:41:34 +01:00
|
|
|
if m.type.kind == TypeKind.POINTER and \
|
2021-03-01 17:52:59 +01:00
|
|
|
(m.type.get_pointee().kind == TypeKind.UNEXPOSED or m.type.get_pointee().kind == TypeKind.FUNCTIONPROTO):
|
2021-11-12 17:14:14 +01:00
|
|
|
to_file.write(f" void *{m.displayname}; /*fn pointer*/\n")
|
2019-05-16 18:23:30 +02:00
|
|
|
else:
|
2021-11-12 17:14:14 +01:00
|
|
|
to_file.write(f" {m.type.spelling} {m.displayname}{get_field_attribute_str(m)};\n")
|
2019-02-26 16:05:29 +01:00
|
|
|
to_file.write("} __attribute__ ((ms_struct));\n")
|
|
|
|
to_file.write("#pragma pack( pop )\n")
|
|
|
|
|
2018-10-29 15:28:28 +01:00
|
|
|
if cb_num is None:
|
2019-02-26 16:05:29 +01:00
|
|
|
hfile = open("struct_converters.h", "a")
|
2018-10-30 14:09:46 +01:00
|
|
|
|
2018-10-29 16:15:32 +01:00
|
|
|
if not has_fields:
|
|
|
|
return
|
2018-10-30 14:09:46 +01:00
|
|
|
if struct.spelling == "":
|
|
|
|
return
|
|
|
|
if not struct_needs_conversion(struct.type):
|
2018-10-29 16:15:32 +01:00
|
|
|
return
|
2018-10-30 14:09:46 +01:00
|
|
|
|
2021-11-12 17:14:14 +01:00
|
|
|
struct_name = f"{struct.displayname}_{sdkver}"
|
2019-05-17 16:33:44 +02:00
|
|
|
|
|
|
|
if struct_name in converted_structs:
|
|
|
|
return
|
|
|
|
converted_structs.append(struct_name)
|
|
|
|
|
2021-11-12 17:14:14 +01:00
|
|
|
w2l_handler_name = f"win_to_lin_struct_{struct_name}"
|
|
|
|
l2w_handler_name = f"lin_to_win_struct_{struct_name}"
|
2019-06-13 16:12:28 +02:00
|
|
|
l2w_handler_name64 = None
|
2018-10-29 17:38:13 +01:00
|
|
|
|
2021-11-12 17:14:14 +01:00
|
|
|
hfile.write(f"#if defined(SDKVER_{sdkver}) || !defined(__cplusplus)\n")
|
2019-06-13 16:12:28 +02:00
|
|
|
dump_win_struct(hfile, struct_name)
|
2021-11-12 17:14:14 +01:00
|
|
|
hfile.write(f"typedef struct win{struct_name} win{struct_name};\n")
|
|
|
|
hfile.write(f"struct {struct.displayname};\n")
|
2019-02-26 16:05:29 +01:00
|
|
|
|
2019-05-16 18:23:30 +02:00
|
|
|
if strip_const(struct.spelling) in manually_handled_structs:
|
|
|
|
hfile.write("#endif\n\n")
|
|
|
|
return
|
|
|
|
|
2021-11-12 17:14:14 +01:00
|
|
|
hfile.write(f"extern void {w2l_handler_name}(const struct win{struct_name} *w, struct {struct.displayname} *l);\n")
|
|
|
|
hfile.write(f"extern void {l2w_handler_name}(const struct {struct.displayname} *l, struct win{struct_name} *w);\n")
|
2019-02-26 16:05:29 +01:00
|
|
|
hfile.write("#endif\n\n")
|
2018-10-29 15:28:28 +01:00
|
|
|
else:
|
2018-10-30 14:09:46 +01:00
|
|
|
#for callbacks, we use the windows struct size in the cb dispatch switch
|
|
|
|
windows_struct = find_windows_struct(struct.type)
|
2019-06-13 16:12:28 +02:00
|
|
|
windows_struct64 = find_windows64_struct(struct.type)
|
|
|
|
struct64 = find_linux64_struct(struct.type)
|
2021-11-12 17:14:14 +01:00
|
|
|
struct_name = f"{struct.displayname}_{windows_struct.get_size()}"
|
|
|
|
l2w_handler_name = f"cb_{struct_name}"
|
2019-06-13 16:12:28 +02:00
|
|
|
if windows_struct64.get_size() != windows_struct.get_size():
|
2021-11-12 17:14:14 +01:00
|
|
|
struct_name64 = f"{struct.displayname}_{windows_struct64.get_size()}"
|
|
|
|
l2w_handler_name64 = f"cb_{struct_name64}"
|
2019-06-13 16:12:28 +02:00
|
|
|
else:
|
|
|
|
l2w_handler_name64 = None
|
2018-10-29 16:15:32 +01:00
|
|
|
if l2w_handler_name in generated_cb_handlers:
|
2018-10-29 15:28:28 +01:00
|
|
|
# we already have a handler for the callback struct of this size
|
|
|
|
return
|
2018-10-30 14:09:46 +01:00
|
|
|
if not struct_needs_conversion(struct.type):
|
2018-10-29 15:28:28 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
cb_id = cb_num | (struct.type.get_size() << 16)
|
2019-06-13 16:12:28 +02:00
|
|
|
cb_id64 = cb_num | (struct64.get_size() << 16)
|
2018-10-29 15:28:28 +01: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 17:38:13 +01:00
|
|
|
datfile = open("cb_converters.dat", "a")
|
2019-06-13 16:12:28 +02:00
|
|
|
if l2w_handler_name64:
|
|
|
|
datfile.write("#ifdef __i386__\n")
|
2021-11-12 17:14:14 +01:00
|
|
|
datfile.write(f"case 0x{cb_id:08x}: win_msg->m_cubParam = {windows_struct.get_size()}; 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 16:12:28 +02:00
|
|
|
datfile.write("#endif\n")
|
|
|
|
|
|
|
|
datfile.write("#ifdef __x86_64__\n")
|
2021-11-12 17:14:14 +01:00
|
|
|
datfile.write(f"case 0x{cb_id64:08x}: win_msg->m_cubParam = {windows_struct64.get_size()}; 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 16:12:28 +02:00
|
|
|
datfile.write("#endif\n")
|
|
|
|
else:
|
2021-11-12 17:14:14 +01:00
|
|
|
datfile.write(f"case 0x{cb_id:08x}: win_msg->m_cubParam = {windows_struct.get_size()}; 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 15:28:28 +01:00
|
|
|
|
2018-10-29 16:15:32 +01:00
|
|
|
generated_cb_handlers.append(l2w_handler_name)
|
2018-10-29 15:28:28 +01:00
|
|
|
|
|
|
|
if not cb_num in cb_table.keys():
|
2018-10-30 14:09:46 +01:00
|
|
|
# latest SDK linux size, list of windows struct sizes and names
|
2018-10-29 15:28:28 +01:00
|
|
|
cb_table[cb_num] = (struct.type.get_size(), [])
|
2019-06-13 16:12:28 +02:00
|
|
|
if l2w_handler_name64:
|
|
|
|
cb_table64[cb_num] = (struct64.get_size(), [])
|
2019-06-27 15:59:19 +02:00
|
|
|
else:
|
|
|
|
cb_table64[cb_num] = (struct.type.get_size(), [])
|
2018-10-30 14:09:46 +01:00
|
|
|
cb_table[cb_num][1].append((windows_struct.get_size(), struct_name))
|
2019-06-27 15:59:19 +02:00
|
|
|
if l2w_handler_name64:
|
|
|
|
cb_table64[cb_num][1].append((windows_struct64.get_size(), struct_name64))
|
|
|
|
else:
|
|
|
|
cb_table64[cb_num][1].append((windows_struct.get_size(), struct_name))
|
2018-01-18 17:24:05 +01:00
|
|
|
|
2018-10-29 17:38:13 +01:00
|
|
|
hfile = open("cb_converters.h", "a")
|
2021-11-12 17:14:14 +01:00
|
|
|
hfile.write(f"struct {struct.displayname};\n")
|
2019-06-13 16:12:28 +02:00
|
|
|
if l2w_handler_name64:
|
|
|
|
hfile.write("#ifdef __i386__\n")
|
2021-11-12 17:14:14 +01:00
|
|
|
hfile.write(f"struct win{struct_name};\n")
|
|
|
|
hfile.write(f"extern void {l2w_handler_name}(const struct {struct.displayname} *l, struct win{struct_name} *w);\n")
|
2019-06-13 16:12:28 +02:00
|
|
|
hfile.write("#endif\n")
|
|
|
|
hfile.write("#ifdef __x86_64__\n")
|
2021-11-12 17:14:14 +01:00
|
|
|
hfile.write(f"struct win{struct_name64};\n")
|
|
|
|
hfile.write(f"extern void {l2w_handler_name64}(const struct {struct.displayname} *l, struct win{struct_name64} *w);\n")
|
2019-06-13 16:12:28 +02:00
|
|
|
hfile.write("#endif\n\n")
|
|
|
|
else:
|
2021-11-12 17:14:14 +01:00
|
|
|
hfile.write(f"struct win{struct_name};\n")
|
|
|
|
hfile.write(f"extern void {l2w_handler_name}(const struct {struct.displayname} *l, struct win{struct_name} *w);\n\n")
|
2018-10-29 17:38:13 +01:00
|
|
|
|
2021-11-12 17:14:14 +01:00
|
|
|
cppname = f"struct_converters_{sdkver}.cpp"
|
2018-01-18 17:24:05 +01: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 16:00:45 +02:00
|
|
|
cppfile.write("#pragma push_macro(\"__cdecl\")\n")
|
|
|
|
cppfile.write("#undef __cdecl\n")
|
2021-11-12 17:14:14 +01: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 16:00:45 +02:00
|
|
|
cppfile.write("#pragma pop_macro(\"__cdecl\")\n")
|
2018-10-30 20:06:46 +01:00
|
|
|
cppfile.write("#include \"steamclient_private.h\"\n")
|
2018-01-18 17:24:05 +01:00
|
|
|
cppfile.write("extern \"C\" {\n")
|
2021-11-12 17:14:14 +01:00
|
|
|
cppfile.write(f"#define SDKVER_{sdkver}\n")
|
2019-02-26 16:05:29 +01:00
|
|
|
cppfile.write("#include \"struct_converters.h\"\n")
|
2018-01-18 17:24:05 +01:00
|
|
|
cpp_files_need_close_brace.append(cppname)
|
|
|
|
|
2018-11-20 18:10:12 +01:00
|
|
|
path_conv = get_path_converter(struct.type)
|
|
|
|
|
2018-10-29 16:15:32 +01:00
|
|
|
def handle_field(m, src, dst):
|
2021-12-21 10:41:34 +01: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 14:09:46 +01:00
|
|
|
not struct_needs_conversion(m.type.element_type))
|
2021-11-12 17:14:14 +01:00
|
|
|
cppfile.write(f" memcpy({dst}->{m.displayname}, {src}->{m.displayname}, sizeof({dst}->{m.displayname}));\n")
|
2021-12-21 10:41:34 +01:00
|
|
|
elif m.type.kind == TypeKind.RECORD and \
|
2018-10-30 14:09:46 +01:00
|
|
|
struct_needs_conversion(m.type):
|
2021-11-12 17:14:14 +01:00
|
|
|
cppfile.write(f" {src}_to_{dst}_struct_{m.type.spelling}_{sdkver}(&{src}->{m.displayname}, &{dst}->{m.displayname});\n")
|
2018-11-20 18:10:12 +01:00
|
|
|
elif path_conv and m.displayname in path_conv["l2w_names"]:
|
2019-06-17 20:05:41 +02:00
|
|
|
for i in range(len(path_conv["l2w_names"])):
|
|
|
|
if path_conv["l2w_names"][i] == m.displayname:
|
|
|
|
url = path_conv["l2w_urls"][i]
|
|
|
|
break
|
2021-11-12 17:14:14 +01:00
|
|
|
cppfile.write(f" steamclient_unix_path_to_dos_path(1, {src}->{m.displayname}, g_tmppath, sizeof(g_tmppath), {to_c_bool(url)});\n")
|
|
|
|
cppfile.write(f" {dst}->{m.displayname} = g_tmppath;\n")
|
2018-01-18 17:24:05 +01:00
|
|
|
else:
|
2021-11-12 17:14:14 +01:00
|
|
|
cppfile.write(f" {dst}->{m.displayname} = {src}->{m.displayname};\n")
|
2018-10-29 16:15:32 +01:00
|
|
|
|
2019-02-26 16:05:29 +01:00
|
|
|
if not cb_num is None:
|
2019-06-13 16:12:28 +02: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 16:05:29 +01:00
|
|
|
|
2018-10-29 16:15:32 +01:00
|
|
|
if w2l_handler_name:
|
2021-11-12 17:14:14 +01:00
|
|
|
cppfile.write(f"void {w2l_handler_name}(const struct win{struct_name} *win, struct {struct.displayname} *lin)\n{{\n")
|
2018-10-29 16:15:32 +01:00
|
|
|
for m in struct.get_children():
|
|
|
|
handle_field(m, "win", "lin")
|
|
|
|
cppfile.write("}\n\n")
|
|
|
|
|
2019-06-13 16:12:28 +02:00
|
|
|
if l2w_handler_name64:
|
|
|
|
cppfile.write("#ifdef __x86_64__\n")
|
2021-11-12 17:14:14 +01:00
|
|
|
cppfile.write(f"void {l2w_handler_name64}(const struct {struct.displayname} *lin, struct win{struct_name64} *win)\n{{\n")
|
2019-06-13 16:12:28 +02:00
|
|
|
for m in struct.get_children():
|
|
|
|
handle_field(m, "lin", "win")
|
|
|
|
cppfile.write("}\n")
|
|
|
|
cppfile.write("#endif\n\n")
|
|
|
|
|
2018-10-29 16:15:32 +01:00
|
|
|
if l2w_handler_name:
|
2019-06-13 16:12:28 +02:00
|
|
|
if l2w_handler_name64:
|
|
|
|
cppfile.write("#ifdef __i386__\n")
|
2021-11-12 17:14:14 +01:00
|
|
|
cppfile.write(f"void {l2w_handler_name}(const struct {struct.displayname} *lin, struct win{struct_name} *win)\n{{\n")
|
2018-10-29 16:15:32 +01:00
|
|
|
for m in struct.get_children():
|
|
|
|
handle_field(m, "lin", "win")
|
2019-06-13 16:12:28 +02:00
|
|
|
cppfile.write("}\n")
|
|
|
|
if l2w_handler_name64:
|
|
|
|
cppfile.write("#endif\n\n")
|
|
|
|
else:
|
|
|
|
cppfile.write("\n")
|
2018-01-18 17:24:05 +01:00
|
|
|
|
|
|
|
prog = re.compile("^#define\s*(\w*)\s*\"(.*)\"")
|
|
|
|
for sdkver in sdk_versions:
|
2022-01-06 15:52:49 +01:00
|
|
|
print(f"parsing SDK version {sdkver}...")
|
|
|
|
sdkdir = f"steamworks_sdk_{sdkver}"
|
|
|
|
|
|
|
|
sources = {}
|
2018-01-18 17:24:05 +01:00
|
|
|
iface_versions = {}
|
2022-01-06 15:52:49 +01:00
|
|
|
for file in os.listdir(sdkdir):
|
2020-11-04 12:56:12 +01: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 15:52:49 +01:00
|
|
|
lines = open(f"{sdkdir}/{file}", "r", errors="replace").readlines()
|
|
|
|
if file == "isteammasterserverupdater.h":
|
|
|
|
if """#error "This file isn't used any more"\n""" in lines:
|
|
|
|
sources[f"{sdkdir}/isteammasterserverupdater.h"] = ""
|
|
|
|
|
|
|
|
for line in lines:
|
|
|
|
if "define STEAM" in line and "_VERSION" in line:
|
|
|
|
result = prog.match(line)
|
2018-01-18 17:24:05 +01:00
|
|
|
if result:
|
|
|
|
iface, version = result.group(1, 2)
|
|
|
|
iface_versions[iface] = version
|
|
|
|
|
2022-01-06 15:52:49 +01:00
|
|
|
source = [f"""#if __has_include("{sdkdir}/{file}")
|
|
|
|
#include "{sdkdir}/{file}"
|
|
|
|
#endif""" for file, _ in files]
|
|
|
|
sources["source.cpp"] = "\n".join(source)
|
|
|
|
windows_args = ["-D_WIN32", "-fms-extensions", "-Wno-ignored-attributes",
|
|
|
|
"-mms-bitfields", "-U__linux__", "-Wno-incompatible-ms-struct"]
|
|
|
|
windows_args += ['-I' + CLANG_PATH + '/include/']
|
|
|
|
linux_args = ["-DGNUC"]
|
|
|
|
linux_args += ['-I' + CLANG_PATH + '/include/']
|
|
|
|
|
|
|
|
index = Index.create()
|
|
|
|
|
|
|
|
linux_build32 = index.parse("source.cpp", args=linux_args + ["-m32"], unsaved_files=sources.items())
|
|
|
|
diagnostics = list(linux_build32.diagnostics)
|
|
|
|
for diag in diagnostics: print(diag)
|
|
|
|
assert len(diagnostics) == 0
|
|
|
|
|
|
|
|
linux_build64 = index.parse("source.cpp", args=linux_args + ["-m64"], unsaved_files=sources.items())
|
|
|
|
diagnostics = list(linux_build64.diagnostics)
|
|
|
|
for diag in diagnostics: print(diag)
|
|
|
|
assert len(diagnostics) == 0
|
|
|
|
|
|
|
|
windows_build32 = index.parse("source.cpp", args=windows_args + ["-m32"], unsaved_files=sources.items())
|
|
|
|
diagnostics = list(windows_build32.diagnostics)
|
|
|
|
for diag in diagnostics: print(diag)
|
|
|
|
assert len(diagnostics) == 0
|
|
|
|
|
|
|
|
windows_build64 = index.parse("source.cpp", args=windows_args + ["-m64"], unsaved_files=sources.items())
|
|
|
|
diagnostics = list(windows_build64.diagnostics)
|
|
|
|
for diag in diagnostics: print(diag)
|
|
|
|
assert len(diagnostics) == 0
|
|
|
|
|
|
|
|
linux_structs64 = dict(reversed([(child.spelling, child.type) for child
|
|
|
|
in linux_build64.cursor.get_children()]))
|
|
|
|
windows_structs32 = dict(reversed([(child.spelling, child.type) for child
|
|
|
|
in windows_build32.cursor.get_children()]))
|
|
|
|
windows_structs64 = dict(reversed([(child.spelling, child.type) for child
|
|
|
|
in windows_build64.cursor.get_children()]))
|
|
|
|
|
|
|
|
classes = dict([(klass, file) for file, classes in files for klass in classes])
|
|
|
|
for child in linux_build32.cursor.get_children():
|
|
|
|
if child.kind == CursorKind.CLASS_DECL and child.displayname in classes:
|
|
|
|
handle_class(sdkver, child, classes[child.displayname])
|
|
|
|
if child.kind in [CursorKind.STRUCT_DECL, CursorKind.CLASS_DECL]:
|
|
|
|
handle_struct(sdkver, child)
|
|
|
|
if child.displayname in print_sizes:
|
|
|
|
print("size of %s is %u" % (child.displayname, child.type.get_size()))
|
2018-01-18 17:24:05 +01:00
|
|
|
|
|
|
|
for f in cpp_files_need_close_brace:
|
|
|
|
m = open(f, "a")
|
|
|
|
m.write("\n}\n")
|
|
|
|
|
|
|
|
getapifile = open("cb_getapi_table.dat", "w")
|
|
|
|
cbsizefile = open("cb_getapi_sizes.dat", "w")
|
2019-06-13 16:12:28 +02:00
|
|
|
|
|
|
|
cbsizefile.write("#ifdef __i386__\n")
|
|
|
|
getapifile.write("#ifdef __i386__\n")
|
2020-11-04 12:46:07 +01:00
|
|
|
for cb in sorted(cb_table.keys()):
|
2021-11-12 17:14:14 +01: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 17:24:05 +01: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 14:09:46 +01:00
|
|
|
for (size, name) in cb_table[cb][1]:
|
2021-11-12 17:14:14 +01:00
|
|
|
getapifile.write(f" case {size}: cb_{name}(lin_callback, callback); break;\n")
|
2018-01-18 17:24:05 +01:00
|
|
|
getapifile.write(" }\n break;\n")
|
2019-06-13 16:12:28 +02:00
|
|
|
cbsizefile.write("#endif\n")
|
|
|
|
getapifile.write("#endif\n")
|
|
|
|
|
|
|
|
cbsizefile.write("#ifdef __x86_64__\n")
|
|
|
|
getapifile.write("#ifdef __x86_64__\n")
|
2020-11-04 12:46:07 +01:00
|
|
|
for cb in sorted(cb_table64.keys()):
|
2021-11-12 17:14:14 +01: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 16:12:28 +02: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 17:14:14 +01:00
|
|
|
getapifile.write(f" case {size}: cb_{name}(lin_callback, callback); break;\n")
|
2019-06-13 16:12:28 +02:00
|
|
|
getapifile.write(" }\n break;\n")
|
|
|
|
cbsizefile.write("#endif\n")
|
|
|
|
getapifile.write("#endif\n")
|