lsteamclient: Generate wtou / utow struct conversion helpers.

CW-Bug-Id: #22729
This commit is contained in:
Rémi Bernon 2023-09-28 22:22:25 +02:00 committed by Arkadiusz Hiler
parent f1f483a443
commit 1fc7e4381a
4 changed files with 5440 additions and 8 deletions

View File

@ -510,7 +510,7 @@ class Struct:
def fields(self):
return [f for f in self.padded_fields if type(f) is not Padding]
def write_definition(self, out, prefix):
def write_definition(self, out, prefix, converters):
version = all_versions[sdkver][self.name]
kind = 'union' if type(self) is Union else 'struct'
wrapped = len(prefix) > 0
@ -523,6 +523,10 @@ class Struct:
out(f' {declspec(f._cursor, f.name, prefix, wrapped)};\n')
else:
out(f' uint8_t __pad_{f.offset}[{f.size}];\n')
for conv in converters:
out(u'#ifdef __cplusplus\n')
out(f' operator {conv}{version}() const;\n')
out(u'#endif /* __cplusplus */\n')
out(u'};\n')
out(u'#pragma pack( pop )\n\n')
@ -535,6 +539,20 @@ class Struct:
out(f'C_ASSERT( sizeof({prefix}{version}().{f.name}) >= {f.size} );\n')
out(u'\n')
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')
def needs_conversion(self, other):
if other.id in self._conv_cache:
return self._conv_cache[other.id]
@ -1617,7 +1635,7 @@ with open('steamclient_structs_generated.h', 'w') as file:
kind = 'union' if type(abis['w64']) is Union else 'struct'
out(f'typedef {kind} {version} {version};\n')
abis['w64'].write_definition(out, "")
abis['w64'].write_definition(out, "", [])
for name, structs in all_structs.items():
if name in EXEMPT_STRUCTS: continue
@ -1669,13 +1687,17 @@ with open('steamclient_structs_generated.h', 'w') as file:
abis['u64'].write_definition(out, "u_")
continue
abis['w64'].write_definition(out, "w64_")
if abis["w64"].needs_conversion(abis["u64"]):
abis['u64'].write_definition(out, "u64_")
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_"])
abis['w32'].write_definition(out, "w32_")
if abis["w32"].needs_conversion(abis["u32"]):
abis['u32'].write_definition(out, "u32_")
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_"])
out(u'#ifdef __i386__\n')
out(f'typedef w32_{version} w_{version};\n')
@ -1722,6 +1744,35 @@ with open('unixlib_generated.cpp', 'w') as file:
abis['w32'].write_checks(out, "w32_")
abis['u32'].write_checks(out, "u32_")
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')
getapifile = open("cb_getapi_table.dat", "w")
cbsizefile = open("cb_getapi_sizes.dat", "w")

View File

@ -53,6 +53,11 @@ typedef struct { uint8_t _[20]; } SteamIPAddress_t;
#include "steamclient_structs_generated.h"
#define PATH_MAX 4096
extern char g_tmppath[PATH_MAX];
extern unsigned int steamclient_unix_path_to_dos_path( bool api_result, const char *src, char *dst, uint32_t dst_bytes, int is_url );
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff