77 lines
4.9 KiB
C++
77 lines
4.9 KiB
C++
// FreeBSD-only offline link probe. Links the real game objects, replacing only
|
|
// the executable main symbol. Synthetic in-memory proto, no sockets or DB.
|
|
#include "stdafx.h"
|
|
#include "char.h"
|
|
#include "item.h"
|
|
#include "item_manager.h"
|
|
#include "item_addon.h"
|
|
#include "skill.h"
|
|
#include "unique_item.h"
|
|
#include "desc_client.h"
|
|
#include "port_cube_factory.h"
|
|
#include "port_cube_ids.h"
|
|
#include "event.h"
|
|
#include "utils.h"
|
|
#include <algorithm>
|
|
#include <cassert>
|
|
#include <cstdio>
|
|
#include <ctime>
|
|
|
|
struct NativeItemManager:ITEM_MANAGER {
|
|
size_t Delayed()const{return m_set_pkItemForDelayedSave.size();}
|
|
void DropTemplate(LPITEM item){assert(item->PortCubeIsTemplate()&&!item->GetOwner());assert(Find(item->GetID())==item);m_map_pkItemByID.erase(item->GetID());m_VIDMap.erase(item->GetVID());M2_DESTROY_ITEM(item);}
|
|
};
|
|
int main()
|
|
{
|
|
assert(!db_clientdesc&&!event_count());
|
|
NativeItemManager manager;CItemAddonManager addons;CSkillManager skills;
|
|
std::vector<TItemTable> tables(10);
|
|
for(unsigned i=0;i<6;++i){tables[i].dwVnum=10000+i;tables[i].bSize=1;tables[i].bType=ITEM_USE;}
|
|
tables[0].bType=ITEM_WEAPON;tables[0].bSubType=WEAPON_SWORD;
|
|
tables[0].sAddonType=-1;tables[0].bGainSocketPct=2;
|
|
tables[1].bType=ITEM_UNIQUE;tables[1].alValues[0]=600;
|
|
tables[2].bType=ITEM_UNIQUE;tables[2].alValues[0]=600;tables[2].alValues[2]=1;
|
|
tables[3].aLimits[0].bType=LIMIT_REAL_TIME;tables[3].aLimits[0].lValue=60;
|
|
tables[4].aLimits[0].bType=LIMIT_TIMER_BASED_ON_WEAR;tables[4].aLimits[0].lValue=60;
|
|
tables[5].bType=ITEM_ELK;
|
|
tables[6].dwVnum=ITEM_AUTO_HP_RECOVERY_S;tables[6].bType=ITEM_USE;tables[6].bSize=1;tables[6].alValues[0]=7;
|
|
tables[7].dwVnum=50300;tables[7].bType=ITEM_USE;tables[7].bSize=1;
|
|
tables[8].dwVnum=10006;tables[8].bType=ITEM_USE;tables[8].bSize=1;tables[8].dwFlags=ITEM_FLAG_STACKABLE;
|
|
tables[9].dwVnum=10007;tables[9].bType=ITEM_COSTUME;tables[9].bSubType=COSTUME_SASH;tables[9].bSize=1;tables[9].alValues[0]=4;
|
|
std::sort(tables.begin(),tables.end(),[](const auto& a,const auto& b){return a.dwVnum<b.dwVnum;});
|
|
assert(manager.Initialize(tables.data(),tables.size()));
|
|
TItemIDRangeTable range{};range.dwMin=1000;range.dwMax=2000;range.dwUsableItemIDMin=1000;
|
|
assert(manager.SetMaxItemID(range));
|
|
uint32_t next=1000;
|
|
for(uint32_t vnum:{10000u,10001u,10002u,10003u,10004u,10007u,uint32_t(ITEM_AUTO_HP_RECOVERY_S)}) {
|
|
std::vector<PortEconomy::Reward> images;
|
|
assert(PortCubeBuildRewardTemplates(vnum,2,images)&&images.size()==2);
|
|
assert(!event_count()&&!PortCubeCurrentFactorySlot()&&!db_clientdesc);
|
|
for(const auto& image:images) {
|
|
assert(image.id==next++&&image.vnum==vnum&&image.count==1&&!manager.Find(image.id));
|
|
if(vnum==10000){assert(image.sockets[0]==1&&image.sockets[1]==1);bool addon=false;for(auto type:image.types)if(type==APPLY_NORMAL_HIT_DAMAGE_BONUS)addon=true;assert(addon);}
|
|
if(vnum==10001)assert(image.sockets[2]==600);
|
|
if(vnum==10002)assert(image.sockets[2]>600);
|
|
if(vnum==10003)assert(image.sockets[0]>60);
|
|
if(vnum==10004)assert(image.sockets[0]==60);
|
|
if(vnum==10007)assert(image.sockets[0]>=11&&image.sockets[0]<=19);
|
|
if(vnum==ITEM_AUTO_HP_RECOVERY_S)assert(image.sockets[2]==7);
|
|
}
|
|
}
|
|
std::vector<PortEconomy::Reward> untouched(1);untouched[0].id=77;
|
|
assert(!PortCubeBuildRewardTemplates(10005,1,untouched)&&untouched[0].id==77);
|
|
assert(!PortCubeBuildRewardTemplates(50300,1,untouched)&&untouched[0].id==77);
|
|
assert(!manager.FindByVID(0)&&!manager.FindByVID(1));
|
|
std::vector<uint32_t> after;assert(PortCubeReserveItemIDs(1,after)&&after[0]==next);
|
|
auto* old=manager.CreateItem(10006,10);assert(old&&manager.Delayed()==1);const auto oldID=old->GetID();
|
|
PortEconomy::Reward persisted;persisted.id=oldID;persisted.vnum=10006;persisted.count=4;persisted.sockets[0]=-123;persisted.extra[68]=255;
|
|
auto* restored=PortCubeRestoreItem(persisted,old);assert(restored&&restored->GetCount()==4&&restored->GetSocket(0)==-123&&restored->GetPortExtra().name[24]==char(255)&&manager.Find(oldID)==old);
|
|
manager.SaveSingleItem(restored);assert(!db_clientdesc); // template must never emit a DB delete/save
|
|
assert(manager.PortCubeSwapRegistry({old},{restored})&&manager.Find(oldID)==restored&&manager.FindByVID(restored->GetVID())==restored&&!manager.Delayed());
|
|
old->PortCubeMarkTemplate();M2_DESTROY_ITEM(old);assert(manager.Find(oldID)==restored);
|
|
manager.DropTemplate(restored);std::vector<uint32_t> nextID;assert(PortCubeReserveItemIDs(1,nextID)&&nextID[0]==oldID+1);
|
|
manager.Update();manager.GracefulShutdown();
|
|
assert(!db_clientdesc&&!event_count());
|
|
puts("PASS real FreeBSD game objects: actual addon/socket/clock/sash initialization, exact persisted same-ID restore, atomic registry replacement and old-object cleanup, no template SaveSingleItem/DB write/events or restore ID consumption; synthetic proto, no actor freeze/live acceptance");
|
|
}
|