|
| 1 | +#pragma once |
| 2 | +#ifdef __cplusplus |
| 3 | +#include <libbndl/bundle.hpp> |
| 4 | +#endif |
| 5 | +#include <libbndl/internal/export.h> |
| 6 | +#include <stdbool.h> |
| 7 | +#include <stdint.h> |
| 8 | + |
| 9 | +#ifdef __has_feature |
| 10 | +# define LIBBNDL_HAS_FEATURE(feat) __has_feature(feat) |
| 11 | +#else |
| 12 | +# define LIBBNDL_HAS_FEATURE(feat) 0 |
| 13 | +#endif |
| 14 | + |
| 15 | +#if LIBBNDL_HAS_FEATURE(nullability) |
| 16 | +# define LIBBNDL_NONNULL _Nonnull |
| 17 | +# define LIBBNDL_NULLABLE _Nullable |
| 18 | +#else |
| 19 | +# define LIBBNDL_NONNULL |
| 20 | +# define LIBBNDL_NULLABLE |
| 21 | +#endif |
| 22 | + |
| 23 | +#ifdef __cplusplus |
| 24 | +extern "C" |
| 25 | +{ |
| 26 | +#endif |
| 27 | + typedef struct libbndl_bundle libbndl_bundle; |
| 28 | + |
| 29 | + typedef enum |
| 30 | + { |
| 31 | + LIBBNDL_ERROR_SUCCESS = 0, |
| 32 | + |
| 33 | + LIBBNDL_ERROR_INVALID_BUNDLE = 1, |
| 34 | + LIBBNDL_ERROR_GENERIC_FAILURE = 2, |
| 35 | + LIBBNDL_ERROR_RESOURCE_NOT_FOUND = 3, |
| 36 | + LIBBNDL_ERROR_DEBUG_DATA_NOT_FOUND = 4, |
| 37 | + LIBBNDL_ERROR_OUT_OF_RANGE = 5, |
| 38 | + |
| 39 | + LIBBNDL_ERROR_MEMORY_ALLOCATION = -1, |
| 40 | + } libbndl_error; |
| 41 | + |
| 42 | + enum { |
| 43 | +#define LIBBNDL_ENUM_MAGIC(_, name, value) LIBBNDL_MAGIC_##name = value, |
| 44 | +#include <libbndl/internal/enum.inc> |
| 45 | +#undef LIBBNDL_ENUM_MAGIC |
| 46 | + }; |
| 47 | + typedef uint8_t libbndl_magic; |
| 48 | + |
| 49 | + enum |
| 50 | + { |
| 51 | +#define LIBBNDL_ENUM_PLATFORM(_, name, value) LIBBNDL_PLATFORM_##name = value, |
| 52 | +#include <libbndl/internal/enum.inc> |
| 53 | +#undef LIBBNDL_ENUM_PLATFORM |
| 54 | + }; |
| 55 | + typedef uint16_t libbndl_platform; |
| 56 | + |
| 57 | + enum |
| 58 | + { |
| 59 | +#define LIBBNDL_ENUM_FLAGS(_, name, value) LIBBNDL_FLAGS_##name = value, |
| 60 | +#include <libbndl/internal/enum.inc> |
| 61 | +#undef LIBBNDL_ENUM_FLAGS |
| 62 | + }; |
| 63 | + typedef uint32_t libbndl_flags; |
| 64 | + |
| 65 | + |
| 66 | + LIBBNDL_EXPORT libbndl_error libbndl_load(libbndl_bundle *LIBBNDL_NULLABLE *LIBBNDL_NONNULL bundle, const char *LIBBNDL_NONNULL path); |
| 67 | + LIBBNDL_EXPORT libbndl_error libbndl_create(libbndl_bundle *LIBBNDL_NULLABLE *LIBBNDL_NONNULL bundle, libbndl_magic magic, uint16_t version, libbndl_platform platform, libbndl_flags flags); |
| 68 | + LIBBNDL_EXPORT void libbndl_free(libbndl_bundle *LIBBNDL_NULLABLE bundle); |
| 69 | + |
| 70 | + LIBBNDL_EXPORT libbndl_error libbndl_save(libbndl_bundle *LIBBNDL_NONNULL bundle, const char *LIBBNDL_NONNULL path); |
| 71 | + |
| 72 | + LIBBNDL_EXPORT libbndl_magic libbndl_get_magic(const libbndl_bundle *LIBBNDL_NONNULL bundle); |
| 73 | + LIBBNDL_EXPORT uint16_t libbndl_get_version(const libbndl_bundle *LIBBNDL_NONNULL bundle); |
| 74 | + LIBBNDL_EXPORT libbndl_platform libbndl_get_platform(const libbndl_bundle *LIBBNDL_NONNULL bundle); |
| 75 | + LIBBNDL_EXPORT libbndl_flags libbndl_get_flags(const libbndl_bundle *LIBBNDL_NONNULL bundle); |
| 76 | + |
| 77 | + LIBBNDL_EXPORT bool libbndl_is_burnout_era(const libbndl_bundle *LIBBNDL_NONNULL bundle); |
| 78 | + LIBBNDL_EXPORT bool libbndl_is_need_for_speed_era(const libbndl_bundle *LIBBNDL_NONNULL bundle); |
| 79 | + |
| 80 | + |
| 81 | + /* Resource ID */ |
| 82 | + typedef uint64_t libbndl_resource_id; |
| 83 | + |
| 84 | + enum |
| 85 | + { |
| 86 | +#define LIBBNDL_ENUM_ID_TYPE(_, name, value) LIBBNDL_RESOURCE_ID_TYPE_##name = value, |
| 87 | +#include <libbndl/internal/enum.inc> |
| 88 | +#undef LIBBNDL_ENUM_ID_TYPE |
| 89 | + }; |
| 90 | + typedef uint8_t libbndl_resource_id_type; |
| 91 | + |
| 92 | + LIBBNDL_EXPORT libbndl_resource_id libbndl_resource_id_from_name(const char *LIBBNDL_NONNULL name); |
| 93 | + LIBBNDL_EXPORT libbndl_resource_id libbndl_resource_id_from_game_changer(uint32_t id, uint16_t resourceType, uint8_t index); |
| 94 | + LIBBNDL_EXPORT libbndl_resource_id libbndl_resource_id_from_components(uint32_t id, uint16_t resourceType, uint8_t index, libbndl_resource_id_type idType); |
| 95 | + |
| 96 | + LIBBNDL_EXPORT uint32_t libbndl_resource_id_get_game_changer_id(libbndl_resource_id resourceID); |
| 97 | +# define libbndl_resource_id_get_id32(resourceID) libbndl_resource_id_get_game_changer_id(resourceID) |
| 98 | + LIBBNDL_EXPORT uint16_t libbndl_resource_id_get_resource_type_id(libbndl_resource_id resourceID); |
| 99 | + LIBBNDL_EXPORT uint8_t libbndl_resource_id_get_index(libbndl_resource_id resourceID); |
| 100 | + LIBBNDL_EXPORT libbndl_resource_id_type libbndl_resource_id_get_id_type(libbndl_resource_id resourceID); |
| 101 | + |
| 102 | + |
| 103 | + /* Resource debug data */ |
| 104 | + typedef struct libbndl_resource_debug_data libbndl_resource_debug_data; |
| 105 | + |
| 106 | + LIBBNDL_EXPORT libbndl_error libbndl_get_resource_debug_data(const libbndl_bundle *LIBBNDL_NONNULL bundle, libbndl_resource_debug_data *LIBBNDL_NULLABLE *LIBBNDL_NONNULL debugData, libbndl_resource_id resourceID, uint8_t streamIndex); |
| 107 | + |
| 108 | + LIBBNDL_EXPORT libbndl_error libbndl_resource_debug_data_create(libbndl_resource_debug_data *LIBBNDL_NULLABLE *LIBBNDL_NONNULL debugData, const char *LIBBNDL_NONNULL name, const char *LIBBNDL_NONNULL typeName); |
| 109 | + LIBBNDL_EXPORT void libbndl_resource_debug_data_free(libbndl_resource_debug_data *LIBBNDL_NULLABLE debugData); |
| 110 | + |
| 111 | + LIBBNDL_EXPORT libbndl_error libbndl_resource_debug_data_get_name(const libbndl_resource_debug_data *LIBBNDL_NONNULL debugData, char *LIBBNDL_NONNULL buffer, size_t length); |
| 112 | + LIBBNDL_EXPORT libbndl_error libbndl_resource_debug_data_get_type_name(const libbndl_resource_debug_data *LIBBNDL_NONNULL debugData, char *LIBBNDL_NONNULL buffer, size_t length); |
| 113 | + |
| 114 | + LIBBNDL_EXPORT void libbndl_add_resource_debug_data(libbndl_bundle *LIBBNDL_NONNULL bundle, libbndl_resource_id resourceID, const libbndl_resource_debug_data *LIBBNDL_NONNULL debugData, uint8_t streamIndex); |
| 115 | + |
| 116 | + |
| 117 | + /* Resource type */ |
| 118 | + enum |
| 119 | + { |
| 120 | +#define LIBBNDL_ENUM_RESOURCE_TYPE_BURNOUT(_, name, value) LIBBNDL_RESOURCE_TYPE_BURNOUT_##name = value, |
| 121 | +#include <libbndl/internal/enum.inc> |
| 122 | +#undef LIBBNDL_ENUM_RESOURCE_TYPE_BURNOUT |
| 123 | + }; |
| 124 | + enum |
| 125 | + { |
| 126 | +#define LIBBNDL_ENUM_RESOURCE_TYPE_NFS(_, name, value) LIBBNDL_RESOURCE_TYPE_NFS_##name = value, |
| 127 | +#include <libbndl/internal/enum.inc> |
| 128 | +#undef LIBBNDL_ENUM_RESOURCE_TYPE_NFS |
| 129 | + }; |
| 130 | + typedef uint32_t libbndl_resource_type; |
| 131 | + |
| 132 | + LIBBNDL_EXPORT libbndl_error libbndl_get_resource_type(const libbndl_bundle *LIBBNDL_NONNULL bundle, libbndl_resource_type *LIBBNDL_NONNULL resourceType, libbndl_resource_id resourceID, uint8_t streamIndex); |
| 133 | + |
| 134 | + |
| 135 | + /* Buffer */ |
| 136 | + typedef struct libbndl_buffer libbndl_buffer; |
| 137 | + |
| 138 | + enum |
| 139 | + { |
| 140 | +#define LIBBNDL_ENUM_MEMORY_TYPE(_, name, value) LIBBNDL_MEMORY_TYPE_##name = value, |
| 141 | +#include <libbndl/internal/enum.inc> |
| 142 | +#undef LIBBNDL_ENUM_MEMORY_TYPE |
| 143 | + }; |
| 144 | + typedef uint8_t libbndl_memory_type; |
| 145 | + |
| 146 | + LIBBNDL_EXPORT libbndl_error libbndl_buffer_create(libbndl_buffer *LIBBNDL_NULLABLE *LIBBNDL_NONNULL buffer, const void *LIBBNDL_NONNULL data, size_t size, uint32_t alignment); |
| 147 | + LIBBNDL_EXPORT void libbndl_buffer_free(libbndl_buffer *LIBBNDL_NULLABLE buffer); |
| 148 | + |
| 149 | + LIBBNDL_EXPORT libbndl_error libbndl_copy_binary(const libbndl_bundle *LIBBNDL_NONNULL bundle, libbndl_buffer *LIBBNDL_NULLABLE *LIBBNDL_NONNULL buffer, libbndl_resource_id resourceID, libbndl_memory_type memoryType, uint8_t streamIndex); |
| 150 | + |
| 151 | + LIBBNDL_EXPORT void *LIBBNDL_NULLABLE libbndl_buffer_get_data(const libbndl_buffer *LIBBNDL_NONNULL buffer); |
| 152 | + LIBBNDL_EXPORT size_t libbndl_buffer_get_size(const libbndl_buffer *LIBBNDL_NONNULL buffer); |
| 153 | + LIBBNDL_EXPORT uint32_t libbndl_buffer_get_alignment(const libbndl_buffer *LIBBNDL_NONNULL buffer); |
| 154 | + |
| 155 | + |
| 156 | + /* Import */ |
| 157 | + typedef struct libbndl_import libbndl_import; |
| 158 | + |
| 159 | + enum |
| 160 | + { |
| 161 | +#define LIBBNDL_ENUM_IMPORT_TYPE(_, name, value) LIBBNDL_IMPORT_TYPE_##name = value, |
| 162 | +#include <libbndl/internal/enum.inc> |
| 163 | +#undef LIBBNDL_ENUM_IMPORT_TYPE |
| 164 | + }; |
| 165 | + typedef uint8_t libbndl_import_type; |
| 166 | + |
| 167 | + LIBBNDL_EXPORT libbndl_error libbndl_import_create(libbndl_import *LIBBNDL_NULLABLE *LIBBNDL_NONNULL import, libbndl_resource_id resourceID, uint32_t offset, libbndl_import_type importType); |
| 168 | + LIBBNDL_EXPORT void libbndl_import_free(libbndl_import *LIBBNDL_NULLABLE import); |
| 169 | + |
| 170 | + LIBBNDL_EXPORT libbndl_resource_id libbndl_import_get_resource_id(const libbndl_import *LIBBNDL_NONNULL import); |
| 171 | + LIBBNDL_EXPORT uint32_t libbndl_import_get_offset(const libbndl_import *LIBBNDL_NONNULL import); |
| 172 | + LIBBNDL_EXPORT libbndl_import_type libbndl_import_get_import_type(const libbndl_import *LIBBNDL_NONNULL import); |
| 173 | + |
| 174 | + |
| 175 | + /* Resource */ |
| 176 | + typedef struct libbndl_resource libbndl_resource; |
| 177 | + |
| 178 | + LIBBNDL_EXPORT libbndl_error libbndl_resource_create(libbndl_resource *LIBBNDL_NULLABLE *LIBBNDL_NONNULL resource, libbndl_resource_type resourceType); |
| 179 | + LIBBNDL_EXPORT void libbndl_resource_free(libbndl_resource *LIBBNDL_NULLABLE resource); |
| 180 | + |
| 181 | + LIBBNDL_EXPORT libbndl_error libbndl_copy_resource(const libbndl_bundle *LIBBNDL_NONNULL bundle, libbndl_resource *LIBBNDL_NULLABLE *LIBBNDL_NONNULL resource, libbndl_resource_id resourceID, uint8_t streamIndex); |
| 182 | + |
| 183 | + LIBBNDL_EXPORT libbndl_error libbndl_resource_get_binary_mut(libbndl_resource *LIBBNDL_NONNULL resource, libbndl_buffer *LIBBNDL_NULLABLE *LIBBNDL_NONNULL buffer, libbndl_memory_type memoryType); |
| 184 | + LIBBNDL_EXPORT libbndl_error libbndl_resource_get_binary_const(const libbndl_resource *LIBBNDL_NONNULL resource, const libbndl_buffer *LIBBNDL_NULLABLE *LIBBNDL_NONNULL buffer, libbndl_memory_type memoryType); |
| 185 | +# define libbndl_resource_get_binary(resource, buffer, memoryType) _Generic((resource), \ |
| 186 | + const libbndl_resource *: libbndl_resource_get_binary_const, \ |
| 187 | + libbndl_resource *: libbndl_resource_get_binary_mut)(resource, buffer, memoryType) |
| 188 | + |
| 189 | + LIBBNDL_EXPORT size_t libbndl_resource_get_import_count(const libbndl_resource *LIBBNDL_NONNULL resource); |
| 190 | + LIBBNDL_EXPORT libbndl_error libbndl_resource_copy_import(const libbndl_resource *LIBBNDL_NONNULL resource, libbndl_import *LIBBNDL_NULLABLE *LIBBNDL_NONNULL import, size_t index); |
| 191 | + |
| 192 | + LIBBNDL_EXPORT libbndl_error libbndl_resource_replace_binary(libbndl_resource *LIBBNDL_NONNULL resource, const libbndl_buffer *LIBBNDL_NONNULL buffer, libbndl_memory_type memoryType); |
| 193 | + LIBBNDL_EXPORT void libbndl_resource_add_import(libbndl_resource *LIBBNDL_NONNULL resource, libbndl_import *LIBBNDL_NONNULL import); |
| 194 | + |
| 195 | + LIBBNDL_EXPORT libbndl_error libbndl_add_resource(libbndl_bundle *LIBBNDL_NONNULL bundle, libbndl_resource_id resourceID, const libbndl_resource *LIBBNDL_NONNULL resource, uint8_t streamIndex); |
| 196 | + |
| 197 | + LIBBNDL_EXPORT libbndl_error libbndl_replace_resource(libbndl_bundle *LIBBNDL_NONNULL bundle, libbndl_resource_id resourceID, const libbndl_resource *LIBBNDL_NONNULL resource, uint8_t streamIndex); |
| 198 | + |
| 199 | + |
| 200 | + /* Bundle helpers */ |
| 201 | + LIBBNDL_EXPORT uint32_t libbndl_get_resource_count(const libbndl_bundle *LIBBNDL_NONNULL bundle); |
| 202 | + LIBBNDL_EXPORT libbndl_error libbndl_get_resource_id_at_index(const libbndl_bundle *LIBBNDL_NONNULL bundle, libbndl_resource_id *LIBBNDL_NONNULL resourceID, uint32_t index); |
| 203 | + |
| 204 | +# define LIBBNDL_STREAM_MAX_COUNT 4 |
| 205 | + LIBBNDL_EXPORT bool libbndl_is_populated_resource_stream_index(const libbndl_bundle *LIBBNDL_NONNULL bundle, libbndl_resource_id resourceID, uint8_t streamIndex); |
| 206 | + |
| 207 | + LIBBNDL_EXPORT libbndl_resource_id libbndl_get_default_resource_id(const libbndl_bundle *LIBBNDL_NONNULL bundle); |
| 208 | + LIBBNDL_EXPORT int32_t libbndl_get_default_resource_stream_index(const libbndl_bundle *LIBBNDL_NONNULL bundle); |
| 209 | + |
| 210 | +# define LIBBNDL_STREAM_NAME_MAX_LENGTH 15 |
| 211 | + LIBBNDL_EXPORT libbndl_error libbndl_get_stream_name(const libbndl_bundle *LIBBNDL_NONNULL bundle, char *LIBBNDL_NONNULL buffer, size_t length, uint8_t streamIndex); |
| 212 | + |
| 213 | + LIBBNDL_EXPORT bool libbndl_is_valid_memory_type(const libbndl_bundle *LIBBNDL_NONNULL bundle, libbndl_memory_type memoryType); |
| 214 | +#ifdef __cplusplus |
| 215 | +} |
| 216 | +#endif |
0 commit comments