- gr2: BitKnit2 decompression, 64-bit LE files, compressed curves - net: remaining GamePhase handlers, generated GC packet table - python: event/chat/chr/minimap/guild/quest/messenger/shop-search and other native modules ported against the AVA2 Windows client - render: D3D8 fixed-function lighting in Gr2ModelRenderer, terrain without baked shade; cape/NPC equipment attachment - tests + audits updated; docs/PORT-PLAN.md and WINDOWS-PARITY.md Batch 4 (render pipeline: background.*, app.RenderGame/UpdateGame, camera bindings, main.cpp fake-content removal) is still in progress. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
134 lines
8.4 KiB
C++
134 lines
8.4 KiB
C++
// CPythonEventManager / script::Group and the pass-23 lookups (item.GetApplyPoint,
|
|
// player.SlotTypeToInvenType, app.GetRandom, nonplayer.GetResist, player getters) against the
|
|
// original AVA2 behaviour.
|
|
#include "windows_item_oracle.h"
|
|
#include "nonplayer_data.h"
|
|
#include "python_event_manager.h"
|
|
#include "python_runtime.h"
|
|
#include "eter_lib/parser.h"
|
|
#include "eter_net/PythonNetworkStream.h"
|
|
#include <cstring>
|
|
#include <iostream>
|
|
#include <stdexcept>
|
|
using namespace ava2;
|
|
void require(bool ok,const char* why) { if(!ok)throw std::runtime_error(why); }
|
|
std::vector<uint8_t> literalLzo(const uint8_t* bytes,size_t size) {
|
|
std::vector<uint8_t> out{uint8_t(17+size)};
|
|
out.insert(out.end(),bytes,bytes+size);out.insert(out.end(),{17,0,0});return out;
|
|
}
|
|
void put32(std::vector<uint8_t>& p,uint32_t n) { for(unsigned i=0;i<4;++i)p.push_back(uint8_t(n>>(i*8))); }
|
|
void loadMob(uint32_t vnum) {
|
|
ava2_windows_mob::TMobTable_r235 row{};row.dwVnum=vnum;
|
|
for(size_t i=0;i<sizeof(row.cResists);++i) row.cResists[i]=static_cast<char>(int(i)-5);
|
|
auto packed=literalLzo(reinterpret_cast<const uint8_t*>(&row),sizeof(row));
|
|
std::vector<uint8_t> p{'M','M','P','T'};put32(p,1);put32(p,uint32_t(20+packed.size()));
|
|
p.insert(p.end(),{'M','C','O','Z'});put32(p,0);put32(p,uint32_t(packed.size()));put32(p,sizeof(row));put32(p,0);
|
|
p.insert(p.end(),packed.begin(),packed.end());
|
|
NonPlayerData::Instance().clear();
|
|
require(NonPlayerData::Instance().load(std::string(p.begin(),p.end())),"mob fixture failed to load");
|
|
}
|
|
int main(int argc,char** argv) {
|
|
if(argc!=3)return 2;
|
|
try {
|
|
// Parser: one LETTER per character, [CMD a;1|b;2] arguments, '\n' outside commands counted.
|
|
script::Group group;
|
|
require(group.Create("ab\n[QUESTION a;Yes|b;No]\n[DELAY value;0]")==2,"line count");
|
|
script::TCmd cmd;
|
|
require(group.GetCmd(cmd) && cmd.name=="LETTER" && cmd.argList.front().strValue=="a","letter");
|
|
require(group.GetCmd(cmd) && group.GetCmd(cmd) && cmd.name=="QUESTION" && cmd.argList.size()==2,"question");
|
|
require(cmd.argList.front().strName=="a" && cmd.argList.back().strValue=="No","question args");
|
|
require(group.ReadCmd(cmd) && cmd.name=="DELAY" && group.GetCmd(cmd) && !group.GetCmd(cmd),"peek/pop");
|
|
require(group.Create("[UNCLOSED")==-1,"syntax error accepted");
|
|
|
|
PythonRuntime python(argv[1],argv[2]);
|
|
auto& stream=PythonNetworkStream::Instance();stream.ResetConnection();stream.SetPhase(PHASE_GAME);
|
|
auto& events=CPythonEventManager::Instance();
|
|
python.execute(
|
|
"import event, net\n"
|
|
"assert (event.BUTTON_TYPE_NEXT,event.BUTTON_TYPE_DONE,event.BUTTON_TYPE_CANCEL)==(0,1,2)\n"
|
|
"assert event.BOX_VISIBLE_LINE_COUNT==14\n"
|
|
"assert not hasattr(event,'GetTotalLineCount')\n"
|
|
"class Handler:\n"
|
|
" def __init__(self):\n self.calls=[]\n"
|
|
" def MakeNextButton(self,t):\n self.calls.append(('next',t))\n"
|
|
" def DoneEvent(self):\n self.calls.append(('done',))\n"
|
|
" def MakeQuestion(self,n):\n self.calls.append(('question',n))\n"
|
|
" def AppendQuestion(self,s,i):\n self.calls.append(('answer',s,i))\n"
|
|
" def OnTitleImage(self,s):\n self.calls.append(('title',s))\n"
|
|
"h=Handler()\n"
|
|
"idx=event.RegisterEventSetFromString('Hi[ENTER]ab[NEXT][QUESTION a;Yes|b;No][TITLE_IMAGE src;t.tga][DONE][WAIT]x\\n')\n"
|
|
"assert idx==0\n"
|
|
"event.SetEventHandler(idx,h)\n"
|
|
"assert event.GetLineCount(idx)==0\n"
|
|
"event.AllProcessEventSet(idx)\n"
|
|
"assert h.calls==[('next',0),('question',2),('answer','Yes',0),('answer','No',1),('title','t.tga'),('next',1),('done',)],h.calls\n"
|
|
"assert event.IsWait(idx)\n"
|
|
"assert event.GetProcessedLineCount(idx)==1\n"
|
|
"assert event.GetLineCount(idx)==5\n"
|
|
"event.Skip(idx)\n"
|
|
"assert not event.IsWait(idx)\n"
|
|
"event.AllProcessEventSet(idx)\n"
|
|
"assert event.IsWait(idx)\n"
|
|
"event.SetVisibleStartLine(idx,2)\n"
|
|
"assert event.GetVisibleStartLine(idx)==0\n"
|
|
"event.SetVisibleStartLine(idx,1)\n"
|
|
"assert event.GetVisibleStartLine(idx)==1\n"
|
|
"assert event.RegisterEventSetFromString('[UNCLOSED')==-1\n"
|
|
"assert event.RegisterEventSetFromString('[RUN_CINEMA value;missing_cinema.txt]')==-1\n");
|
|
const auto* set=events.GetEventSet(0);
|
|
require(set && set->strCurrentLine=="abx" && set->iTotalLineCount==1,"current line / total line count");
|
|
// UpdateEventSet: the frame's elapsed time is taken off the delay twice (Windows quirk), then
|
|
// spent command by command at the [DELAY] pace.
|
|
python.execute("j=event.RegisterEventSetFromString('[DELAY value;100]abc')\nassert j==1\n");
|
|
events.SetElapsedMillisecond(0);
|
|
python.execute("event.UpdateEventSet(j,0,0)\n");
|
|
require(events.GetEventSet(1)->strCurrentLine.empty() && events.GetEventSet(1)->lLastDelayTime==0,"zero elapsed processed a command");
|
|
events.SetElapsedMillisecond(15);
|
|
python.execute("event.UpdateEventSet(j,0,0)\n");
|
|
require(events.GetEventSet(1)->lWaitingTime==100 && events.GetEventSet(1)->strCurrentLine.empty(),"DELAY command");
|
|
python.execute("event.UpdateEventSet(j,0,0)\n");
|
|
require(events.GetEventSet(1)->strCurrentLine=="a" && events.GetEventSet(1)->lLastDelayTime==85,"first letter");
|
|
python.execute("event.UpdateEventSet(j,0,0)\n");
|
|
require(events.GetEventSet(1)->strCurrentLine=="a" && events.GetEventSet(1)->lLastDelayTime==55,"double elapsed subtraction");
|
|
events.SetElapsedMillisecond(1000);
|
|
python.execute("event.UpdateEventSet(j,0,0)\nevent.ClearEventSet(j)\n");
|
|
require(!events.GetEventSet(1),"cleared slot");
|
|
|
|
// Answers and quest buttons reach the wire: CG_SCRIPT_ANSWER (29) / CG_SCRIPT_BUTTON (66).
|
|
stream.PopSendBytes();
|
|
python.execute("event.SelectAnswer(idx,3)\nevent.SelectAnswer(99,4)\nevent.QuestButtonClick(0x01020304)\n");
|
|
require(stream.PopSendBytes()==std::vector<uint8_t>{29,3,66,4,3,2,1},"answer/button packets");
|
|
|
|
// AddEvent registers, sizes to 30 visible lines and opens the game phase quest window.
|
|
python.execute(
|
|
"class Game:\n def __init__(self):\n self.opened=[]\n def OpenQuestWindow(self,skin,index):\n self.opened.append((skin,index))\n"
|
|
"g=Game()\nnet.SetPhaseWindow(net.PHASE_WINDOW_GAME,g)\n"
|
|
"event.AddEvent('[ENTER]',7)\n"
|
|
"assert g.opened==[(7,1)],g.opened\n");
|
|
require(events.GetEventSet(1)->iVisibleLineCount==30,"AddEvent visible line count");
|
|
python.execute("event.Destroy()\nassert event.GetLineCount(idx)==0\n");
|
|
|
|
// initNonPlayer clears the table, so the fixture goes in after the first import.
|
|
python.execute("import item, player, app, nonplayer\n");
|
|
loadMob(2001);
|
|
python.execute(
|
|
"assert item.GetApplyPoint(0)==0 and item.GetApplyPoint(1)==6\n"
|
|
"assert item.GetApplyPoint(177)==0\n"
|
|
"try:\n item.GetApplyPoint('x')\n raise AssertionError('bad apply type accepted')\nexcept TypeError:\n pass\n"
|
|
"assert player.SlotTypeToInvenType(1)==1 and player.SlotTypeToInvenType(11)==5\n"
|
|
"assert player.SlotTypeToInvenType(18)==12 and player.SlotTypeToInvenType(99)==0\n"
|
|
"for n in range(200):\n r=app.GetRandom(5,1)\n assert 1<=r<=5\n"
|
|
"assert app.GetRandom(3,3)==3\n"
|
|
"assert nonplayer.GetResist(2001,0)==-5 and nonplayer.GetResist(2001,10)==5\n"
|
|
"assert nonplayer.GetResist(2001,11)==0 and nonplayer.GetResist(2001,256)==-5\n"
|
|
"assert nonplayer.GetResist(9999,0)==0\n"
|
|
"assert player.GetGuildID()==0 and player.GetGuildName()=='' and player.GetPKMode()==0\n"
|
|
"assert player.IsGameMaster()==0 and player.GetEXP()==0 and player.GetConquerorEXP()==0\n"
|
|
"player.SetPlayTime(77)\nassert player.GetPlayTime()==77\n"
|
|
"assert player.SetPlayTime('x') is None and player.GetPlayTime()==77\n"
|
|
"assert player.GetJob()==player.GetRace()%4\n");
|
|
NonPlayerData::Instance().clear();stream.ResetConnection();
|
|
std::cout<<"AVA2 event manager and simple lookups parity passed\n";
|
|
} catch(const std::exception& e) { std::cerr<<e.what()<<'\n';return 1; }
|
|
}
|