lsteamclient: Use upper-case global constants.

CW-Bug-Id: #22729
This commit is contained in:
Rémi Bernon 2023-09-20 21:02:50 +02:00 committed by Arkadiusz Hiler
parent 34f52223fc
commit adbe64d4bf

View File

@ -11,7 +11,7 @@ import os
import re import re
import math import math
sdk_versions = [ SDK_VERSIONS = [
"158", "158",
"157", "157",
"156", "156",
@ -98,7 +98,7 @@ sdk_versions = [
"099u", "099u",
] ]
files = [ SDK_SOURCES = [
("steam_api.h", [ ("steam_api.h", [
"ISteamApps", "ISteamApps",
"ISteamAppList", "ISteamAppList",
@ -164,7 +164,7 @@ files = [
]), ]),
] ]
aliases = { VERSION_ALIASES = {
#these interfaces are undocumented and binary compatible #these interfaces are undocumented and binary compatible
#"target interface": ["alias 1", "alias 2"], #"target interface": ["alias 1", "alias 2"],
"SteamUtils004":["SteamUtils003"], "SteamUtils004":["SteamUtils003"],
@ -176,7 +176,7 @@ aliases = {
} }
# these structs are manually confirmed to be equivalent # these structs are manually confirmed to be equivalent
exempt_structs = [ EXEMPT_STRUCTS = [
"CSteamID", "CSteamID",
"CGameID", "CGameID",
"CCallbackBase", "CCallbackBase",
@ -185,13 +185,13 @@ exempt_structs = [
] ]
# we have converters for these written by hand because they're too complicated to generate # we have converters for these written by hand because they're too complicated to generate
manually_handled_structs = [ MANUAL_STRUCTS = [
"SteamNetworkingMessage_t" "SteamNetworkingMessage_t"
] ]
Method = namedtuple('Method', ['name', 'version_func'], defaults=[lambda _: True]) Method = namedtuple('Method', ['name', 'version_func'], defaults=[lambda _: True])
manually_handled_methods = { MANUAL_METHODS = {
#TODO: 001 005 007 #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) #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": [ "cppISteamNetworkingSockets_SteamNetworkingSockets": [
@ -235,7 +235,7 @@ manually_handled_methods = {
post_execution_functions = { POST_EXEC_FUNCS = {
"ISteamClient_BShutdownIfAllPipesClosed" : "after_shutdown", "ISteamClient_BShutdownIfAllPipesClosed" : "after_shutdown",
"ISteamClient_CreateSteamPipe" : "after_steam_pipe_create", "ISteamClient_CreateSteamPipe" : "after_steam_pipe_create",
} }
@ -247,23 +247,23 @@ def method_needs_manual_handling(interface_with_version, method_name):
interface = match_dict['name'] interface = match_dict['name']
version = int(match_dict['version']) if match_dict['version'] else None version = int(match_dict['version']) if match_dict['version'] else None
method_list = manually_handled_methods.get(interface, []) method_list = MANUAL_METHODS.get(interface, [])
method = next(filter(lambda m: m.name == method_name, method_list), None) method = next(filter(lambda m: m.name == method_name, method_list), None)
return method and method.version_func(version) return method and method.version_func(version)
def post_execution_function(classname, method_name): def post_execution_function(classname, method_name):
return post_execution_functions.get(classname + "_" + method_name) return POST_EXEC_FUNCS.get(classname + "_" + method_name)
# manual converters for simple types (function pointers) # manual converters for simple types (function pointers)
manual_type_converters = [ MANUAL_TYPES = [
"FSteamNetworkingSocketsDebugOutput", "FSteamNetworkingSocketsDebugOutput",
"SteamAPIWarningMessageHook_t", "SteamAPIWarningMessageHook_t",
"SteamAPI_CheckCallbackRegistered_t" "SteamAPI_CheckCallbackRegistered_t"
] ]
# manual converters for specific parameters # manual converters for specific parameters
manual_param_converters = [ MANUAL_PARAMS = [
"nNativeKeyCode" "nNativeKeyCode"
] ]
@ -278,7 +278,7 @@ struct_conversion_cache = {}
converted_structs = [] converted_structs = []
# callback classes for which we have a linux wrapper # callback classes for which we have a linux wrapper
wrapped_classes = [ WRAPPED_CLASSES = [
"ISteamMatchmakingServerListResponse", "ISteamMatchmakingServerListResponse",
"ISteamMatchmakingPingResponse", "ISteamMatchmakingPingResponse",
"ISteamMatchmakingPlayersResponse", "ISteamMatchmakingPlayersResponse",
@ -288,7 +288,7 @@ wrapped_classes = [
class_versions = {} class_versions = {}
path_conversions = [ PATH_CONV = [
{ {
"parent_name": "GetAppInstallDir", "parent_name": "GetAppInstallDir",
"l2w_names": ["pchDirectory"], "l2w_names": ["pchDirectory"],
@ -608,9 +608,9 @@ def find_linux64_struct(struct):
return linux_structs64.get(strip_const(struct.spelling), None) return linux_structs64.get(strip_const(struct.spelling), None)
def struct_needs_conversion_nocache(struct): def struct_needs_conversion_nocache(struct):
if strip_const(struct.spelling) in exempt_structs: if strip_const(struct.spelling) in EXEMPT_STRUCTS:
return False return False
if strip_const(struct.spelling) in manually_handled_structs: if strip_const(struct.spelling) in MANUAL_STRUCTS:
return True return True
#check 32-bit compat #check 32-bit compat
@ -656,7 +656,7 @@ def handle_destructor(cfile, classname, winclassname, method):
return "destructor" return "destructor"
def get_path_converter(parent): def get_path_converter(parent):
for conv in path_conversions: for conv in PATH_CONV:
if conv["parent_name"] in parent.spelling: if conv["parent_name"] in parent.spelling:
if None in conv["l2w_names"]: if None in conv["l2w_names"]:
return conv return conv
@ -742,14 +742,14 @@ def handle_method(cfile, classname, winclassname, cppname, method, cpp, cpp_h, e
real_type = real_type.get_pointee() real_type = real_type.get_pointee()
win_name = typename win_name = typename
if real_type.kind == TypeKind.RECORD and \ if real_type.kind == TypeKind.RECORD and \
not real_type.spelling in wrapped_classes and \ not real_type.spelling in WRAPPED_CLASSES and \
struct_needs_conversion(real_type): struct_needs_conversion(real_type):
need_convert.append(param) need_convert.append(param)
#preserve pointers #preserve pointers
win_name = typename.replace(real_type.spelling, f"win{real_type.spelling}_{sdkver}") win_name = typename.replace(real_type.spelling, f"win{real_type.spelling}_{sdkver}")
elif real_type.spelling in manual_type_converters: elif real_type.spelling in MANUAL_TYPES:
manual_convert.append(param) manual_convert.append(param)
elif param.spelling in manual_param_converters: elif param.spelling in MANUAL_PARAMS:
manual_convert.append(param) manual_convert.append(param)
win_name = win_name.replace('&', '*') win_name = win_name.replace('&', '*')
@ -792,7 +792,7 @@ def handle_method(cfile, classname, winclassname, cppname, method, cpp, cpp_h, e
while real_type.kind == TypeKind.POINTER: while real_type.kind == TypeKind.POINTER:
real_type = real_type.get_pointee() real_type = real_type.get_pointee()
assert(param.type.get_pointee().kind == TypeKind.RECORD or \ assert(param.type.get_pointee().kind == TypeKind.RECORD or \
strip_const(real_type.spelling) in manually_handled_structs) strip_const(real_type.spelling) in MANUAL_STRUCTS)
cpp.write(f" {strip_const(param.type.get_pointee().spelling)} lin_{param.spelling};\n") 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") cpp.write(f" win_to_lin_struct_{strip_const(real_type.spelling)}_{sdkver}({param.spelling}, &lin_{param.spelling});\n")
else: else:
@ -800,7 +800,7 @@ def handle_method(cfile, classname, winclassname, cppname, method, cpp, cpp_h, e
cpp.write(f" {param.type.spelling} lin_{param.spelling};\n") 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") cpp.write(f" win_to_lin_struct_{param.type.spelling}_{sdkver}(&{param.spelling}, &lin_{param.spelling});\n")
for param in manual_convert: for param in manual_convert:
if param.spelling in manual_param_converters: if param.spelling in MANUAL_PARAMS:
cpp.write(f" {param.spelling} = manual_convert_{param.spelling}({param.spelling});\n") cpp.write(f" {param.spelling} = manual_convert_{param.spelling}({param.spelling});\n")
else: else:
cpp.write(f" {param.spelling} = ({param.type.spelling})manual_convert_{param.type.spelling}((void*){param.spelling});\n") cpp.write(f" {param.spelling} = ({param.type.spelling})manual_convert_{param.type.spelling}((void*){param.spelling});\n")
@ -852,7 +852,7 @@ def handle_method(cfile, classname, winclassname, cppname, method, cpp, cpp_h, e
cpp.write(f"({param.type.spelling})_{unnamed}") cpp.write(f"({param.type.spelling})_{unnamed}")
unnamed = chr(ord(unnamed) + 1) unnamed = chr(ord(unnamed) + 1)
elif param.type.kind == TypeKind.POINTER and \ elif param.type.kind == TypeKind.POINTER and \
param.type.get_pointee().spelling in wrapped_classes: param.type.get_pointee().spelling in WRAPPED_CLASSES:
cfile.write(f", create_Linux{param.type.get_pointee().spelling}({param.spelling}, \"{winclassname}\")") cfile.write(f", create_Linux{param.type.get_pointee().spelling}({param.spelling}, \"{winclassname}\")")
cpp.write(f"({param.type.spelling}){param.spelling}") cpp.write(f"({param.type.spelling}){param.spelling}")
elif path_conv and param.spelling in path_conv["w2l_names"]: elif path_conv and param.spelling in path_conv["w2l_names"]:
@ -1000,7 +1000,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(steamclient);
cfile.write("}\n") cfile.write("}\n")
cfile.write("#endif\n\n") cfile.write("#endif\n\n")
cfile.write(f"{winclassname} *create_{winclassname}(void *linux_side)\n{{\n") cfile.write(f"{winclassname} *create_{winclassname}(void *linux_side)\n{{\n")
if classnode.spelling in wrapped_classes: if classnode.spelling in WRAPPED_CLASSES:
cfile.write(f" {winclassname} *r = HeapAlloc(GetProcessHeap(), 0, sizeof({winclassname}));\n") cfile.write(f" {winclassname} *r = HeapAlloc(GetProcessHeap(), 0, sizeof({winclassname}));\n")
else: else:
cfile.write(f" {winclassname} *r = alloc_mem_for_iface(sizeof({winclassname}), \"{iface_version}\");\n") cfile.write(f" {winclassname} *r = alloc_mem_for_iface(sizeof({winclassname}), \"{iface_version}\");\n")
@ -1016,8 +1016,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(steamclient);
constructors = open("win_constructors_table.dat", "a") constructors = open("win_constructors_table.dat", "a")
constructors.write(f" {{\"{iface_version}\", &create_{winclassname}}},\n") constructors.write(f" {{\"{iface_version}\", &create_{winclassname}}},\n")
if iface_version in aliases.keys(): if iface_version in VERSION_ALIASES.keys():
for alias in aliases[iface_version]: for alias in VERSION_ALIASES[iface_version]:
constructors.write(f" {{\"{alias}\", &create_{winclassname}}}, /* alias */\n") constructors.write(f" {{\"{alias}\", &create_{winclassname}}}, /* alias */\n")
@ -1100,7 +1100,7 @@ def handle_struct(sdkver, struct):
hfile.write(f"typedef struct win{struct_name} win{struct_name};\n") hfile.write(f"typedef struct win{struct_name} win{struct_name};\n")
hfile.write(f"struct {struct.displayname};\n") hfile.write(f"struct {struct.displayname};\n")
if strip_const(struct.spelling) in manually_handled_structs: if strip_const(struct.spelling) in MANUAL_STRUCTS:
hfile.write("#endif\n\n") hfile.write("#endif\n\n")
return return
@ -1259,7 +1259,7 @@ def handle_struct(sdkver, struct):
cppfile.write("\n") cppfile.write("\n")
prog = re.compile("^#define\s*(\w*)\s*\"(.*)\"") prog = re.compile("^#define\s*(\w*)\s*\"(.*)\"")
for sdkver in sdk_versions: for sdkver in SDK_VERSIONS:
print(f"parsing SDK version {sdkver}...") print(f"parsing SDK version {sdkver}...")
sdkdir = f"steamworks_sdk_{sdkver}" sdkdir = f"steamworks_sdk_{sdkver}"
@ -1283,7 +1283,7 @@ for sdkver in sdk_versions:
source = [f"""#if __has_include("{sdkdir}/{file}") source = [f"""#if __has_include("{sdkdir}/{file}")
#include "{sdkdir}/{file}" #include "{sdkdir}/{file}"
#endif""" for file, _ in files] #endif""" for file, _ in SDK_SOURCES]
sources["source.cpp"] = "\n".join(source) sources["source.cpp"] = "\n".join(source)
windows_args = ["-D_WIN32", "-fms-extensions", "-Wno-ignored-attributes", windows_args = ["-D_WIN32", "-fms-extensions", "-Wno-ignored-attributes",
"-mms-bitfields", "-U__linux__", "-Wno-incompatible-ms-struct"] "-mms-bitfields", "-U__linux__", "-Wno-incompatible-ms-struct"]
@ -1320,7 +1320,7 @@ for sdkver in sdk_versions:
windows_structs64 = dict(reversed([(child.spelling, child.type) for child windows_structs64 = dict(reversed([(child.spelling, child.type) for child
in windows_build64.cursor.get_children()])) in windows_build64.cursor.get_children()]))
classes = dict([(klass, file) for file, classes in files for klass in classes]) classes = dict([(klass, file) for file, classes in SDK_SOURCES for klass in classes])
for child in linux_build32.cursor.get_children(): for child in linux_build32.cursor.get_children():
if child.kind == CursorKind.CLASS_DECL and child.displayname in classes: if child.kind == CursorKind.CLASS_DECL and child.displayname in classes:
handle_class(sdkver, child, classes[child.displayname]) handle_class(sdkver, child, classes[child.displayname])