feat: add CH5 cube renewal presentation, trade level UI, audit manifests, and test fixtures
This commit is contained in:
@@ -536,6 +536,10 @@ try:
|
||||
if getattr(app, 'ENABLE_LEVEL_IN_TRADE', 0) and getattr(self, 'TitleName', None):
|
||||
target_name = exchange.GetNameFromTarget()
|
||||
target_lvl = exchange.GetLevelFromTarget()
|
||||
if not target_lvl:
|
||||
# An old server did not supply START.arg3. Never display cached or fabricated Lv.0.
|
||||
self.TitleName.SetText(target_name)
|
||||
return
|
||||
title_fmt = getattr(localeInfo, 'EXCHANGE_TITLE', '%s (%d)')
|
||||
try:
|
||||
if '%' in title_fmt and title_fmt.count('%') >= 2:
|
||||
|
||||
@@ -1,28 +1,153 @@
|
||||
// PORT: Modern Cube Renewal (F21) script module "cube_renewal".
|
||||
// Provides data structures and entrypoints for uicuberenewal.py.
|
||||
// PORT: server-backed modern Cube recipe preview, NOT a crafting backend.
|
||||
static const char c_szCubeRenewalScript[] = R"PY(# -*- coding: utf-8 -*-
|
||||
_dates = []
|
||||
_handler = None
|
||||
import game
|
||||
import chat
|
||||
import mt_feature_service
|
||||
from mt_biolog import L
|
||||
|
||||
def CountDates():
|
||||
return len(_dates)
|
||||
_dates=[]
|
||||
_recipes=[]
|
||||
_handler=None
|
||||
_window=None
|
||||
_epoch=0
|
||||
_npc=0
|
||||
_readonly=False
|
||||
_last_preflight=None
|
||||
_last_error=None
|
||||
_check_serial=0
|
||||
|
||||
def CountDates():return len(_dates)
|
||||
|
||||
def GetDates(index):
|
||||
if 0 <= index < len(_dates):
|
||||
return _dates[index]
|
||||
# (vnum_reward, count_reward, item_reward_stackable,
|
||||
# vnum_material_1..5, count_material_1..5, gold, percent, category)
|
||||
return (0, 0, False, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "None")
|
||||
if 0<=index<len(_dates):return _dates[index]
|
||||
return (0,0,False,0,0,0,0,0,0,0,0,0,0,0,0,'None')
|
||||
|
||||
def SetCubeRenewalHandler(handler):
|
||||
global _handler
|
||||
_handler = handler
|
||||
_handler=handler
|
||||
|
||||
def CubeRenewalMakeItem(index_craft, count_item, index_improve=0):
|
||||
raise RuntimeError('Cube Renewal requires an implemented server crafting contract')
|
||||
def _Tuple(row):
|
||||
values=[row['reward'],row['count'],row['stackable']]
|
||||
for v,n in row['materials']:values.extend((v,n))
|
||||
values.extend([0,0]*(5-len(row['materials'])))
|
||||
return tuple(values+[row['gold'],row['percent'],row['category']])
|
||||
|
||||
def CubeRenewalClose():
|
||||
global _handler
|
||||
_handler = None
|
||||
del _dates[:]
|
||||
global _handler,_epoch,_npc,_readonly,_last_preflight
|
||||
_epoch+=1;_npc=0;_readonly=False;_handler=None;_last_preflight=None
|
||||
del _dates[:];del _recipes[:]
|
||||
if _window:_window.Hide()
|
||||
|
||||
def LoadCatalogue(npc,callback=None):
|
||||
global _epoch,_npc,_last_error,_readonly,_last_preflight
|
||||
_epoch+=1;epoch=_epoch;_npc=npc;_last_error=None;_readonly=False;_last_preflight=None
|
||||
if _window:_window.Hide()
|
||||
del _dates[:];del _recipes[:]
|
||||
service=mt_feature_service.g_service
|
||||
if not service:
|
||||
_last_error='offline'
|
||||
if callback:callback(None,'offline')
|
||||
return 0
|
||||
pending=[];state={'total':None,'revision':None}
|
||||
def fail(error):
|
||||
global _last_error
|
||||
_last_error=error
|
||||
if callback:callback(None,error)
|
||||
def receive(result,error):
|
||||
if epoch!=_epoch:return
|
||||
if error:fail(error);return
|
||||
if state['total'] is None:state['total']=result['total']
|
||||
if result['total']!=state['total'] or result['offset']!=len(pending):fail('stale_catalogue');return
|
||||
ids=set(r['id'] for r in pending)
|
||||
for row in result['rows']:
|
||||
if state['revision'] is None:state['revision']=row['catalogue']
|
||||
if row['catalogue']!=state['revision'] or row['id'] in ids:fail('stale_catalogue');return
|
||||
ids.add(row['id']);pending.append(row)
|
||||
if len(pending)<state['total']:
|
||||
service.Request('cube',npc,len(pending),receive);return
|
||||
_recipes[:]=pending;_dates[:]=[_Tuple(row) for row in pending]
|
||||
if callback:callback(list(_recipes),None)
|
||||
return service.Request('cube',npc,0,receive)
|
||||
|
||||
def CheckBatch(index,attempts,callback=None):
|
||||
global _last_error,_last_preflight,_check_serial
|
||||
_last_preflight=None;_last_error=None;_check_serial+=1;serial=_check_serial
|
||||
if not isinstance(index,int) or not isinstance(attempts,int) or not 0<=index<len(_recipes) or not 1<=attempts<=100:
|
||||
_last_error='invalid'
|
||||
if callback:callback(None,'invalid')
|
||||
return 0
|
||||
service=mt_feature_service.g_service
|
||||
if not service:
|
||||
_last_error='offline'
|
||||
if callback:callback(None,'offline')
|
||||
return 0
|
||||
epoch=_epoch;recipe=_recipes[index]
|
||||
def receive(result,error):
|
||||
global _last_error,_last_preflight
|
||||
if epoch!=_epoch or serial!=_check_serial:return
|
||||
_last_error=error
|
||||
if error:pass
|
||||
else:
|
||||
values=dict(result['rows']);version='%08x%08x'%(values['revision_hi'],values['revision_lo'])
|
||||
if version!=recipe['revision']:_last_error='stale_recipe'
|
||||
elif values['gold_required']!=recipe['gold']*attempts or values['reward_maximum']!=recipe['count']*attempts or bool(values['copy_required'])!=recipe['copy']:_last_error='bad_preflight'
|
||||
else:
|
||||
for i,(v,n) in enumerate(recipe['materials'],1):
|
||||
if values.get('material%d'%i)!=v or values.get('needed%d'%i)!=n*attempts or values.get('available%d'%i,-1)<0:
|
||||
_last_error='bad_preflight';break
|
||||
keys=set(('revision_hi','revision_lo','attempts','gold_required','gold_available','materials_ok','gold_ok','mutation_enabled','reward_maximum','capacity_reserved','copy_required'))
|
||||
for i in range(1,len(recipe['materials'])+1):keys.update(('material%d'%i,'needed%d'%i,'available%d'%i))
|
||||
material_ok=all(values.get('available%d'%i,-1)>=n*attempts for i,(v,n) in enumerate(recipe['materials'],1))
|
||||
if set(values)!=keys or values['gold_available']>2000000000000000 or bool(values['gold_ok'])!=(values['gold_available']>=values['gold_required']) or bool(values['materials_ok'])!=material_ok:_last_error='bad_preflight'
|
||||
if not _last_error:_last_preflight=values
|
||||
if callback:callback(_last_preflight,_last_error)
|
||||
return service.Request('cubecheck',recipe['id'],attempts,receive)
|
||||
|
||||
def CubeRenewalMakeItem(index_craft,count_item,index_improve=0):
|
||||
# Original UI name; only our labeled preview can use it, for a read-only check.
|
||||
if not _readonly:raise RuntimeError('Cube Renewal requires an implemented durable server crafting contract')
|
||||
if index_improve not in (0,-1):
|
||||
chat.AppendChat(chat.CHAT_TYPE_INFO,L('预检暂不支持成功率道具;未扣除材料。'));return 0
|
||||
def checked(result,error):
|
||||
if error:chat.AppendChat(chat.CHAT_TYPE_INFO,L('配方预检失败,未扣料、未制作:')+str(error));return
|
||||
chat.AppendChat(chat.CHAT_TYPE_INFO,L('只读预检:尝试 %d 次,需金币 %d;材料%s,金币%s。未预留背包、未扣料、未制作。')%
|
||||
(result['attempts'],result['gold_required'],L('充足' if result['materials_ok'] else '不足'),L('充足' if result['gold_ok'] else '不足')))
|
||||
return CheckBatch(index_craft,count_item,checked)
|
||||
|
||||
def OpenPreview(npc):
|
||||
def loaded(rows,error):
|
||||
global _window,_readonly,_last_error
|
||||
if error:
|
||||
if error!='unsupported':chat.AppendChat(chat.CHAT_TYPE_INFO,L('制作配方预览不可用:')+str(error))
|
||||
return
|
||||
try:
|
||||
if _window is None:
|
||||
import uiCubeRenewal
|
||||
_window=uiCubeRenewal.CubeRenewalWindows()
|
||||
SetCubeRenewalHandler(_window)
|
||||
_window.BINARY_CUBE_RENEWAL_LOADING()
|
||||
_window.button_ok.SetText(L('批量预检'))
|
||||
_window.slot_improve.Hide();_window.imporve_slot.Hide()
|
||||
_window.SetCenterPosition();_window.Show();_readonly=True
|
||||
except Exception:
|
||||
_readonly=False;_last_error='cube_ui_unavailable';SetCubeRenewalHandler(None)
|
||||
if _window:_window.Hide()
|
||||
_window=None
|
||||
chat.AppendChat(chat.CHAT_TYPE_INFO,L('现代制作界面资源不可用,保留原制作窗口;未扣料、未制作。'))
|
||||
return
|
||||
chat.AppendChat(chat.CHAT_TYPE_INFO,L('现代制作只读预览:当前不扣料、不发奖;原制作窗口保持不变。'))
|
||||
return LoadCatalogue(npc,loaded)
|
||||
|
||||
_open=game.GameWindow.BINARY_Cube_Open
|
||||
_close=game.GameWindow.BINARY_Cube_Close
|
||||
_game_close=game.GameWindow.Close
|
||||
def Open(self,npc):
|
||||
_open(self,npc);OpenPreview(npc)
|
||||
def Close(self):
|
||||
CubeRenewalClose();return _close(self)
|
||||
def GameClose(self):
|
||||
CubeRenewalClose();return _game_close(self)
|
||||
game.GameWindow.BINARY_Cube_Open=Open
|
||||
game.GameWindow.BINARY_Cube_Close=Close
|
||||
game.GameWindow.Close=GameClose
|
||||
)PY";
|
||||
|
||||
@@ -7,7 +7,7 @@ import ui
|
||||
import binascii
|
||||
from mt_wiki_data import Number
|
||||
|
||||
BITS={'mob':1,'chest':2,'stats':4,'sources':8,'dungeons':16,'calendar':32,'bosses':256,'travel':512,'rank':1024,'quiver':2048}
|
||||
BITS={'mob':1,'chest':2,'stats':4,'sources':8,'dungeons':16,'calendar':32,'bosses':256,'travel':512,'rank':1024,'quiver':2048,'cube':4096,'cubecheck':4096}
|
||||
WHOLE=('stats','dungeons','bosses','quiver') # one reply with every row; no subject or page
|
||||
g_service=None
|
||||
g_tick=None
|
||||
@@ -33,6 +33,8 @@ class Service(object):
|
||||
callback(None,'invalid');return 0
|
||||
if kind=='rank' and (subject>=10 or offset):
|
||||
callback(None,'invalid');return 0
|
||||
if kind in ('cube','cubecheck') and (not subject or (kind=='cubecheck' and not 1<=offset<=100)):
|
||||
callback(None,'invalid');return 0
|
||||
_serial=(_serial%2147483647)+1
|
||||
self.queue.append(dict(id=_serial,kind=kind,subject=subject,offset=offset,callback=callback,retries=0))
|
||||
return _serial
|
||||
@@ -84,16 +86,17 @@ class Service(object):
|
||||
elif op=='begin' and len(w)==9 and p['kind']!='cap':
|
||||
if 'result' in p or w[3]!=p['kind'] or Number(w[4])!=p['subject'] or Number(w[5])!=p['offset']:
|
||||
raise ValueError('mismatched response')
|
||||
total=Number(w[6],10 if p['kind']=='rank' else 128 if p['kind'] in WHOLE else 256 if p['kind']=='calendar' else 4096)
|
||||
if total<p['offset']:raise ValueError('invalid page')
|
||||
total=Number(w[6],10 if p['kind']=='rank' else 128 if p['kind'] in WHOLE+('cubecheck',) else 256 if p['kind']=='calendar' else 4096)
|
||||
if p['kind']!='cubecheck' and total<p['offset']:raise ValueError('invalid page')
|
||||
p['result']=dict(kind=w[3],subject=p['subject'],offset=p['offset'],total=total,mode=Number(w[7],11),
|
||||
time=Number(w[8]),rows=[])
|
||||
if p['kind']=='rank' and p['result']['mode']!=0:raise ValueError('invalid rank mode')
|
||||
elif op in ('row','stat','event','boss','rank') and 'result' in p:
|
||||
if p['kind'] in ('rank','cube','cubecheck') and p['result']['mode']!=0:raise ValueError('invalid mode')
|
||||
elif op in ('row','stat','event','boss','rank','recipe') and 'result' in p:
|
||||
result=p['result'];rows=result['rows']
|
||||
limit=result['total'] if p['kind'] in WHOLE+('rank',) else min(8,result['total']-p['offset'])
|
||||
if len(rows)>=limit or Number(w[3])!=p['offset']+len(rows):raise ValueError('invalid row order')
|
||||
if op=='row' and len(w)==12 and p['kind'] not in WHOLE+('calendar','rank'):
|
||||
limit=result['total'] if p['kind'] in WHOLE+('rank','cubecheck') else min(8,result['total']-p['offset'])
|
||||
base=0 if p['kind']=='cubecheck' else p['offset']
|
||||
if len(rows)>=limit or Number(w[3])!=base+len(rows):raise ValueError('invalid row order')
|
||||
if op=='row' and len(w)==12 and p['kind'] not in WHOLE+('calendar','rank','cube','cubecheck'):
|
||||
values=[Number(v) for v in w[4:]]
|
||||
if values[2] not in (0,1,2,3,4,5,10,11,20,21) or not values[0]:raise ValueError('invalid row')
|
||||
rows.append(values)
|
||||
@@ -107,9 +110,25 @@ class Service(object):
|
||||
values=[Number(w[4]),Number(w[5]),Signed(w[6]),Signed(w[7])]+[Number(v) for v in w[8:]]
|
||||
if not values[0] or not values[1] or values[4]>255 or values[6]>255 or values[5]>values[6] or not values[8]:raise ValueError('invalid boss')
|
||||
rows.append(values)
|
||||
elif op=='stat' and len(w)==6 and p['kind'] in ('stats','dungeons'):
|
||||
if not w[4].replace('_','').isalpha() or len(w[4])>32 or any(r[0]==w[4] for r in rows):raise ValueError('invalid stat')
|
||||
elif op=='stat' and len(w)==6 and p['kind'] in ('stats','dungeons','cubecheck'):
|
||||
key=w[4].replace('_','')
|
||||
if not (key.isalnum() if p['kind']=='cubecheck' else key.isalpha()) or len(w[4])>32 or any(r[0]==w[4] for r in rows):raise ValueError('invalid stat')
|
||||
rows.append((w[4],Signed(w[5])))
|
||||
elif op=='recipe' and p['kind']=='cube' and len(w)>=17:
|
||||
count=Number(w[14],5)
|
||||
if not count or len(w)!=15+count*2:raise ValueError('invalid recipe materials')
|
||||
for token in w[5:7]:
|
||||
if len(token)!=16 or any(c not in '0123456789abcdef' for c in token):raise ValueError('invalid recipe revision')
|
||||
rid=Number(w[4],4096);reward=Number(w[7],4294967295);qty=Number(w[8],2000)
|
||||
stack=Number(w[9],1);gold=Number(w[10],4294967295);chance=Number(w[11],100);copy=Number(w[12],1)
|
||||
if not rid or not reward or not qty or (not stack and qty!=1):raise ValueError('invalid recipe reward')
|
||||
if not 2<=len(w[13])<=48 or len(w[13])%2 or any(c not in '0123456789abcdef' for c in w[13]):raise ValueError('invalid recipe category')
|
||||
category=binascii.unhexlify(w[13]).decode('ascii')
|
||||
if not category.replace('_','').isalnum():raise ValueError('invalid recipe category')
|
||||
materials=[(Number(w[i],4294967295),Number(w[i+1],2000)) for i in range(15,len(w),2)]
|
||||
if any(not v or not n for v,n in materials) or len(set(v for v,n in materials))!=len(materials):raise ValueError('invalid recipe materials')
|
||||
if any(r['id']==rid or r['catalogue']!=w[5] for r in rows):raise ValueError('mixed recipe snapshot')
|
||||
rows.append(dict(id=rid,catalogue=w[5],revision=w[6],reward=reward,count=qty,stackable=bool(stack),gold=gold,percent=chance,copy=bool(copy),category=category,materials=materials))
|
||||
elif op=='rank' and len(w)==7 and p['kind']=='rank':
|
||||
if not 2<=len(w[4])<=48 or len(w[4])%2 or any(c not in '0123456789abcdef' for c in w[4]):raise ValueError('invalid rank name')
|
||||
name=binascii.unhexlify(w[4])
|
||||
@@ -119,7 +138,7 @@ class Service(object):
|
||||
rows.append((name,empire,value))
|
||||
else:raise ValueError('invalid row format')
|
||||
elif op=='end' and len(w)==4 and 'result' in p:
|
||||
result=p['result'];expected=result['total'] if p['kind'] in WHOLE+('rank',) else min(8,result['total']-p['offset'])
|
||||
result=p['result'];expected=result['total'] if p['kind'] in WHOLE+('rank','cubecheck') else min(8,result['total']-p['offset'])
|
||||
if Number(w[3])!=expected or len(result['rows'])!=expected:raise ValueError('incomplete reply')
|
||||
if p['kind']=='dungeons':
|
||||
values=dict(result['rows'])
|
||||
@@ -129,9 +148,14 @@ class Service(object):
|
||||
weekly=('weekly_end','weekly_hunt_end','weekly_active','weekly_npc','weekly_map')
|
||||
if any(k in values for k in weekly) and any(k not in values or values[k]<0 for k in weekly):raise ValueError('incomplete weekly state')
|
||||
if values.get('weekly_active',0)>1:raise ValueError('invalid weekly state')
|
||||
if p['kind']=='cubecheck':
|
||||
values=dict(result['rows'])
|
||||
required=('revision_hi','revision_lo','attempts','gold_required','gold_available','materials_ok','gold_ok','mutation_enabled','reward_maximum','capacity_reserved','copy_required')
|
||||
if any(k not in values or values[k]<0 for k in required):raise ValueError('incomplete cube preflight')
|
||||
if values['attempts']!=p['offset'] or values['revision_hi']>4294967295 or values['revision_lo']>4294967295 or values['mutation_enabled'] or values['capacity_reserved'] or values['materials_ok']>1 or values['gold_ok']>1 or values['copy_required']>1:raise ValueError('invalid cube preflight')
|
||||
self.Finish(result)
|
||||
else:raise ValueError('unknown response')
|
||||
except (ValueError,TypeError,IndexError,OverflowError):
|
||||
except (ValueError,TypeError,IndexError,OverflowError,UnicodeError):
|
||||
if p and self.pending is p:
|
||||
if p['kind']=='cap':self.mask=0;self.pending=None
|
||||
else:self.Finish(None,'bad_reply')
|
||||
|
||||
@@ -100,7 +100,7 @@ def _InstallScriptPatch():
|
||||
|
||||
def ExecFile(fileName, dict):
|
||||
execfile(fileName, dict)
|
||||
if fileName.replace("\\", "/").split("/")[-1].lower() == "inventorywindow.py" and "window" in dict:
|
||||
if fileName.replace("\\", "/").split("/")[-1].lower() in ("inventorywindow.py", "inventorywindowex.py") and "window" in dict:
|
||||
_PatchInventoryWindow(dict["window"])
|
||||
|
||||
ui.execfile = ExecFile
|
||||
@@ -126,6 +126,8 @@ def _InstallInventoryWindow():
|
||||
dbg.TraceError("mt_inventory: cannot bind the page tabs")
|
||||
|
||||
def SetInventoryPage(self, page):
|
||||
if page < 0 or page >= PAGE_COUNT:
|
||||
return
|
||||
self.inventoryPageIndex = page
|
||||
for i in xrange(len(self.inventoryTab)):
|
||||
if i != page:
|
||||
|
||||
@@ -3,7 +3,8 @@ static const char c_szQuiverMotionScript[] = R"PY(
|
||||
import chr
|
||||
import chrmgr
|
||||
import pack
|
||||
import playersettingmodule
|
||||
# Packed scripts import this case-sensitive Python module name during loading.
|
||||
import playerSettingModule as playersettingmodule
|
||||
|
||||
loaded={}
|
||||
FILES=(('MOTION_WAIT','wait.msa',70),('MOTION_WAIT','wait_1.msa',30),
|
||||
|
||||
@@ -3,8 +3,9 @@ static const char c_szTargetElementScript[] = R"PY(# -*- coding: utf-8 -*-
|
||||
import app
|
||||
import chr
|
||||
import nonplayer
|
||||
import pack
|
||||
import ui
|
||||
import uitarget
|
||||
import uiTarget as uitarget
|
||||
|
||||
ELEMENTAL_PATH = "d:/ymir work/ui/game/12zi/element/{}.sub"
|
||||
|
||||
@@ -24,9 +25,10 @@ def GetElementalFilename(mobVnum):
|
||||
if not mobVnum:
|
||||
return ""
|
||||
dwRaceFlag = nonplayer.GetMonsterRaceFlag(mobVnum)
|
||||
for k, v in SUB_RACE_FLAG_TO_FILENAME.iteritems():
|
||||
# Deterministic single-icon compatibility policy: lowest known elemental flag first.
|
||||
for k in sorted(SUB_RACE_FLAG_TO_FILENAME):
|
||||
if HAS_FLAG(dwRaceFlag, k):
|
||||
return v
|
||||
return SUB_RACE_FLAG_TO_FILENAME[k]
|
||||
return ""
|
||||
|
||||
def _EnsureElementImage(targetBoard):
|
||||
@@ -44,11 +46,14 @@ def SetRaceElement(targetBoard, vid):
|
||||
if not mobVnum:
|
||||
mobVnum = chr.GetVirtualNumber(vid)
|
||||
imagePath = GetElementalFilename(mobVnum)
|
||||
if imagePath:
|
||||
if imagePath and pack.Exist(imagePath):
|
||||
try:
|
||||
elementImage.LoadImage(imagePath)
|
||||
elementImage.SetPosition(-elementImage.GetWidth(), 0)
|
||||
elementImage.Show()
|
||||
if elementImage.GetWidth() > 0:
|
||||
elementImage.Show()
|
||||
else:
|
||||
elementImage.Hide()
|
||||
except Exception:
|
||||
elementImage.Hide()
|
||||
else:
|
||||
@@ -69,6 +74,10 @@ def Hooked_SetTargetVID(self, vid):
|
||||
|
||||
uitarget.TargetBoard.SetEnemyVID = Hooked_SetEnemyVID
|
||||
uitarget.TargetBoard.SetTargetVID = Hooked_SetTargetVID
|
||||
# The CH5 original SetEnemyVID invokes this method internally. Replace that unsafe
|
||||
# loader as well, so a missing image cannot fail before the outer hook runs.
|
||||
if hasattr(uitarget.TargetBoard, 'SetRaceElement'):
|
||||
uitarget.TargetBoard.SetRaceElement = SetRaceElement
|
||||
if _orig_ResetTargetBoard:
|
||||
def Hooked_ResetTargetBoard(self):
|
||||
_orig_ResetTargetBoard(self)
|
||||
|
||||
@@ -314,6 +314,15 @@ if(BUILD_TESTING AND CMAKE_SYSTEM_NAME STREQUAL CMAKE_HOST_SYSTEM_NAME)
|
||||
add_test(NAME port.login_flow
|
||||
COMMAND $<TARGET_FILE:port_login_flow_test> ${MT_40250_CLIENT} ${MT_PYTHON_STDLIB_ZIP})
|
||||
set_tests_properties(port.login_flow PROPERTIES SKIP_RETURN_CODE 77)
|
||||
add_test(NAME port.quiver_sync
|
||||
COMMAND $<TARGET_FILE:port_login_flow_test> ${MT_40250_CLIENT} ${MT_PYTHON_STDLIB_ZIP})
|
||||
set_tests_properties(port.quiver_sync PROPERTIES SKIP_RETURN_CODE 77 ENVIRONMENT "MT_TEST_QUIVER=1")
|
||||
add_test(NAME port.trade_level
|
||||
COMMAND $<TARGET_FILE:port_login_flow_test> ${MT_40250_CLIENT} ${MT_PYTHON_STDLIB_ZIP})
|
||||
set_tests_properties(port.trade_level PROPERTIES SKIP_RETURN_CODE 77 ENVIRONMENT "MT_TEST_TRADE_LEVEL=1")
|
||||
add_test(NAME port.cube_catalog
|
||||
COMMAND $<TARGET_FILE:port_login_flow_test> ${MT_40250_CLIENT} ${MT_PYTHON_STDLIB_ZIP})
|
||||
set_tests_properties(port.cube_catalog PROPERTIES SKIP_RETURN_CODE 77 ENVIRONMENT "MT_TEST_CUBE=1")
|
||||
add_test(NAME port.autohunt_batch
|
||||
COMMAND $<TARGET_FILE:port_login_flow_test> ${MT_40250_CLIENT} ${MT_PYTHON_STDLIB_ZIP})
|
||||
set_tests_properties(port.autohunt_batch PROPERTIES SKIP_RETURN_CODE 77
|
||||
|
||||
@@ -412,7 +412,7 @@ typedef struct TPlayerItemAttribute
|
||||
typedef struct packet_item
|
||||
{
|
||||
DWORD vnum;
|
||||
BYTE count;
|
||||
DWORD count; // PORT: internal-only full count; classic wire structs remain BYTE.
|
||||
DWORD flags;
|
||||
DWORD anti_flags;
|
||||
LONG alSockets[ITEM_SOCKET_SLOT_MAX_NUM]; // PORT: LONG, the 32-bit Win32 long
|
||||
|
||||
@@ -1595,7 +1595,7 @@ void initapp()
|
||||
PyModule_AddIntConstant(poModule, "ENABLE_VIEW_TARGET_DECIMAL_HP", 1);
|
||||
PyModule_AddIntConstant(poModule, "ENABLE_VIEW_TARGET_PLAYER_HP", 1);
|
||||
PyModule_AddIntConstant(poModule, "ENABLE_WINDOW_SLIDE_EFFECT", 0);
|
||||
// PORT: the Won exchange window binds the cheque slot, so it follows ENABLE_CHEQUE_SYSTEM (off).
|
||||
// PORT: Won wallet/transactions are gated off; its dependent window must be off too.
|
||||
PyModule_AddIntConstant(poModule, "ENABLE_WON_EXCHANGE_WINDOW", 0);
|
||||
PyModule_AddIntConstant(poModule, "BL_MOVE_COSTUME_ATTR", 1);
|
||||
PyModule_AddIntConstant(poModule, "DISABLE_CHEQUE_DROP", 0);
|
||||
|
||||
@@ -23,12 +23,12 @@ char * CPythonExchange::GetNameFromTarget()
|
||||
|
||||
void CPythonExchange::SetSelfLevel(DWORD level)
|
||||
{
|
||||
m_self.level = level;
|
||||
m_self.level = level >= 1 && level <= 255 ? level : 0;
|
||||
}
|
||||
|
||||
void CPythonExchange::SetTargetLevel(DWORD level)
|
||||
{
|
||||
m_victim.level = level;
|
||||
m_victim.level = level >= 1 && level <= 255 ? level : 0;
|
||||
}
|
||||
|
||||
DWORD CPythonExchange::GetLevelFromSelf()
|
||||
@@ -255,6 +255,9 @@ void CPythonExchange::Start()
|
||||
void CPythonExchange::End()
|
||||
{
|
||||
m_isTrading = false;
|
||||
// PORT: snapshots belong to this trade only, not a future partner/session.
|
||||
m_self.level = 0;
|
||||
m_victim.level = 0;
|
||||
}
|
||||
|
||||
bool CPythonExchange::isTrading()
|
||||
@@ -285,4 +288,4 @@ CPythonExchange::CPythonExchange()
|
||||
}
|
||||
CPythonExchange::~CPythonExchange()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1910,6 +1910,8 @@ bool CPythonNetworkStream::RecvExchangePacket()
|
||||
CPythonExchange::Instance().Start();
|
||||
CPythonExchange::Instance().SetSelfName(CPythonPlayer::Instance().GetName());
|
||||
CPythonExchange::Instance().SetSelfLevel(CPythonPlayer::Instance().GetStatus(POINT_LEVEL));
|
||||
// PORT: START.arg3 is the server's partner-level snapshot; zero means legacy/unknown.
|
||||
CPythonExchange::Instance().SetTargetLevel(exchange_packet.arg3);
|
||||
|
||||
{
|
||||
CInstanceBase * pCharacterInstance = CPythonCharacterManager::Instance().GetInstancePtr(exchange_packet.arg1);
|
||||
@@ -1917,7 +1919,6 @@ bool CPythonNetworkStream::RecvExchangePacket()
|
||||
if (pCharacterInstance)
|
||||
{
|
||||
CPythonExchange::Instance().SetTargetName(pCharacterInstance->GetNameString());
|
||||
CPythonExchange::Instance().SetTargetLevel(pCharacterInstance->GetLevel());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4529,7 +4530,7 @@ bool CPythonNetworkStream::SendClientVersionPacket()
|
||||
kVersionPacket.header = HEADER_CG_CLIENT_VERSION2;
|
||||
strncpy(kVersionPacket.filename, filename.c_str(), sizeof(kVersionPacket.filename)-1);
|
||||
// PORT: revision mt20261024 adds 64-bit shop prices, fixed offline records and 64-bit exchange/guild money; preserve the numeric prefix for atoi version checks.
|
||||
strncpy(kVersionPacket.timestamp, "1215955205 mt20261024", sizeof(kVersionPacket.timestamp)-1); // # python time.time 앞자리
|
||||
strncpy(kVersionPacket.timestamp, "1215955205 mt20261025", sizeof(kVersionPacket.timestamp)-1); // PORT: revision25 adds full-count and Cube presentation companions.
|
||||
//strncpy(kVersionPacket.timestamp, __TIMESTAMP__, sizeof(kVersionPacket.timestamp)-1); // old_string_ver
|
||||
//strncpy(kVersionPacket.timestamp, "1218055205", sizeof(kVersionPacket.timestamp)-1); // new_future
|
||||
//strncpy(kVersionPacket.timestamp, "1214055205", sizeof(kVersionPacket.timestamp)-1); // old_past
|
||||
@@ -4543,7 +4544,7 @@ bool CPythonNetworkStream::SendClientVersionPacket()
|
||||
kVersionPacket.header = HEADER_CG_CLIENT_VERSION;
|
||||
strncpy(kVersionPacket.filename, filename.c_str(), sizeof(kVersionPacket.filename)-1);
|
||||
// PORT: 64-bit money protocol requires mt20261024; older AVA2 services retain their own revision gates.
|
||||
strncpy(kVersionPacket.timestamp, "mt20261024", sizeof(kVersionPacket.timestamp)-1);
|
||||
strncpy(kVersionPacket.timestamp, "mt20261025", sizeof(kVersionPacket.timestamp)-1); // PORT: revision25 is backward-compatible with revision24 money.
|
||||
|
||||
if (!Send(sizeof(kVersionPacket), &kVersionPacket))
|
||||
Tracef("SendClientReportPacket Error");
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <vector>
|
||||
#include "PythonPlayer.h"
|
||||
#include "PythonSafeBox.h"
|
||||
#include "../common/CubePresentation.h"
|
||||
|
||||
bool CPythonNetworkStream::SendAva2DropQuery(BYTE subheader,LONG vnum) {
|
||||
if (!PORT_IsGamePhase() || (subheader!=0 && subheader!=1 && subheader!=6 && subheader!=7 && subheader!=8 && subheader!=9 && subheader!=10) || vnum<0)return false;
|
||||
@@ -32,6 +33,25 @@ bool CPythonNetworkStream::RecvAva2ItemShop() {
|
||||
if (!Recv(sizeof(p),&p) || p.size<sizeof(p)+1 || p.size>32768)return false;
|
||||
std::vector<char> data(p.size-sizeof(p));
|
||||
if (!Recv(data.size(),data.data()))return false;
|
||||
if(uint8_t(data[0])==11) {
|
||||
// PORT: full Cube presentation is validated before any player mutation.
|
||||
PortCubeView::Frame frame;
|
||||
if(!PortCubeView::Decode(std::string(data.begin(),data.end()),frame)||!CPythonPlayer::Instance().PORT_ApplyCubeView(frame))return false;
|
||||
__RefreshInventoryWindow();__RefreshStatus();return true;
|
||||
}
|
||||
if(uint8_t(data[0])==12) {
|
||||
// PORT: full count companion; classic byte-sized item packets stay intact.
|
||||
if(data.size()!=83)return false;const std::string bytes(data.begin(),data.end());PortCubeView::Reader r{bytes};r.at=1;
|
||||
const auto window=uint8_t(r.n(1));const auto cell=uint16_t(r.n(2));const auto vnum=uint32_t(r.n(4)),id=uint32_t(r.n(4));const auto count=uint16_t(r.n(2));
|
||||
if(!r.ok||!vnum||!id||!count||count>2000)return false;PortItemExtra extra;std::memcpy(&extra,bytes.data()+r.at,69);
|
||||
TItemData* target=nullptr;
|
||||
if(window==SAFEBOX){if(!CPythonSafeBox::Instance().GetItemDataPtr(cell,&target))return false;}
|
||||
else if(window==MALL){if(!CPythonSafeBox::Instance().GetMallItemDataPtr(cell,&target))return false;}
|
||||
else {TItemPos pos(window,cell);if(!pos.IsValidCell())return false;target=const_cast<TItemData*>(CPythonPlayer::Instance().GetItemData(pos));}
|
||||
if(!target||target->vnum!=vnum||(target->portId&&target->portId!=id))return true; // PORT: stale same-vnum companion cannot replace a newer identity.
|
||||
target->count=count;target->portId=id;target->extra=extra;
|
||||
if(window==SAFEBOX)__RefreshSafeboxWindow();else if(window==MALL)__RefreshMallWindow();else __RefreshInventoryWindow();return true;
|
||||
}
|
||||
if(uint8_t(data[0])==10) {
|
||||
#pragma pack(push,1)
|
||||
struct Extra {uint8_t op,window;uint16_t cell;uint32_t vnum,id;PortItemExtra extra;};
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "../EterBase/Timer.h"
|
||||
|
||||
#include "AbstractPlayer.h"
|
||||
#include "../common/CubePresentation.h"
|
||||
|
||||
enum
|
||||
{
|
||||
@@ -21,6 +22,8 @@ enum
|
||||
|
||||
const DWORD POINT_MAGIC_NUMBER = 0xe73ac1da;
|
||||
|
||||
#include "PythonPlayerCubeView.inc"
|
||||
|
||||
void CPythonPlayer::SPlayerStatus::SetPoint(UINT ePoint, long lPoint)
|
||||
{
|
||||
m_alPoint[ePoint]=lPoint ^ POINT_MAGIC_NUMBER;
|
||||
@@ -750,7 +753,9 @@ DWORD CPythonPlayer::GetItemID(TItemPos Cell)
|
||||
const char* CPythonPlayer::GetItemNewName(TItemPos Cell)
|
||||
{
|
||||
const auto item=Cell.IsValidCell() ? GetItemData(Cell) : nullptr;
|
||||
return item ? item->extra.name : "";
|
||||
// PORT: keep all69 authoritative bytes; expose only the 24 display bytes.
|
||||
static thread_local char name[25];std::memset(name,0,sizeof(name));
|
||||
if(item)std::memcpy(name,item->extra.name,24);return name;
|
||||
}
|
||||
|
||||
DWORD CPythonPlayer::GetItemMetinSocket(TItemPos Cell, DWORD dwMetinSocketIndex)
|
||||
@@ -1754,6 +1759,7 @@ void CPythonPlayer::ClearSkillDict()
|
||||
|
||||
void CPythonPlayer::Clear()
|
||||
{
|
||||
m_portCubeViewEpoch=0;m_portCubeViewBytes.clear(); // PORT: character/session boundary.
|
||||
memset(&m_playerStatus, 0, sizeof(m_playerStatus));
|
||||
m_i64Gold = 0;
|
||||
NEW_ClearSkillData(true);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "PythonSkill.h"
|
||||
|
||||
class CInstanceBase;
|
||||
namespace PortCubeView {struct Frame;}
|
||||
|
||||
/*
|
||||
* 메인 캐릭터 (자신이 조정하는 캐릭터) 가 가진 정보들을 관리한다.
|
||||
@@ -286,6 +287,7 @@ class CPythonPlayer : public CSingleton<CPythonPlayer>, public IAbstractPlayer
|
||||
void SetStatus(DWORD dwType, long lValue);
|
||||
int GetStatus(DWORD dwType);
|
||||
void SetGold64(int64_t gold);
|
||||
bool PORT_ApplyCubeView(const PortCubeView::Frame&);
|
||||
void ChangeGold64(int64_t amount);
|
||||
int64_t GetGold64() const;
|
||||
bool IsConqueror() const { return const_cast<CPythonPlayer*>(this)->GetStatus(POINT_CONQUEROR_LEVEL) >= 1; }
|
||||
@@ -629,6 +631,8 @@ class CPythonPlayer : public CSingleton<CPythonPlayer>, public IAbstractPlayer
|
||||
|
||||
TPlayerStatus m_playerStatus;
|
||||
int64_t m_i64Gold;
|
||||
uint64_t m_portCubeViewEpoch=0; // PORT: presentation replay guard, reset on player Clear.
|
||||
std::string m_portCubeViewBytes;
|
||||
|
||||
UINT m_iComboOld;
|
||||
DWORD m_dwVIDReserved;
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
// PORT: one validated presentation commit; no Python callbacks while staging.
|
||||
bool CPythonPlayer::PORT_ApplyCubeView(const PortCubeView::Frame& f)
|
||||
{
|
||||
static_assert(QUICKSLOT_MAX_NUM==PortCubeView::Quickslots,"Cube quickslot contract");
|
||||
if(!PortCubeView::Valid(f))return false;
|
||||
if(f.epoch<m_portCubeViewEpoch)return true; // PORT: never replay an older view over newer state.
|
||||
auto canonical=PortCubeView::Encode(f);
|
||||
if(f.epoch==m_portCubeViewEpoch)return canonical==m_portCubeViewBytes;
|
||||
std::array<TItemData,PortCubeView::Slots> staged{};std::array<bool,PortCubeView::Slots> grid{};
|
||||
for(const auto& row:f.items) {
|
||||
CItemData* proto=nullptr;
|
||||
if(!CItemManager::Instance().GetItemDataPointer(row.vnum,&proto)||!proto)return false;
|
||||
const auto size=proto->GetSize();
|
||||
if(size<1||size>3||(row.cell%45)/5+size>9||(!proto->IsFlag(CItemData::ITEM_FLAG_STACKABLE)&&row.count!=1))return false;
|
||||
for(unsigned n=0;n<size;++n){const auto at=row.cell+5*n;if(at>=grid.size()||grid[at])return false;grid[at]=true;}
|
||||
auto& item=staged[row.cell];item.vnum=row.vnum;item.count=row.count;item.portId=row.id;item.flags=row.flags;item.anti_flags=row.anti;
|
||||
for(unsigned n=0;n<3;++n)item.alSockets[n]=row.sockets[n];
|
||||
for(unsigned n=0;n<7;++n){item.aAttr[n].bType=row.types[n];item.aAttr[n].sValue=row.values[n];}
|
||||
static_assert(sizeof(item.extra)==69,"complete presentation metadata");std::memcpy(&item.extra,row.extra,69);
|
||||
}
|
||||
for(const auto& slot:f.quickslots) {
|
||||
if(slot.type==SLOT_TYPE_INVENTORY) {
|
||||
bool valid=slot.cell<c_ItemSlot_Count;
|
||||
#ifdef ENABLE_NEW_EQUIPMENT_SYSTEM
|
||||
valid=valid||(slot.cell>=c_Belt_Inventory_Slot_Start&&slot.cell<c_Belt_Inventory_Slot_End);
|
||||
#endif
|
||||
if(!valid)return false;
|
||||
if(slot.cell<PortCubeView::Slots&&!staged[slot.cell].vnum)return false;
|
||||
} else if(slot.type==SLOT_TYPE_SKILL&&slot.cell>=SKILL_MAX_NUM)return false;
|
||||
}
|
||||
for(unsigned cell=0;cell<staged.size();++cell)m_playerStatus.aItem[cell]=staged[cell];
|
||||
for(unsigned n=0;n<PortCubeView::Quickslots;++n){m_playerStatus.aQuickSlot[n].Type=f.quickslots[n].type;m_playerStatus.aQuickSlot[n].Position=f.quickslots[n].cell;}
|
||||
SetGold64(int64_t(f.gold));m_portCubeViewEpoch=f.epoch;m_portCubeViewBytes=std::move(canonical);return true;
|
||||
}
|
||||
@@ -181,7 +181,7 @@ PyObject * safeboxGetItemNewName(PyObject * poSelf, PyObject * poArgs)
|
||||
if (!CPythonSafeBox::Instance().GetItemDataPtr(ipos, &pInstance))
|
||||
return Py_BuildValue("s", "");
|
||||
|
||||
return Py_BuildValue("s", pInstance->extra.name);
|
||||
return Py_BuildValue("s#", pInstance->extra.name,int(strnlen(pInstance->extra.name,24))); // PORT: raw metadata need not be NUL-terminated.
|
||||
}
|
||||
|
||||
PyObject * safeboxGetItemCount(PyObject * poSelf, PyObject * poArgs)
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
#pragma once
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// PORT: GC93 bounded LE presentation only. Never a craft request or thaw ACK.
|
||||
namespace PortCubeView {
|
||||
constexpr unsigned Slots=225,Quickslots=36,Maximum=32768;
|
||||
constexpr int64_t GoldLimit=2000000000000000LL;
|
||||
struct Quickslot {uint8_t type=0;uint16_t cell=0;};
|
||||
inline bool operator==(const Quickslot& a,const Quickslot& b){return a.type==b.type&&a.cell==b.cell;}
|
||||
struct Item {
|
||||
uint16_t cell=0,count=0;uint32_t id=0,vnum=0,flags=0,anti=0;
|
||||
int32_t sockets[3]={};uint8_t types[7]={};int16_t values[7]={};uint8_t extra[69]={};
|
||||
};
|
||||
struct Frame {uint64_t epoch=0,gold=0;std::vector<Item> items;std::array<Quickslot,Quickslots> quickslots={};};
|
||||
inline bool Valid(const Frame& f) {
|
||||
if(!f.epoch||f.gold>uint64_t(GoldLimit)||f.items.size()>Slots)return false;
|
||||
int last=-1;std::set<uint32_t> ids;
|
||||
for(const auto& i:f.items)if(i.cell>=Slots||int(i.cell)<=last||!i.id||!i.vnum||!i.count||i.count>2000||!ids.insert(i.id).second)return false;else last=i.cell;
|
||||
for(const auto& q:f.quickslots)if(q.type>3||(!q.type&&q.cell))return false;
|
||||
return true;
|
||||
}
|
||||
struct Writer {std::string bytes;void n(uint64_t v,unsigned width){for(unsigned j=0;j<width;++j)bytes+=char(v>>(8*j));}};
|
||||
struct Reader {const std::string& bytes;size_t at=0;bool ok=true;uint64_t n(unsigned width){if(at+width>bytes.size()){ok=false;return 0;}uint64_t v=0;for(unsigned j=0;j<width;++j)v|=uint64_t(uint8_t(bytes[at++]))<<(8*j);return v;}};
|
||||
inline std::string Encode(const Frame& f) {
|
||||
if(!Valid(f))return {};Writer w;w.n(11,1);w.bytes+="CCP1";w.n(f.epoch,8);w.n(f.gold,8);w.n(f.items.size(),2);w.n(Quickslots,1);
|
||||
for(const auto& q:f.quickslots){w.n(q.type,1);w.n(q.cell,2);}
|
||||
for(const auto& i:f.items) {
|
||||
w.n(i.cell,2);w.n(i.count,2);w.n(i.id,4);w.n(i.vnum,4);w.n(i.flags,4);w.n(i.anti,4);
|
||||
for(auto v:i.sockets)w.n(uint32_t(v),4);
|
||||
for(unsigned j=0;j<7;++j){w.n(i.types[j],1);w.n(uint16_t(i.values[j]),2);}
|
||||
w.bytes.append(reinterpret_cast<const char*>(i.extra),69);
|
||||
}
|
||||
return w.bytes.size()+5<=Maximum?w.bytes:std::string{};
|
||||
}
|
||||
inline bool Decode(const std::string& bytes,Frame& out) {
|
||||
out={};if(bytes.size()<132||bytes.size()+5>Maximum||uint8_t(bytes[0])!=11||bytes.substr(1,4)!="CCP1")return false;
|
||||
Reader r{bytes};r.at=5;Frame f;f.epoch=r.n(8);f.gold=r.n(8);const auto count=r.n(2);
|
||||
if(count>Slots||r.n(1)!=Quickslots||bytes.size()!=132+122*count)return false;
|
||||
for(auto& q:f.quickslots){q.type=uint8_t(r.n(1));q.cell=uint16_t(r.n(2));}
|
||||
for(unsigned j=0;j<count;++j) {
|
||||
Item i;i.cell=uint16_t(r.n(2));i.count=uint16_t(r.n(2));i.id=uint32_t(r.n(4));i.vnum=uint32_t(r.n(4));i.flags=uint32_t(r.n(4));i.anti=uint32_t(r.n(4));
|
||||
for(auto& v:i.sockets){uint32_t bits=uint32_t(r.n(4));std::memcpy(&v,&bits,4);}
|
||||
for(unsigned k=0;k<7;++k){i.types[k]=uint8_t(r.n(1));uint16_t bits=uint16_t(r.n(2));std::memcpy(&i.values[k],&bits,2);}
|
||||
for(auto& v:i.extra)v=uint8_t(r.n(1));f.items.push_back(i);
|
||||
}
|
||||
if(!r.ok||r.at!=bytes.size()||!Valid(f)||Encode(f)!=bytes)return false;out=std::move(f);return true;
|
||||
}
|
||||
// Snapshot old bindings ONCE before installing any new items. Never bind a
|
||||
// consumed item's shortcut to a new reward merely reusing the same cell.
|
||||
inline bool Rebind(const std::vector<Item>& before,const Frame& after,const std::array<Quickslot,Quickslots>& original,std::array<Quickslot,Quickslots>& result) {
|
||||
if(!Valid(after))return false;std::set<uint16_t> cells;std::set<uint32_t> ids;
|
||||
for(const auto& i:before)if(i.cell>=Slots||!i.id||!cells.insert(i.cell).second||!ids.insert(i.id).second)return false;
|
||||
auto plan=original;
|
||||
for(auto& q:plan) {
|
||||
if(q.type>3||(!q.type&&q.cell))return false;if(q.type!=1||q.cell>=Slots)continue;
|
||||
const auto old=std::find_if(before.begin(),before.end(),[&](const Item& i){return i.cell==q.cell;});
|
||||
const auto next=old==before.end()?after.items.end():std::find_if(after.items.begin(),after.items.end(),[&](const Item& i){return i.id==old->id;});
|
||||
if(next==after.items.end())q={};else q.cell=next->cell;
|
||||
}
|
||||
result=plan;return true;
|
||||
}
|
||||
inline std::string Packet(const Frame& f){const auto body=Encode(f);if(body.empty())return {};Writer w;w.n(93,1);w.n(body.size()+5,4);return w.bytes+body;}
|
||||
}
|
||||
Reference in New Issue
Block a user