-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbl3data.py
168 lines (147 loc) · 5.85 KB
/
bl3data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/env python
# vim: set expandtab tabstop=4 shiftwidth=4:
# Copyright 2019-2020 Christopher J. Kucera
# <http://apocalyptech.com/contact.php>
#
# Borderlands 3 Data Library is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
#
# Borderlands 3 Data Library is distributed in the hope that it will
# be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Borderlands 3 Data Library. If not, see
# <https://www.gnu.org/licenses/>.
# Adjusted and stripped down version of original file by SSpyR
import os
import re
import json
import glob
import appdirs
#import pymysql
#pymysql.install_as_MySQLdb()
#import MySQLdb
import subprocess
#import configparser
from bl3hotfixmod import BVC
class BL3Data(object):
# Data serialization version requirements
data_version = 7
# Hardcoded BVA values
bva_values = {
}
# Hardcoded part-category values
cats_shields = [
'BODY',
'RARITY',
'LEGENDARY AUG',
'AUGMENT',
'ELEMENT',
'MATERIAL',
]
cats_grenades = [
'MANUFACTURER',
'ELEMENT',
'RARITY',
'AUGMENT',
'BEHAVIOR',
'MATERIAL',
]
cats_coms = [
'CHARACTER',
'MODTYPE',
'RARITY',
'PRIMARY',
'SECONDARY',
'SKILLS',
'(unknown)',
]
cats_artifacts = [
'RARITY',
'LEGENDARY ABILITY',
'ABILITY',
'PRIMARY',
'SECONDARY',
]
def __init__(self):
"""
Initialize a BL3Data object. Will create a sample config file if one
is not already found. Will require that the "filesystem" section be
properly filled in, or we'll raise an exception.
"""
# config_dir = appdirs.user_config_dir('bl3data')
# # Create the config dir if it doesn't exist
# if not os.path.exists(config_dir):
# os.makedirs(config_dir, exist_ok=True)
# # Create a sample INI file it if doesn't exist
# self.config_file = os.path.join(config_dir, 'bl3data.ini')
# if not os.path.exists(self.config_file):
# dir=os.path.dirname(__file__)
# config = configparser.ConfigParser()
# config['filesystem'] = {
# 'data_dir': os.path.join(dir, '/utils'),
# 'ueserialize_path': os.path.join(dir, '/utils/john-wick-parse.exe'),
# }
# with open(self.config_file, 'w') as odf:
# config.write(odf)
# print('Created sample config file {}'.format(self.config_file))
# # Read in the config file and at least make sure we have filesystem
# # data available
# self.config = configparser.ConfigParser()
# self.config.read(self.config_file)
# self._enforce_config_section('filesystem')
# Convenience var
dir=os.path.dirname(__file__)
self.data_dir = os.path.join(dir, '/utils')
self.ueserialize_path = os.path.join(dir, '/utils/john-wick-parse.exe')
# Now the rest of the vars we'll use
self.cache = {}
self.balance_to_extra_anoints = None
self.db = None
self.curs = None
def get_data(self, obj_name):
"""
Returns a JSON-serialized version of the object `obj_name`, if possible.
May return None, either due to the object not existing, or if JohnWickParse
can't actually produce a serialization for the object. Results will be
cached, so requesting the same object more than once will not result in
re-parsing JSON content.
"""
if obj_name not in self.cache:
dir=os.path.dirname(__file__)
base_path = '{}{}'.format(dir, '/utils'+str.rstrip(obj_name))
json_file = '{}.json'.format(base_path)
print(json_file)
if not os.path.exists(json_file):
# PyPy3 is still on 3.6, which doesn't have capture_output
#subprocess.run([self.config['filesystem']['ueserialize_path'], base_path], encoding='utf-8', capture_output=True)
subprocess.run([self.ueserialize_path, base_path], encoding='utf-8', stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if os.path.exists(json_file):
with open(json_file) as df:
self.cache[obj_name] = json.load(df)
if len(self.cache[obj_name]) > 0:
if '_apoc_data_ver' not in self.cache[obj_name][0] or self.cache[obj_name][0]['_apoc_data_ver'] < BL3Data.data_version:
# Regenerate if we have an old serialization
subprocess.run([self.ueserialize_path, base_path], encoding='utf-8', stdout=subprocess.PIPE, stderr=subprocess.PIPE)
with open(json_file) as df:
self.cache[obj_name] = json.load(df)
else:
self.cache[obj_name] = None
return self.cache[obj_name]
def get_exports(self, obj_name, export_type):
"""
Given an object `obj_name`, return a list of serialized exports which match
the type `export_type`.
"""
exports = []
data = self.get_data(obj_name)
if data:
for export in data:
if export['export_type'] == export_type:
exports.append(export)
return exports