@@ -26,6 +26,31 @@ def to_bytes(self, version: Version) -> bytes:
2626 ])
2727
2828
29+ @dataclass (slots = True )
30+ class ResearchLocation (GenieClass ):
31+ location_id : int
32+ research_time : int
33+ button_id : int
34+ hot_key_id : int
35+
36+ @classmethod
37+ def from_bytes (cls , content : ByteHandler ) -> 'ResearchLocation' :
38+ return cls (
39+ location_id = content .read_int_16 (),
40+ research_time = content .read_int_16 (),
41+ button_id = content .read_int_8 (),
42+ hot_key_id = content .read_int_32 (),
43+ )
44+
45+ def to_bytes (self , version : Version ) -> bytes :
46+ return b'' .join ([
47+ self .write_int_16 (self .location_id ),
48+ self .write_int_16 (self .research_time ),
49+ self .write_int_8 (self .button_id ),
50+ self .write_int_32 (self .hot_key_id ),
51+ ])
52+
53+
2954@dataclass (slots = True )
3055class Tech (GenieClass ):
3156 required_techs : tuple [int , int , int , int , int , int ]
@@ -46,31 +71,116 @@ class Tech(GenieClass):
4671 hot_key : int
4772 name : str
4873 repeatable : int
74+ research_locations : list [ResearchLocation ]
4975
5076 @classmethod
5177 def from_bytes (cls , content : ByteHandler ) -> 'Tech' :
78+ if content .version >= Version .VER_88 :
79+ return cls .from_bytes_88 (content )
80+ return cls .from_bytes_84 (content )
81+
82+ @classmethod
83+ def from_bytes_84 (cls , content : ByteHandler ) -> 'Tech' :
84+ required_techs = content .read_int_16_array_6 ()
85+ resource_costs = content .read_class_array_3 (ResearchResourceCost )
86+ required_tech_count = content .read_int_16 ()
87+ civ = content .read_int_16 ()
88+ full_tech_mode = content .read_int_16 ()
89+ research_location = content .read_int_16 ()
90+ language_dll_name = content .read_int_32 ()
91+ language_dll_description = content .read_int_32 ()
92+ research_time = content .read_int_16 ()
93+ effect_id = content .read_int_16 ()
94+ type = content .read_int_16 ()
95+ icon_id = content .read_int_16 ()
96+ button_id = content .read_int_8 ()
97+ language_dll_help = content .read_int_32 ()
98+ language_dll_tech_tree = content .read_int_32 ()
99+ hot_key = content .read_int_32 ()
100+ name = content .read_debug_string ()
101+ repeatable = content .read_int_8 ()
102+ research_locations = [ResearchLocation (
103+ button_id = button_id ,
104+ research_time = research_time ,
105+ hot_key_id = hot_key ,
106+ location_id = research_location ,
107+ )]
52108 return cls (
53- required_techs = content .read_int_16_array_6 (),
54- resource_costs = content .read_class_array_3 (ResearchResourceCost ),
55- required_tech_count = content .read_int_16 (),
56- civ = content .read_int_16 (),
57- full_tech_mode = content .read_int_16 (),
58- research_location = content .read_int_16 (),
59- language_dll_name = content .read_int_32 (),
60- language_dll_description = content .read_int_32 (),
61- research_time = content .read_int_16 (),
62- effect_id = content .read_int_16 (),
63- type = content .read_int_16 (),
64- icon_id = content .read_int_16 (),
65- button_id = content .read_int_8 (),
66- language_dll_help = content .read_int_32 (),
67- language_dll_tech_tree = content .read_int_32 (),
68- hot_key = content .read_int_32 (),
69- name = content .read_debug_string (),
70- repeatable = content .read_int_8 (),
109+ required_techs = required_techs ,
110+ resource_costs = resource_costs ,
111+ required_tech_count = required_tech_count ,
112+ civ = civ ,
113+ full_tech_mode = full_tech_mode ,
114+ research_location = research_location ,
115+ language_dll_name = language_dll_name ,
116+ language_dll_description = language_dll_description ,
117+ research_time = research_time ,
118+ effect_id = effect_id ,
119+ type = type ,
120+ icon_id = icon_id ,
121+ button_id = button_id ,
122+ language_dll_help = language_dll_help ,
123+ language_dll_tech_tree = language_dll_tech_tree ,
124+ hot_key = hot_key ,
125+ name = name ,
126+ repeatable = repeatable ,
127+ research_locations = research_locations ,
128+ )
129+
130+ @classmethod
131+ def from_bytes_88 (cls , content : ByteHandler ) -> 'Tech' :
132+ required_techs = content .read_int_16_array_6 ()
133+ resource_costs = content .read_class_array_3 (ResearchResourceCost )
134+ required_tech_count = content .read_int_16 ()
135+ civ = content .read_int_16 ()
136+ full_tech_mode = content .read_int_16 ()
137+ language_dll_name = content .read_int_32 ()
138+ language_dll_description = content .read_int_32 ()
139+ effect_id = content .read_int_16 ()
140+ type = content .read_int_16 ()
141+ icon_id = content .read_int_16 ()
142+ language_dll_help = content .read_int_32 ()
143+ language_dll_tech_tree = content .read_int_32 ()
144+ name = content .read_debug_string ()
145+ repeatable = content .read_int_8 ()
146+ research_location_count = content .read_int_16 ()
147+ research_locations = content .read_class_array (ResearchLocation , research_location_count )
148+ research_location = - 1
149+ research_time = 0
150+ button_id = 0
151+ hot_key = - 1
152+ if len (research_locations ):
153+ research_location = research_locations [0 ].location_id
154+ research_time = research_locations [0 ].research_time
155+ button_id = research_locations [0 ].button_id
156+ hot_key = research_locations [0 ].hot_key_id
157+ return cls (
158+ required_techs = required_techs ,
159+ resource_costs = resource_costs ,
160+ required_tech_count = required_tech_count ,
161+ civ = civ ,
162+ full_tech_mode = full_tech_mode ,
163+ research_location = research_location ,
164+ language_dll_name = language_dll_name ,
165+ language_dll_description = language_dll_description ,
166+ research_time = research_time ,
167+ effect_id = effect_id ,
168+ type = type ,
169+ icon_id = icon_id ,
170+ button_id = button_id ,
171+ language_dll_help = language_dll_help ,
172+ language_dll_tech_tree = language_dll_tech_tree ,
173+ hot_key = hot_key ,
174+ name = name ,
175+ repeatable = repeatable ,
176+ research_locations = research_locations ,
71177 )
72178
73179 def to_bytes (self , version : Version ) -> bytes :
180+ if version >= Version .VER_88 :
181+ return self .to_bytes_88 (version )
182+ return self .to_bytes_84 (version )
183+ def to_bytes_84 (self , version : Version ) -> bytes :
74184 return b'' .join ([
75185 self .write_int_16_array (self .required_techs ),
76186 self .write_class_array (self .resource_costs , version ),
@@ -91,3 +201,23 @@ def to_bytes(self, version: Version) -> bytes:
91201 self .write_debug_string (self .name ),
92202 self .write_int_8 (self .repeatable ),
93203 ])
204+
205+ def to_bytes_88 (self , version : Version ) -> bytes :
206+ return b'' .join ([
207+ self .write_int_16_array (self .required_techs ),
208+ self .write_class_array (self .resource_costs , version ),
209+ self .write_int_16 (self .required_tech_count ),
210+ self .write_int_16 (self .civ ),
211+ self .write_int_16 (self .full_tech_mode ),
212+ self .write_int_32 (self .language_dll_name ),
213+ self .write_int_32 (self .language_dll_description ),
214+ self .write_int_16 (self .effect_id ),
215+ self .write_int_16 (self .type ),
216+ self .write_int_16 (self .icon_id ),
217+ self .write_int_32 (self .language_dll_help ),
218+ self .write_int_32 (self .language_dll_tech_tree ),
219+ self .write_debug_string (self .name ),
220+ self .write_int_8 (self .repeatable ),
221+ self .write_int_16 (len (self .research_locations )),
222+ self .write_class_array (self .research_locations , version ),
223+ ])
0 commit comments