Files
djhackersdev_bemanitools/src/main/cconfig/cconfig-util.c
T
icex2 57e68f928a feat: bemanitools 6 initial refactoring drop, alpha 1
**THIS IS A HIGHLY WORK/DEVELOPMENT IN PROGRESS VERSION**

**THINGS ARE BROKEN AND EVERYTHING IS SUBJECT TO CHANGE**

First cut after massive refactoring with most critical and fundamental changes implemented.
We need to start somewhere, and this might be as good as anything else, so we can get started
with testing, bug fixing and iterating for the next releases.

The following list is non-exhaustive, does not guarantee anything does work, yet, and is supposed
to give a high level idea of what all of this is about. Updated documentation will reflect all of
this at some later point in time in more detail.

* A common "core" now abstracts logging, thread, property and configuration infrastructure and
  provides a common interface. This is used by bemanitools internally as well as all tools, hooks
  and APIs provided and don't depend on the game, version of the game or AVS version available
  anymore
* New bemanitools (public) API
  * Versioned API allowing for handling incremental API changes as well as breaking changes by
    providing a new/different version when necessary
  * Unified interfaces for bemanitools core API, i.e. logging, threads, configuration
  * SDK with examples (TBD)
  * Dogfooding approach: Bemanitools uses its own (public) API to implement and provide fundamental
    features like configurable keyboard implementations for IO or hooks for different games and
    versions
* All bemanitools hooks and IO libraries have been or are about to be re-worked to use the new APIs
* New hook API allows for more fine grained runtime control when stages of the hook are to be
  executed, i.e. pre AVS, before main game, iat hooking instead of relying purely on DllMain
  (which is still a compatible option though)
* launcher as a replacement for bootstrap: Bring it significantly closer to the original bootstrap
  by supporting completely vanilla data and bootstrap.xml configurations to run the games. Note
  that bemanitools does not include any code or means to run DRM'd data, only decrypted
* inject is also being reworked to use as much of the same "infrastructure" as launcher to provide
  a more seamless bootstrapping process for games that keeps pre-eapki data as vanilla as possible
Summary:

Test Plan:
Summary:

Test Plan:
Summary:

Test Plan:
Summary:

Test Plan:
2024-08-15 11:34:31 +02:00

233 lines
4.5 KiB
C

#define LOG_MODULE "cconfig-util"
#include <stdio.h>
#include <string.h>
#include "cconfig/cconfig-util.h"
#include "iface-core/log.h"
#include "util/hex.h"
#include "util/mem.h"
bool cconfig_util_get_int(
struct cconfig *config,
const char *key,
int32_t *ret,
int32_t default_value)
{
struct cconfig_entry *entry;
log_assert(config);
log_assert(key);
entry = cconfig_get(config, key);
if (entry) {
if (sscanf(entry->value, "%d", ret) == 1) {
return true;
}
}
*ret = default_value;
return false;
}
bool cconfig_util_get_float(
struct cconfig *config, const char *key, float *ret, float default_value)
{
struct cconfig_entry *entry;
log_assert(config);
log_assert(key);
entry = cconfig_get(config, key);
if (entry) {
if (sscanf(entry->value, "%f", ret) == 1) {
return true;
}
}
*ret = default_value;
return false;
}
bool cconfig_util_get_bool(
struct cconfig *config, const char *key, bool *ret, bool default_value)
{
struct cconfig_entry *entry;
log_assert(config);
log_assert(key);
entry = cconfig_get(config, key);
if (entry) {
if (!strcmp(entry->value, "true")) {
*ret = true;
return true;
} else if (!strcmp(entry->value, "false")) {
*ret = false;
return true;
}
}
*ret = default_value;
return false;
}
bool cconfig_util_get_str(
struct cconfig *config,
const char *key,
char *buffer,
size_t len,
const char *default_value)
{
struct cconfig_entry *entry;
size_t str_len;
log_assert(config);
log_assert(key);
entry = cconfig_get(config, key);
if (entry) {
str_len = strlen(entry->value);
if (str_len <= len) {
strcpy(buffer, entry->value);
return true;
}
}
strcpy(buffer, default_value);
return false;
}
bool cconfig_util_get_data(
struct cconfig *config,
const char *key,
uint8_t *buffer,
size_t len,
const uint8_t *default_value)
{
size_t res_len;
struct cconfig_entry *entry;
log_assert(config);
log_assert(key);
log_assert(len);
entry = cconfig_get(config, key);
if (entry) {
res_len = strlen(entry->value);
res_len = res_len / 2 + res_len % 2;
if (len <= res_len) {
if (hex_decode(buffer, len, entry->value, strlen(entry->value))) {
return true;
}
}
}
memcpy(buffer, default_value, len);
return false;
}
void cconfig_util_set_int(
struct cconfig *config, const char *key, int32_t value, const char *desc)
{
char *str;
size_t str_len;
log_assert(config);
log_assert(key);
log_assert(desc);
str_len = snprintf(NULL, 0, "%d", value) + 1;
str = xmalloc(str_len);
snprintf(str, str_len, "%d", value);
cconfig_set(config, key, str, desc);
free(str);
}
void cconfig_util_set_float(
struct cconfig *config, const char *key, float value, const char *desc)
{
char *str;
size_t str_len;
log_assert(config);
log_assert(key);
log_assert(desc);
str_len = snprintf(NULL, 0, "%f", value) + 1;
str = xmalloc(str_len);
snprintf(str, str_len, "%f", value);
cconfig_set(config, key, str, desc);
free(str);
}
void cconfig_util_set_bool(
struct cconfig *config, const char *key, bool value, const char *desc)
{
log_assert(config);
log_assert(key);
log_assert(desc);
cconfig_set(config, key, value ? "true" : "false", desc);
}
void cconfig_util_set_str(
struct cconfig *config,
const char *key,
const char *value,
const char *desc)
{
log_assert(config);
log_assert(key);
log_assert(desc);
log_assert(value);
cconfig_set(config, key, value, desc);
}
void cconfig_util_set_data(
struct cconfig *config,
const char *key,
const uint8_t *value,
size_t len,
const char *desc)
{
char *str;
size_t str_len;
log_assert(config);
log_assert(key);
log_assert(desc);
str_len = len * 2 + 1;
str = xmalloc(str_len);
hex_encode_uc(value, len, str, str_len);
cconfig_set(config, key, str, desc);
free(str);
}
void cconfig_util_log(struct cconfig *config, bt_core_log_message_t log_message)
{
for (uint32_t i = 0; i < config->nentries; i++) {
log_message(
LOG_MODULE,
"%s=%s",
config->entries[i].key,
config->entries[i].value);
}
}