summaryrefslogtreecommitdiff
path: root/bcsv_funcs.py
diff options
context:
space:
mode:
authorOwl <isaclien9752@gmail.com>2025-09-29 12:54:17 -0400
committerOwl <isaclien9752@gmail.com>2025-09-29 12:54:17 -0400
commit3ee4e9d9f74ae99cb17ca45a511b66dcd755d1b9 (patch)
treef9c3abfa3897097fa42adc5a3163608d76b04496 /bcsv_funcs.py
parent70e647076418d114111aa76b5d3639a5b4271e94 (diff)
downloadblenxy-3ee4e9d9f74ae99cb17ca45a511b66dcd755d1b9.tar.gz
blenxy-3ee4e9d9f74ae99cb17ca45a511b66dcd755d1b9.zip
some small bcsv thingsHEADmaster
Diffstat (limited to 'bcsv_funcs.py')
-rw-r--r--bcsv_funcs.py27
1 files changed, 14 insertions, 13 deletions
diff --git a/bcsv_funcs.py b/bcsv_funcs.py
index 26686e0..796d97c 100644
--- a/bcsv_funcs.py
+++ b/bcsv_funcs.py
@@ -322,15 +322,12 @@ def read_bcsv_file(filepath_or_stream, endian):
value_offset = base_offset + (j * bcsv_raw_info.header.row_data_length)
# grab the specific datatype
value = None
- # crazy this but I will do the bitmask and right shift even with a float
- # treat integer variables as signed, it is actually a bit more readable
- if (data_type == "LONG" or data_type == "LONG_2" or data_type == "STRING_OFFSET" or data_type == "FLOAT"):
+ # bitmask/bitshift wont be done on STRING/STRING_OFFSET/FLOAT types (it would be weird)
+ # treat integer variables as signed. It is actually a bit more readable
+ if (data_type in ["LONG", "LONG_2"]):
value = struct.unpack(endian_ch + "I", bcsv_raw_info.data_pool[value_offset : value_offset + 4])[0]
value = (value & bcsv_table_info.cols_info[i].bitmask) >> bcsv_table_info.cols_info[i].rshift
- if (data_type == "LONG" or data_type == "LONG_2"):
- value = struct.unpack(">i", struct.pack(">I", value))[0]
- elif (data_type == "STRING"):
- value = bcsv_raw_info.data_pool[value_offset : value_offset + 32].decode("cp932").replace("\0", "")
+ value = struct.unpack(">i", struct.pack(">I", value))[0]
elif (data_type == "SHORT"):
value = struct.unpack(endian_ch + "H", bcsv_raw_info.data_pool[value_offset : value_offset + 2])[0]
value = (value & bcsv_table_info.cols_info[i].bitmask) >> bcsv_table_info.cols_info[i].rshift
@@ -339,11 +336,15 @@ def read_bcsv_file(filepath_or_stream, endian):
value = struct.unpack(endian_ch + "B", bcsv_raw_info.data_pool[value_offset : value_offset + 1])[0]
value = (value & bcsv_table_info.cols_info[i].bitmask) >> bcsv_table_info.cols_info[i].rshift
value = struct.unpack(">b", struct.pack(">B", value))[0]
-
- # check if the data type was a string offset or a float
- if (data_type == "FLOAT"):
- value = struct.unpack(">f", struct.pack(">I", value))[0]
+ elif (data_type == "FLOAT"):
+ value = struct.unpack(endian_ch + "f", bcsv_raw_info.data_pool[value_offset : value_offset + 4])[0]
elif (data_type == "STRING_OFFSET"):
+ value = struct.unpack(endian_ch + "I", bcsv_raw_info.data_pool[value_offset : value_offset + 4])[0]
+ elif (data_type == "STRING"):
+ value = bcsv_raw_info.data_pool[value_offset : value_offset + 32].decode("cp932").replace("\0", "")
+
+ # check if the data type was a string offset
+ if (data_type == "STRING_OFFSET"):
string_offset = value
string_length = 0
while (bcsv_raw_info.string_pool[string_offset + string_length] != 0):
@@ -704,14 +705,14 @@ def create_smg_bcsv_raw(table, endian_ch, use_std_pad_size):
# only for integers
type_ch = None
# LONG or LONG_2
- if (raw.columns_info[j].data_type == 0 or raw.columns_info[j].data_type == 3): type_ch = "I"
+ if (raw.columns_info[j].data_type in [0, 3]): type_ch = "I"
# SHORT
elif (raw.columns_info[j].data_type == 4): type_ch = "H"
# CHAR
elif (raw.columns_info[j].data_type == 5): type_ch = "B"
# LONG, LONG_2, SHORT or CHAR
- if (type_ch == "I" or type_ch == "H" or type_ch == "B"):
+ if (type_ch in ["I", "H", "B"]):
# ~ print((table.rows_data[i][j] << raw.columns_info[j].data_rshift) & raw.columns_info[j].data_bitmask)
tmp = struct.pack(endian_ch + type_ch,
(table.rows_data[i][j] << raw.columns_info[j].data_rshift) & raw.columns_info[j].data_bitmask)