#!/usr/bin/env python3 """Attribute lock: compile the production CItem::ChangeAttribute body against a stub item and check the lock rules.""" from pathlib import Path import re import subprocess import tempfile ROOT=Path(__file__).resolve().parents[2] SRC=ROOT/'src/server/game/src' def text(name):return (SRC/name).read_bytes().decode('latin1') attribute=text('item_attribute.cpp');glue=text('port_attr_lock.cpp');main=text('main.cpp') body=re.search(r'void CItem::ChangeAttribute\(const int\* aiChangeProb\)\n\{.*?\n\}\n',attribute,re.S).group(0) copy=re.search(r'void CItem::CopyAttributeTo\(LPITEM pItem\)\n\{.*?\n\}\n',attribute,re.S).group(0) assert 'PortAttrLockSet(GetOwner(), pItem, lock)' in copy # refine / replacement keeps the lock assert 'port_attr_lock.cpp' in text('Makefile') and '#include "port_attr_lock.h"' in attribute assert 'if (!g_bAuthServer)\n\t{\n\t\tPortAttrLockBoot();' in main.split('config_init(st_localeServiceName);',1)[1][:120] assert 'CREATE TABLE IF NOT EXISTS mt_item_attr_lock' in glue and 'item->m_portAttrLockLoaded=true' in glue assert 'm_portAttrLockLoaded = false;' in text('item.cpp') code=r''' #include #include #include #include #include typedef unsigned char BYTE; enum {ITEM_ATTRIBUTE_MAX_LEVEL=5,ITEM_ATTRIBUTE_MAX_NUM=7,SKILL=71,NORMAL=72}; const int MAX_NORM_ATTR_NUM=5; struct TPlayerItemAttribute{BYTE bType;short sValue;}; struct TItemTable{short sAddonType;}; class CHARACTER; #include "port_attr_lock.h" static unsigned g_lock=0;static int g_lookups=0;static BYTE g_next=10; class CItem { public: TPlayerItemAttribute m_aAttr[ITEM_ATTRIBUTE_MAX_NUM];TItemTable proto; CItem(){memset(m_aAttr,0,sizeof(m_aAttr));proto.sAddonType=0;} BYTE GetAttributeType(int i){return m_aAttr[i].bType;} int GetAttributeCount(){int i=0;while(i& types,bool addon){ CItem item;item.proto.sAddonType=addon; for(size_t i=0;i>i&1)assert(item.m_aAttr[i].bType==before.m_aAttr[i].bType && item.m_aAttr[i].sValue==before.m_aAttr[i].sValue); for(int j=0;j