Skip to content

Commit d03a5a4

Browse files
committed
Update DB (add typeds from hideout level)
Fixed bug in db loader Small refactoring in decompose.py & CMakeLists.txt
1 parent c6242ce commit d03a5a4

File tree

4 files changed

+35
-36
lines changed

4 files changed

+35
-36
lines changed

Diff for: Tools/GMSInfo/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ if (NOT CMAKE_SIZEOF_VOID_P EQUAL 4) # TODO: Think about how to do it better
77
message(FATAL_ERROR "Supported only x86 arch!")
88
endif()
99

10-
add_executable(HBM_GMSTool ${CMAKE_CURRENT_SOURCE_DIR}/source/main.cpp)
10+
file(GLOB_RECURSE GMSTOOL_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/source/*.cc ${CMAKE_CURRENT_SOURCE_DIR}/source/*.c)
11+
add_executable(HBM_GMSTool ${GMSTOOL_SOURCES})
12+
1113
target_link_libraries(HBM_GMSTool PRIVATE fmt::fmt nlohmann_json zlibstatic)
1214
target_compile_definitions(HBM_GMSTool PRIVATE -D_CRT_SECURE_NO_WARNINGS=1)
1315
target_include_directories(HBM_GMSTool PRIVATE

Diff for: Tools/GMSInfo/data/typeids.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,10 @@
8383
"0x100034": ["ZSlider","ZCONTROL"],
8484
"0x8000049": ["ZWINOBJSPRITEHOLDER","ZLIST"],
8585
"0x20004C": ["ZKerningFont","ZTTFONT"],
86-
"0x80100032": ["ZCONTROL","ZWINGROUP"]
86+
"0x80100032": ["ZCONTROL","ZWINGROUP"],
87+
"0x100434": ["ZHM3ItemAmmo","ZItemAmmo"],
88+
"0x10042B": ["ZHM3ItemWeapon","ZItemWeapon"],
89+
"0x10042D": ["ZHM3ItemWeaponCustom","ZHM3ItemWeapon"],
90+
"0x4000022": ["ZSHAPE","ZGEOM"],
91+
"0x1007D3": ["ZItemTemplate","ZGROUP"]
8792
}

Diff for: Tools/GMSInfo/source/main.cpp

+12-21
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99

1010
#include <array>
1111
#include <string>
12+
#include <fstream>
1213
#include <unordered_map>
1314

1415
extern "C" {
1516
#include "zlib.h"
1617
}
1718

18-
#include "GlacierTypeDefs.h"
19-
20-
#include "nlohmann/json.hpp"
19+
#include <GlacierTypeDefs.h>
20+
#include <nlohmann/json.hpp>
2121
#include <fmt/format.h>
2222

2323
#define GLACIER_GMS_ZLIB_WBTS -15
@@ -43,34 +43,25 @@ std::unordered_map<std::string, std::array<std::string, 2>> g_typeInfoDB;
4343

4444
void loadTypesDataBase()
4545
{
46-
FILE* fp = fopen("typeids.json", "r");
47-
if (!fp)
46+
std::ifstream fileStream("typeids.json", std::ifstream::binary);
47+
if (!fileStream)
4848
{
49-
printf("Failed to load typeids.json! All types will not be undecorated!\n");
49+
printf("Failed to open typeids.json! All types will be not resolved!\n");
5050
return;
5151
}
5252

53-
fseek(fp, 0L, SEEK_END);
54-
size_t bufferSize = ftell(fp);
55-
rewind(fp);
56-
char* buffer = (char*)calloc(1, bufferSize);
57-
fread(buffer, bufferSize, 1, fp);
58-
fclose(fp);
59-
60-
std::string sv(buffer, bufferSize);
61-
62-
/// parse json
6353
try
6454
{
65-
nlohmann::json j = nlohmann::json::parse(sv);
66-
nlohmann::adl_serializer<decltype(g_typeInfoDB)>::from_json(j, g_typeInfoDB);
67-
printf("Type Information Database loaded!\n");
68-
}
69-
catch (nlohmann::json::exception& ex)
55+
auto db = nlohmann::json::parse(fileStream);
56+
nlohmann::adl_serializer<decltype(g_typeInfoDB)>::from_json(db, g_typeInfoDB);
57+
printf("Type information DB loaded!\n");
58+
} catch (nlohmann::json::exception& ex)
7059
{
7160
printf("Bad typeids.json file! JSON Error: %s\n", ex.what());
7261
throw;
7362
}
63+
64+
fileStream.close();
7465
}
7566

7667
std::string getEntityTypeAsStringIfItPossible(unsigned int typeIndex)

Diff for: Tools/GMSInfo/utils/decompose.py

+14-13
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,26 @@ def generate_definitions(input_definitions_file, output_cpp_header_file):
1111
class_list = []
1212
used_keys_set = set()
1313

14-
for typeId in type_info_file_json:
15-
if not type_info_file_json[typeId][0] in used_keys_set:
16-
used_keys_set.add(type_info_file_json[typeId][0])
14+
for type_id in type_info_file_json:
15+
if not type_info_file_json[type_id][0] in used_keys_set:
16+
used_keys_set.add(type_info_file_json[type_id][0])
1717
class_list.append("\t\t{}_{} = {}".format(
18-
type_info_file_json[typeId][0],
19-
type_info_file_json[typeId][1],
20-
typeId))
18+
type_info_file_json[type_id][0],
19+
type_info_file_json[type_id][1],
20+
type_id))
2121
else:
2222
for copy_index in range(1, 100):
23-
if not "{}_{}".format(type_info_file_json[typeId][0], copy_index) in used_keys_set:
23+
if not "{}_{}".format(type_info_file_json[type_id][0], copy_index) in used_keys_set:
2424
class_list.append("\t\t{}_{}_{} = {}".format(
25-
type_info_file_json[typeId][0],
26-
type_info_file_json[typeId][1],
25+
type_info_file_json[type_id][0],
26+
type_info_file_json[type_id][1],
2727
copy_index,
28-
typeId))
28+
type_id))
2929
break
3030

31-
cpp_header_output_file.write("// THIS IS AUTOGENERATED FILE! DO NOT EDIT!\n")
32-
cpp_header_output_file.write("// Generated by decompose.py at {}\n".format(datetime.datetime.now()))
31+
cpp_header_output_file.write("/*\n")
32+
cpp_header_output_file.write(" THIS IS AUTOGENERATED FILE! DO NOT EDIT!\n")
33+
cpp_header_output_file.write(" Generated by decompose.py at {}\n*/\n\n".format(datetime.datetime.now()))
3334
cpp_header_output_file.write("#ifndef __GLACIER_TYPE_IDS_H__\n")
3435
cpp_header_output_file.write("#define __GLACIER_TYPE_IDS_H__\n\n")
3536
cpp_header_output_file.write("namespace Glacier {\n")
@@ -47,7 +48,7 @@ def generate_definitions(input_definitions_file, output_cpp_header_file):
4748
if len(sys.argv) < 3:
4849
print("""
4950
Usage:
50-
python decompose.py [typeids.json file path] [GlacierTypeInfo.h output location]
51+
python decompose.py [glacier types database file path] [header output location]
5152
""")
5253
else:
5354
generate_definitions(sys.argv[1], sys.argv[2])

0 commit comments

Comments
 (0)