-
Notifications
You must be signed in to change notification settings - Fork 5
/
area.py
378 lines (279 loc) · 11.1 KB
/
area.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
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# PointlessMaker
# Version 0.2
# Copyright © 2017 MasterVermilli0n/AboodXD
# This file is part of PointlessMaker.
# PointlessMaker 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.
# PointlessMaker 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 this program. If not, see <http://www.gnu.org/licenses/>.
import math
import zlib
from PyQt5 import QtGui
from PyQt5.QtCore import Qt
import globals
from items import PixmapItem, RectItem
from objects import *
from structs import *
class Area:
def __init__(self, inb, cdt, bom):
self.objects = []
for attr in dir(cdt):
if not attr.startswith('__') and not callable(getattr(cdt, attr)):
exec('self.%s = cdt.%s' % (attr, attr))
self.bom = bom
mode = self.mode.decode('utf-8')
theme = self.theme
self.loadTileset(mode, theme)
globals.mainWindow.objPicker.model.loadObjects()
self.objectsBlock = inb[0xF0:0x145F0]
self.effectsBlock = inb[0x145F0:0x15000]
self.loadObjects()
def loadTileset(self, mode, theme):
globals.Tiles = []
widths = {"M1": 16, "M3": 16, "MW": 16, "WU": 64}
themes = {0: "plain", 1: "underground", 2: "castle", 3: "airship", 4: "water", 5: "hauntedhouse"}
width = widths[mode]
Tileset = QtGui.QPixmap('tilesets/%s_Field_%s.png' % (mode, themes[theme]))
xcount = Tileset.width() // width
ycount = Tileset.height() // width
sourcex = 0
sourcey = 0
for y in range(ycount):
for x in range(xcount):
if mode == "WU":
if globals.TileWidth != 60:
bmp = Tileset.copy(sourcex + 2, sourcey + 2,
width - 4, width - 4).scaledToWidth(globals.TileWidth, Qt.SmoothTransformation)
else:
bmp = Tileset.copy(sourcex + 2, sourcey + 2, width - 4, width - 4)
else:
if globals.TileWidth != width:
bmp = Tileset.copy(sourcex, sourcey,
width, width).scaledToWidth(globals.TileWidth, Qt.SmoothTransformation)
else:
bmp = Tileset.copy(sourcex, sourcey, width, width)
globals.Tiles.append(bmp)
sourcex += width
sourcex = 0
sourcey += width
def loadObjects(self):
pos = (self.numObjects - 1) * 0x20
for _ in range(self.numObjects):
obj = Object(self.bom)
obj.data(self.objectsBlock, pos)
pos -= 0x20
rx = obj.x / 160 * globals.TileWidth
ry = -obj.y / 160 * globals.TileWidth
# Oh, this game has layers BTW
rz = obj.z
if 0 <= rz < 11740:
rz = 0
elif 11740 <= rz < 13000:
rz = 11740
elif 13000 <= rz < 23010:
rz = 13000
elif 23010 <= rz < 44000:
rz = 23010
elif 44000 <= rz < 48010:
rz = 44000
elif 48010 <= rz < 59990:
rz = 48010
elif 59990 <= rz < 62600:
rz = 59990
elif 62600 <= rz < 72140:
rz = 62600
elif 72140 <= rz < 92670:
rz = 72140
elif 92670 <= rz < 93540:
rz = 92670
elif 93540 <= rz < 4294897396:
rz = 93540
elif 4294897396 <= rz < 4294907296:
rz = 4294897396
elif 4294907296 <= rz < 4294910396:
rz = 4294907296
elif 4294910396 <= rz < 4294910496:
rz = 4294910396
elif 4294910496 <= rz < 4294911506:
rz = 4294910496
elif 4294911506 <= rz < 4294916516:
rz = 4294911506
else:
rz = 4294916516
ry -= (obj.h - 1) * globals.TileWidth
rw = obj.w * globals.TileWidth
rh = obj.h * globals.TileWidth
if obj.objType in TilesetObjects:
if obj.objType == EditRengaBlock:
pix = globals.Tiles[1]
elif obj.objType == EditHatenaBlock:
pix = globals.Tiles[2]
elif obj.objType == EditHardBlock:
pix = globals.Tiles[6]
elif obj.objType == EditKumoBlock:
pix = globals.Tiles[102]
elif obj.objType == EditIceBlock:
pix = globals.Tiles[120]
elif obj.objType == EditGround:
pix = globals.Tiles[184 + obj.data]
elif obj.objType == EditCoin:
if obj.parentFlags & 4 == 4:
pix = globals.Tiles[256]
else:
pix = globals.Tiles[7]
elif obj.objType == EditDokan:
direction = obj.parentFlags & 0x60
if direction != 0x40:
ry += (obj.h - 1) * globals.TileWidth
if direction == 0x60:
rx -= globals.TileWidth
else:
rx -= (obj.w - 1) * globals.TileWidth
if not direction:
rx += globals.TileWidth
else:
rx -= (obj.h - 2) * globals.TileWidth
ry -= globals.TileWidth
pix, rw, rh = globals.mainWindow.paintPipe(obj.w, obj.h, direction)
elif obj.objType == EditGroundBox:
type_ = ((obj.parentFlags >> 16) & 0xF) // 4
pix, rw, rh = globals.mainWindow.paintGroundBox(obj.w, obj.h, type_)
rz -= 0x100000000
elif obj.objType == EditGroundGoal:
pix, rw, rh = globals.mainWindow.paintGroundGoal(obj.w, obj.h)
elif obj.objType == EditGroundStart:
pix, rw, rh = globals.mainWindow.paintGroundStart(obj.w, obj.h)
# Snap to grid
rx -= globals.TileWidth // 2
ry -= globals.TileWidth // 2
rx = math.ceil(rx / globals.TileWidth) * globals.TileWidth
ry = math.ceil(ry / globals.TileWidth) * globals.TileWidth
rx += globals.TileWidth // 2
ry += globals.TileWidth // 2
item = PixmapItem(obj.objType, rx, ry, rz, rw, rh, pix, obj.data)
else:
item = RectItem(obj.objType, rx, ry, rz, rw, rh, obj.data)
item.parentFlags = obj.parentFlags
item.childFlags = obj.childFlags
item.childType = obj.childType
item.linkID = obj.linkID
item.eIndex = obj.eIndex
item._1E = obj._1E
item.cTID = obj.cTID
self.objects.append(item)
globals.mainWindow.scene.addItem(item)
self.objects = list(reversed(self.objects))
def save(self):
self.saveObjectsBlock()
courseBuffer = bytearray()
courseStruct = CourseData('>')
courseBuffer += courseStruct.pack(
self.version,
0, # to be calculated and replaced later on
self.year,
self.month,
self.day,
self.hour,
self.minute,
self.unk1,
self.unk2,
self.levelcode,
self.unk3,
self.name,
self.mode,
self.theme,
self.unk4,
self.unk5,
self.timer,
self.scroll,
self.flags,
self.areaWidth,
self.miiData,
self.numObjects,
)
courseBuffer += self.objectsBlock
courseBuffer += self.effectsBlock
self.checksum = zlib.crc32(courseBuffer[16:]) % (1 << 32)
courseBuffer[8:12] = self.checksum.to_bytes(4, "big")
return courseBuffer
def saveObjectsBlock(self):
buffer = bytearray()
objects_count = 0
numGoundBoxes = 0
for obj in reversed(self.objects):
rw, rh, rx, ry, rz = obj.width, obj.height, obj.realX, obj.realY, obj.objz
if obj.objType == EditDokan:
direction = obj.parentFlags & 0x60
if direction in [0x40, 0x60]:
rw, rh = (obj.width, obj.height)
else:
rw, rh = (obj.height, obj.width)
if direction != 0x40:
ry -= rh - globals.TileWidth
if direction == 0x60:
rx += globals.TileWidth
else:
rx += rw - globals.TileWidth
if not direction:
rx -= globals.TileWidth
else:
rx += rh - (2 * globals.TileWidth)
ry += globals.TileWidth
elif obj.objType == EditGroundBox:
rz += 0x100000000
elif obj.objType in [EditGroundGoal, EditGroundStart]:
rw += globals.TileWidth * 3
x = rx * 160 / globals.TileWidth
y = -ry * 160 / globals.TileWidth
z = rz
y -= (rh - globals.TileWidth) * 160 / globals.TileWidth
w = rw // globals.TileWidth
h = rh // globals.TileWidth
x = int(x)
y = int(y)
z = int(z)
"""
print(type(x))
print(type(z))
print(type(y))
print(type(w))
print(type(h))
print(type(obj.parentFlags))
print(type(obj.childFlags))
print(type(obj.data))
print(type(obj.objType))
print(type(obj.childType))
print(type(obj.linkID))
print(type(obj.eIndex))
print(type(obj._1E))
print(type(obj.cTID))
"""
objStruct = Object('>')
buffer += objStruct.pack(
x,
z,
y,
w,
h,
obj.parentFlags,
obj.childFlags,
obj.data,
obj.objType,
obj.childType,
obj.linkID,
obj.eIndex,
obj._1E,
obj.cTID,
)
objects_count += 1
self.numObjects = objects_count
buffer += b'\0' * 0x20 * (2600-objects_count)
self.objectsBlock = buffer