-
Notifications
You must be signed in to change notification settings - Fork 0
/
NuStatic.bi
358 lines (282 loc) · 12.6 KB
/
NuStatic.bi
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
#IFDEF __DOWNLOAD_TURNS__
type ParseHullDesign
TechLevel as short
HullName as string
HullMass as integer
NeuMax as integer
Cargo as integer
Crew as integer
Engines as short
BeamBanks as short
TorpTubes as short
FighterBays as short
MegacreditCost as integer
DuraniumCost as integer
TritaniumCost as integer
MolybdenumCost as integer
AdvantageValue as short
end type
type ParsePartDesign
TechLevel as short
PartName as string
PartMass as integer
PartCost as integer
DuraniumCost as integer
TritaniumCost as integer
MolybdenumCost as integer
AmmoCost as integer
WarpEfficiency(9) as integer
WepKill as short
WepBlast as short
end type
sub fetchStaticData
dim SendBuffer as string
dim RecvBuffer as zstring * RECVBUFFLEN+1
dim Bytes as integer
dim as integer ObjIDa, ObjIDb, ObjCount, BlockChar(2), SeekChar(2)
dim as string InStream, TargetFile(1)
dim as ParseHullDesign InterHull
dim as ParsePartDesign InterPart
SendBuffer = loadAddress("static/all?compress=false")
TargetFile(0) = "raw/staticData.txt"
ErrorMsg = ""
cls
print "Fetching raw static data...";
screencopy
NuSocket = SDLNet_TCP_Open( @NuIP )
if( NuSocket = 0 ) then
ErrorMsg = "Nu Replayer did not successfully open a socket to Planets Nu's servers."
else
if SDLNet_TCP_Send(NuSocket, strptr(SendBuffer), len(SendBuffer)) < len(SendBuffer) then
ErrorMsg = "Nu Replayer did not successfully send its request to Planets Nu's servers."
else
mkdir "raw"
mkdir "raw/"+str(GameID)+""
open TargetFile(0) for output as #4
do
Bytes = SDLNet_TCP_Recv( NuSocket, strptr( RecvBuffer ), RECVBUFFLEN )
if( Bytes <= 0 ) then
exit do
end if
'' add the null-terminator
RecvBuffer[Bytes] = 0
'' print it as string
print #4, RecvBuffer;
loop
close #4
end if
if ErrorMsg = "" then
open TargetFile(0) for input as #5
do
if eof(5) then
ErrorMsg = "Nu Replayer could not successfully download the static data file due to lack of opening brace."
exit do
end if
line input #5, InStream
loop until left(InStream,1) = "{"
close #5
end if
if instr(Instream,"{"+quote("success")+":false") then
ErrorMsg = "Nu Replayer could not successfully download the static data file due to API error."
elseif ErrorMsg = "" then
cls
print "Converting available hulls and parts...";
ObjCount = 0
screencopy
'Hulls
BlockChar(0) = instr(InStream,quote("hulls")+": [")
if BlockChar(0) > 0 then
BlockChar(2) = instr(BlockChar(0),InStream,ArrayClose)
BlockChar(1) = BlockChar(0)
TargetFile(1) = "games/Default Shiplist.csv"
open TargetFile(1) for output as #6
print #6, quote("ID")+","+quote("Tech")+","+quote("Hull")+","+quote("Mass")+","+_
quote("Ne")+","+quote("Car")+","+quote("Crew")+","+quote("En")+","+_
quote("Bm")+","+quote("Tp")+","+quote("Ftr")+","+quote("mc")+","+_
quote("Du")+","+quote("Tr")+","+quote("Mo")+","+quote("Adv")
do
with InterHull
SeekChar(0) = instr(BlockChar(1),InStream,quote("name"))
SeekChar(1) = instr(SeekChar(0)+8,InStream,chr(34))
.HullName = mid(InStream, SeekChar(0)+8, SeekChar(1)-SeekChar(0)-8)
.HullName = findReplace(.HullName, "Class Torpedo ", "")
.HullName = findReplace(.HullName, "Class ", "")
.HullName = findReplace(.HullName, "Deep Space Freighter", "Freighter")
if .HullName = "Bloodfang" then
.HullName = "Bloodfang Stealth Carrier"
end if
SeekChar(0) = instr(BlockChar(1),InStream,quote("duranium"))
.DuraniumCost = valint(mid(InStream,SeekChar(0)+11,4))
SeekChar(0) = instr(BlockChar(1),InStream,quote("tritanium"))
.TritaniumCost = valint(mid(InStream,SeekChar(0)+12,4))
SeekChar(0) = instr(BlockChar(1),InStream,quote("molybdenum"))
.MolybdenumCost = valint(mid(InStream,SeekChar(0)+13,4))
SeekChar(0) = instr(BlockChar(1),InStream,quote("fueltank"))
.NeuMax = valint(mid(InStream,SeekChar(0)+11,5))
SeekChar(0) = instr(BlockChar(1),InStream,quote("crew"))
.Crew = valint(mid(InStream,SeekChar(0)+7,5))
SeekChar(0) = instr(BlockChar(1),InStream,quote("engines"))
.Engines = valint(mid(InStream,SeekChar(0)+10,3))
SeekChar(0) = instr(BlockChar(1),InStream,quote("mass"))
.HullMass = valint(mid(InStream,SeekChar(0)+7,5))
SeekChar(0) = instr(BlockChar(1),InStream,quote("techlevel"))
.TechLevel = valint(mid(InStream,SeekChar(0)+12,3))
SeekChar(0) = instr(BlockChar(1),InStream,quote("cargo"))
.Cargo = valint(mid(InStream,SeekChar(0)+8,5))
SeekChar(0) = instr(BlockChar(1),InStream,quote("fighterbays"))
.FighterBays = valint(mid(InStream,SeekChar(0)+14,3))
SeekChar(0) = instr(BlockChar(1),InStream,quote("launchers"))
.TorpTubes = valint(mid(InStream,SeekChar(0)+12,3))
SeekChar(0) = instr(BlockChar(1),InStream,quote("beams"))
.BeamBanks = valint(mid(InStream,SeekChar(0)+8,3))
SeekChar(0) = instr(BlockChar(1),InStream,quote("cost"))
.MegacreditCost = valint(mid(InStream,SeekChar(0)+7,6))
SeekChar(0) = instr(BlockChar(1),InStream,quote("advantage"))
.AdvantageValue = valint(mid(InStream,SeekChar(0)+12,4))
SeekChar(0) = instr(BlockChar(1),InStream,quote("id"))
ObjIDa = valint(mid(InStream,SeekChar(0)+5,5))
print #6, ""& ObjIDa;","& .TechLevel;",";quote(.HullName);","& .HullMass; _
","& .NeuMax;","& .Cargo;","& .Crew;","& .Engines;","& .BeamBanks; _
","& .TorpTubes;","& .FighterBays;","& .MegacreditCost;","& .DuraniumCost; _
","& .TritaniumCost;","& .MolybdenumCost;","& .AdvantageValue
end with
ObjCount += 1
BlockChar(1) = instr(BlockChar(1) + len(ObjClose),InStream,ObjClose)
loop until BlockChar(1) = 0 OR BlockChar(1) > BlockChar(2)
close #6
end if
'The rest of the parts belong in one file
TargetFile(1) = "games/Default Partlist.csv"
open TargetFile(1) for output as #7
print #7, quote("Category")+","+quote("ID")+","+quote("Tech")+","+quote("Part")+","+_
quote("kT")+","+quote("mc")+","+quote("Du")+","+quote("Tr")+","+quote("Mo")+","+_
quote("Kill")+","+quote("Dmg")+","+quote("W1")+","+quote("W2")+","+quote("W3")+","+quote("W4")+","+quote("W5")+","+_
quote("W6")+","+quote("W7")+","+quote("W8")+","+quote("W9")
'Engines
BlockChar(0) = instr(InStream,quote("engines")+": [")
if BlockChar(0) > 0 then
BlockChar(2) = instr(BlockChar(0),InStream,ArrayClose)
BlockChar(1) = BlockChar(0)
do
with InterPart
SeekChar(0) = instr(BlockChar(1),InStream,quote("name"))
SeekChar(1) = instr(SeekChar(0)+8,InStream,chr(34))
.PartName = mid(InStream, SeekChar(0)+8, SeekChar(1)-SeekChar(0)-8)
.PartMass = 0
SeekChar(0) = instr(BlockChar(1),InStream,quote("duranium"))
.DuraniumCost = valint(mid(InStream,SeekChar(0)+11,4))
SeekChar(0) = instr(BlockChar(1),InStream,quote("tritanium"))
.TritaniumCost = valint(mid(InStream,SeekChar(0)+12,4))
SeekChar(0) = instr(BlockChar(1),InStream,quote("molybdenum"))
.MolybdenumCost = valint(mid(InStream,SeekChar(0)+13,4))
SeekChar(0) = instr(BlockChar(1),InStream,quote("techlevel"))
.TechLevel = valint(mid(InStream,SeekChar(0)+12,3))
SeekChar(0) = instr(BlockChar(1),InStream,quote("cost"))
.PartCost = valint(mid(InStream,SeekChar(0)+7,6))
for WID as byte = 1 to 9
SeekChar(0) = instr(BlockChar(1),InStream,quote("warp"+str(WID)))
.WarpEfficiency(WID) = valint(mid(InStream,SeekChar(0)+7+len(str(WID)),6))
next WID
SeekChar(0) = instr(BlockChar(1),InStream,quote("id"))
ObjIDa = valint(mid(InStream,SeekChar(0)+5,5))
print #7, quote("Engine")+","& ObjIDa;","& .TechLevel;",";quote(.PartName); _
",0,"& .PartCost;","& .DuraniumCost;","& .TritaniumCost;","& .MolybdenumCost;",0,0";
for WID as byte = 1 to 9
if WID < 9 then
print #7, ","& .WarpEfficiency(WID);
else
print #7, ","& .WarpEfficiency(WID)
end if
next WID
end with
ObjCount += 1
BlockChar(1) = instr(BlockChar(1) + len(ObjClose),InStream,ObjClose)
loop until BlockChar(1) = 0 OR BlockChar(1) > BlockChar(2)
end if
'Beams
BlockChar(0) = instr(InStream,quote("beams")+": [")
if BlockChar(0) > 0 then
BlockChar(2) = instr(BlockChar(0),InStream,ArrayClose)
BlockChar(1) = BlockChar(0)
do
with InterPart
SeekChar(0) = instr(BlockChar(1),InStream,quote("name"))
SeekChar(1) = instr(SeekChar(0)+8,InStream,chr(34))
.PartName = mid(InStream, SeekChar(0)+8, SeekChar(1)-SeekChar(0)-8)
SeekChar(0) = instr(BlockChar(1),InStream,quote("mass"))
.PartMass = valint(mid(InStream,SeekChar(0)+7,4))
SeekChar(0) = instr(BlockChar(1),InStream,quote("duranium"))
.DuraniumCost = valint(mid(InStream,SeekChar(0)+11,4))
SeekChar(0) = instr(BlockChar(1),InStream,quote("tritanium"))
.TritaniumCost = valint(mid(InStream,SeekChar(0)+12,4))
SeekChar(0) = instr(BlockChar(1),InStream,quote("molybdenum"))
.MolybdenumCost = valint(mid(InStream,SeekChar(0)+13,4))
SeekChar(0) = instr(BlockChar(1),InStream,quote("techlevel"))
.TechLevel = valint(mid(InStream,SeekChar(0)+12,3))
SeekChar(0) = instr(BlockChar(1),InStream,quote("cost"))
.PartCost = valint(mid(InStream,SeekChar(0)+7,6))
SeekChar(0) = instr(BlockChar(1),InStream,quote("crewkill"))
.WepKill = valint(mid(InStream,SeekChar(0)+11,4))
SeekChar(0) = instr(BlockChar(1),InStream,quote("damage"))
.WepBlast = valint(mid(InStream,SeekChar(0)+9,4))
SeekChar(0) = instr(BlockChar(1),InStream,quote("id"))
ObjIDa = valint(mid(InStream,SeekChar(0)+5,5))
print #7, quote("Beam")+","& ObjIDa;","& .TechLevel;",";quote(.PartName); _
","& .PartMass;","& .PartCost;","& .DuraniumCost;","& .TritaniumCost;","& .MolybdenumCost; _
","& .WepKill;","& .WepBlast
end with
ObjCount += 1
BlockChar(1) = instr(BlockChar(1) + len(ObjClose),InStream,ObjClose)
loop until BlockChar(1) = 0 OR BlockChar(1) > BlockChar(2)
end if
'Tubes and Torps
BlockChar(0) = instr(InStream,quote("torpedosall")+": [")
if BlockChar(0) > 0 then
BlockChar(2) = instr(BlockChar(0),InStream,ArrayClose)
BlockChar(1) = BlockChar(0)
do
with InterPart
SeekChar(0) = instr(BlockChar(1),InStream,quote("name"))
SeekChar(1) = instr(SeekChar(0)+8,InStream,chr(34))
.PartName = mid(InStream, SeekChar(0)+8, SeekChar(1)-SeekChar(0)-8)
SeekChar(0) = instr(BlockChar(1),InStream,quote("mass"))
.PartMass = valint(mid(InStream,SeekChar(0)+7,4))
SeekChar(0) = instr(BlockChar(1),InStream,quote("duranium"))
.DuraniumCost = valint(mid(InStream,SeekChar(0)+11,4))
SeekChar(0) = instr(BlockChar(1),InStream,quote("tritanium"))
.TritaniumCost = valint(mid(InStream,SeekChar(0)+12,4))
SeekChar(0) = instr(BlockChar(1),InStream,quote("molybdenum"))
.MolybdenumCost = valint(mid(InStream,SeekChar(0)+13,4))
SeekChar(0) = instr(BlockChar(1),InStream,quote("techlevel"))
.TechLevel = valint(mid(InStream,SeekChar(0)+12,3))
SeekChar(0) = instr(BlockChar(1),InStream,quote("launchercost"))
.PartCost = valint(mid(InStream,SeekChar(0)+15,5))
SeekChar(0) = instr(BlockChar(1),InStream,quote("torpedocost"))
.AmmoCost = valint(mid(InStream,SeekChar(0)+14,5))
SeekChar(0) = instr(BlockChar(1),InStream,quote("crewkill"))
.WepKill = valint(mid(InStream,SeekChar(0)+11,4))
SeekChar(0) = instr(BlockChar(1),InStream,quote("damage"))
.WepBlast = valint(mid(InStream,SeekChar(0)+9,4))
SeekChar(0) = instr(BlockChar(1),InStream,quote("id"))
ObjIDa = valint(mid(InStream,SeekChar(0)+5,5))
print #7, quote("Tube")+","& ObjIDa;","& .TechLevel;",";quote(.PartName); _
","& .PartMass;","& .PartCost;","& .DuraniumCost;","& .TritaniumCost;","& .MolybdenumCost; _
","& .WepKill;","& .WepBlast
print #7, quote("Torp")+","& ObjIDa;","& .TechLevel;",";quote(.PartName); _
",1,"& .AmmoCost;",1,1,1,"& .WepKill;","& .WepBlast
end with
ObjCount += 1
BlockChar(1) = instr(BlockChar(1) + len(ObjClose),InStream,ObjClose)
loop until BlockChar(1) = 0 OR BlockChar(1) > BlockChar(2)
end if
close #7
end if
end if
SDLNet_TCP_Close( NuSocket )
if ErrorMsg <> "" then
print " Failure! ";ErrorMsg
screencopy
sleep
end if
end sub
#ENDIF