lsteamclient: Simplify the struct converter code generation.

This commit is contained in:
Rémi Bernon 2025-01-16 01:32:23 +01:00 committed by Arkadiusz Hiler
parent 0804e0b81f
commit 8cd16ffc70
6 changed files with 2664 additions and 3209 deletions

View File

@ -478,8 +478,6 @@ class BasicType:
return False
written_converters = set()
class Struct:
def __init__(self, sdkver, abi, cursor):
self._cursor = cursor
@ -580,21 +578,6 @@ class Struct:
def write_converter(self, prefix, path_conv_fields):
version = all_versions[sdkver][self.name]
from_abi = self._abi[0]
func_name = f'{version}_{prefix[0]}_from_{from_abi}'
if not func_name in written_converters:
written_converters.add(func_name)
out(f'static void {func_name}(void *dst, const void *src)\n')
out(u'{\n')
out(f' {prefix[0]}_{version} *d = ({prefix[0]}_{version} *)dst;\n')
out(f' const {from_abi}_{version} *s = (const {from_abi}_{version} *)src;\n\n')
for field in self.fields:
if field.name not in path_conv_fields:
out(f' d->{field.name} = s->{field.name};\n')
else:
out(f' steamclient_unix_path_to_dos_path(1, s->{field.name}, g_tmppath, TEMP_PATH_BUFFER_LENGTH, 1);\n')
out(f' d->{field.name} = g_tmppath;\n')
out(u'}\n')
if self._abi[1:3] == '64':
out(u'#ifdef __x86_64__\n')
@ -606,7 +589,12 @@ class Struct:
out(f'{self._abi}_{version}::operator {prefix}{version}() const\n')
out(u'{\n')
out(f' {prefix}{version} ret;\n')
out(f' {func_name}((void *)&ret, (const void *)this);\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, TEMP_PATH_BUFFER_LENGTH, 1);\n')
out(f' ret.{field.name} = g_tmppath;\n')
out(u' return ret;\n')
out(u'}\n')
out(u'#endif\n\n')
@ -1701,14 +1689,17 @@ with open('unixlib_generated.cpp', 'w') as file:
if abis["w64"].needs_conversion(abis["u64"]):
abis['w64'].write_converter('u64_', {})
out(u'\n')
abis['u64'].write_converter('w64_', path_conv_fields)
if abis["w32"].needs_conversion(abis["u32"]):
abis['w32'].write_converter('u32_', {})
out(u'\n')
abis['u32'].write_converter('w32_', path_conv_fields)
out(f'static void {version}_utow(void *dst, const void *src)\n')
out(u'{\n')
out(f' *(w_{version} *)dst = *(const u_{version} *)src;\n')
out(u'}\n\n')
out(u'#ifdef __i386__\n')
out(u'const struct callback_def callback_data[] =\n{\n');
values = set()
@ -1716,14 +1707,10 @@ with open('unixlib_generated.cpp', 'w') as file:
name, value = abis["u32"].name, (cbid, abis["w32"].size, abis["u32"].size)
if name in all_versions[sdkver]: name = all_versions[sdkver][name]
w_from_u = f'{name}_w_from_u'
if not w_from_u in written_converters:
w_from_u = u'nullptr'
if value not in values:
out(f' {{ {cbid}, {sdkver}, {abis["w32"].size}, {abis["u32"].size}, {w_from_u} }},\n')
out(f' {{ {cbid}, {sdkver}, {abis["w32"].size}, {abis["u32"].size}, {name}_utow }},\n')
else:
out(f' /*{{ {cbid}, {sdkver}, {abis["w32"].size}, {abis["u32"].size}, {w_from_u} }},*/\n')
out(f' /*{{ {cbid}, {sdkver}, {abis["w32"].size}, {abis["u32"].size}, {name}_utow }},*/\n')
values.add(value)
out(u'};\n');
out(u'#endif\n')
@ -1734,14 +1721,10 @@ with open('unixlib_generated.cpp', 'w') as file:
name, value = abis["u64"].name, (cbid, abis["w64"].size, abis["u64"].size)
if name in all_versions[sdkver]: name = all_versions[sdkver][name]
w_from_u = f'{name}_w_from_u'
if not w_from_u in written_converters:
w_from_u = u'nullptr'
if value not in values:
out(f' {{ {cbid}, {sdkver}, {abis["w64"].size}, {abis["u64"].size}, {w_from_u} }},\n')
out(f' {{ {cbid}, {sdkver}, {abis["w64"].size}, {abis["u64"].size}, {name}_utow }},\n')
else:
out(f' /*{{ {cbid}, {sdkver}, {abis["w64"].size}, {abis["u64"].size}, {w_from_u} }},*/\n')
out(f' /*{{ {cbid}, {sdkver}, {abis["w64"].size}, {abis["u64"].size}, {name}_utow }},*/\n')
values.add(value)
out(u'};\n');
out(u'#endif\n')

File diff suppressed because it is too large Load Diff

View File

@ -4059,7 +4059,7 @@ struct ISteamRemotePlay_STEAMREMOTEPLAY_INTERFACE_VERSION003_GetSessionSteamID_p
struct ISteamRemotePlay_STEAMREMOTEPLAY_INTERFACE_VERSION003_GetSessionClientName_params
{
struct u_iface u_iface;
const char *_ret;
struct u_buffer _ret;
uint32_t unSessionID;
};
@ -22615,7 +22615,7 @@ struct ISteamUserStats_STEAMUSERSTATS_INTERFACE_VERSION013_GetAchievementIcon_pa
struct ISteamUserStats_STEAMUSERSTATS_INTERFACE_VERSION013_GetAchievementDisplayAttribute_params
{
struct u_iface u_iface;
const char *_ret;
struct u_buffer _ret;
const char *pchName;
const char *pchKey;
};
@ -22638,7 +22638,7 @@ struct ISteamUserStats_STEAMUSERSTATS_INTERFACE_VERSION013_GetNumAchievements_pa
struct ISteamUserStats_STEAMUSERSTATS_INTERFACE_VERSION013_GetAchievementName_params
{
struct u_iface u_iface;
const char *_ret;
struct u_buffer _ret;
uint32_t iAchievement;
};
@ -22712,7 +22712,7 @@ struct ISteamUserStats_STEAMUSERSTATS_INTERFACE_VERSION013_FindLeaderboard_param
struct ISteamUserStats_STEAMUSERSTATS_INTERFACE_VERSION013_GetLeaderboardName_params
{
struct u_iface u_iface;
const char *_ret;
struct u_buffer _ret;
uint64_t hSteamLeaderboard;
};
@ -33266,7 +33266,7 @@ struct ISteamFriends_SteamFriends017_GetProfileItemPropertyUint_params
struct ISteamFriends_SteamFriends018_GetPersonaName_params
{
struct u_iface u_iface;
const char *_ret;
struct u_buffer _ret;
};
struct ISteamFriends_SteamFriends018_GetPersonaState_params
@ -33307,7 +33307,7 @@ struct ISteamFriends_SteamFriends018_GetFriendPersonaState_params
struct ISteamFriends_SteamFriends018_GetFriendPersonaName_params
{
struct u_iface u_iface;
const char *_ret;
struct u_buffer _ret;
CSteamID steamIDFriend;
};
@ -33322,7 +33322,7 @@ struct ISteamFriends_SteamFriends018_GetFriendGamePlayed_params
struct ISteamFriends_SteamFriends018_GetFriendPersonaNameHistory_params
{
struct u_iface u_iface;
const char *_ret;
struct u_buffer _ret;
CSteamID steamIDFriend;
int32_t iPersonaName;
};
@ -33337,7 +33337,7 @@ struct ISteamFriends_SteamFriends018_GetFriendSteamLevel_params
struct ISteamFriends_SteamFriends018_GetPlayerNickname_params
{
struct u_iface u_iface;
const char *_ret;
struct u_buffer _ret;
CSteamID steamIDPlayer;
};
@ -33357,7 +33357,7 @@ struct ISteamFriends_SteamFriends018_GetFriendsGroupIDByIndex_params
struct ISteamFriends_SteamFriends018_GetFriendsGroupName_params
{
struct u_iface u_iface;
const char *_ret;
struct u_buffer _ret;
int16_t friendsGroupID;
};
@ -33400,14 +33400,14 @@ struct ISteamFriends_SteamFriends018_GetClanByIndex_params
struct ISteamFriends_SteamFriends018_GetClanName_params
{
struct u_iface u_iface;
const char *_ret;
struct u_buffer _ret;
CSteamID steamIDClan;
};
struct ISteamFriends_SteamFriends018_GetClanTag_params
{
struct u_iface u_iface;
const char *_ret;
struct u_buffer _ret;
CSteamID steamIDClan;
};
@ -33572,7 +33572,7 @@ struct ISteamFriends_SteamFriends018_ClearRichPresence_params
struct ISteamFriends_SteamFriends018_GetFriendRichPresence_params
{
struct u_iface u_iface;
const char *_ret;
struct u_buffer _ret;
CSteamID steamIDFriend;
const char *pchKey;
};
@ -33587,7 +33587,7 @@ struct ISteamFriends_SteamFriends018_GetFriendRichPresenceKeyCount_params
struct ISteamFriends_SteamFriends018_GetFriendRichPresenceKeyByIndex_params
{
struct u_iface u_iface;
const char *_ret;
struct u_buffer _ret;
CSteamID steamIDFriend;
int32_t iKey;
};
@ -33815,7 +33815,7 @@ struct ISteamFriends_SteamFriends018_BHasEquippedProfileItem_params
struct ISteamFriends_SteamFriends018_GetProfileItemPropertyString_params
{
struct u_iface u_iface;
const char *_ret;
struct u_buffer _ret;
CSteamID steamID;
uint32_t itemType;
uint32_t prop;

View File

@ -10769,7 +10769,7 @@ const char * __thiscall winISteamFriends_SteamFriends018_GetPersonaName(struct w
};
TRACE("%p\n", _this);
STEAMCLIENT_CALL( ISteamFriends_SteamFriends018_GetPersonaName, &params );
return params._ret;
return get_unix_buffer( params._ret );
}
uint32_t __thiscall winISteamFriends_SteamFriends018_GetPersonaState(struct w_iface *_this)
@ -10842,7 +10842,7 @@ const char * __thiscall winISteamFriends_SteamFriends018_GetFriendPersonaName(st
};
TRACE("%p\n", _this);
STEAMCLIENT_CALL( ISteamFriends_SteamFriends018_GetFriendPersonaName, &params );
return params._ret;
return get_unix_buffer( params._ret );
}
int8_t __thiscall winISteamFriends_SteamFriends018_GetFriendGamePlayed(struct w_iface *_this, CSteamID steamIDFriend, FriendGameInfo_t *pFriendGameInfo)
@ -10868,7 +10868,7 @@ const char * __thiscall winISteamFriends_SteamFriends018_GetFriendPersonaNameHis
};
TRACE("%p\n", _this);
STEAMCLIENT_CALL( ISteamFriends_SteamFriends018_GetFriendPersonaNameHistory, &params );
return params._ret;
return get_unix_buffer( params._ret );
}
int32_t __thiscall winISteamFriends_SteamFriends018_GetFriendSteamLevel(struct w_iface *_this, CSteamID steamIDFriend)
@ -10892,7 +10892,7 @@ const char * __thiscall winISteamFriends_SteamFriends018_GetPlayerNickname(struc
};
TRACE("%p\n", _this);
STEAMCLIENT_CALL( ISteamFriends_SteamFriends018_GetPlayerNickname, &params );
return params._ret;
return get_unix_buffer( params._ret );
}
int32_t __thiscall winISteamFriends_SteamFriends018_GetFriendsGroupCount(struct w_iface *_this)
@ -10927,7 +10927,7 @@ const char * __thiscall winISteamFriends_SteamFriends018_GetFriendsGroupName(str
};
TRACE("%p\n", _this);
STEAMCLIENT_CALL( ISteamFriends_SteamFriends018_GetFriendsGroupName, &params );
return params._ret;
return get_unix_buffer( params._ret );
}
int32_t __thiscall winISteamFriends_SteamFriends018_GetFriendsGroupMembersCount(struct w_iface *_this, int16_t friendsGroupID)
@ -11001,7 +11001,7 @@ const char * __thiscall winISteamFriends_SteamFriends018_GetClanName(struct w_if
};
TRACE("%p\n", _this);
STEAMCLIENT_CALL( ISteamFriends_SteamFriends018_GetClanName, &params );
return params._ret;
return get_unix_buffer( params._ret );
}
const char * __thiscall winISteamFriends_SteamFriends018_GetClanTag(struct w_iface *_this, CSteamID steamIDClan)
@ -11013,7 +11013,7 @@ const char * __thiscall winISteamFriends_SteamFriends018_GetClanTag(struct w_ifa
};
TRACE("%p\n", _this);
STEAMCLIENT_CALL( ISteamFriends_SteamFriends018_GetClanTag, &params );
return params._ret;
return get_unix_buffer( params._ret );
}
int8_t __thiscall winISteamFriends_SteamFriends018_GetClanActivityCounts(struct w_iface *_this, CSteamID steamIDClan, int32_t *pnOnline, int32_t *pnInGame, int32_t *pnChatting)
@ -11303,7 +11303,7 @@ const char * __thiscall winISteamFriends_SteamFriends018_GetFriendRichPresence(s
TRACE("%p\n", _this);
IsBadStringPtrA(pchKey, -1);
STEAMCLIENT_CALL( ISteamFriends_SteamFriends018_GetFriendRichPresence, &params );
return params._ret;
return get_unix_buffer( params._ret );
}
int32_t __thiscall winISteamFriends_SteamFriends018_GetFriendRichPresenceKeyCount(struct w_iface *_this, CSteamID steamIDFriend)
@ -11328,7 +11328,7 @@ const char * __thiscall winISteamFriends_SteamFriends018_GetFriendRichPresenceKe
};
TRACE("%p\n", _this);
STEAMCLIENT_CALL( ISteamFriends_SteamFriends018_GetFriendRichPresenceKeyByIndex, &params );
return params._ret;
return get_unix_buffer( params._ret );
}
void __thiscall winISteamFriends_SteamFriends018_RequestFriendRichPresence(struct w_iface *_this, CSteamID steamIDFriend)
@ -11719,7 +11719,7 @@ const char * __thiscall winISteamFriends_SteamFriends018_GetProfileItemPropertyS
};
TRACE("%p\n", _this);
STEAMCLIENT_CALL( ISteamFriends_SteamFriends018_GetProfileItemPropertyString, &params );
return params._ret;
return get_unix_buffer( params._ret );
}
uint32_t __thiscall winISteamFriends_SteamFriends018_GetProfileItemPropertyUint(struct w_iface *_this, CSteamID steamID, uint32_t itemType, uint32_t prop)

View File

@ -316,7 +316,7 @@ const char * __thiscall winISteamRemotePlay_STEAMREMOTEPLAY_INTERFACE_VERSION003
};
TRACE("%p\n", _this);
STEAMCLIENT_CALL( ISteamRemotePlay_STEAMREMOTEPLAY_INTERFACE_VERSION003_GetSessionClientName, &params );
return params._ret;
return get_unix_buffer( params._ret );
}
uint32_t __thiscall winISteamRemotePlay_STEAMREMOTEPLAY_INTERFACE_VERSION003_GetSessionClientFormFactor(struct w_iface *_this, uint32_t unSessionID)

View File

@ -5880,7 +5880,7 @@ const char * __thiscall winISteamUserStats_STEAMUSERSTATS_INTERFACE_VERSION013_G
IsBadStringPtrA(pchName, -1);
IsBadStringPtrA(pchKey, -1);
STEAMCLIENT_CALL( ISteamUserStats_STEAMUSERSTATS_INTERFACE_VERSION013_GetAchievementDisplayAttribute, &params );
return params._ret;
return get_unix_buffer( params._ret );
}
int8_t __thiscall winISteamUserStats_STEAMUSERSTATS_INTERFACE_VERSION013_IndicateAchievementProgress(struct w_iface *_this, const char *pchName, uint32_t nCurProgress, uint32_t nMaxProgress)
@ -5918,7 +5918,7 @@ const char * __thiscall winISteamUserStats_STEAMUSERSTATS_INTERFACE_VERSION013_G
};
TRACE("%p\n", _this);
STEAMCLIENT_CALL( ISteamUserStats_STEAMUSERSTATS_INTERFACE_VERSION013_GetAchievementName, &params );
return params._ret;
return get_unix_buffer( params._ret );
}
uint64_t __thiscall winISteamUserStats_STEAMUSERSTATS_INTERFACE_VERSION013_RequestUserStats(struct w_iface *_this, CSteamID steamIDUser)
@ -6043,7 +6043,7 @@ const char * __thiscall winISteamUserStats_STEAMUSERSTATS_INTERFACE_VERSION013_G
};
TRACE("%p\n", _this);
STEAMCLIENT_CALL( ISteamUserStats_STEAMUSERSTATS_INTERFACE_VERSION013_GetLeaderboardName, &params );
return params._ret;
return get_unix_buffer( params._ret );
}
int32_t __thiscall winISteamUserStats_STEAMUSERSTATS_INTERFACE_VERSION013_GetLeaderboardEntryCount(struct w_iface *_this, uint64_t hSteamLeaderboard)