|
11 | 11 |
|
12 | 12 | # Source.Python
|
13 | 13 | # Core
|
| 14 | +from core import GameConfigObj |
14 | 15 | from core import PLATFORM
|
15 | 16 | # Memory
|
16 | 17 | from memory import Convention
|
17 | 18 | from memory import DataType
|
18 | 19 | from memory import Function
|
19 | 20 | from memory import Pointer
|
20 | 21 | from memory import TYPE_SIZES
|
| 22 | +from memory import find_binary |
21 | 23 | from memory import make_object
|
22 | 24 |
|
23 | 25 |
|
@@ -404,6 +406,85 @@ def parse_data(manager, raw_data, keys):
|
404 | 406 |
|
405 | 407 | yield (name, temp_data)
|
406 | 408 |
|
| 409 | +def check_type_signature_from_file(file): |
| 410 | + """Checks if the data signatures are valid.""" |
| 411 | + raw_data = GameConfigObj(file) |
| 412 | + |
| 413 | + # get the binary name from the data(defaults to server if not present) |
| 414 | + _binary = Key.as_str(None, raw_data.get( |
| 415 | + Key.BINARY + '_' + PLATFORM, raw_data.get(Key.BINARY, 'server'))) |
| 416 | + _srv_check = Key.as_bool(None, raw_data.get( |
| 417 | + Key.SRV_CHECK + '_' + PLATFORM, raw_data.get(Key.SRV_CHECK, 'True'))) |
| 418 | + |
| 419 | + key = Key.IDENTIFIER |
| 420 | + binary = None |
| 421 | + |
| 422 | + for method, default in (('function', NO_DEFAULT), ): |
| 423 | + for name, data in raw_data.get(method, {}).items(): |
| 424 | + identifier = data.get(key + '_' + PLATFORM, data.get(key, default)) |
| 425 | + |
| 426 | + # ignore identifier |
| 427 | + if identifier is None: |
| 428 | + continue |
| 429 | + |
| 430 | + # if the identifier is NO_DEFAULT, the key is obviously missing |
| 431 | + if identifier is NO_DEFAULT: |
| 432 | + raise KeyError( |
| 433 | + 'Missing identifier for "{0}".\nFile: {1}'.format( |
| 434 | + name, file)) |
| 435 | + |
| 436 | + if binary is None: |
| 437 | + try: |
| 438 | + binary = find_binary(_binary, _srv_check) |
| 439 | + except OSError as error: |
| 440 | + print(error) |
| 441 | + raise ValueError( |
| 442 | + 'Could not find the binary.\nFile: {0}'.format(file)) |
| 443 | + |
| 444 | + try: |
| 445 | + identifier = Key.as_identifier(None, identifier) |
| 446 | + binary[identifier] |
| 447 | + except ValueError: |
| 448 | + yield (name, identifier) |
| 449 | + |
| 450 | +def check_pipe_signature_from_file(file): |
| 451 | + """Checks if the data signatures are valid.""" |
| 452 | + raw_data = GameConfigObj(file) |
| 453 | + |
| 454 | + key = Key.IDENTIFIER |
| 455 | + |
| 456 | + for name, data in raw_data.items(): |
| 457 | + identifier = data.get(key + '_' + PLATFORM, data.get(key, NO_DEFAULT)) |
| 458 | + |
| 459 | + # if the identifier is NO_DEFAULT, the key is obviously missing |
| 460 | + if identifier is NO_DEFAULT: |
| 461 | + raise KeyError( |
| 462 | + 'Missing identifier for "{0}".\nFile: {1}'.format( |
| 463 | + name, file)) |
| 464 | + |
| 465 | + _binary = Key.as_str(None, data.get( |
| 466 | + Key.BINARY + '_' + PLATFORM, data.get(Key.BINARY, NO_DEFAULT))) |
| 467 | + if _binary is NO_DEFAULT: |
| 468 | + raise KeyError( |
| 469 | + 'Missing binary for "{0}".\nFile: {1}'.format( |
| 470 | + name, file)) |
| 471 | + |
| 472 | + _srv_check = Key.as_bool(None, data.get( |
| 473 | + Key.SRV_CHECK + '_' + PLATFORM, data.get(Key.SRV_CHECK, 'True'))) |
| 474 | + |
| 475 | + try: |
| 476 | + binary = find_binary(_binary, _srv_check) |
| 477 | + except OSError as error: |
| 478 | + print(error) |
| 479 | + raise ValueError( |
| 480 | + 'Could not find the binary.\nFile: {0}'.format(file)) |
| 481 | + |
| 482 | + try: |
| 483 | + identifier = Key.as_identifier(None, identifier) |
| 484 | + binary[identifier] |
| 485 | + except ValueError: |
| 486 | + yield (name, identifier) |
| 487 | + |
407 | 488 | # Use this as a default value if the key is not allowed to have a default
|
408 | 489 | # value
|
409 | 490 | NO_DEFAULT = object()
|
0 commit comments