1 | #ifdef _WIN32 |
1 | #ifdef _WIN32 |
2 | # define WIN32_LEAN_AND_MEAN |
2 | # define WIN32_LEAN_AND_MEAN |
3 | # define _WIN32_WINNT 0x0500 // needed to get win2000 api calls |
3 | # define _WIN32_WINNT 0x0500 // needed to get win2000 api calls |
4 | # include <malloc.h> |
4 | # include <malloc.h> |
5 | # include <windows.h> |
5 | # include <windows.h> |
|
|
6 | # include <wininet.h> |
6 | # pragma warning(disable:4244) |
7 | # pragma warning(disable:4244) |
7 | #endif |
8 | #endif |
8 | |
9 | |
9 | #include "EXTERN.h" |
10 | #include "EXTERN.h" |
10 | #include "perl.h" |
11 | #include "perl.h" |
… | |
… | |
169 | float s, t; |
170 | float s, t; |
170 | uint8_t r, g, b, a; |
171 | uint8_t r, g, b, a; |
171 | } maptex; |
172 | } maptex; |
172 | |
173 | |
173 | typedef struct { |
174 | typedef struct { |
174 | int16_t darkness; |
175 | uint32_t player; |
175 | mapface face[3]; |
176 | mapface face[3]; |
|
|
177 | uint16_t darkness; |
|
|
178 | uint8_t stat_width, stat_hp, flags; |
176 | } mapcell; |
179 | } mapcell; |
177 | |
180 | |
178 | typedef struct { |
181 | typedef struct { |
179 | int32_t c0, c1; |
182 | int32_t c0, c1; |
180 | mapcell *col; |
183 | mapcell *col; |
… | |
… | |
293 | static void |
296 | static void |
294 | map_blank (CFPlus__Map self, int x0, int y0, int w, int h) |
297 | map_blank (CFPlus__Map self, int x0, int y0, int w, int h) |
295 | { |
298 | { |
296 | int x, y; |
299 | int x, y; |
297 | maprow *row; |
300 | maprow *row; |
|
|
301 | mapcell *cell; |
298 | |
302 | |
299 | for (y = y0; y < y0 + h; y++) |
303 | for (y = y0; y < y0 + h; y++) |
300 | if (y >= 0) |
304 | if (y >= 0) |
301 | { |
305 | { |
302 | if (y >= self->rows) |
306 | if (y >= self->rows) |
… | |
… | |
308 | if (x >= row->c0) |
312 | if (x >= row->c0) |
309 | { |
313 | { |
310 | if (x >= row->c1) |
314 | if (x >= row->c1) |
311 | break; |
315 | break; |
312 | |
316 | |
313 | row->col[x - row->c0].darkness = -1; |
317 | cell = row->col + x - row->c0; |
|
|
318 | |
|
|
319 | cell->darkness = 0; |
|
|
320 | cell->stat_hp = 0; |
|
|
321 | cell->flags = 0; |
|
|
322 | cell->player = 0; |
314 | } |
323 | } |
315 | } |
324 | } |
316 | } |
325 | } |
317 | |
326 | |
318 | static void |
327 | static void |
… | |
… | |
643 | #ifndef _WIN32 |
652 | #ifndef _WIN32 |
644 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
653 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
645 | #endif |
654 | #endif |
646 | |
655 | |
647 | void |
656 | void |
|
|
657 | win32_proxy_info () |
|
|
658 | PPCODE: |
|
|
659 | { |
|
|
660 | #ifdef _WIN32 |
|
|
661 | char buffer[2048]; |
|
|
662 | DWORD buflen; |
|
|
663 | |
|
|
664 | EXTEND (SP, 3); |
|
|
665 | |
|
|
666 | buflen = sizeof (buffer); |
|
|
667 | if (InternetQueryOption (0, INTERNET_OPTION_PROXY, (void *)buffer, &buflen)) |
|
|
668 | if (((INTERNET_PROXY_INFO *)buffer)->dwAccessType == INTERNET_OPEN_TYPE_PROXY) |
|
|
669 | { |
|
|
670 | PUSHs (newSVpv (((INTERNET_PROXY_INFO *)buffer)->lpszProxy, 0)); |
|
|
671 | |
|
|
672 | buflen = sizeof (buffer); |
|
|
673 | if (InternetQueryOption (0, INTERNET_OPTION_PROXY_USERNAME, (void *)buffer, &buflen)) |
|
|
674 | { |
|
|
675 | PUSHs (newSVpv (buffer, 0)); |
|
|
676 | |
|
|
677 | buflen = sizeof (buffer); |
|
|
678 | if (InternetQueryOption (0, INTERNET_OPTION_PROXY_PASSWORD, (void *)buffer, &buflen)) |
|
|
679 | PUSHs (newSVpv (buffer, 0)); |
|
|
680 | } |
|
|
681 | } |
|
|
682 | #endif |
|
|
683 | } |
|
|
684 | |
|
|
685 | void |
648 | add_font (char *file) |
686 | add_font (char *file) |
649 | CODE: |
687 | CODE: |
650 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
688 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
651 | |
689 | |
652 | void |
690 | void |
… | |
… | |
754 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
792 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
755 | #endif |
793 | #endif |
756 | _exit (1); |
794 | _exit (1); |
757 | |
795 | |
758 | void |
796 | void |
759 | _exit (int retval) |
797 | _exit (int retval = 0) |
760 | CODE: |
798 | CODE: |
761 | _exit (retval); |
799 | _exit (retval); |
762 | |
800 | |
763 | MODULE = CFPlus PACKAGE = CFPlus::Font |
801 | MODULE = CFPlus PACKAGE = CFPlus::Font |
764 | |
802 | |
… | |
… | |
1238 | void |
1276 | void |
1239 | scroll (CFPlus::Map self, int dx, int dy) |
1277 | scroll (CFPlus::Map self, int dx, int dy) |
1240 | CODE: |
1278 | CODE: |
1241 | { |
1279 | { |
1242 | if (dx > 0) |
1280 | if (dx > 0) |
1243 | map_blank (self, self->x, self->y, dx - 1, self->h); |
1281 | map_blank (self, self->x, self->y, dx, self->h); |
1244 | else if (dx < 0) |
1282 | else if (dx < 0) |
1245 | map_blank (self, self->x + self->w + dx + 1, self->y, 1 - dx, self->h); |
1283 | map_blank (self, self->x + self->w + dx + 1, self->y, -dx, self->h); |
1246 | |
1284 | |
1247 | if (dy > 0) |
1285 | if (dy > 0) |
1248 | map_blank (self, self->x, self->y, self->w, dy - 1); |
1286 | map_blank (self, self->x, self->y, self->w, dy); |
1249 | else if (dy < 0) |
1287 | else if (dy < 0) |
1250 | map_blank (self, self->x, self->y + self->h + dy + 1, self->w, 1 - dy); |
1288 | map_blank (self, self->x, self->y + self->h + dy + 1, self->w, -dy); |
1251 | |
1289 | |
1252 | self->ox += dx; self->x += dx; |
1290 | self->ox += dx; self->x += dx; |
1253 | self->oy += dy; self->y += dy; |
1291 | self->oy += dy; self->y += dy; |
1254 | |
1292 | |
1255 | while (self->y < 0) |
1293 | while (self->y < 0) |
… | |
… | |
1260 | self->y += MAP_EXTEND_Y; |
1298 | self->y += MAP_EXTEND_Y; |
1261 | } |
1299 | } |
1262 | } |
1300 | } |
1263 | |
1301 | |
1264 | void |
1302 | void |
1265 | map1a_update (CFPlus::Map self, SV *data_) |
1303 | map1a_update (CFPlus::Map self, SV *data_, int extmap) |
1266 | CODE: |
1304 | CODE: |
1267 | { |
1305 | { |
1268 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1306 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1269 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1307 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1270 | mapcell *cell; |
1308 | mapcell *cell; |
1271 | int x, y, flags; |
1309 | int x, y, flags; |
1272 | |
1310 | |
1273 | while (data < data_end) |
1311 | while (data < data_end - 1) |
1274 | { |
1312 | { |
1275 | flags = (data [0] << 8) + data [1]; data += 2; |
1313 | flags = (data [0] << 8) + data [1]; data += 2; |
1276 | |
1314 | |
1277 | x = self->x + ((flags >> 10) & 63); |
1315 | x = self->x + ((flags >> 10) & 63); |
1278 | y = self->y + ((flags >> 4) & 63); |
1316 | y = self->y + ((flags >> 4) & 63); |
1279 | |
1317 | |
1280 | cell = map_get_cell (self, x, y); |
1318 | cell = map_get_cell (self, x, y); |
1281 | |
1319 | |
1282 | if (flags & 15) |
1320 | if (flags & 15) |
1283 | { |
1321 | { |
1284 | if (cell->darkness < 0) |
1322 | if (!cell->darkness) |
1285 | { |
1323 | { |
|
|
1324 | memset (cell, 0, sizeof (*cell)); |
1286 | cell->darkness = 0; |
1325 | cell->darkness = 256; |
1287 | cell->face [0] = 0; |
|
|
1288 | cell->face [1] = 0; |
|
|
1289 | cell->face [2] = 0; |
|
|
1290 | } |
1326 | } |
1291 | |
1327 | |
1292 | cell->darkness = flags & 8 ? *data++ : 255; |
|
|
1293 | |
|
|
1294 | //TODO: don't trust server data to be in-range(!) |
1328 | //TODO: don't trust server data to be in-range(!) |
|
|
1329 | |
|
|
1330 | if (flags & 8) |
|
|
1331 | { |
|
|
1332 | if (extmap) |
|
|
1333 | { |
|
|
1334 | uint8_t ext, cmd; |
|
|
1335 | |
|
|
1336 | do |
|
|
1337 | { |
|
|
1338 | ext = *data++; |
|
|
1339 | cmd = ext & 0x3f; |
|
|
1340 | |
|
|
1341 | if (cmd < 4) |
|
|
1342 | cell->darkness = 255 - ext * 64 + 1; |
|
|
1343 | else if (cmd == 5) // health |
|
|
1344 | { |
|
|
1345 | cell->stat_width = 1; |
|
|
1346 | cell->stat_hp = *data++; |
|
|
1347 | } |
|
|
1348 | else if (cmd == 6) // monster width |
|
|
1349 | cell->stat_width = *data++ + 1; |
|
|
1350 | else if (cmd == 0x47) // monster width |
|
|
1351 | { |
|
|
1352 | if (*data == 4) |
|
|
1353 | ; // decode player tag |
|
|
1354 | |
|
|
1355 | data += *data + 1; |
|
|
1356 | } |
|
|
1357 | else if (cmd == 8) // cell flags |
|
|
1358 | cell->flags = *data++; |
|
|
1359 | else if (ext & 0x40) // unknown, multibyte => skip |
|
|
1360 | data += *data + 1; |
|
|
1361 | else |
|
|
1362 | data++; |
|
|
1363 | } |
|
|
1364 | while (ext & 0x80); |
|
|
1365 | } |
|
|
1366 | else |
|
|
1367 | cell->darkness = *data++ + 1; |
|
|
1368 | } |
1295 | |
1369 | |
1296 | if (flags & 4) |
1370 | if (flags & 4) |
1297 | { |
1371 | { |
1298 | cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1372 | cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1299 | } |
1373 | } |
… | |
… | |
1307 | { |
1381 | { |
1308 | cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1382 | cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1309 | } |
1383 | } |
1310 | } |
1384 | } |
1311 | else |
1385 | else |
1312 | cell->darkness = -1; |
1386 | cell->darkness = 0; |
1313 | } |
1387 | } |
1314 | } |
1388 | } |
1315 | |
1389 | |
1316 | SV * |
1390 | SV * |
1317 | mapmap (CFPlus::Map self, int x0, int y0, int w, int h) |
1391 | mapmap (CFPlus::Map self, int x0, int y0, int w, int h) |
… | |
… | |
1417 | { |
1491 | { |
1418 | mapcell *cell = row->col + (x + vx - row->c0); |
1492 | mapcell *cell = row->col + (x + vx - row->c0); |
1419 | |
1493 | |
1420 | face = cell->face [z]; |
1494 | face = cell->face [z]; |
1421 | |
1495 | |
1422 | if (face) |
1496 | if (face && face < self->texs) |
1423 | { |
1497 | { |
1424 | maptex tex = self->tex [face]; |
1498 | maptex tex = self->tex [face]; |
1425 | |
|
|
1426 | int px = (x + 1) * 32 - tex.w; |
1499 | int px = (x + 1) * 32 - tex.w; |
1427 | int py = (y + 1) * 32 - tex.h; |
1500 | int py = (y + 1) * 32 - tex.h; |
1428 | |
1501 | |
1429 | if (last_name != tex.name) |
1502 | if (last_name != tex.name) |
1430 | { |
1503 | { |
1431 | glEnd (); |
1504 | glEnd (); |
1432 | last_name = tex.name; |
|
|
1433 | glBindTexture (GL_TEXTURE_2D, last_name); |
1505 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
1434 | glBegin (GL_QUADS); |
1506 | glBegin (GL_QUADS); |
1435 | } |
1507 | } |
1436 | |
1508 | |
1437 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
1509 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
1438 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
1510 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
1439 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
1511 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
1440 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
1512 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
1441 | } |
1513 | } |
|
|
1514 | |
|
|
1515 | if (cell->flags && z == 2) |
|
|
1516 | { |
|
|
1517 | if (cell->flags & 1) |
|
|
1518 | { |
|
|
1519 | maptex tex = self->tex [1]; |
|
|
1520 | int px = (x + 1) * 32 - tex.w + 2; |
|
|
1521 | int py = (y + 1) * 32 - tex.h - 6; |
|
|
1522 | |
|
|
1523 | glEnd (); |
|
|
1524 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
|
|
1525 | glBegin (GL_QUADS); |
|
|
1526 | |
|
|
1527 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
|
|
1528 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
|
|
1529 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
|
|
1530 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
|
|
1531 | } |
|
|
1532 | } |
1442 | } |
1533 | } |
1443 | } |
1534 | } |
1444 | |
1535 | |
1445 | glEnd (); |
1536 | glEnd (); |
1446 | |
1537 | |
1447 | glDisable (GL_TEXTURE_2D); |
1538 | glDisable (GL_TEXTURE_2D); |
1448 | glDisable (GL_BLEND); |
1539 | glDisable (GL_BLEND); |
|
|
1540 | |
|
|
1541 | // top layer: overlays such as the health bar |
|
|
1542 | for (y = 0; y < sh; y++) |
|
|
1543 | if (0 <= y + vy && y + vy < self->rows) |
|
|
1544 | { |
|
|
1545 | maprow *row = self->row + (y + vy); |
|
|
1546 | |
|
|
1547 | for (x = 0; x < sw; x++) |
|
|
1548 | if (row->c0 <= x + vx && x + vx < row->c1) |
|
|
1549 | { |
|
|
1550 | mapcell *cell = row->col + (x + vx - row->c0); |
|
|
1551 | |
|
|
1552 | int px = x * 32; |
|
|
1553 | int py = y * 32; |
|
|
1554 | |
|
|
1555 | if (cell->stat_hp) |
|
|
1556 | { |
|
|
1557 | int width = cell->stat_width * 32; |
|
|
1558 | int thick = sh / 28 + 1 + cell->stat_width; |
|
|
1559 | |
|
|
1560 | glColor3ub (0, 0, 0); |
|
|
1561 | glRectf (px + 1, py - thick - 2, |
|
|
1562 | px + width - 1, py); |
|
|
1563 | |
|
|
1564 | glColor3ub (cell->stat_hp, 255 - cell->stat_hp, 0); |
|
|
1565 | glRectf (px + 2, |
|
|
1566 | py - thick - 1, |
|
|
1567 | px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1); |
|
|
1568 | } |
|
|
1569 | } |
|
|
1570 | } |
1449 | } |
1571 | } |
1450 | |
1572 | |
1451 | void |
1573 | void |
1452 | draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) |
1574 | draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) |
1453 | CODE: |
1575 | CODE: |
… | |
… | |
1533 | for (x = 0; x < sw; x++) |
1655 | for (x = 0; x < sw; x++) |
1534 | if (row->c0 <= x + vx && x + vx < row->c1) |
1656 | if (row->c0 <= x + vx && x + vx < row->c1) |
1535 | { |
1657 | { |
1536 | mapcell *cell = row->col + (x + vx - row->c0); |
1658 | mapcell *cell = row->col + (x + vx - row->c0); |
1537 | |
1659 | |
1538 | darkness[y * sw4 + x] = cell->darkness < 0 |
1660 | darkness[y * sw4 + x] = cell->darkness |
|
|
1661 | ? 255 - (cell->darkness - 1) |
1539 | ? 255 - FOW_DARKNESS |
1662 | : 255 - FOW_DARKNESS; |
1540 | : 255 - cell->darkness; |
|
|
1541 | } |
1663 | } |
1542 | } |
1664 | } |
1543 | |
1665 | |
1544 | EXTEND (SP, 3); |
1666 | EXTEND (SP, 3); |
1545 | PUSHs (sv_2mortal (newSViv (sw4))); |
1667 | PUSHs (sv_2mortal (newSViv (sw4))); |
… | |
… | |
1660 | |
1782 | |
1661 | if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } |
1783 | if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } |
1662 | if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } |
1784 | if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } |
1663 | if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } |
1785 | if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } |
1664 | |
1786 | |
1665 | if (cell->darkness <= 0) |
1787 | if (cell->darkness == 0) |
1666 | { |
1788 | { |
1667 | cell->darkness = -1; |
1789 | cell->darkness = 0; |
1668 | |
1790 | |
1669 | for (z = 0; z <= 2; z++) |
1791 | for (z = 0; z <= 2; z++) |
1670 | { |
1792 | { |
1671 | cell->face[z] = face[z]; |
1793 | cell->face[z] = face[z]; |
1672 | |
1794 | |