MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / MultiGetUniqueIDFromString

Function MultiGetUniqueIDFromString

Descent3/multi.cpp:6558–6603  ·  view source on GitHub ↗

Given a string, returns a unique integer for that string

Source from the content-addressed store, hash-verified

6556
6557// Given a string, returns a unique integer for that string
6558uint32_t MultiGetUniqueIDFromString(char *plainstring) {
6559 int i, t, len;
6560 uint32_t ret;
6561 uint8_t cryptstring[PAGENAME_LEN];
6562 uint32_t vals[4];
6563
6564 len = strlen(plainstring);
6565
6566 if (len < 4) {
6567 for (i = len; i < 4; i++)
6568 plainstring[i] = ('g' + i);
6569
6570 len = 4;
6571 }
6572
6573 for (i = 0; i < 4; i++) {
6574 cryptstring[i] = 0;
6575 uint8_t backbyte;
6576
6577 if (i == 0)
6578 backbyte = 0x9a;
6579 else
6580 backbyte = plainstring[i - 1];
6581
6582 for (t = 0; t < len; t++) {
6583 uint8_t a = plainstring[t];
6584 uint8_t b = plainstring[i % (t + 1)];
6585
6586 a *= a;
6587 b *= b * b;
6588
6589 cryptstring[i] += a ^ b ^ (backbyte + t);
6590 }
6591
6592 vals[i] = cryptstring[i];
6593 }
6594
6595 ret = (vals[0] << 24) | (vals[1] << 16) | (vals[2] << 8) | (vals[3]);
6596
6597 if (ret == 0) {
6598 Int3(); // Get Jason, no match at all
6599 return 0;
6600 }
6601
6602 return ret;
6603}
6604
6605// Returns the unique id of a given object type/id
6606uint32_t MultiGetMatchChecksum(int type, int id) {

Callers 1

MultiBuildMatchTablesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected