lsteamclient: Simplify manual method description.

CW-Bug-Id: #22729
This commit is contained in:
Rémi Bernon 2023-09-18 10:18:19 +02:00
parent 619aa95d93
commit 4092684400

View file

@ -6,7 +6,6 @@
CLANG_PATH='/usr/lib/clang/15' CLANG_PATH='/usr/lib/clang/15'
from clang.cindex import Cursor, CursorKind, Index, TypeKind from clang.cindex import Cursor, CursorKind, Index, TypeKind
from collections import namedtuple
import concurrent.futures import concurrent.futures
import os import os
import re import re
@ -201,65 +200,55 @@ MANUAL_STRUCTS = [
"SteamNetworkingMessage_t" "SteamNetworkingMessage_t"
] ]
Method = namedtuple('Method', ['name', 'version_func'], defaults=[lambda _: True])
MANUAL_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": [ "ISteamNetworkingSockets_ReceiveMessagesOnConnection": lambda ver, abi: abi == 'u',
Method("ReceiveMessagesOnConnection"), "ISteamNetworkingSockets_ReceiveMessagesOnListenSocket": lambda ver, abi: abi == 'u',
Method("ReceiveMessagesOnListenSocket"), "ISteamNetworkingSockets_ReceiveMessagesOnPollGroup": lambda ver, abi: abi == 'u',
Method("ReceiveMessagesOnPollGroup"), "ISteamNetworkingSockets_SendMessages": lambda ver, abi: abi == 'u',
Method("SendMessages"), "ISteamNetworkingSockets_CreateFakeUDPPort": lambda ver, abi: abi == 'u',
Method("CreateFakeUDPPort"),
], "ISteamNetworkingUtils_AllocateMessage": lambda ver, abi: abi == 'u',
"cppISteamNetworkingUtils_SteamNetworkingUtils": [ "ISteamNetworkingUtils_SetConfigValue": lambda ver, abi: abi == 'u' and ver >= 3,
Method("AllocateMessage"),
Method("SetConfigValue", lambda version: version >= 3) "ISteamNetworkingMessages_ReceiveMessagesOnChannel": lambda ver, abi: abi == 'u',
],
"cppISteamNetworkingMessages_SteamNetworkingMessages": [ "ISteamInput_EnableActionEventCallbacks": lambda ver, abi: abi == 'u',
Method("ReceiveMessagesOnChannel"), "ISteamInput_GetGlyphForActionOrigin": lambda ver, abi: abi == 'u',
], "ISteamInput_GetGlyphPNGForActionOrigin": lambda ver, abi: abi == 'u',
"cppISteamInput_SteamInput": [ "ISteamInput_GetGlyphSVGForActionOrigin": lambda ver, abi: abi == 'u',
Method("EnableActionEventCallbacks"), "ISteamInput_GetGlyphForActionOrigin_Legacy": lambda ver, abi: abi == 'u',
Method("GetGlyphForActionOrigin"), "ISteamInput_GetGlyphForXboxOrigin": lambda ver, abi: abi == 'u',
Method("GetGlyphPNGForActionOrigin"),
Method("GetGlyphSVGForActionOrigin"), "ISteamController_GetGlyphForActionOrigin": lambda ver, abi: abi == 'u',
Method("GetGlyphForActionOrigin_Legacy"), "ISteamController_GetGlyphForXboxOrigin": lambda ver, abi: abi == 'u',
Method("GetGlyphForXboxOrigin"),
], "ISteamNetworkingFakeUDPPort_DestroyFakeUDPPort": lambda ver, abi: abi == 'u',
"cppISteamController_SteamController": [ "ISteamNetworkingFakeUDPPort_ReceiveMessages": lambda ver, abi: abi == 'u',
Method("GetGlyphForActionOrigin"),
Method("GetGlyphForXboxOrigin"), "ISteamClient_Set_SteamAPI_CCheckCallbackRegisteredInProcess": lambda ver, abi: abi == 'u' and ver >= 20,
],
"cppISteamNetworkingFakeUDPPort_SteamNetworkingFakeUDPPort": [
Method("DestroyFakeUDPPort"),
Method("ReceiveMessages"),
],
"cppISteamClient_SteamClient": [
Method("Set_SteamAPI_CCheckCallbackRegisteredInProcess", lambda version: version >= 20),
],
} }
POST_EXEC_FUNCS = { POST_EXEC_FUNCS = {
"ISteamClient_BShutdownIfAllPipesClosed" : "after_shutdown", "ISteamClient_BShutdownIfAllPipesClosed" : "after_shutdown",
"ISteamClient_CreateSteamPipe" : "after_steam_pipe_create", "ISteamClient_CreateSteamPipe" : "after_steam_pipe_create",
} }
INTERFACE_NAME_VERSION = re.compile(r'^(?P<name>.+?)(?P<version>\d*)$')
DEFINE_INTERFACE_VERSION = re.compile(r'^#define\s*(?P<name>STEAM(?:\w*)_VERSION(?:\w*))\s*"(?P<version>.*)"') DEFINE_INTERFACE_VERSION = re.compile(r'^#define\s*(?P<name>STEAM(?:\w*)_VERSION(?:\w*))\s*"(?P<version>.*)"')
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 = MANUAL_METHODS.get(interface, []) def is_manual_method(klass, method, abi):
method = next(filter(lambda m: m.name == method_name, method_list), None) version = re.search(r'(\d+)$', klass.version)
key = f'{klass.name}_{method.name}'
needs_manual = MANUAL_METHODS.get(key, False)
if callable(needs_manual) and version:
return needs_manual(int(version[0]), abi)
return needs_manual
return method and method.version_func(version)
def post_execution_function(classname, method_name): def post_execution_function(classname, method_name):
return POST_EXEC_FUNCS.get(classname + "_" + method_name, None) return POST_EXEC_FUNCS.get(classname + "_" + method_name, None)
@ -987,7 +976,7 @@ def handle_thiscall_wrapper(klass, method, out):
out(f'DEFINE_THISCALL_WRAPPER({name}, {size})\n') out(f'DEFINE_THISCALL_WRAPPER({name}, {size})\n')
def handle_method_c(method, winclassname, cppname, out): def handle_method_c(klass, method, winclassname, cppname, out):
returns_void = method.result_type.kind == TypeKind.VOID returns_void = method.result_type.kind == TypeKind.VOID
returns_record = method.result_type.get_canonical().kind == TypeKind.RECORD returns_record = method.result_type.get_canonical().kind == TypeKind.RECORD
@ -1035,7 +1024,7 @@ def handle_method_c(method, winclassname, cppname, out):
out(f' {cppname}_{method.name}( &params );\n') out(f' {cppname}_{method.name}( &params );\n')
should_gen_wrapper = not method_needs_manual_handling(cppname, method.name) and \ should_gen_wrapper = not is_manual_method(klass, method, "u") and \
(method.result_type.spelling.startswith("ISteam") or \ (method.result_type.spelling.startswith("ISteam") or \
method.name.startswith("GetISteamGenericInterface")) method.name.startswith("GetISteamGenericInterface"))
if should_gen_wrapper: if should_gen_wrapper:
@ -1072,7 +1061,7 @@ def handle_class(klass):
for method in klass.methods: for method in klass.methods:
if type(method) is Destructor: if type(method) is Destructor:
continue continue
if method_needs_manual_handling(cppname, method.name): if is_manual_method(klass, method, "u"):
ext = "hpp" ext = "hpp"
with open(f"{cppname}.h", "w") as file: with open(f"{cppname}.h", "w") as file:
@ -1109,7 +1098,7 @@ def handle_class(klass):
for method in klass.methods: for method in klass.methods:
if type(method) is Destructor: if type(method) is Destructor:
continue continue
if method_needs_manual_handling(cppname, method.spelling): if is_manual_method(klass, method, "u"):
continue continue
handle_method_cpp(method, klass.name, cppname, out) handle_method_cpp(method, klass.name, cppname, out)
@ -1126,10 +1115,12 @@ def handle_class(klass):
out('\n') out('\n')
for method in klass.methods: for method in klass.methods:
if is_manual_method(klass, method, "w"):
continue
if type(method) is Destructor: if type(method) is Destructor:
out(f'void __thiscall {winclassname}_{method.name}(struct w_steam_iface *_this)\n{{/* never called */}}\n\n') out(f'void __thiscall {winclassname}_{method.name}(struct w_steam_iface *_this)\n{{/* never called */}}\n\n')
else: else:
handle_method_c(method, winclassname, cppname, out) handle_method_c(klass, method, winclassname, cppname, out)
out(f'extern vtable_ptr {winclassname}_vtable;\n') out(f'extern vtable_ptr {winclassname}_vtable;\n')
out(u'\n') out(u'\n')