Skip to content

Commit 85b8c58

Browse files
authored
Merge pull request #7 from devloglogan/code-gen-fixes
Fix some SDK code gen issues
2 parents 549a038 + 6989dfe commit 85b8c58

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

generate_platform_sdk_bindings.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
'ovr_Message_GetRequestID',
4545
'ovr_HttpTransferUpdate_GetID',
4646

47+
# These functions should return PackedByteArray instead of String
48+
'ovr_ChallengeEntry_GetExtraData',
49+
'ovr_LeaderboardEntry_GetExtraData',
50+
4751
# Exclude the deprecated Platform VoIP functions.
4852
# Note: We need to keep a few that are associated with System VoIP.
4953
'ovr_Voip_Accept',
@@ -127,7 +131,7 @@
127131
'ovr_RichPresence_Set',
128132
]
129133

130-
# Exclude these OVR functions from both source generation only (the headers will still be generated).
134+
# Exclude these OVR functions from source generation only (the headers will still be generated).
131135
EXCLUDE_OVR_FUNCTION_SOURCE = [
132136
'ovr_HttpTransferUpdate_GetBytes',
133137
'ovr_Packet_GetBytes',
@@ -972,6 +976,8 @@ def make_null_value(type, plan):
972976
def convert_argument_value_to_ovr(name, ovr_type, godot_type, plan):
973977
if godot_type == 'const String &':
974978
return f'{name}.utf8().ptr()'
979+
elif godot_type == 'const PackedStringArray &':
980+
return f'({ovr_type})CharStringList({name}).pointers.ptr(), {name}.size()'
975981
elif godot_type.startswith('const Packed'):
976982
return f'({ovr_type}){name}.ptr(), {name}.size()'
977983
elif godot_type.startswith('MetaPlatformSDK::'):
@@ -1145,6 +1151,12 @@ def generate_header(class_name, class_def, plan):
11451151
if class_name == 'MetaPlatformSDK_HttpTransferUpdate':
11461152
lines.append('\tuint64_t get_id() const;')
11471153
lines.append('')
1154+
if class_name == 'MetaPlatformSDK_ChallengeEntry':
1155+
lines.append('\tPackedByteArray get_extra_data() const;')
1156+
lines.append('')
1157+
if class_name == 'MetaPlatformSDK_LeaderboardEntry':
1158+
lines.append('\tPackedByteArray get_extra_data() const;')
1159+
lines.append('')
11481160

11491161
# Iterator functions for arrays.
11501162
if class_def['type'] == 'result' and class_def['is_array']:
@@ -1180,6 +1192,8 @@ def generate_source(class_name, class_def, plan):
11801192

11811193
lines.append(f'#include "platform_sdk/{camel_to_snake_case(class_name)}.h"')
11821194
lines.append('')
1195+
lines.append('#include "util.h"')
1196+
lines.append('')
11831197
lines.append('#include <godot_cpp/core/class_db.hpp>')
11841198
lines.append('#include <godot_cpp/variant/utility_functions.hpp>')
11851199

@@ -1244,13 +1258,20 @@ def generate_source(class_name, class_def, plan):
12441258
lines.append('\tClassDB::bind_method(D_METHOD("get_data"), &MetaPlatformSDK_Message::get_data);')
12451259
lines.append('\tADD_PROPERTY(PropertyInfo(Variant::INT, "type"), "", "get_type");')
12461260
lines.append('\tADD_PROPERTY(PropertyInfo(Variant::NIL, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT), "", "get_data");')
1261+
lines.append('\tADD_PROPERTY(PropertyInfo(Variant::NIL, "error", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT), "", "get_error");')
12471262
lines.append('\tClassDB::bind_method(D_METHOD("is_success"), &MetaPlatformSDK_Message::is_success);')
12481263
lines.append('\tClassDB::bind_method(D_METHOD("get_request_id"), &MetaPlatformSDK_Message::get_request_id);')
12491264
lines.append('\tADD_PROPERTY(PropertyInfo(Variant::INT, "request_id"), "", "get_request_id");')
12501265
lines.append('\tClassDB::bind_method(D_METHOD("get_type_as_string"), &MetaPlatformSDK_Message::get_type_as_string);')
12511266
elif class_name == 'MetaPlatformSDK_HttpTransferUpdate':
12521267
lines.append('\tClassDB::bind_method(D_METHOD("get_id"), &MetaPlatformSDK_HttpTransferUpdate::get_id);')
12531268
lines.append('\tADD_PROPERTY(PropertyInfo(Variant::INT, "id"), "", "get_id");')
1269+
if class_name == 'MetaPlatformSDK_ChallengeEntry':
1270+
lines.append('\tClassDB::bind_method(D_METHOD("get_extra_data"), &MetaPlatformSDK_ChallengeEntry::get_extra_data);')
1271+
lines.append('\tADD_PROPERTY(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "extra_data"), "", "get_extra_data");')
1272+
if class_name == 'MetaPlatformSDK_LeaderboardEntry':
1273+
lines.append('\tClassDB::bind_method(D_METHOD("get_extra_data"), &MetaPlatformSDK_LeaderboardEntry::get_extra_data);')
1274+
lines.append('\tADD_PROPERTY(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "extra_data"), "", "get_extra_data");')
12541275
if class_def['type'] == 'result' and class_def['is_array']:
12551276
lines.append(f'\tClassDB::bind_method(D_METHOD("_iter_init"), &{class_name}::_iter_init);')
12561277
lines.append(f'\tClassDB::bind_method(D_METHOD("_iter_next"), &{class_name}::_iter_next);')
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) 2024-present Meta Platforms, Inc. and affiliates. All rights reserved.
2+
3+
#pragma once
4+
5+
#include <godot_cpp/templates/local_vector.hpp>
6+
7+
struct CharStringList {
8+
LocalVector<CharString> list;
9+
LocalVector<const char *> pointers;
10+
11+
CharStringList(const PackedStringArray &p_array) {
12+
list.resize(p_array.size());
13+
pointers.resize(p_array.size());
14+
for (int i = 0; i < p_array.size(); i++) {
15+
list[i] = p_array[i].utf8();
16+
pointers[i] = list[i].get_data();
17+
}
18+
}
19+
};

toolkit/src/main/cpp/platform_sdk/meta_platform_sdk.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,44 @@ uint64_t MetaPlatformSDK_HttpTransferUpdate::get_id() const {
166166
#endif
167167
}
168168

169+
PackedByteArray MetaPlatformSDK_ChallengeEntry::get_extra_data() const {
170+
#ifdef ANDROID_ENABLED
171+
PackedByteArray result;
172+
173+
const char *data = ovr_ChallengeEntry_GetExtraData(handle);
174+
if (data) {
175+
size_t size = ovr_ChallengeEntry_GetExtraDataLength(handle);
176+
if (size > 0) {
177+
result.resize(size);
178+
memcpy(result.ptrw(), data, size);
179+
}
180+
}
181+
182+
return result;
183+
#else
184+
return PackedByteArray();
185+
#endif
186+
}
187+
188+
PackedByteArray MetaPlatformSDK_LeaderboardEntry::get_extra_data() const {
189+
#ifdef ANDROID_ENABLED
190+
PackedByteArray result;
191+
192+
const char *data = ovr_LeaderboardEntry_GetExtraData(handle);
193+
if (data) {
194+
size_t size = ovr_LeaderboardEntry_GetExtraDataLength(handle);
195+
if (size > 0) {
196+
result.resize(size);
197+
memcpy(result.ptrw(), data, size);
198+
}
199+
}
200+
201+
return result;
202+
#else
203+
return PackedByteArray();
204+
#endif
205+
}
206+
169207
PackedByteArray MetaPlatformSDK_HttpTransferUpdate::get_bytes() const {
170208
#ifdef ANDROID_ENABLED
171209
PackedByteArray result;

0 commit comments

Comments
 (0)