int entityUseItem(pent e, int slot){ struct inventory *inv = e->inventory; if(!inv) return INVE_NOINV; pitem it = inv->items[slot]; if(!it) return INVE_NOITEM; struct itemData idat = itemDatas[it->itemid]; if(e->abi < idat.abiCost) return INVE_NOABI; if(appTime - it->lastUse < idat.cooldown) return INVE_ONCOOLDOWN; itemUseFunction iuf = idat.onUse; if(!iuf) return INVE_NOFUNC; int ret = iuf(e, it); if(ret != INVE_DONTCOOLDOWN){ e->abi -= idat.abiCost; it->lastUse = appTime; } return 0; }
static void fcrc32_final(uint32_t* crc32, unsigned char* result); /* some helper macroses * like shift in bytes of a message digest in a hash sum context */ #define dgshft(name) (((char*)&((name##_ctx*)0)->hash) - (char*)0) #define dgshft2(name, field) (((char*)&((name##_ctx*)0)->field) - (char*)0) #define ini(name) ((pinit_t)(name##_init)) #define upd(name) ((pupdate_t)(name##_update)) #define fin(name) ((pfinal_t)(name##_final)) #define iuf(name) ini(name), upd(name), fin(name) #define diuf(name) dgshft(name), ini(name), upd(name), fin(name) /* information about all hashes */ rhash_hash_info rhash_hash_info_default[RHASH_HASH_COUNT] = { { { RHASH_CRC32, F_BE32, 4, "CRC32" }, sizeof(uint32_t), 0, iuf(fcrc32), 0}, /* 32 bit */ { { RHASH_MD4, F_LE32, 16, "MD4" }, sizeof(md4_ctx), diuf(md4), 0 }, /* 128 bit */ { { RHASH_MD5, F_LE32, 16, "MD5" }, sizeof(md5_ctx), diuf(md5), 0 }, /* 128 bit */ { { RHASH_SHA1, F_BE32, 20, "SHA1" }, sizeof(sha1_ctx), diuf(sha1), 0 }, /* 160 bit */ { { RHASH_TIGER, F_LE64, 24, "TIGER" }, sizeof(tiger_ctx), diuf(tiger), 0 }, /* 192 bit */ { { RHASH_TTH, F_BS32, 24, "TTH" }, sizeof(tth_ctx), dgshft2(tth, tiger.hash), iuf(tth), 0 }, /* 192 bit */ { { RHASH_BTIH, 0, 20, "BTIH" }, sizeof(torrent_ctx), dgshft2(torrent, btih), iuf(torrent), (pcleanup_t)torrent_cleanup }, /* 160 bit */ { { RHASH_ED2K, F_LE32, 16, "ED2K" }, sizeof(ed2k_ctx), dgshft2(ed2k, md4_context_inner.hash), iuf(ed2k), 0 }, /* 128 bit */ { { RHASH_AICH, F_BS32, 20, "AICH" }, sizeof(aich_ctx), dgshft2(aich, sha1_context.hash), iuf(aich), (pcleanup_t)aich_cleanup }, /* 160 bit */ { { RHASH_WHIRLPOOL, F_BE64, 64, "WHIRLPOOL" }, sizeof(whirlpool_ctx), diuf(whirlpool), 0 }, /* 512 bit */ { { RHASH_RIPEMD160, F_LE32, 20, "RIPEMD-160" }, sizeof(ripemd160_ctx), diuf(ripemd160), 0 }, /* 160 bit */ { { RHASH_GOST, F_LE32, 32, "GOST" }, sizeof(gost_ctx), diuf(gost), 0 }, /* 256 bit */ { { RHASH_GOST_CRYPTOPRO, F_LE32, 32, "GOST-CRYPTOPRO" }, sizeof(gost_ctx), dgshft(gost), ini(gost_cryptopro), upd(gost), fin(gost), 0 }, /* 256 bit */ { { RHASH_HAS160, F_LE32, 20, "HAS-160" }, sizeof(has160_ctx), diuf(has160), 0 }, /* 160 bit */ { { RHASH_SNEFRU128, F_BE32, 16, "SNEFRU-128" }, sizeof(snefru_ctx), dgshft(snefru), ini(snefru128), upd(snefru), fin(snefru), 0 }, /* 128 bit */ { { RHASH_SNEFRU256, F_BE32, 32, "SNEFRU-256" }, sizeof(snefru_ctx), dgshft(snefru), ini(snefru256), upd(snefru), fin(snefru), 0 }, /* 256 bit */