Skip to content

Commit

Permalink
Remove string data
Browse files Browse the repository at this point in the history
  • Loading branch information
Nickid2018 committed Jul 17, 2024
1 parent dcb609c commit f1f7786
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 657 deletions.
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ macro(invoke_py message)
endif ()
endmacro(invoke_py)

invoke_py("Generate Java String Data"
"${PROJECT_SOURCE_DIR}/codegen_script/string_gen.py" "${PROJECT_SOURCE_DIR}/strings/strings_je.json"
"${GEN_RESOURCE_DIR}/strings_je.c" "${GEN_RESOURCE_DIR}/strings_je.h" "je")
invoke_py("Generate Entity ID Data"
"${PROJECT_SOURCE_DIR}/codegen_script/entity_id_gen.py" "${PROJECT_SOURCE_DIR}/minecraft-data/java"
"${CMAKE_CURRENT_BINARY_DIR}/preprocess_resources")
Expand Down
60 changes: 0 additions & 60 deletions codegen_script/string_gen.py

This file was deleted.

1 change: 0 additions & 1 deletion protocol/protocol_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ gint read_var_int_with_limit(tvbuff_t *tvb, gint offset, gint max_length, gint *
*result |= (read & 0x7F) << (7 * p++);
} while ((read & 0x80) != 0);
return p;

}

gint read_var_long(tvbuff_t *tvb, gint offset, gint64 *result) {
Expand Down
27 changes: 20 additions & 7 deletions protocol/storage/storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@

extern gchar *pref_protocol_data_dir;

cJSON *cached_versions = NULL;
cJSON *cached_protocol_data_mapping = NULL;

#define JSON_CACHED(name, path) \
cJSON* cached_##name = NULL; \
void ensure_cached_##name() { \
if (cached_##name == NULL) { \
gchar *file = g_build_filename(pref_protocol_data_dir, path, NULL); \
Expand All @@ -25,12 +23,12 @@ void ensure_cached_##name() { \
}

#define DATA_CACHED_UINT(name) \
wmem_map_t *cached_##name; \
wmem_map_t *cached_##name = NULL; \
void *get_cached_##name(guint version) { \
if (cached_##name == NULL) \
return NULL; \
return wmem_map_lookup(cached_##name, GUINT_TO_POINTER(version)); \
} \
} \
void set_cached_##name(guint version, void *value) { \
if (cached_##name == NULL) \
cached_##name = wmem_map_new(wmem_epan_scope(), g_direct_hash, g_direct_equal); \
Expand All @@ -43,7 +41,7 @@ void *get_cached_##name(gchar *java_version) { \
if (cached_##name == NULL) \
return NULL; \
return wmem_map_lookup(cached_##name, java_version); \
} \
} \
void set_cached_##name(gchar *java_version, void *value) { \
if (cached_##name == NULL) \
cached_##name = wmem_map_new(wmem_epan_scope(), g_str_hash, g_str_equal); \
Expand All @@ -66,11 +64,14 @@ JSON_CACHED(versions, "java_edition/versions.json")

JSON_CACHED(protocol_data_mapping, "java_edition/protocol_mapping.json")

JSON_CACHED(packet_names, "java_edition/packet_names.json")

DATA_CACHED_UINT(protocol)

void clear_storage() {
CLEAR_CACHED_JSON(versions)
CLEAR_CACHED_JSON(protocol_data_mapping)
CLEAR_CACHED_JSON(packet_names)
CLEAR_CACHED_DATA(protocol)
}

Expand Down Expand Up @@ -105,6 +106,17 @@ gint get_data_version(gchar *java_version) {
return -1;
}

gchar *get_readable_packet_name(bool to_client, gchar *packet_name) {
ensure_cached_packet_names();
cJSON *found = cJSON_GetObjectItem(
cJSON_GetObjectItem(cached_packet_names, to_client ? "toClient" : "toServer"),
packet_name
);
if (found == NULL)
return packet_name;
return found->valuestring;
}

protocol_je_set get_protocol_set_je(guint protocol_version, protocol_settings settings) {
ensure_cached_protocol_data_mapping();
protocol_je_set cached = get_cached_protocol(protocol_version);
Expand All @@ -117,7 +129,8 @@ protocol_je_set get_protocol_set_je(guint protocol_version, protocol_settings se
if (found == NULL)
return NULL;

gchar *file = g_build_filename(pref_protocol_data_dir, "java_edition/protocols", found->valuestring, "protocol.json", NULL);
gchar *file = g_build_filename(pref_protocol_data_dir, "java_edition/protocols", found->valuestring,
"protocol.json", NULL);
gchar *content = NULL;
if (!g_file_get_contents(file, &content, NULL, NULL)) {
ws_log("MC-Dissector", LOG_LEVEL_WARNING, "Cannot read file %s", file);
Expand Down
3 changes: 2 additions & 1 deletion protocol/storage/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#ifndef MC_DISSECTOR_STORAGE_H
#define MC_DISSECTOR_STORAGE_H

#include <glib.h>
#include "protocol/schema/protocol_schema.h"

typedef struct _protocol_je_set {
Expand All @@ -20,6 +19,8 @@ gchar **get_mapped_java_versions(guint protocol_version);

gint get_data_version(gchar *java_version);

gchar *get_readable_packet_name(bool to_client, gchar *packet_name);

protocol_je_set get_protocol_set_je(guint protocol_version, protocol_settings settings);

#endif //MC_DISSECTOR_STORAGE_H
17 changes: 6 additions & 11 deletions protocol_je/je_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "mc_dissector.h"
#include "je_dissect.h"
#include "je_protocol.h"
#include "strings_je.h"

extern int hf_invalid_data_je;
extern int hf_ignored_packet_je;
Expand Down Expand Up @@ -232,24 +231,20 @@ void handle(proto_tree *packet_tree, packet_info *pinfo, tvbuff_t *tvb, mcje_pro
proto_tree_add_string(packet_tree, hf_invalid_data_je, tvb, 0, 1, "Can't find protocol set");
return;
}

protocol_entry protocol = get_protocol_entry(protocol_set, packet_id, is_client);
proto_tree_add_uint(packet_tree, hf_packet_id_je, tvb, 0, read, packet_id);
if (protocol == NULL) {
proto_tree_add_string(packet_tree, hf_unknown_packet_je, tvb, 0, 1, "Unknown Packet ID");
return;
}

gchar *packet_name = get_packet_name(protocol);
gchar *better_name = wmem_map_lookup(
is_client ? protocol_name_map_client_je : protocol_name_map_server_je,
packet_name
gchar *better_name = get_readable_packet_name(is_client, packet_name);
proto_tree_add_string_format_value(
packet_tree, hf_packet_name_je, tvb, 0, read, packet_name,
"%s (%s)", better_name, packet_name
);
if (better_name == NULL)
proto_tree_add_string(packet_tree, hf_packet_name_je, tvb, 0, read, packet_name);
else
proto_tree_add_string_format_value(
packet_tree, hf_packet_name_je, tvb, 0, read, packet_name,
"%s (%s)", better_name, packet_name
);

bool ignore = false;
if (strlen(pref_ignore_packets_je) != 0) {
Expand Down
3 changes: 0 additions & 3 deletions protocol_je/je_registers.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include <epan/packet.h>
#include "mc_dissector.h"
#include "strings_je.h"
#include "je_protocol.h"

// ett
Expand Down Expand Up @@ -50,8 +49,6 @@ int hf_legacy_slp_payload = -1;
void proto_register_mcje() {
proto_mcje = proto_register_protocol(MCJE_NAME, MCJE_SHORT_NAME, MCJE_FILTER);

register_string_je();

static hf_register_info hf_je[] = {
DEFINE_HF(hf_int8_je, " [int8]", "mcje.int8", INT8, DEC)
DEFINE_HF(hf_uint8_je, " [uint8]", "mcje.uint8", UINT8, DEC)
Expand Down
Loading

0 comments on commit f1f7786

Please sign in to comment.